ArticlesRocky Linux

Installing the NRPE Plugin for Nagios Core on Rocky Linux

Introduction

The Nagios Remote Plugin Executor (NRPE) plugin is fundamental when combined with Nagios for adequate monitoring and provides you with system metrics including CPU, memory, disk usage and more from your Linux and Windows fleet.

This article will detail how to setup a basic Nagios Core server-client environment on Rocky Linux 9.5, how to install the NRPE plugin, and provide example NRPE commands with which to check the status of your Nagios clients.

Prerequisites

  • Two baremetal or virtual nodes running Rocky Linux 9.5, with at a minimal of 1 vCPU, 512MB RAM, and 500MB of disk space. The recommendation for Rocky Linux is 4 vCPU cores, 4096MB RAM and 10GB of disk space.

  • Access to either the root account or a user with sudo privileges.

Nagios Core server configuration

Initial setup

  • To install the latest version of Nagios Core Server, it is recommended to build directly from source, as opposed to downloading the packages from the EPEL repository.

  • Upgrade all packages:

dnf upgrade -y
  • Reboot the server:
reboot
  • Install the required packages for Nagios:
dnf install -y gcc gd gd-devel glibc glibc-common httpd perl php openssl-devel wget
  • Install the Development Tools group to aid with the source compilation process:
dnf groupinstall -y "Development Tools"
  • Switch to the tmp directory:
cd /tmp
  • Pull down the latest Nagios Core source code:
wget --output-document="nagioscore.tar.gz" $(wget -q -O - https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest  | grep '"browser_download_url":' | grep -o 'https://[^"]*')
  • Extract the tarball:
tar xzf nagioscore.tar.gz
  • Change into the nagios directory (in this example, the version is 4.5.9):
cd /tmp/nagios-4.5.9/
  • Run configure to make sure all required dependencies are available:
./configure
  • Run make all to compile the source code:
make all
  • Generate the nagios user and group:
make install-groups-users
  • Add the apache user that was generated from the previous dnf package installs into the nagios group:
usermod -a -G nagios apache
  • Install the required binaries, CGIs and HTML files:
make install
  • Install the nagios daemon:
make install-daemoninit
  • Download the latest plugins pack:
wget --output-document="nagios-plugins.tar.gz" $(wget -q -O - https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest  | grep '"browser_download_url":' | grep -o 'https://[^"]*')
  • Unpack the tarball:
tar -xf nagios-plugins.tar.gz
  • Change into the plugins directory, in this case it is version 2.4.12:
cd nagios-plugins-2.4.12/
  • Check for dependencies:
./configure
  • Compile from source:
make
  • Install the plugins to the appropriate directories:
make install
  • Confirm the plugins were installed correctly. The number of plugins should be between 60~70:
ls -l /usr/local/nagios/libexec/ | wc -l
  • Set the httpd systemd service to restart on the next reboot:
systemctl enable httpd
  • Similarly, configure the nagios service to start on a reboot:
systemctl enable nagios
  • Setup Command Mode:
make install-commandmode
  • Install the required configuration files:
make install-config
  • Install the Apache web server files:
make install-webconf
  • Configure firewalld to allow traffic on TCP port 80:
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
  • Create the nagiosadmin account and set a password:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  • Start the httpd service:
systemctl start httpd
  • Start the nagios service:
systemctl start nagios

NRPE plugin installation

wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.1.3/nrpe-4.1.3.tar.gz
  • Extract the tarball:
tar -xf nrpe-4.1.3.tar.gz
  • Change into the nagios directory (in this case version 4.1.3):
cd nrpe-4.1.3/
  • Check for dependency issues:
./configure
  • Compile from source:
make all
  • Install the plugin daemon and sample config files:
make install-daemon
make install-init
make install-plugin

Nagios Core client configuration

Initial setup

  • Make sure all packages are up to date:
dnf upgrade -y
  • Reboot the client machine:
reboot
  • Install required packages:
dnf install -y automake autoconf gcc gd gd-devel gettext glibc glibc-common make net-snmp net-snmp-utils openssl-devel tar wget
  • Generate the nagios user and assign a password:
useradd nagios
passwd nagios
  • Change into the tmp directory:
cd /tmp
  • Download the plugins pack:
wget --output-document="nagios-plugins.tar.gz" $(wget -q -O - https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest  | grep '"browser_download_url":' | grep -o 'https://[^"]*')
  • Extract the tarball:
tar -xf nagios-plugins.tar.gz
  • Change into the plugins directory (in this case the version is 2.4.12):
cd nagios-plugins-2.4.12/
  • Check for dependency issues:
./configure
  • Compile from source:
make
  • Install the required packages:
make install
  • Ensure the plugins were installed correctly (there are usually 60~70 plugins available):
ls -l /usr/local/nagios/libexec/ | wc -l
  • Configure directory permissions for the nagios user:
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec

NRPE installation

  • Pull down the latest version of the NRPE plugin (as mentioned above, the current version is 4.1.3):
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.1.3/nrpe-4.1.3.tar.gz
  • Extract the tarball:
tar -xf ./nrpe-4.1.3.tar.gz
  • Change into the nagios directory:
cd nrpe-4.1.3/
  • Check for any dependency issues:
./configure
  • Compile the NRPE daemon and client:
make all
  • Install the plugin daemon and sample config files:
make install-config
make install-daemon
make install-plugin
  • Create a systemd service for the NRPE daemon:
make install-init
  • Enable the NRPE daemon systemd service to start on next boot:
systemctl enable nrpe
  • Configure the NRPE plugin configuration file at /usr/local/nagios/etc/nrpe.cfg and add the address of your Nagios server. In the example illustrated below, the Nagios server address is 192.168.1.11:
sed -i 's/allowed_hosts=127.0.0.1,::1/allowed_hosts=127.0.0.1,192.168.1.11/' /usr/local/nagios/etc/nrpe.cfg
  • Open TCP port 5666 in firewalld:
firewall-cmd --zone=public --add-port=5666/tcp --permanent
firewall-cmd --reload
  • Start the nrpe service:
systemctl start nrpe
  • Verify that NRPE was installed successfully:
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1

Commands to check metrics on a Nagios client from the server

  • In the following examples, the Nagios client has an IP of 192.168.1.12:

  • Initial check that the Nagios client can be reached:

/usr/local/nagios/libexec/check_nrpe -H 192.168.1.12
NRPE v4.1.3
  • Check the amount of logged-in users:
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.12 -c check_users
USERS OK - 1 users currently logged in |users=1;5;10;0
  • Check the load on the client system:
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.12 -c check_load
OK - load average per CPU: 0.00, 0.01, 0.01|load1=0.000;0.150;0.300;0; load5=0.007;0.100;0.250;0; load15=0.010;0.050;0.200;0;

Notes

  • The above configurations for server and client work on both FIPS and non-FIPS systems.

  • nagios logs are located under /usr/local/nagios/var/nagios.log.

  • Further logs and outputs can be found by running journalctl -exu nrpe and netstat -at | grep nrpe.

  • Make sure the latest plugins pack is installed. If not, you will observe NRPE: Unable to read output in your terminal, when running commands such as /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_load.

References & related articles (Optional)