Ask Your Question

Remove old Nagios services / hosts

asked 2013-03-05 20:46:04 -0500

STOIE gravatar image

Hi there,

I have the following setup for my nagios monitoring in Puppet:

@@nagios_service { "check_ping_${hostname}":
   use                     => "all-hours-neverdown",
   host_name               => "${fqdn}",
   service_description     => "Ping",
   check_command           => "check_ping!50!1!100!5!5!10!4",
   target                  => "/data00/sw/nagios/admin/services/services_${fqdn}.cfg",
   register                => "1",

Now, how can I make the module rebuild all the config every time puppet is run on the Nagios server, so it will remove anything that is no longer included and only build what is...

For example, I have a loop in my Nagios module (for clients), where a puppet fact returns the disks on a host, then ... (more)

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2013-03-08 08:05:04 -0500

Daenney gravatar image

There's a cleaner way to do it than using an exec.

What I'd suggest:

  • Let Puppet manage and purge the direcotry where the host files are put;
  • Require that directory for every resource.


file { '/data00/sw/nagios/admin/hosts':
  ensure => directory,
  purge => true,
  force => true,


Nagios_host << || >> {
  require => File['/data00/sw/nagios/admin/hosts'],

It has one side-effect that I know of; because you're removing every file every time that file gets sent to the filebucket, therefor it might grow in size quickly.

edit flag offensive delete link more


You can disable backups of the files with "backup => false' in the file declaration, which will stop the filebucket growing at all for these auto-generated files.

David Gardner gravatar imageDavid Gardner ( 2014-08-14 04:06:03 -0500 )edit

answered 2013-03-06 12:16:19 -0500

llowder gravatar image

The "standard answer" would be set use resources{ 'nagios_service': purge => true }.

Unfortunately, in their present state, purge does not function well or at all, and I cannot think of a good, safe, reliable way to do this until those types are updated.

The good news, I think someone is actively working on getting that done.

If the database you are using to store the configs in has a timestamp on the entries, it might be possibly to periodically run a query to remove all the exported resources that are older than a certain time (ie, they haven't been updated ... (more)

edit flag offensive delete