Monitooring Nagios-ega

Installing Nagios On Debian Lenny And Monitoring A Debian Lenny Server

  1. Installation Of Two Default Debian Machines

Prepare two Debian Lenny machines with a minimal setup. Build yourself a good working environment.

In this howto I will refer to the following default configuration:

  • Nagios Host:
    • Hostname: monitor
    • IP: 10.10.105
  • Example Server:
    • Hostname: server1
    • IP: 10.10.100

 

  1. Install Nagios

monitor:~# apt-get install nagios3 nagios-plugins nagios-nrpe-plugin
server1:~# apt-get install nagios-nrpe-server nagios-plugins

In the process of installing you get asked for samba workgroup and WINS Settings just let these set on default.

 

  1. Putting Up A Basic Nagios Configuration On The Monitoring Host

To get access to the Nagios Configuration Page we have to set the password for the nagiosadmin user:

monitor:~# htpasswd -c /etc/nagios3/htpasswd.users nagiosadmin

After this you should be able to login to: http://10.10.10.105/nagios3/ with the username nagiosadmin and the password you just set before.

If you go to the service detail site you will see that Nagios provides already a basic configuration for the localhost.

 

  1. Install A Webserver On The Example Server

server1:~# apt-get install apache2

 

  1. Create A New Config File On The Nagios Host

monitor:~# nano /etc/nagios3/conf.d/server1_nagios2.cfg

define host{

use             generic-host

host_name       server1

alias           server1

address         10.10.10.100

}

define service{

use                     generic-service

host_name               server1

service_description     HTTP-Server

check_command           check_http

}

Restart the nagios service with:

monitor:~# /etc/init.d/nagios3 restart

The ‘use’ variable in every object here indicates which template is used. The generic-host object can be found in the file /etc/nagios3/generic-host_nagios2.cfg, while the generic-service is determined in the file /etc/nagios3/generic-service_nagios2.cfg.

You should now be able to see the server1 and http service on the Service Detail Site of Nagios.

 

  1. Prepare nrpe Client On server1 To Submit More Data To Nagios

We have to change the nrpe config of the server we want to overwatch, first change the line for the allowed host (line 79 by default):

server1:~# nano /etc/nagios/nrpe.cfg

From

allowed_hosts=127.0.0.1

to

allowed_hosts=10.10.10.105

Restart the nrpe service on server1:

server1:~# /etc/init.d/nagios-nrpe-server restart

Check the nrpe-service by hand before we continue to change the config. We do this from our Nagios host.

monitor:~# cd /usr/lib/nagios/plugins/
monitor:/usr/lib/nagios/plugins# ./check_nrpe -H 10.10.10.100 -c check_users

The output should be something like this:

USERS OK – 2 users currently logged in |users=2;5;10;0

 

 

Installing Nagios On Debian Lenny And Monitoring A Debian Lenny Server – Page 2

We need to change our hostconfig we created in step 5 to monitor the new services we can now discover with nrpe.

monitor:~# nano /etc/nagios3/conf.d/server1_nagios2.cfg

Add this to the end of the file:

define service{        use                     generic-service        host_name               server1        service_description     Current Load        check_command           check_nrpe_1arg!check_load}define service{        use                     generic-service        host_name               server1        service_description     Current Users        check_command           check_nrpe_1arg!check_users}define service{        use                     generic-service        host_name               server1        service_description     Disk Space        check_command           check_nrpe_1arg!check_hda1}define service{        use                     generic-service        host_name               server1        service_description     Total Processes        check_command           check_nrpe_1arg!check_total_procs}

Do a restart of the nagios service:

monitor:~# /etc/init.d/nagios3 restart

In the webservice you should now be able to see the added services and slowly they should pick up, beside one of them, the Check for the Disk Space will most likely fail cause you have no /dev/hda1 partition nor device.

Change this check on the monitor1 server to reflect the actual partition that we want to check. In my case the machine sits on a virtual server host by xen, we can determine the used partition by using the following command on server1:

server1:~# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/iscsi1-root
7.3G  714M  6.2G  11% /
tmpfs                 137M     0  137M   0% /lib/init/rw
udev                   10M  568K  9.5M   6% /dev
tmpfs                 137M     0  137M   0% /dev/shm
/dev/xvda1            228M  9.5M  207M   5% /boot

This will show us the partitions and the mountpoints of them, in my case the actual ‘root’ partition is /dev/mapper/iscsi1-root and i discovered this by looking for the mountpoint ‘/’.

Now we can continue to change our nrpe config on the server to make this check working. For this we open the nrpe.cfg file again:

server1:~# nano /etc/nagios/nrpe.cfg

Then we go to the line which contains (line 201 by default):

command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1

And change it to:

command[check_iscsi1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/iscsi1-root

Change the hostconfig on the Nagios server to reflect these changes:

monitor:~# nano /etc/nagios3/conf.d/server1_nagios2.cfg

From:

define service{        use                     generic-service        host_name               server1        service_description     Disk Space        check_command           check_nrpe_1arg!check_hda1}

To:

define service{        use                     generic-service        host_name               server1        service_description     Disk Space        check_command           check_nrpe_1arg!check_iscsi1}

Restart both services.

server1:~# /etc/init.d/nagios-nrpe-server restart
monitor:~# /etc/init.d/nagios3 restart

 

8. Configure Notifications Per Mail

You want to be notified per email when a service gets into critical status. So we have to configure the email address for the usernagiosadmin.

Go into the file /etc/nagios3/conf.d/contacts_nagios2.cfg and change the email address to your own one. If you want to add more users, just copy the ’define contact’ section, create a second one with it and add your user(s) to the contactgroup below.

define contact{        contact_name                    root        alias                           Root        service_notification_period     24×7        host_notification_period        24×7        service_notification_options    w,u,c,r        host_notification_options       d,r        service_notification_commands   notify-service-by-email        host_notification_commands      notify-host-by-email        email                           admin@domain.com        }               define contact{        contact_name                    example        alias                           example        service_notification_period     24×7        host_notification_period        24×7        service_notification_options    w,u,c,r        host_notification_options       d,r        service_notification_commands   notify-service-by-email        host_notification_commands      notify-host-by-email        email                           anotheradmin@domain.com        }define contactgroup{        contactgroup_name       admins        alias                   Nagios Administrators        members                 root,example        }

To activate simple mail notification we have to enable the smtp transport of the Debian system, because all that Nagios does is to give over the message with a Linux pipe to the standard program /usr/bin/mail.

We have to install Postfix and set up a basic configuration to let the Nagios server send out emails by himself.

monitor:~# apt-get install postfix mailx

Now configure Postfix as “Internet Site” and set a domain where the Nagios mails will come from.

After this do a restart and stop the apache service on the testserver:

monitor:~# /etc/init.d/nagios3 restart
server1:~# /etc/init.d/apache2 stop

This will create a notification message which should be received if you set your email address in the file contacts_nagios2.cfg.

 

Misc: About Icinga

Icinga is a Nagios fork with a larger developer community and will most likely be the software in the future to use, you will find howtos about Icinga on HowtoForge and you can reuse your custom plugins with Icinga as the Nagios plugins can be used to.

I would recommend anyone to play around with Nagios and Icinga.