Rethinking Nagios config layouts

I've been using Nagios 1.4 in Debian Etch for some time now. By default they set you up with a working layout like this:


The services.cfg file started out with a generic-service template where you set the standard options most generic-service services will be using, and then a list of services. A service definition must contain, among other things, the name of the host or host_group that the service runs on. So each time I setup a new host, I would enter it in the hosts.cfg, hostgroups.cfg, and add all of it's services in services.cfg. I was using hostgroup objects just for display and contact_groups and not taking advantage of them in service objects. Those two things combined made for a long services.cfg file. At least I was taking advantage of a couple of service object templates.

The nagios3 config layout shipped with Debian 5.0 (Lenny) opened my eyes to a new structure. It uses the cfg_dir directive to point to /etc/nagios3/conf.d and in there we have:


In the localhost_nagios2.cfg file they define a simple host that inherits from geric-host and a few extra services, rather than putting localhost entries into the services config file. Checking out services_nagios2.cfg I found a bunch of generic (eg check_http, check_ssh, check_ping) services using host_group names instead of hosts.

Wandering over to hostgroups_nagios2.cfg I found a bunch of very simple hostgroup object definitions. Some like http-servers listed localhost as one of their members. If we reverse that situaion though and drop the hostgroup.members declaration and instead set host.hostgroups to include http-servers, then if I need to make customizations to localhost or delete it alltogether, I do it all in/to localhost_nagios2.cfg. One file. I like this much better!

Nagios' object based configuration system is very flexible. I don't think any of this stuff is new to version 3. I've read the docs dozens of times but it took a fresh install with a new layout idea, some mistakes on my part and some help from Marc on nagios-users to get it sorted out in my head and on disk. Once I had that, the migration of other hosts to the nagios3 setup has been fast and minimal.