Nagios Remote Plugin Executor (NRPE) is used to remotely execute Nagios plugins on Linux/Unix machines. This makes it easy to monitor remote machine metrics such as disk usage, CPU load, number of running processes, logged in users etc.
In this tutorial, we are going to learn how to install and configure NRPE from source for use with Nagios Server. You may also want to check our previous article on how to configure Nagios Aviailability monitoring on AlienVault USM/OSSIM.
As a prerequisite, ensure that the C compilers and sare installed on the server since we are compiling NRPE from the source code;
yum install -y gcc glibc glibc-common openssl openssl-devel
Download NRPE Source File
Run the command below to download NRPE source file under the /tmp directory.
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz -P /tmp/
Extract NRPE Source File
Once the download is complete, navigate to the download directory and run the command below to extract the source file.
cd /tmp tar zxvf nrpe-3.2.1.tar.gz
In order to compile NRPE package, you first need to set all the options and dependencies required for the rest of the build and install process.
Run the command below to configure NRPE program;
cd nrpe-3.2.1 ./configure --enable-command-args --with-nrpe-user=nagios --with-nrpe-group=nagios
- –enable-command-args options enables you to pass arguments through NRPE. If omitted, then the arguments have to be explicitly set on the nrpe configuration file, nrpe.cfg.
- –with-nrpe-user=nagios –with-nrpe-group=nagios sets the ownership of the configuration files.
If for some reason you encounter an issue during compilation regarding openssl, run thw compilation with –disable-ssl option.
If the compilation is successful, you should see the sample output below.
...output snipped... *** Configuration summary for nrpe 3.2.1 2017-09-01 ***: General Options: ------------------------- NRPE port: 5666 NRPE user: nagios NRPE group: nagios Nagios user: nagios Nagios group: nagios Review the options above for accuracy. If they look okay, type 'make all' to compile the NRPE daemon and client or type 'make' to get a list of make options.
Create User And Group
The ownership of the configuration files is set to nagios:nagios above . You therefore need to create the nagios user and group.
To confirm that the user and the group is actually created, run id command
id nagios uid=993(nagios) gid=993(nagios) groups=993(nagios)
If the above compilation options are fine, run the command below to compile the NRPE daemon and client.
Once the compilation process is done, continue to install NRPE Daemon and the check_nrpe plugin.
Install NRPE Configuration File and Service
Run the following commands to install NRPE sample configuration file as well as the NRPE service.
make install-config make install-init
Define NRPE Service, Port and Protocol
Edit the service configuration file and map the nrpe service to its specific port and protocol, 5666/tcp by adding the following line at the bottom.
vim /etc/services ... nrpe 5666/tcp # NRPE Service
Allow NRPE through firewall
NRPE uses port TCP 5666 by default. If firewall is running, open this port.
firewall-cmd --add-port=5666/tcp --permanent firewall-cmd --reload
iptables -I INPUT -p tcp --dport 5666 -j ACCEPT iptables-save > /etc/sysconfig/iptables
Start and Enable NRPE
Run the commands below to start and enable nrpe to run on system boot.
systemctl start nrpe systemctl enable nrpe
You can check the status of NRPE agent as shown below;
systemctl status nrpe ● nrpe.service - Nagios Remote Plugin Executor Loaded: loaded (/usr/lib/systemd/system/nrpe.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2018-12-05 16:38:25 EAT; 7s ago Docs: http://www.nagios.org/documentation Main PID: 24778 (nrpe) CGroup: /system.slice/nrpe.service └─24778 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -f
Verify that NRPE port 5666 is open;
ss -altn | grep 5666 LISTEN 0 5 *:5666 *:* LISTEN 0 5 :::5666 :::*
Install Nagios Plugins
In order to monitor various services, NRPE utilizes nagios plugins. Therefore you need to install Nagios Plugins before you can proceed to cofigure NRPE. You can check our previous article on how to install Nagios plugins.
Once the Nagios plugins are installed, update NRPE configuration file. When installed from source, the configuration file will reside under, /usr/local/nagios/etc/nrpe.cfg, although this can be changed.
Therefore, edit the file and make the following changes.
You may want to define a different IP address on which the service will listen on instead of the loopback. You can do so by changing the following line replacing loopback address with your interface IP address..
... server_address=127.0.0.1 ...
Under allowed hosts, replace the loopback6 address with Nagios Server IP such that the line looks like:
Replace the dont_blame_nrpe=0 setting with dont_blame_nrpe=1 to allow command arguments.
Next, you need to define the commands that will used to check for various system services. Note that these commands relies on the Nagios plugins installed above. You may comment out the existing commands and define your own, for example;
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10 command[check_load]=/usr/local/nagios/libexec/check_load -r -w 8.0,7.5,7.0 -c 11.0,10.0,9.0 command[check_disk]=/usr/local/nagios/libexec/check_disk -w 15% -c 10% / command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 300 -c 400 command[check_swap]=/usr/local/nagios/libexec/check_swap -w 10 -c 5
Save the configuration file once done editing and restrt NRPE service.
systemctl restart nrpe
Test the Plugins
Once you are done with installing the nagios plugins and configuring NRPE, execute the commands below to if all is well.
Check the version of installed NRPE;
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 NRPE v3.2.1
Check for running processes;
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_total_procs PROCS OK: 114 processes | procs=114;300;400;0;
Check for logged in users;
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_users USERS OK - 2 users currently logged in |users=2;5;10;0
Perfect, you are all set and good to go. That is all about configuring NRPE plugins. We hope this was informative.
For other Related guides, see the links below;