Nagios Configuration

Introduction

Nagios is an open source computer system and network monitoring software application. It can be used to monitor hosts and services, alerting users when things go wrong and again when they get better. Nagios is a widely used pular enterprise-class monitoring tool. It is stable, scalable, supported, and extensible. See http://en.wikipedia.org/wiki/Nagios for introductory information.

Nagios was originally designed to run under Linux, but also runs well on other Unix variants.

Nagios is free software licensed under the terms of the GNU General Public License version 2 (http://en.wikipedia.org/wiki/GNU_General_Public_License) as published by the Free Software Foundation (http://en.wikipedia.org/wiki/Free_Software_Foundation).

Example screenshots are available at http://www.nagios.org/about/screenshots.php.

The following guidance might be useful in helping to configure Nagios on a Linux server.


My Nagios Configuration

Essentially the standard installation procedure as described in the Nagios documentation/installation link below was followed.

The nagios.cfg configuration file (and the object configuration files is uses) do take some effort to get right in order to get a working configuration going.

The command line shown in the fragment of screen output below is useful in testing/debugging the nagios.cfg configuration file. Typical output from the command is also shown.

[peter@host ~]$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios 3.0.2
Copyright (c) 1999-2008 Ethan Galstad (http://www.nagios.org)
Last Modified: 05-19-2008
License: GPL

Reading configuration data...

Running pre-flight check on configuration data...

Checking services...
        Checked 37 services.
Checking hosts...
        Checked 10 hosts.
Checking host groups...
        Checked 5 host groups.
Checking service groups...
        Checked 0 service groups.
Checking contacts...
        Checked 1 contacts.
Checking contact groups...
        Checked 1 contact groups.
Checking service escalations...
        Checked 0 service escalations.
Checking service dependencies...
        Checked 0 service dependencies.
Checking host escalations...
        Checked 0 host escalations.
Checking host dependencies...
        Checked 0 host dependencies.
Checking commands...
        Checked 25 commands.
Checking time periods...
        Checked 6 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check
[peter@host ~]$

With suitable configuration of a number of object configuration files (as used by the nagios.cfg configuration file) a working configuration was achieved.

[peter@host ~]$ ll /usr/local/nagios/etc/objects/
total 84
-rw-rw-r--  1 nagios nagios  8444 Oct 26  2008 commands.cfg
-rw-rw-r--  1 nagios nagios  2175 Oct 16  2008 contacts.cfg
-rw-r--r--  1 nagios nagios  3708 Oct 27  2008 ip-devices.cfg
-rw-r--r--  1 nagios nagios 10463 Oct 27  2008 linux.cfg
-rw-rw-r--  1 nagios nagios  6289 Oct 27  2008 localhost.cfg
-rw-rw-r--  1 nagios nagios  3124 Oct 14  2008 printer.cfg
-rw-r--r--  1 nagios nagios  4013 Oct 27  2008 router.cfg
-rw-rw-r--  1 nagios nagios  3279 Oct 14  2008 switch.cfg
-rw-rw-r--  1 nagios nagios 10812 Oct 16  2008 templates.cfg
-rw-rw-r--  1 nagios nagios  4184 Oct 14  2008 timeperiods.cfg
-rw-rw-r--  1 nagios nagios  8617 Oct 27  2008 windows.cfg
[peter@host ~]$

The outputs from nagios are displayed in the web-browser (the default is to logon as user nagiosadmin). In addition to the on-screen display email notifications can be configured to be triggered by particular events (such as the loss or recovery of hosts or services in the defined configuration).


Troubleshooting

For example, use the "pre-flight checks" command as above.

Also to investigate individual commands that are failing there are other options. For example, if the MySQL check is failing, try:

[root@host]# export NAGIOS=/usr/local/nagios
[root@host]# $NAGIOS/libexec/check_mysql -s /var/lib/mysql/mysql.sock
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@host]#

and follow up. Could be permissions issues (no permission to access directory, etc, either due to simple file permissions, or if running with SELinux enabled then an issue there).

Integration with gnokii

Nagios can be integrated with an SMS application in order to send SMS notifications (in place or, or addition to, email notifications). One such SMS application is gnokii, is a suite of programs for communicating with mobile phones.

In order to send SMS notifications a mobile phone, or GSM modem, needs of course to be connected in some way to the Linux server. There are numerous alternative ways of achieving this (serial cable, USB cable, infrared or bluetooth connection, using a modem card, etc).

A couple of available mobile phones were commandered for testing:

Using the Nokia E65 initially connection via a USB cable (no suitable serial cable being available) into the Linux box was tried. This was successful. In addition investigations using bluetooth were also carried out. This too was successful. However this testing wsa just to prove a point; the intention was not to use this handset (it was unavailable for long-term dedication to the task).

The Siemens S55 is getting a bit long in the tooth, but none the-less-perfectly serviceable (and available!). Initially connection via a USB cable (no suitable serial cable being available) into the Linux box was tried. But this was unsuccessful - although the mobile was charging it was not possible to effect data transfer. Thereafter, in order to connect the mobile phone to the server, investigation involving using infrared and/or bluetooth were carried out. Details for each approach are described in:

Following successful connection of the mobile phone to the server using the Bluetooth connection, the gnokii application was configued as described in gnokii to make use of the bluetooth connectivity.

Once gnokii was configured, tested and successfully sending text messages then Nagios was integrated with it to include a "notify-by-SMS" feature. The integrated Nagios solution was tested and successfully generated notifications issued as SMS text messages.


General Links

The following general links are useful references when setting up Nagios:


URLSummary/Description
http://www.nagios.org/ Home page
http://www.nagios.org/docs/ Nagios documentation/installation
http://nagioswiki.com/wiki/index.php/Main_Page Nagios Wiki
http://nagioswiki.org/wiki/Main_Page NagiosWiki.org
http://en.gentoo-wiki.com/wiki/HOWTO_Install_Nagios HOWTO Install Nagios - Gentoo Linux Wiki
http://www.maxsworld.org/index.php/how-tos/nagios Thoughts from the abyss - Nagios
http://nagios.manubulon.com/traduction/docs14en/config.html Configuring Nagios