Nagios Setup and configuration on Fedora Core 2.

Resources:
Overview: The General Process
  1. Install Nagios either from source or rpm.
  2. Install plugins.
  3. Set up the Web Interface
    1. Authentication And Authorization In The CGIs
  4. Edit Configuration Files
    1. Main Configuration File
    2. Resource Files
    3. Object Definition Files
      1. hosts.cfg
      2. hostgroups.cfg
      3. services.cfg
      4. contactgroup.cfg
      5. contacts.cfg
      6. escalations.cfg
      7. dependencies.cfg
Installation

Since I was looking to learn how to use an already installed copy of nagios on a work system I decided to do a quick install on my own network by rpm:

[root@paulororke nagios]# rpm -ivf nagios-1.2-2.1.fc2.rf.i386.rpm

The rpm put thing in a different place to what the documentation for the src install describes.  I believe the configuration files required are essentially the same so I will try to document here when the file locations differ from the official documentation.

Installation Directory

According to the documentation for the src install, there should be a directory structure in /usr/local/nagios like the following excerpt from the Nagios docs: [  show table]

What I got after installing from RPM looked more like this: [  show output] So I'll just refer to the files by name and you'll have to locate them yourself. The package installation also took care of setting the nagios daemon to run at startup. This can be verified by:

[root@paulororke nagios]# chkconfig --list |grep nagios
  nagios    0:off 1:off 2:off 3:on 4:on 5:on 6:off

It also put a nagios executable in /usr/bin.  Trying to run this without arguements produced the following: [  show output] so we use the - v option and provide the path to the config file /etc/nagios/nagios.cfg to run the preflight check. [  show preflight1].  It is failing due to some errors in the config files so let's move on with installation before we try running it again.

Installing the Plugins

Install the plugins. Plugins provide the core functionality of Nagios. Without any plugins defined Nagios is effectively useless.
I had some issues installing the plugins. I tried using an rpm and had a dependency issue:
[root@paulororke nagios]# rpm -ivf nagios-plugins-1.3.1-10.1.fc2.dag.i386.rpm
warning: nagios-plugins-1.3.1-10.1.fc2.dag.i386.rpm: V3 DSA signature: NOKEY, key ID 6b8d79e6
error: Failed dependencies:
perl(Net::SNMP) is needed by nagios-plugins-1.3.1-10.1.fc2.dag
Yet, according to CPAN, perl(Net::SNMP) is installed: [  show cpan output].  so I downloaded the source and tried building it myself:

Configuration

Setting up the Web Interface

  1. httpd.conf

    The rpm install took care of much of this with this nagios.conf file being created in /etc/httpd.cong.d/  If you're setting up from source you will need to do this yourself, a sample httpd.conf file being generated by the ./configure script.  Complete instructions here.
  2. Authentication And Authorization In The CGIs

    Added .htaccess to /usr/lib/nagios/cgi:
    AuthName "Nagios Access"
    AuthType Basic
    AuthUserFile /usr/lib/nagios/cgi/htpasswd.users
    require valid-user
    and /usr/share/nagios:
    AuthName "Nagios Access"
    AuthType Basic
    AuthUserFile /usr/share/nagios/htpasswd.users
    require valid-user
    These files contain the directives for authentication of their respective directories. In order for them to work you need the password file specified. Use htpasswd and set up passwords:
    [root@paulororke nagios]# htpasswd -c /usr/lib/nagios/cgi/htpasswd.users nagios
    New password:
    Re-type new password:
    Updating password for user nagios
    and
    [root@paulororke nagios]# htpasswd -c /usr/share/nagios/htpasswd.users nagios
    New password:
    Re-type new password:
    Updating password for user nagios

Configuring Nagios

  1. Main Configuration File

    This is usually /usr/local/nagios/etc/nagios.cfg though I found it in /etc/nagios/nagios.cfg.  Extensive documentation on this file can be found here.  My nagios.cfg looks like this.  I have left it unmodified from the install.
  2. Resource Files

    The main point of having resource files is to use them to store sensitive configuration information and not make them available to the CGIs.
  3. Object Definition Files

    Object definition files are used to define hosts, services, hostgroups, contacts, contactgroups, commands, etc. This is where you define what things you want monitor and how you want to monitor them.  Nagios uses Template-Based Object Configuration.   It also makes heavy use of Object Inheritance.  To this end I edited /etc/nagios/hosts.cfg. See it here.   Again running the 'preflight test' with the - v option:

    [root@paulororke nagios]# nagios -v /etc/nagios/nagios.cfg

    [  show preflight2.]  So now we edit /etc/nagios/hostgroups.cfg and look for the 'printer1'.  hostgroups.cfg now looks like this.

    [root@paulororke nagios]# nagios -v /etc/nagios/nagios.cfg

    [  show preflight3].  This had the effect of making it through the hosts sections of the configuration files and now it is reporting errors from the services sections. This is due to the fact that the services files are still configured for the old hosts.  Let's edit /etc/nagios/services.cfg.  It now looks like this.  Time to run the preflight check again...

    [root@paulororke nagios]# nagios -v /etc/nagios/nagios.cfg

    [  show preflight4]  Wow - looks like we're going backwards here with more errors than ever before, but it isn't really so bad - there are just many references to the contact group 'admin' and we haven't defined it yet.  So edit /etc/nagios/contactgroups.cfg to look like this, and preemtively, lets edit /etc/nagios/contacts.cfg to look like this.

    [root@paulororke nagios]# nagios -v /etc/nagios/nagios.cfg

    [  show preflight5]  We must be making headway - now it is the values in escalations.cfg that causes the error. Editing /etc/nagios/escalations.cfg to look like this.

    [root@paulororke nagios]# nagios -v /etc/nagios/nagios.cfg

    [  show preflight6]  Down to 12 errors so now look to dependencies.cfg and correct the offending lines as described in the above output such that /etc/nagios/dependencies.cfg looks like this.

    [root@paulororke nagios]# nagios -v /etc/nagios/nagios.cfg

    [  show preflight7]  Success! Looks like the basic setup was successful. Lets try it out for real...
Operation

Run it as a daemon.

[root@paulororke nagios]# chkconfig nagios on

[root@paulororke nagios]# service nagios start
  Starting network monitor: nagios
  NAGIOS ok - status written 1 seconds ago

Other stuff
[  show output]
The end of the document.
The end of the page.