
In our previous guide, we touched base on how to install the Nagios Monitoring Server on Ubuntu 20.04. For this second part, we will show you how to add a Ubuntu host to Nagios server for monitoring using NRPE plugin.
NRPE, short for Nagios Remote Plugin Executor, is an agent that allows remote execution of scripts located on the remote host. It allows the gathering of metrics such as system load, disk utilization, and uptime, etc.
NRPE Server (agent) and Plugins are installed on the remote host. The agent will wait for check_nrpe request from Nagios Core Server. Once the agent receives the check request it will execute a plugin on the remote host and send back the request to Nagios server.
Step 1: Install NRPE on Ubuntu
By default, Nagios only detects and monitors the server on which is it installed ( localhost ). To monitor a remote host, we must first install the NRPE packages on the remote host. For illustration purposes, we will use Ubuntu 20.04 as our remote host on our local network.
So log in to the remote host and first update the package index using apt command:
$ sudo apt update
Then run the following command to install the Nagios plugins and NRPE agent:
$ sudo apt install nagios-plugins nagios-nrpe-server
Once installed, verify the status of the NRPE agent using the following command:
$ sudo systemctl status nagios-nrpe-server

The output above confirms that the NRPE agent is up and running.
Step 2: Configure the NRPE agent
To monitor the remote target, we need to go a step further and make changes to the NRPE configuration file. So proceed and open the /etc/nagios/nrpe.cfg
file.
$ sudo vim /etc/nagios/nrpe.cfg
Locate the server_address
parameter and set it to the IP address of the Nagios host. In this case, the private IP of the remote host is '10.128.15.202'.

Next, locate the allowed_hosts
parameter which by default holds the value 127.0.0.1,0.0.0.0
.
Modify the second IP ( 0.0.0.0 ) to the IP address of your Nagios server. The Private IP of our Nagios Server is '10.128.15.204'

Save the changes and exit the configuration file. For the changes to take effect, be sure to restart the NRPE agent daemon
$ sudo systemctl restart nagios-nrpe-server
To check NRPE version run the following command on remote host:
$ sudo /usr/sbin/nrpe -V /etc/nagios/nrpe.cfg -f
Output:
NRPE - Nagios Remote Plugin Executor
Version: 4.0.0
You can verify the connection from Nagios server to remote use check_nrpe script, which is available on the Nagios core server.
Run the following check_nrpe script which under plugins directory to verify connection, type:
$ sudo check_nrpe -H remote-host-ip-address
Step 3: Add host to Nagios server
We are done with the configurations on the host side. The only thing remaining is to add the host on the Nagios monitoring server. But first, let's edit the Nagios configuration file.
$ sudo vim /usr/local/nagios/etc/nagios.cfg
Define the location of the Nagios host configuration directory by uncommenting the line below.
cfg_dir=/usr/local/nagios/etc/servers

Then proceed to make the directory in the path that you defined.
$ sudo mkdir -p /usr/local/nagios/etc/servers
And create the host's configuration file, in this case , host.cfg
file.
$ sudo vim /usr/local/nagios/etc/servers/host.cfg

Paste the content below. Replace the 'use', 'host_name' , 'alias' and 'address' values to match your remote host's values.
define host { use linux-server host_name ubuntu-host alias Apache server address 10.128.15.202 max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 }
Finally, restart Nagios service for the changes to take effect.
$ sudo systemctl restart nagios
Step 4: Configure the UFW firewall
Nagios NRPE agent listens to port 5666 by default. If you have UFW firewall running, you need to open this port both on the Nagios host and the server. Therefore run the following commands to achieve this.
$ sudo ufw allow 5666/tcp
$ sudo ufw reload
Then verify that the port has been allowed.
$ sudo ufw status

Lastly, ensure that all the configurations are sound using the command:
$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

So, head over to the Nagios dashboard, click on the 'Hosts' link on the left sidebar and you will notice that your host has been automatically detected and added to the Nagios server for monitoring.

You can click on the host selection to view additional details about the host.
Conclusion
In this tutorial, we learned how to add a Ubuntu host to Nagios Core server for monitoring. We would like to hear about your experience using these tools.