Sysadmin's Shouts!

a blog for sysadmin's rants and raves…

HowTo: Find out Nagios Configuration Files

Leave a comment

It looks simple, and it should be, but as it goes, I have seen installations with different nagios versions & configurations.

In one particularly hairy case, the administrators had been migrating from one version to other, and to be on the safe side, they just installed the new nagios version in a different folder, say nagios3, but because some of the checks migrated to the new version where broken, somebody fixed them by pointing to the scripts and config files from the previous version, instead of fixing or replacing the ones in the new nagios3 folder. (Nice!)

So they ended up with a nagios folder, and nagios3 folder…

The thing is: Nagios works. And by following the rule: “If it ain’t broke, don’t fix it”, nobody has done anything with the nagios install.

What happens when you want to upgrade to a newer nagios version like nagios 4? -well, you will probably have lots of fun…


So I will just describe in some easy steps how to find out the correct config files that the “good nagios set” is using, and what is not being used & it has just been left there from previous installs or configurations.

1.- Locate the nagios binary and it’s good config file.

[root@nagserv ~]# ps -ef | grep nagios

nagios 2026 1 0 18:15 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

2.- Navigate to the path where that config file resides.
cd /usr/local/nagios/bin

3.- Execute a Nagios validation, this step must be done every time that we modify/add something in nagios, as it checks the configuration files integrity.

Note: if we don’t want to validate the integrity, just remember that nagios won’t start if it has errors, and next time the nagios service gets restarted or a new one spawn off, it will just throw back errors, until these get fixed.

./nagios -v /usr/local/nagios/etc/nagios.cfg

Once nagios does the config validation, it will report in all config files used in the actual nagios running state.

Nagios Core 3.3.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 07-25-2011
License: GPL

Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/localhost.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/contactgroups.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/hosts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/dependencies.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/www_xxx.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvaaa.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvbbb.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/servnew.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvdb.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvmsg.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvapp.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvtsm.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvsap1.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvapp2.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/nagservios.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvdb2.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvtraps.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvunk.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/OLD'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvccc.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/servddd.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvpre.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/NETWORK'... <-- Empty directory (for nagios)
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/Switch_03.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/Switch_04.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/SAN01.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/SAN02.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/Switch_02.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/Switch_01.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/OLD'... <-- Empty directory (for nagios)
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-1.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-2.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/cmm-1.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-8.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/cmm-2.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-9.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-10.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/OLD'... <-- Empty directory (for nagios)
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-xxx.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/hostgroups.cfg'...
Read object config files okay...
---cut---
4.- From the validation, we can see that most nagios objects are stored in the path /usr/local/nagios/etc/objects
so, we have a look there:
cd /usr/local/nagios/etc/objects
ls -l
total 96

-rw-r--r-- 1 nagios nagios 8362 Oct 1 2013 commands.cfg
-rw-r--r-- 1 nagios nagios 8362 Oct 1 2013 commands.cfg.bak
-rw-rw-r-- 1 nagios nagios 2167 Oct 11 2013 contacts.cfg
-rw-rw-r-- 1 nagios nagios 5441 Aug 6 2013 localhost.cfg
drwxrwxr-x 2 nagios nagios 4096 Nov 12 2013 nagios3
-rw-rw-r--. 1 nagios nagios 3124 Apr 4 2012 printer.cfg

drwxrwxr-x 3 nagios nagios 4096 Sep 9 17:45 nagserv
-rw-rw-r--. 1 nagios nagios 3293 Apr 4 2012 switch.cfg
-rw-rw-r-- 1 nagios nagios 11225 Apr 4 2012 templates.cfg
-rw-rw-r--. 1 nagios nagios 10812 Apr 4 2012 templates.cfg.original
-rw-rw-r-- 1 nagios nagios 4428 Sep 9 18:38 timeperiods.cfg
-rw-rw-r-- 1 nagios nagios 1221 Nov 26 2013 timeperiods.cfg.old.bz2
-rw-rw-r-- 1 nagios nagios 4037 Aug 13 2013 timeperiods.cfg.wip

-rw-rw-r--. 1 nagios nagios 4019 Apr 4 2012 windows.cfg

5.- The files in red are not being used by nagios (specially important is nagios3 directory, which in this case contains lots of config files for alarms, hosts, etc, and it’s not being used anymore).

The directory nagserv, is where all the good config files are stored.

So, if we wanted to do a bit of cleanup, we could safely delete the following folders:

/usr/local/nagios/etc/objects/nagserv/HOSTS/NETWORK
/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/OLD
/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/OLD
/usr/local/nagios/etc/objects/nagios3

Before that tho, might as well double check that they don’t contain any files, or backup the folders with TSM or whatever backup product you use, and then delete them.
Having folders lying around without a good use, it’s bound to be counterproductive soon or later.

So there you go, we’ve identified the good folders and .cfg files used by nagios; any other file that does not use a .cfg extension, won’t be picked up by nagios (all the files listed here with extensions like: cfg.bak, cfg.original, cfg.old.bz2, cfg.wip, etc, are just backups of the real config files).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s