How to Add Linux Host Machine to Nagios Monitoring Server Using NRPE Plugin

The NRPE (Nagios Remote Plugin Executor) plugin allows you to monitor any remote Linux/Unix services, network devices, or resources like CPU

load, Swap, Memory usage, Online users, etc. on local/remote Linux machines.

In this article, we will show you how to add a Remote Linux machine and its

services to the Nagios Core Monitoring host using NRPE (Nagios Remote Plugin Executor) agent.

Make sure Nagios Core is already installed and running. If not, follow this installation guide to set it up.

Note: The NRPE addon requires that Nagios Plugins must be installed on the

remote Linux machine. Without these, the NRPE daemon will not work and will not monitor anything.

Installing Nagios Plugins and NRPE On Remote Linux Host

Install Required Dependencies

# yum install -y gcc glibc glibc-common gd gd-devel make net- snmp openssl-devel tar wget

Create Nagios User

# useradd nagios
# passwd nagios

Install the Nagios Plugins

# mkdir nagios
# cd nagios/
# wget https://nagios-plugins.org/download/nagios-plugins-2.4.11.tar.gz

Extract Nagios Plugins

# tar -xvf nagios-plugins-2.4.11.tar.gz

Compile and Install Nagios Plugins

# cd nagios-plugins-2.4.11/
# ./configure
# make
# make install

Set the permissions on the plugin directory

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

Installing NRPE Plugin

# cd nagios/
# wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.0.2/nrpe-4.0.2.tar.gz
# tar zxfv nrpe-4.0.2.tar.gz
# cd nrpe-4.0.2/
# ./configure
# make all

Install the NRPE plugin daemon, and sample config files

# make install-plugin
# make install-daemon
# make install-config
# make install-init

Configuring NRPE Plugin

Open the /usr/local/nagios/etc/nrpe.cfg file and add the localhost and Nagios server’s IP address.

# vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,::1
allowed_hosts=192.168.1.10
# systemctl enable nrpe.service
# systemctl restart nrpe.service
# systemctl status nrpe

Verify NRPE Daemon Locally

# netstat -tunlp | grep nrpe

Run the “check_nrpe” command to test if the NRPE daemon is working correctly.

# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1

Customize NRPE Commands

# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_users
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_load
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_hda1
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_total_procs
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_zombie_procs

The NRPE agent is now installed and set up on the remote Linux host.

Installing NRPE On Nagios Monitoring Server

Install NRPE Plugin in Nagios

Now, login our Nagios server machine and configure NRPE

# cd nagios/
# wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.0.2/nrpe-4.0.2.tar.gz
# tar xfv nrpe-4.0.2.tar.gz
# cd nrpe-4.0.2/
# ./configure
# make all

If you’re facing some error like during make all

# make all
/usr/bin/ld: /tmp/ccArtMbW.o: in function `init_ssl':
/root/nagios/nrpe-4.0.2/src/./nrpe.c:474: undefined reference to `get_dh2048'
collect2: error: ld returned 1 exit status make[1]: *** [Makefile:48: nrpe] Error 1
make[1]: Leaving directory '/root/nagios/nrpe-4.0.2/src' make: *** [Makefile:65: all] Error 2
# ./configure --disable-ssl
# make all

Next, install the NRPE plugin daemon, and sample config files.

# make install-plugin
# make install-daemon
# make install-config
# make install-init

Verify NRPE Daemon Remotely

Ensure the check_nrpe plugin can connect to the NRPE daemon on the remote Linux host. Replace the IP address in the command with the remote host’s IP. My remote IP is 192.168.1.7

# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.7

Adding Remote Linux Host to Nagios Monitoring Server Creating Nagios Host and Services File

# cd /usr/local/nagios/etc
# touch hosts.cfg
# touch services.cfg
# vim nagios.cfg
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg

Configuring Nagios Host and Services File

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

## Default Linux Host Template ##

define host{

name   linux-box           ; Name of this template

use        generic-host   ;

Inherit default values

check_period 24x7

check_interval               5

retry_interval  1

max_check_attempts               10

check_command        check-host-alive

notification_period     24x7

notification_interval  30

notification_options  d,r

contact_groups            admins

register               0             ; DONT REGISTER THIS - ITS A TEMPLATE

}

## Default

define host{

use        linux-box           ;

Inherit default values from a template

host_name      host.bitscentric.com

; The name we're giving to this server

alias     Rocky 8.10      ; A longer name for the server

address             192.168.1.7    ; IP address of Remote Linux host

}
# vim /usr/local/nagios/etc/services.cfg

define service{

use        generic-service

host_name      host.bitscentric.com service_description  CPU Load

check_command        check_nrpe!check_load

}

define service{

use        generic-service

host_name      host.bitscentric.com service_description  Total Processes

check_command        check_nrpe!check_total_procs

}

define service{

use        generic-service

host_name      host.bitscentric.com service_description  Current Users

check_command        check_nrpe!check_users

}

define service{

use        generic-service

host_name      host.bitscentric.com service_description  SSH Monitoring

check_command        check_nrpe!check_ssh

}

define service{

use        generic-service

host_name      host.bitscentric.com service_description  FTP Monitoring

check_command        check_nrpe!check_ftp

}

Configuring NRPE Command Definition

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

############################################################### ################

# NRPE CHECK COMMAND #

# Command to use NRPE to check remote host systems

############################################################### ################

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c

$ARG1$

}

Finally, verify Nagios Configuration files for any errors.

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# systemctl restart nagios.service
# systemctl status nagios.service

Monitoring Remote Linux in Nagios

Access the Nagios web interface by visiting http://Your-server-IP-

address/nagios or http://FQDN/nagios. Log in with the username

nagiosadmin and the password, then verify that the remote Linux host is successfully added and monitored.

Check host of remote server

Leave a Reply

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