IT Blog

Linux puppet Quick Tip

Automatically purge old configuration from Nagios deployed by Puppet

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.
resources { [ "nagios_service", "nagios_servicegroup", "nagios_host" ]:
purge => true;
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!

4 thoughts on “Automatically purge old configuration from Nagios deployed by Puppet”

  1. 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?

    1. 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?

  2. 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).

  3. 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.

Comments are closed.