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!