Setup and configure Nagios Client (NRPE) on CentOS/RHEL 6.3

NRPE is called as ‘Nagios Remote Plugin Executer’. It is a Nagios plugin that allows nagios server to remotely execute plugins on other Linux/Unix machines. The main reason for doing this is to allow Nagios to monitor “local” resources (like CPU load, memory usage, etc.) on remote machines. Since these public resources are not usually exposed to external machines, an agent like NRPE must be installed on the remote Linux/Unix machines.

This article will guide you through the installation and configuration steps of Nagios Client – NRPE on CentOS 6.3.

Server side Nagios core and plugin package version:

   Nagios Core: nagios-4.0.0
   Nagios Plugin: nagios-plugins-1.4.16

To install Nagios please see my Nagios Installation Docs.

For testing purpose we have setup following machines:

IP Address Hostname
Nagios Server 10.0.1.10 mon001
Nagios Client 10.0.1.20 haproxy001

1) Prerequisite

  • Nagios server in working condition.
  • Following dependent package to compile and install.

   yum install gcc glibc glibc-common xinetd 

Create nagios user and group by which we will be installing NRPE and Nagios-Plugin

   useradd -m nagios
password nagios

2) Installation

2.1) Create a directory where you would download nagios software:

   mkdir /usr/local/src
   cd /usr/local/src

2.2) First of all we need to Download/Untar/Compile and Install all necessary files for Nagios-Plugin:

   wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
   cd nagios-plugins-1.4.16
   ./configure --with-nagios-user=nagios --with-nagios-group=nagios
   make
   make install

2.3) Then we need to Download/Untar/Compile and Install all necessary files for NRPE:

   cd /usr/local/src/
   wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
   ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios
   make all
   make install-plugin
   make install-daemon
   make install-daemon-config


Note: NRPE by default is installed under /usr/local/nagios directory.

2.4) Install the NRPE daemon as a service under xinetd.

   make install-xinetd

2.5) We need to fix permission as well.

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

3) Configuration

3.1) Nagios Client (NRPE) Configuration

3.1.1) Add the IP Address of the Nagios monitoring server to “only_from” directive in /etc/xinetd.d/nrpe file:

   vi /etc/xinetd.d/nrpe
   only_from = 10.0.1.10

3.1.2) Add the following entry for the NRPE daemon to the /etc/services file:

   vi /etc/services
   nrpe              5666/tcp           # NRPE

3.1.3) Restart the xinetd service:

   service xinetd restart

3.2) Validation and Testing

3.2.1) We need to check if nrpe daemon is running under xinetd:

   netstat -at | grep nrpe
   tcp        0      0 *:nrpe                      *:*                         LISTEN 

3.2.2) Now we need to do the functional testing of NRPE daemon:

   /usr/local/nagios/libexec/check_nrpe -H localhost
   NRPE v2.14

3.2.3) Some inbuild checks that we can check:

   /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
   USERS OK - 3 users currently logged in |users=3;5;10;0
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_load OK - load average: 0.00, 0.02, 0.00|load1=0.000;15.000;30.000;0; load5=0.020;10.000;25.000;0; load15=0.000;5.000;20.000;0;

3.3) Firewall Rule for NRPE:

3.3.1) Firewall port that needs to be open for NRPE daemon on client machine:

   iptables -A INPUT -p tcp -m tcp –dport 5666 -j ACCEPT

3.3.2) Save the Iptables rules and restart it.

   service iptables save
   service iptables restart

Once we are fully convinced that NRPE is running successfully, now is time to do full-fledged setup:

4) Nagios Server Setup
4.1) We need to Download/Untar/Compile and Install NRPE Plugin

   cd /usr/local/src/
   wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
   ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios
   make all
   make install-plugin 

4.2) Validation/Testing
Now we need to make sure that NRPE plugin (from Nagios Server) can talk to nrpe daemon (Client machine).

   /usr/local/nagios/libexec/check_nrpe -H 10.0.1.20
   NRPE v2.14

4.3) Creating Configuration file
4.3.1) Add the following *check_nrpe* definition in “commands.cfg” file:

   vi /usr/local/nagios/etc/commands.cfg
define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }

4.3.2) We also need to create host and service definitions

   vi /usr/local/nagios/etc/objects/hosts.cfg
define host{ use linux-box host_name haproxy001 alias HA Proxy 001 address 10.0.1.20 }

vi /usr/local/nagios/etc/objects/services.cfg
define service{ use generic-service host_name haproxy001 service_description CPU Load check_command check_nrpe!check_load }
define service{ use generic-service host_name haproxy001 service_description Current Users check_command check_nrpe!check_users }
define service{ use generic-service host_name haproxy001 service_description Zombie Processes check_command check_nrpe!check_zombie_procs }
define service{ use generic-service host_name haproxy001 service_description Total Processes check_command check_nrpe!check_total_procs }

4.3.3) Verify your Nagios configuration files:

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

4.3.4) If there are errors, fix them. If everything is fine, restart Nagios:

   service nagios restart

That’s it! You should see the host and service definitions you created in the Nagios web interface. In a few minutes Nagios should have the current status information for the remote Linux/Unix machine.

5) Adding Custom Checks
5.1) Nagios Client (NRPE) Setup

5.1.1) Adding Custom and other in build Checks provided by Nagios plugins you can find it in “/usr/local/nagios/libexec/”

Let say we need to add check_swap plugin that will send warning alert if free space is less than 20% and critical alert if swap free space is less than 10%.

On the NRPE Client machine (haproxy001) verify plugin is working fine:

   /usr/local/nagios/libexec/check_swap -w 20% -c 10%

5.1.1) Once we confirm that the plugin is working fine, we need to add the command entry in config file:

   vi /usr/local/nagios/etc/nrpe.cfg
   command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%

5.1.3) Restart the NRPE Daemon:

   service xinetd restart

5.2) Nagios Server Setup
5.2.1) We need to define a new service for monitoring the swap usage on the remote host, by adding line in “service.cfg” file.

   vi /usr/local/nagios/etc/objects/services.cfg
   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    Swap Usage
      check_command          check_nrpe!check_swap
      }

5.2.2) Verify your Nagios configuration files and in case there is no error restart the nagios server daemon:

   /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
   service nagios reload

You should see the new service definitions that we created in the Nagios web interface.


Related Posts:

Installing Nagios Server (4.0.0) on CentOS/RHEL 6.3
Setup and configure Nagios Client (NSCA) on CentOS/RHEL 6.3
NagiosGraph – Graphs in Nagios on CentOS/RHEL 6.3

Advertisements

One thought on “Setup and configure Nagios Client (NRPE) on CentOS/RHEL 6.3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.