Monitor Remote Host using Nagios and NRPE Service

Monitor Remote host with Nagios

After understanding the installation and configuration of Nagios server and Nrpe in our previous article. we are now working on to configure NRPE Service on Remote host to monitor.

If you are not installed Nagios server yet then refer below link,

  • http://www.techthings.org/nagios-monitoring-server-installation-and-configuration/

We hope you have Nagios installed and working properly if not follow above provided link.

Once installed completed, we will proceed with installation and configuration of NRPE service on remote host.

Monitor remote host we need to install below two things

  1. NRPE Service
  2. Nagios Plugins

NRPE Service Installation & Configuration

Step 1 : Installation of NRPE Service is easy you just need to update the apt-get repo and the install the nrpe package with apt-get command.

  • apt-get update
  • apt-get install nagios-nrpe-server

Step 2 : Create a new user and group who has access to nrpe and nagios plugins on server.

  • useradd  nagios
  • groupadd nagios

Step 3 : After installation of nrpe service we need to install nagios plugins which is used to monitor remote server.

Download the Nagios Plugins from below mentioned link on your remote server and extract it with tar command.

Follow below steps for installation of nagios plugins

  • cd /opt/
  • wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
  • tar -xvf nagios-plugins-2.0.3.tar.gz
  • cd nagios-plugins-2.0.3/
  • ./configure --with-nagios-user=nagios --with-nagios-group=nagios
  • make
  • make install

Set permissions for the plugins directory :

  • chown -R nagios.nagios /usr/local/nagios/libexec/
  • chmod -R +x /usr/local/nagios/libexec/

Above nagios plugins usually installed under the "/usr/local/nagios/libexec/" so check this directory is available on server which means installation is done successfully.

Step 4 : Open nrpe.cfg file which is resides under "/etc/nagios/" and add below commands which helps to monitor our remote server.

vim /etc/nagios/nrpe.cfg

## Add Nagios server ip in allowed_hosts list ##

allowed_hosts=127.0.0.1, 55.45.264.212 [relpaced this ip with your nagios server ip]

## Add below commands to check or monitor status of server ##

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

command[check_ping]=/usr/local/nagios/libexec/check_ping -H 8.8.8.8 -w 100.0,20% -c 500.0,60%

command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20 -c 10

command[check_cpu]=/usr/local/nagios/libexec/check_cpu -w 80 -c 90

command[check_mem]=/usr/local/nagios/libexec/check_mem -w 10 -c 5 -f

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

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

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

command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

command[check_apache_procs]=/usr/local/nagios/libexec/check_proc_cpu -p apache2 -w 40 -c 50

Save and close the file.

Here above we have use some custom plugins which is provide extra details of our server like apache,nginx process,cpu,mem status etc.

You can download these plugins from below link,

  • http://www.techthings.org/wp-content/uploads/nagios_custom_plugins.zip

Step 5 : To reflect the changes on nrpe.cfg we need to restart the nrpe service and check the service is running properly.

  • /etc/init.d/nagios-nrpe-server restart
  • netstat -tulnp | grep nrpe

Output :

tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      27496/nrpe

tcp        0      0 :::5666                          :::*                           LISTEN      27496/nrpe

If you get output similar to above, means it working correctly.

Configure Firewall rules

Step 6 : Open Echo requests port 5666 which is accessible from the remote server. if you have iptable enabled then add below rule in iptables file.

vim /etc/sysconfig/iptables

##Use your nagios server ip at bold place.##

-A INPUT -s nagios-server-ip -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT

Or if you aws ec2 server then open below ports in security group,

  • Custom  ICMP  Rule  Echo Request  N/A  nagios-server-ip/32
  • Custom  TCP  Rule  TCP  5666   nagios-server-ip/32

Step 7 : Restart nrpe service and use below commands to test added commands in nrpe.cfg is working properly.

  • /etc/init.d/nagios-nrpe-server restart

Run below Commands on remote host :

  • /usr/local/nagios/libexec/check_cpu -w 60 -c 90

Output like this:

OK - user: 6.85, nice: 0.50, sys: 1.23, iowait: 0.50, irq: 0.50, softirq: 0.62 idle: 93.28 | user=6.85; nice=0.50; sys=1.23; softirq=0.62; iowait=0.50; irq=0.50; idle=93.28;

by this way you can check all added commands on remote host.

On Nagios Monitoring Server :

Now we need to install nagios nrpe plugin so go to the /opt/ download below nrpe plugin with wget command.

  • wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
  • tar -xvf nrpe-2.15.tar.gz
  • cd /opt/nrpe-2.15
  • ./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu
  • make all
  • make install-daemon

Now go to the /opt/nrpe-2.15/src and you will find the check_nrpe plugin so just move this plugin under the "/usr/local/nagios/libexec/"

Make sure that the check_nrpe plugin can communicate with the NRPE daemon on the remote Linux host.

Run below command on Nagios server and check :

  • /usr/local/nagios/libexec/check_nrpe -H -c check_mem

Output :

CRITICAL - 3.3% (503084 kB) free!|TOTAL=15375700KB;;;; USED=14872616KB;13838130;14606915;; FREE=503084KB;;;; CACHES=7094916KB;;;;

if above command produced output like this means everything is working properly.

Add Remote host in Nagios :

Step 1 : Go to the "/usr/local/nagios/etc" directory and create directory with name of clients or Remote then touch below two files under the this.

  • cd /usr/local/nagios/etc/
  • mkdir clients
  • touch hosts.cfg
  • touch remote-host.cfg

step 2 : Add this directory in nagios.cfg file.

vim /usr/local/nagios/etc/nagios.cfg

##This will read all the config files from this directory.

cfg_dir=/usr/local/nagios/etc/clients

save and close the file.

Step 3 : Now go back to the clients directory and open the file hosts.cfg and add the default host template name and define remote hosts as shown below.

define host{

       use                           linux-server ## important to define

       host_name               nagios_host

       alias                          Client-url optional

       address                    Remote-host-ip ##important to define

      }

Step 4 : Now open file remote-host.cfg from same directory and add below services.

define service{

       use                                  generic-service

       host_name                       nagios_host

       service_description          Current Users

       check_command              check_nrpe!check_users

       }

 

define service{

       use                                   generic-service

       host_name                       nagios_host

       service_description          Current Load

       check_command              check_nrpe!check_load

       }

 

define service{

       use                                  generic-service

       host_name                      nagios_host

       service_description         PING

       check_command            check_nrpe!check_ping

       }

 

define service{

       use                                  generic-service

       host_name                       nagios_host

       service_description          Swap Usage

       check_command             check_nrpe!check_swap

       }

 

define service{

       use                                  generic-service

       host_name                       nagios_host

       service_description          Current CPU Usage

       check_command              check_nrpe!check_cpu

       }

 

define service{

        use                                  generic-service

        host_name                       nagios_host

        service_description          Current Memory Usage

        check_command              check_nrpe!check_mem

        }

 

define service{

       use                                   generic-service

       host_name                       nagios_host

       service_description          Root Partition

       check_command              check_nrpe!check_root

       }



define service{

       use                                  generic-service

       host_name                       nagios_host

       service_description         Zombie Processes

       check_command             check_nrpe!check_zombie_procs

       }

 

define service{

       use                                  generic-service

       host_name                       nagios_host

       service_description          Total Processes

        check_command             check_nrpe!check_total_procs

       }

Note : From above two files we have use two important things one is linux-server in hosts.cfg file and second is generic-service in remote-host.cfg file.

linux-server and generic-service defined under the objects/templates.cfg file if you use different names then you will get the error.

Step 4 : Now NRPE command definition needs to be created in commands.cfg file

vim /usr/local/nagios/etc/objects/commands.cfg

define command{

       command_name check_nrpe

       command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -t 30

}

save and close the file.

Step 5 : Finally, verify Nagios Configuration files for any errors using below command,

  • /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Restart the nagios service.

  • /etc/init.d/nagios restart

 

That’s it. Now go to Nagios Monitoring Web interface at “http://Your-server-IP-address/” and click on hosts you will see our remote host is successfully added on server.

Nagios Core

If you’re facing any difficulties while adding remote host to Nagios. Please do comment your queries or problem via comment section, till then stay tuned to techthings.org for more such valuable articles.

Latest Comments
  1. Shivkumar Yadav September 10, 2016
    • Prashant Thorat September 10, 2016
  2. hanif January 30, 2017
  3. manjunath March 10, 2017
  4. Satish Singh June 23, 2017
  5. Dhananjaya August 24, 2017

Leave a Reply

Your email address will not be published. Required fields are marked *