Ask Your Question

Remove old Nagios services / hosts

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

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 -0600

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 -0600 )edit

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

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 link more


Also using Nagios resources + purge, also not working. For now I wrap it with a script that runs 'rm -f /etc/nagios/nagios_*.cfg' on my Nagios server.

astrostl gravatar imageastrostl ( 2013-03-11 21:02:35 -0600 )edit

resources + purge also failing to purge anything. rm-ing and rebuilding hundreds of service.cfg's is very far from ideal

TimCherry gravatar imageTimCherry ( 2013-09-12 18:58:00 -0600 )edit

answered 2013-03-07 05:15:57 -0600

mattjb gravatar image

Hi Stoie,

Check out this exported expiration sample from Jordan Sissel @ Dreamhost.

I built something similar in my own environment based on his idea for a lot of our exported resources and it makes life a lot easier. I hope this gives you some ideas.


edit flag offensive delete link more


G'day Matt, thanks for the info, I will check it out now!

STOIE gravatar imageSTOIE ( 2013-03-07 15:11:24 -0600 )edit

answered 2013-03-06 15:40:12 -0600

STOIE gravatar image

updated 2013-03-07 15:39:08 -0600

Damn, that's not exactly the answer I was hoping to hear. Does anyone know where I can see a status of these updates?


Okay so I have a fix - more just a dirty dirty hack... but, for now it's doing what I need it to, which is deleting all the host / service config and rebuilding it each time puppet is run on the nagios host.

exec { "rm-nag-conf-hosts":
   command => '/bin/rm -f /data00/sw/nagios/admin/hosts/*',
   require => File["/data00/sw/nagios/admin/hosts/"],

Nagios_host <<||>> {
   require => [ File["/data00/sw/nagios/admin/hosts/"], Exec[ 'rm-nag-conf-hosts' ] ],
   notify => Exec["fix_nag_cfg_pems"],
edit flag offensive delete link more


There may be some tickets in redmine - I'm not positive. I'll update my answer if I can find them.

llowder gravatar imagellowder ( 2013-03-06 16:45:22 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2013-03-05 20:46:04 -0600

Seen: 10,449 times

Last updated: Mar 08 '13