Nagios Multiple servers config files

I'm already configuring a Nagios setup to monitor about 30 Windows servers. Now i am adding every servers definition to the Windows.cfg file but i think would be easyly configurable to have one .cfg file per server (Server1.cfg, Server2.cfg, Server3.cfg, etc) and link this files from Windows.cfg.

Anyone knows the better way to do this?

Thanks.


If your systems are reletively similiar, you should try and use object inheritance to limit the amount of code you have to modify in the future.

In addition to that, you can use the cfg_dir directive in your top-level config (nagios.cfg) to specify an entire directory of configuration files. Any file ending in .cfg will be included, which allows for configuration to be toggled simply be renaming files.

For example:

cfg_dir=/usr/local/nagios/etc/objects

What you're describing would work. I usually do something like this. Make config dirs for hosts and hostgroups

mkdir nagios/{hosts.d,hostgroups.d}

Create a file per server

cat nagios/hosts.d/db01.cfg
define host {
  host_name     db01.mydomain.com
  alias         db01
  use           generic-host

Then regex match in the hostgroup

cat nagios/hostgroups.d/db.cfg
define hostgroup {
  hostgroup_name  db
  alias           DB Servers
  members         db([0-9]+).mydomain.com
}

You'll need to turn on regex in your nagios.cfg and point to the config dirs

cfg_dir=/etc/nagios/hosts.d
cfg_dir=/etc/nagios/hostgroups.d
use_regexp_matching=1

Well, you can just split up the directives into different files with the cfg extension. Nagios will automatically find them if the are in the config folder. You don't need to put everything in one cfg. You don't even need to link them explicitly.


In addition to using the Nagios object inheritance as mentioned you should write a script that automatically adds/deletes the host definitions from data extracted from your configuration management system (AD in Windows-land?). That way Nagios won't get out of date and you don't have to do busy work.