So I made a mistake today, and because of it I needed to do a quick search of how to do something.  Because of that mistake, I am now showing you how to install NRPE in Ubuntu 18.04.

What is NRPE?

Nagios Remote Plugin Executor (NRPE) is a Nagios agent that allows remote system monitoring using scripts that are hosted on the remote systems. It allows for monitoring of resources such as disk usage, system load or the number of users currently logged in.Nagios Wiki

In plain English, NRPE is something you install on a client machine which you want to monitor.  You can monitor any number of resources, services, storage space, sensors, and more.  Nagios Core can connect to NRPE, and in turn receive responses to tests and checks run on the client machine.  Because of this, it makes for a very extensible monitoring platform tool.

Nagios with NRPE

Prerequisites

  • Running Ubuntu (Tested with 18.04, ymmv)
  • sudo privileges.  (Unmanaged VPS accounts typically run root (unless you set it up right!), while managed shared hosting environments or managed VPS accounts tend to use sudo users)
  • It is highly recommended to do this on a system that has not been modified, as other packages may cause conflicts.  This will always work with a fresh / vanilla install.

Step 1 - Install NRPE on Ubuntu

NRPE is available on Ubuntu without the need for another repository.  You can install NRPE by issuing the following commands:

sudo apt-get update

sudo apt-get install nagios-nrpe-server nagios-plugins

This will first update anything that may need to be, followed by installing the NRPE server and plugins.

Step 2 - Configure NRPE

Once you have installed NRPE, you will then need to configure it so it can communicate with your Nagios Core server.  Edit the file /etc/nagios/nrpe.cfg and edit the line that says:
allowed_hosts=127.0.0.1
and change it to:
allowed_hosts=127.0.0.1,XX.XX.XX.XX
where XX.XX.XX.XX is your Nagios Core Server IP address.  If you have more than one server, place each IP address after 127.0.0.1 in a comma separated list.

Once you have finished configuring NRPE, you will need to restart the services.  To do so, issue the following:

sudo /etc/init.d/nagios-nrpe-server restart

Step 3 - Configure Nagios Core Server

Now that NRPE is configured, you can setup the Nagios Core Server to communicate with NRPE.  To do so, start by logging into your Nagios Core Server.

Locate the plugins directory for Nagios, and use the check_nrpe command.  To do so, issue the following check:

check_nrpe -H YY.YY.YY.YY
where YY.YY.YY.YY is the IP address of the client machine you installed NRPE on. If you configured everything correctly, you will see something similar to NRPE v2.15 If you see something different, check that your firewall is allowing port 5666 from the Nagios Core Server IP.  While you can allow anyone to access the port, and it would likely be safeish, it's just as easy to only allow the single IP address.

Step 4 - Add Checks to NRPE

Since you installed NRPE from a repository, all of the service check commands that you got from the nagios plugins package will be located in /usr/[lib|lib64]/nagios/plugins/ depending on 32bit or 64bit.

Edit the configuration for NRPE to add the checks you need.  To do this, edit the file located at /etc/nagios/nrpe.cfg and scroll toward the bottom. Around line 300, you see the predefined commands

command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -r -w .15,.10,.05 -c .30,.25,.20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200

Typically, I change the check_hda1 to check_root and the end from /dev/hda1 to /

The end result being:
command[check_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /

What this does is tells NRPE to use the command "check_root" to check the partition associated with /

Save and exit the file.

Step 5 - Restart NRPE

Once you complete the configuration changes to NRPE, restart the service as follows:

sudo /etc/init.d/nagios-nrpe-server restart

[ ok ] Restarting nagios-nrpe-server (via systemctl): nagios-nrpe-server.service.

Remember, any time you change the configuration you will need to restart NRPE.

Enjoy!