Nagios linux Hosts Monitoring

I’ve reached a very good knowledge of Nagios and NConf and today i’ve setup the monitoring of a unix host with NRPE.

First of all we need to split the work in two areas, (1)configuring the linux host, (2) configuring Nagios for monitoring.

Following three steps will happen on a very high level when Nagios (installed on the nagios-servers) monitors a service (for e.g. disk space usage) on the remote Linux host.

  1. Nagios will execute check_nrpe command on nagios-server and request it to monitor disk usage on remote host using check_disk command.
  2. The check_nrpe on the nagios-server will contact the NRPE daemon on remote host and request it to execute the check_disk on remote host.
  3. The results of the check_disk command will be returned back by NRPE daemon to the check_nrpe on nagios-server.

For (1)follow these steps:

  1. Install NRPE
  2. Setup NRPE to run as daemon
  3. Modify the /usr/local/nagios/etc/nrpe.cfg

Install NRPE

[remotehost]# cd /home/downloads
[remotehost]# tar xvfz nrpe-2.12.tar.gz
[remotehost]# cd nrpe-2.12

[remotehost]# ./configure
[remotehost]# make all
[remotehost]# make install-plugin
[remotehost]# make install-daemon
[remotehost]# make install-daemon-config
[remotehost]# make install-xinetd

Setup NRPE to run as daemon

  • Modify the /etc/xinetd.d/nrpe to add the ip-address of the Nagios monitoring server to the only_from directive. Note that there is a space after the 127.0.0.1 and the nagios monitoring server ip-address (in this example, nagios monitoring server ip-address is: 192.168.1.2)
       only_from       = 127.0.0.1 192.168.1.2
  • Modify the /etc/services and add the following at the end of the file.
       nrpe 5666/tcp # NRPE
  • Start the service
       [remotehost]#service xinetd restart
  • Verify whether NRPE is listening
       [remotehost]# netstat -at | grep nrpe
       tcp 0      0 *:nrpe *:*                         LISTEN
  • Verify to make sure the NRPE is functioning properly
[remotehost]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12

Modify the /usr/local/nagios/etc/nrpe.cfg

The nrpe.cfg file located on the remote host contains the commands that are needed to check the services on the remote host. By default the nrpe.cfg comes with few standard check commands as samples. check_users and check_load are shown below as an example.

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20


In all the check commands, the “-w” stands for “Warning” and “-c” stands for “Critical”. for e.g. in the check_disk command below, if the available disk space gets to 20% of less, nagios will send warning message. If it gets to 10% or less, nagios will send critical message. Change the value of “-c” and “-w” parameter below depending on your environment.

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1


Note: You can execute any of the commands shown in the nrpe.cfg on the command line on remote host and see the results for yourself. For e.g. When I executed the check_disk command on the command line, it displayed the following:

[remotehost]#/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
DISK CRITICAL - free space: / 6420 MB (10% inode=98%);| /=55032MB;51792;58266;0;64741


In the above example, since the free disk space on /dev/hda1 is only 10% , it is displaying the CRITICAL message, which will be returned to nagios server.

Commands

We now need to look at the available commands to NRPE. If you scroll to the bottom of the nrpe.cfg  file you will see the default commands. The commands are structured like so:

command[check_disk1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1

Command names are completely arbitrary and can be created on the fly, e.g.:

command[check_disk2]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hdb1

Very simple format, check_disk1 is the command name located at/usr/local/nagios/libexec/check_disk with the arugments -w 20 -c 10 -p /dev/hda1. I used this particular command because it contains the disk check—this is the one command that you may possibly need to alter immediately for effective use. At the end of the command we see the path of the disk device to check on, /dev/hda1. You may not have this drive configuration so you will need to replace that with the path to your local disk setup. An easy way to figure this out is to issue the command df -h and use the returned entry for homeas this is the primary usage space for most.

System Setup

At this point, we have completed configuring NRPE and we need to setup the system to accommodate Nagios.

First we need to setup permissions for the Nagios user.

adduser nagios chown -R nagios.nagios /usr/local/nagios/

We’ve setup our Nagios user and changed the ownership of all the files under the nagios/ dir.

Now we need to edit the file /etc/services and add the following line:

nrpe 5666/tcp # NRPE

Now, we need to tell our inetd or xinetd about NRPE. Create a file in /etc/xinetd.d/ callednrpe, and add the following to that file:

# default: on # description: NRPE service nrpe { flags = REUSE socket_type = stream wait = no user = nagios server = /usr/local/nagios/libexec/nrpe server_args = -c /usr/local/nagios/libexec/nrpe.cfg --inetd log_on_failure += USERID disable = no # Change this to your primary Nagios server only_from = 127.0.0.1 }

This describes to the “super server” the various options necessary to launch the NRPE daemon when our remote Nagios monitoring system connects.

Now, open the /etc/hosts.allow file and add an entry for the IP address of your remote monitoring server. If you have a firewall, you will also want to configure it so that you allow remote connections from the IP address of your remote monitoring system to port 5666.

Restart your xinetd daemon to reload the configuration changes:

/etc/init.d/xinetd reload

Let’s test it out real quick to make sure nothing has gone wrong so far. From your remote monitoring server issue the following command:

telnet ip.address.of.remote.nrpe 5666

For (2)follow these steps:

1. Download NRPE Add-on and install on the monitoring server executing NAGIOS

2. Install check_nrpe command on the nagios monitoring server

3. NConf Configuration for using check_nrpe

Download nrpe-2.12.tar.gz from Nagios.org and install.

[nagios-server]# tar xvfz nrpe-2.12.tar.gz
[nagios-server]# cd nrpe-2.1.2
[nagios-server]# ./configure
[nagios-server]# make all
[nagios-server]# make install-plugin

./configure will give a configuration summary as shown below:

*** Configuration summary for nrpe 2.12 05-31-2008 ***:

General Options:
————————-
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios

 

Note: I got the “checking for SSL headers… configure: error: Cannot find ssl headers” error message while performing ./configure. Install openssl-devel as shown below and run the ./configure again to fix the problem.

[nagios-server]# rpm -ivh openssl-devel-0.9.7a-43.16.i386.rpm krb5-devel-1.3.4-47.i386.rpm zlib-devel-1.2.1.2-1.2.i386.rpm e2fsprogs-devel-1.35-12.5.
el4.i386.rpm
warning: openssl-devel-0.9.7a-43.16.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing… ########################################### [100%]
1:e2fsprogs-devel ########################################### [ 25%]
2:krb5-devel ########################################### [ 50%]
3:zlib-devel ########################################### [ 75%]
4:openssl-devel ########################################### [100%]

Verify whether nagios monitoring server can talk to the remotehost.

[nagios-server]#/usr/local/nagios/libexec/check_nrpe -H 192.168.1.3
NRPE v2.12


Note: 192.168.1.3 in the ip-address of the remotehost where the NRPE and nagios plugin was installed as explained in Section II above.

NCONF configuration

For check_nrpe use we must:

a) Configure the Check Command

b) Configure the service to associate to hosts.

——————-

a) Check Command to execute by Nagios

We must use the macros from Nagios  to obtain parameters to substitute when we configure the services to call for every hosts.

b)Service configuration for single host

Choose every arguments %ARG% for command compilation and execution.

Here another useful whitepaper for configuration help:

http://nagios.sourceforge.net/docs/nrpe/NRPE.pdf

~ di diegotech su marzo 30, 2012.

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

 
%d blogger cliccano Mi Piace per questo: