Wednesday, March 12, 2014

Install and Configure the Nagios NRPE - Plugin - on a Remote Client

Install NRPE on Linux


NRPE is called as ‘Nagios Remote Plugin Executere’. NRPE allows nagios server to remotely execute nagios commands or plugins on other Linux/Unix machines. NRPE is also available for windows servers.


The following will show how to install NRPE on Linux from code.

For this example I am installing it on Linux version 2.6.18-308.1.1.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)) #1 SMP Wed Mar 7 04:16:51 EST 2012
1.       Install NRPE required packages.
a.       [root@server ~]# yum install openssl-devel gcc xinetd make.

2.       NRPE runs under the user "nagios", so let's add that user.
a.       [root@server ~]# useradd nagios

3.       Download and install Nagios-plugins.
a.       Create or choose a download folder for the plugin files. i.e.: /downloads then navigate to that folder and run the below command.
b.      [root@server downloads]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
c.       [root@server downloads]# tar -xvzf nagios-plugins-1.5.tar.gz
d.      [root@server downloads]# cd nagios-plugins-1.5
e.      [root@server nagios-plugins-1.5]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
f.        [root@server nagios-plugins-1.5]# make install

4.       Assign nagios user ownership to nagios commands.
a.       [root@server nagios-plugins-1.5]# chown -R nagios:nagios /usr/local/nagios/libexec

5.       Install and configure NRPE nagios client.
a.       Choose and navigate to a download directory i.e. /downloads
b.      [root@server downloads]# wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz?r=&ts=1363788540&use_mirror=hivelocity
c.       [root@server downloads]# tar -xvzf nrpe-2.15.tar.gz
d.      [root@server downloads]# cd nrpe-2.15
e.      [root@server nrpe-2.15]# ./configure --enable-ssl --enable-command-args
f.        [root@server nrpe-2.15]# make all
g.       [root@server nrpe-2.15]# make install-plugin
h.      [root@server nrpe-2.15]# make install-daemon
i.         [root@server nrpe-2.15]# make install-daemon-config –(this command may not work ignore and continue)
j.        [root@server nrpe-2.15]# make install-xinetd



6.       NRPE will run under xinetd daemon. So update xinetd file.
a.       [root@server ~]# vi /etc/xinetd.d/nrpe

# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
        flags           = REUSE
        socket_type     = stream
        port            = 5666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = Your Nagios host server  localhost }

7.       Add following line at the end of file for NRPE in /etc/services
a.       [root@server ~]# vi /etc/services
b.      nrpe            5666/tcp                # NRPE

8.       Determine Drives to monitor
a.       [root@server~]# df –h
Example output
[root@clientserver ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      2.0G  1.4G  458M  76% /
/dev/mapper/VolGroup01-LogVol00
                      1.4T  713G  554G  57% /u1
/dev/mapper/VolGroup00-LogVol02
                      2.0G   68M  1.8G   4% /tmp
/dev/mapper/VolGroup00-LogVol01
                      3.9G  402M  3.3G  11% /var
/dev/mapper/VolGroup00-LogVol03
                      4.9G  2.3G  2.4G  49% /usr
/dev/sda1              99M   78M   16M  84% /boot
tmpfs                 2.0G     0  2.0G   0% /dev/shm

b.      From the example we will want to monitor the following Volumes
                                                               i.      /dev/mapper/VolGroup00-LogVol00 – this is the main OS drive
                                                              ii.      /dev/mapper/VolGroup01-LogVol00 – this is the U1 partition or drive
c.        Using the drive information above you need to modify and add lines to the /usr/local/nagios/etc/nrpe.cfg
d.        Go to the section under hardcoded command arguments. Modify or add the following
                                                               i.      command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/mapper/VolGroup00-LogVol00
                                                              ii.      command[check_hda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/mapper/VolGroup01-LogVol00

e.      There is no need to modify the other hardcoded arguments – these other arguments control CPU load and other checks.

9.       Start/Restart xinetd service.
a.       Any change on the nrpe.cfg file requires xinetd service to be restarted.
                                                               i.      [root@server ~]# service xinetd start
                                                             ii.      [root@server ~]# chkconfig xinetd on


Updating the Nagios host server to monitor the Remote Client Servers


1.       Add a command definition to the command.cfg file for the NRPE Plugin.
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

2.       Add a service definitions to the services.cfg file to monitor the remote host’s drives and CPU load.
 Examples NRPE definitions -(Keep in mind that you can add multiple servers hostnames to each definition) 

define service{
     use                                 generic-service
     host_name                      client1,client2
     service_description           OS Drive
     check_command             check_nrpe!check_hda1
     }

  define service{
     use                                 generic-service
     host_name                      client1,client2
     service_description          U1 Drive
     check_command             check_nrpe!check_hda2
     }

define service{
     use                                 generic-service
     host_name                      client1,client2
     service_description          U3 Drive
     check_command             check_nrpe!check_hda3
     }

define service{
     use                                 generic-service
     host_name                      client1.client2
     service_description           U4 Drive
     check_command             check_nrpe!check_hda4
     }

define service
use                                 generic-service
     host_name                      client1,client2
     service_description          CPU Load
     check_command             check_nrpe!check_load
}

define service{
use                                 generic-service
host_name                      client1,client2
service_description Total Processes
check_command             check_nrpe!check_total_procs
        } 

define service{
use                                 generic-service
host_name                      client1,client2
service_description           Current Users
check_command             check_nrpe!check_users
}

3.       Test the new configuration.
a.      /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg\
b.     If there are no errors you can reload the nagios service in the next step.

4.       Reload the Nagios service
a.       Service nagios reload

5.       Check the web interface of nagios for the new services and run manual checks for each new service.
a.      If errors occur troubleshoot, correct, and retry. 

No comments:

Post a Comment