by Wayne E Goodrich (Outlaw)
(Transferred from the wiki by Peter)


If you manage a network of any size, you want to be notified of problems before your customers or your bosses find out, but you don't want to be tied to a console checking for the availability of hosts and services. This is where Nagios shines. If you put in the time it takes to install and customize Nagios for your environment, you'll be rewarded with a superb monitoring and notification solution that happens to be free. In this PET, I will guide you through the installation and configuration of Nagios, and I will provide examples of customizations you can add using plugins you can write yourself.
Gather up our packages

I will use Redhat Enterprise Linux AS 4.0 in these examples, but they can be adapted for any Linux distribution. The following are required packages for HTTPD services that will drive Nagios's web interface:


Optional (for secure sockets layer, HTTPS interface)
If you selected the default package set during installation, these are already installed. If you opted not to make Apache available during Redhat install, you can grab the packages from RHN using up2date or by manually downloading them.
The following are needed for Nagios basic functionality, really it's the Nagios framework we get. Nagios's checks are accomplished entirely through the use of plugins, which are available in a separate package. From here on out, I will suggest getting prebuilt packages from Dag Wieers's collection, and occasionally from CPAN. To make it easier on yourself, add Dag's repositories if you use YUM.


The following are needed for Nagios to actually perform checks

Nagios Plugins

Install Necessary Packages

We can begin installation of the packages by first installing Nagios:
rpm -ivh nagios-2.2-1.el4.rf.i386.rpm
Now we begin satisfying nagios-plugins dependencies:
rpm -ivh fping-2.4-1.b2.2.el4.rf.i386.rpm
rpm -ivh perl-Crypt-DES-2.03-3.2.el4.rf.i386.rpm
mkdir /tmp/perltmp
cp *gz /tmp/perltmp
cd /tmp/perltmp
find . -name "*gz" -exec tar xvzf {} \;
cd Digest-SHA1-2.11
make test
make install
cd ../Digest-HMAC-1.01
make test
make install
cd ../Socket6-0.19
make test
make install
These next two Dag perl packages expect SHA1, HMAC and Socket6 to be available as rpms, but since they were not, we have to tell rpm not to check dependencies.
rpm -ivh --nodeps perl-Net-SNMP-5.0.1-1.2.el4.rf.noarch.rpm
rpm -ivh --nodeps perl-IO-Socket-INET6-2.51-1.2.el4.rf.noarch.rpm
rpm -ivh nagios-plugins-1.4.1-1.2.el4.rf.i386.rpm
Begin Configuration

Nagios has two methods for arranging its configuration files. One way relies on a single file where you specify hosts, groups, services etc. The other allows you to split these files up by purpose for ease of administration. The single file method can become unwieldy as you add machines and services to monitor. Here, we'll assume the multiple definition file method.
Configure The Nagios Service

Let's become familiar with the file locations that the Dag provided packages use as defaults:

Main Nagios Configs
Plugins and CGIs
Nagios Web Files
Here, we see the example config files in /etc/nagios:
[radar@test2 ~]$ ls -lh /etc/nagios
total 160K
-rw-rw-r--  1 root root  30K Apr  8 08:28 bigger.cfg
-rw-rw-r--  1 root root 9.4K Apr  8 08:28 cgi.cfg
-rw-rw-r--  1 root root 4.8K Apr  8 08:28 checkcommands.cfg
-rw-r--r--  1 root root  16K Aug  5  2005 command-plugins.cfg
-rw-rw-r--  1 root root  14K Apr  8 08:28 minimal.cfg
-rw-rw-r--  1 root root 4.2K Apr  8 08:28 misccommands.cfg
-rw-rw-r--  1 root root  30K Apr  8 08:28 nagios.cfg
-rw-rw----  1 root root 1.3K Apr  8 08:28 resource.cfg
The first file we're interested in is nagios.cfg, the main config file. This file specifies, among other things, the object config (definition) files. Those are what we are most interested in at this point. We want to open /etc/nagios/nagios.cfg in an editor and comment out the line that contains minimal.cfg. Then we'll uncomment the lines containing the object config files that we'll need to create, and populate with our definitions. Let's go ahead and do that, then.

# You can split other types of object definitions across several
# config files if you wish (as done here), or keep them all in a
# single config file.

Here, I have commented out minimal.cfg
And here I have uncommented the object config files we will work with first, to get basic functionality. We will now create these and populate them with some hosts, services, groups, etc.

While we're at it we want to enable service commands in the CGIs, and enable flap detection: