mobile logo

Automatically purge old configuration from Nagios deployed by Puppet

posted on February 16, 2011 / IN Linux / puppet / Quick Tip / 4 Comments

A problem that Puppet administrators have likely noticed when deploying its built-in Nagios functionality (called Naginator) is that creating configuration is very easy but ‘cleaning’ old configuration isn’t as straight-forward. If you are like me, you’d delete the affected file(s) that had cruft and let Puppet re-build the service configuration without the old services or hosts.

This is both a tedious and terrible practice but out of the box it seems like “the way to do it”. Having tired of the problem I was able to find out a proper way to handle the situation. If you add the following block to your Nagios server’s manifest it will automatically purge out configuration that is no longer relevant to the stored configuration. To clarify, your stored configuration has to be first up-to-date and then you should have Puppet run on the Nagios server to clean out cruft.

[code]
resources { [ "nagios_service", "nagios_servicegroup", "nagios_host" ]:
purge => true;
}
[/code]

This list can be shorter/longer depending which files you are generating with Puppet. Now after you delete that old host from Puppet stored configuration, Puppet will remove the affected configuration and prevent you from receiving alerts for a host that no longer exists without any manual labor or frustration on your part!

By admin

4 Comments

Please use the form to leave a comment

    • Dimitri
      Posted on May 16, 201111:37 am Reply

      Hi,

      I am having exactly the same problem as your article describes. I am trying to purge nagios resources. After I succesfully purge them from the storedconfig db they are not purged from the files, even if I add yhe above resources block.

      Do you have any ideas what I am missing? What version of puppet are you using?

      Regards,

      Dimitri

      • nwilkens
        Posted on May 16, 201111:48 am Reply

        Hi Dimitri,

        Currently using 2.6.4 for this deployment. Should work prior to that at least in 2.6.x. There’s nothing in your Nagios manifest that would be re-adding these would there? If that’s not it, did you include the resource purging into the server’s manifest versus Nagios clients?

    • Martijn
      Posted on December 19, 201112:47 pm Reply

      For the archives: the puppet documentation includes a single line that says:

      You can purge Nagios resources using the resources type, but only in the default file locations. This is an architectural limitation.

      This is my problem. No idea how to fix it (except writing a cronjob to delete the nagios config every now and then).

    • Wouter Verhelst
      Posted on June 25, 20129:59 am Reply

      Alternatively, you can do an “ensure => absent” in a previous “@@nagios_service” block (or similar). That leaves old cruft in your .pp files, but it works.

Page 1 of 1

Leave a comment.