Getting started with Nagios 2.1

47

Author: Paul Virijevich

Nagios, the premier open source network monitoring program, is celebrating its 2.1 release. With four years of development under its belt, Nagios is powerful enough to replace expensive proprietary monitoring products and become a tool your organization can’t live without.

The Nagios change log shows more than 126 improvements since version 1.3, which came out a year ago.

You can download Nagios 2.1 as source code from the project site, or from Red Hat RPM binaries from Dag Wieers. If at all possible, install Nagios from a binary. If not, follow the step-by-step instructions in the online manual. Don’t forget to download and install the Nagios plugins; without these, Nagios cannot do its job.

Once you install everything, you still must set up the hosts and services to monitor. Fortunately, Nagios comes with some sample configuration files. Depending on whether you installed from source or RPM, the configuration files will be in /usr/local/etc/nagios or /etc/nagios.

Get Nagios up and running with the minimal.cfg file, which includes command definitions, a host definition for the local machine, and some basic service checks. It also specifies a time period for monitoring, and it provides templates for host and service groups — in other words, everything you need to get started.

As handy as minimal.cfg is, the one file that must exist is the main Nagios configuration file nagios.cfg. Edit it, and make sure these two lines are commented out with a # before them:

#cfg_file=/etc/nagios/checkcommands.cfg
#cfg_file=/etc/nagios/misccommands.cfg

Make sure this line looks just like this:

cfg_file=/etc/nagios/minimal.cfg

Be sure to read over the rest of the file, but that’s enough to test out the program. Use this command to start Nagios as a daemon:

/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

If you installed from source and follow the manual, pointing your browser at http://localhost/nagios displays Nagios in all its glory. If you installed from RPM, check out the file /etc/httpd/conf.d/nagios.conf for ideas on integrating your Nagios installation with Apache. Edit the configuration file cgi.cfg to determine who can access and control the Web interface.

If all goes well, Nagios should be able to monitor the five default resources in minimal.cfg: ping, disk usage, local users, total processes, and load. Although Nagios monitors only the local machine, you can edit these templates to suit your network. For instance, you can scale up using host groups to monitor large numbers of machines with minimal configuration. To do this with the minimal.cfg example, simply add hosts to the already defined host group test, then use the parameter host_group in place of host_name in the service definitions.

If this is your first time witnessing Nagios’ Web interface, don’t let first impressions scare you off. If Nagios has one Achilles’ heel, it’s the user interface. Fortunately, you can give Nagios a face-lift by applying the Nuvola Style theme from NagiosExchange, a collection of third-party add-ons for Nagios. This theme is based on the KDE theme of the same name. Before installing it, make a quick backup of the directory you’ll be overwriting. Then if you installed from source, this command does the trick:

tar -cvf shareback.tar /usr/local/nagios/share

If you used an RPM package for installation, you’ll want to use /usr/share/nagios instead. Next, extract the contents of the theme archive and copy the contents of the html folder to /usr/local/nagios/share:

tar -zxvf nagios-nuvola-1.0.3.tar.gz;cp -r html/* /usr/local/nagios/share

Refresh your browser and behold the beauty. At this point, Nagios looks good and is monitoring some local resources.

Executing remotely

When it comes to remote hosts, Nagios features a number of plugins that check on the health of various services (HTTP, SSH, Telnet). However, you might want to monitor services that are local to the remote hosts, or resources such as disk space or the load on the remote machine. This is where the Nagios Remote Plugin Executor (NRPE) comes in handy.

The NRPE runs as a daemon on remote hosts, which also need the Nagios plugins mentioned earlier. To run the daemon, add a port to /etc/services and decide if you want to run it standalone or from xinetd. You can find full installation instructions in the NRPE README file. Your Nagios monitoring server needs the check_nrpe plugin added its Nagios plugin directory.

To use NRPE, define a service and use check_nrpe for the check command. In contrast to regular check commands, check_nrpe options are specified on the remote hosts in the nrpe.cfg file.

And there you have it. Nagios 2.0 is up and monitoring your network. If you need a more complex configuration, you can break up your configuration files to make administration easier. You can have separate files for just about every section of minimal.cfg, including hosts, host groups, and services.

These examples might be simple, but they show how you can extend Nagios to monitor more hosts and services. NRPE lets you know when local resources get out of hand. With the help of Nagios, and a little luck, you may now notice outages before your users do.