How to Add Linux Host to Nagios Monitoring Using NRPE Plugin

In our previous article, we talked about installing Nagios server on CentOS 7 / RHEL 7. Here, in this article we will see how to add Linux host to Nagios Monitoring using NRPE plugin.

I’m assuming that you have working Nagios setup, if not use the below link to the installation guide.

READ: How to Install Nagios 4.3.2 on CentOS 7 / RHEL 7

NRPE Plugin:

The NRPE (Nagios Remote Plugin Executor) plugin allows you monitor any application or service running on remote Linux / Windows machines. This NRPE Add-on helps Nagios to monitor any local resources like CPU, Memory, Disk, Swap, etc on remote machines. Finally, you must have this NRPE plugin installed on the remote machine.

Steps to add Linux Host to Nagios monitoring,

On Nagios Remote Host:

  1. Add User Account
  2. Download & Install Nagios Plugin
  3. Install NRPE Add-on
  4. Configure NRPE Add-On

On Nagios Server Host:

  1. Configure Nagios Server
  2. Monitor the remote machine.

Nagios Remote Host:

Add User account:

Before proceeding the installation, add the “nagios” user and “nagcmd” group.

su -l

Create a new user in the name of “nagios” and give it a password.

useradd nagios

Set the password.

passwd nagios

Download & Install Nagios Plugin:

Download the Nagios and the Nagios plugins on the remote host using the following command ( For latest version Visit Nagios WebSite )

wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

Extract the Nagios plugins source code tarball.

tar -zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16

Compile and install the plugins. While compiling, i got an error; here is the Nagios troubleshooting Tutorial.

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Change the permission of the Nagios plugin directory on the remote host.

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

Download and install NRPE Add-on:

Visit the Nagios download page and download the NRPE Add-on.

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz

Once downloaded, Extract the tarball.

tar -zxvf nrpe-2.13.tar.gz
cd nrpe-2.13

Compile it.

./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd

Configure NRPE Add-on:

NRPE is the part of the xinetd daemon, modify the NRPE configurations file to accept the connection from the Nagios server, Edit the /etc/xinetd.d/nrpe.

vi /etc/xinetd.d/nrpe

Add the Nagios server IP address like below.

only_from = 127.0.0.1 192.168.0.151

Add NRPE port at the end of the /etc/services file.

nrpe 5666/tcp # NRPE

Restart the xinetd.d service.

/etc/init.d/xinetd restart

Confirm that NRPE Listening.

netstat -at | grep nrpe

tcp 0 0 *:nrpe *:* LISTEN

Confirm the NRPE functioning.

/usr/local/nagios/libexec/check_nrpe -H localhost

NRPE v2.13

Modify NRPE Config file:

Edit the /usr/local/nagios/etc/nrpe.cfg on the remote host, it contains the command argument to check the service on the remote host. The nrpe.cfg file contains the basic commands to check the remote services, below are the command lines to check the CPU load and running process. The check_load and check_total_procshas to be entered on template file on the server host to enable the monitoring.

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

In the above command -w stands for warning whereas -c stands for critical alert. For example if you execute  the second command on the terminal, it will check the running process; it will warn when the process more than 150 or it will report critical when the process more than 200 and at the same time it will say OK if process below 150.

/usr/local/nagios/libexec/check_procs -w 150 -c 200
Output:
PROCS OK: 112 processes
Change warning to 100 and critical to 150 for testing purpose. Now you can see the warning message, according to your requirement you can modify it.
/usr/local/nagios/libexec/check_procs -w 100 -c 150
Output:
PROCS WARNING: 112 processes

Nagios Server Host:

Install NRPE Add-on:

Visit the Nagios download page and download the NRPE Add-on.

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz

Once downloaded, Extract the tarball.

tar -zxvf nrpe-2.13.tar.gz
cd nrpe-2.13

Compile it.

./configure
make all
make install-plugin

Configure Nagios Server: 

Now its the time configure the nagios server to monitor the remote client, You’ll need to create a command definition in one of your Nagios object configuration files in order to use the check_nrpe plugin. Open the sample commands.cfg file for editing…

vi /usr/local/nagios/etc/objects/commands.cfg
Add the following command definition to the file.
# .check_nrpe. command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$

Create the new configuration file (/usr/local/nagios/etc/objects/remote.cfg) to define the host and service definition. You can use the following template, modify according to your requirement. The following is configured to display the Swap,CPU Load,Disk Space,Current Users. Etc..,

define host{

use                     linux-server
host_name             linuxclient1.iii.local
alias                   Client 1
address                 192.168.0.152

}

define hostgroup{
hostgroup_name  Linux Client
alias           Linux Client 1
members         linuxclient1.iii.local

}

define service{

use                             local-service
host_name                       linuxclient1.iii.local
service_description             SWAP Uasge
check_command                   check_nrpe!check_swap

}

define service{

use                             local-service
host_name                       linuxclient1.iii.local
service_description             Root Partition
check_command                   check_nrpe!check_sda1

}

define service{

use                             local-service
host_name                       linuxclient1.iii.local
service_description             Current Users
check_command                   check_nrpe!check_users

}

define service{

use                             local-service
host_name                       linuxclient1.iii.local
service_description             Total Processes
check_command                   check_nrpe!check_total_procs

}

define service{

use                             local-service
host_name                       linuxclient1.iii.local
service_description             Current Load
check_command                   check_nrpe!check_load

}

Add the new template on the nagios.cfg configuration file, so that it will read the new entries.

vi /usr/local/nagios/etc/nagios.cfg

Add just below.

# Definitions for monitoring the Remote (Linux)
hostcfg_file=/usr/local/nagios/etc/objects/remote.cfg

Restart the Nagios server.

service nagios restart

Monitor the remote machine: 

Now login to the web interface and start do the monitoring. The following screenshot shows the remote Linux box with the default service available (which were taken from the localhost.cfg).

That’s All

How to Add Linux Host to Nagios Monitoring Using NRPE Plugin
Rate this post

POSTS YOU MAY LIKE -:)

Share This Post

Shares