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?


5 Answers 5


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:

  • 1
    +1 for cfg_dir. A huge win for organization and flexibility. See my answer about hostgroups for another key win.
    – dmourati
    Apr 4, 2012 at 21:48

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


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.

  • +1 on generating host definitions from the configuration management. That's what we're doing using Chef, but that's probably less applicable on the Windows side of the world.
    – cjc
    Apr 4, 2012 at 22:19

I use hostgroups religiously. By adding machines to a hostgroup and monitoring that serivce on a per-hostgroup basis, adds, moves, and changes are straightforward. I wouldn't dream of running Nagios any other way.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .