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


Introduction

Nagios is an open-source monitoring system that helps system administrators to monitor the performance and availability of various network resources, including hosts, services, and network devices. It is an efficient tool that allows monitoring and notification for a wide range of devices and services in the network.

NRPE (Nagios Remote Plugin Executor) is a plugin that is used to monitor remote hosts or devices from the Nagios server. In this article, we will discuss how to add a Linux host to the Nagios monitoring server using the NRPE plugin.

Prerequisites

Before we begin, there are some prerequisites that need to be met. Firstly, you must have Nagios installed and configured on the monitoring server. Secondly, you must have a Linux machine to monitor, and it should have the NRPE plugin installed on it. Lastly, you should have root access to both the Nagios monitoring server and the Linux host you want to monitor.

Step 1: Installing the NRPE Plugin on the Linux Host

The first step is to install the NRPE plugin on the Linux host you want to monitor. You can use the package manager of your Linux distribution to install the NRPE plugin.

For example, if you are using Ubuntu, you can install the NRPE plugin by running the following command −

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

Once the installation is complete, you need to configure the NRPE plugin.

Step 2: Configuring the NRPE Plugin on the Linux Host

After installing the NRPE plugin, the next step is to configure it on the Linux host. The configuration file for NRPE is located at /etc/nagios/nrpe.cfg.

You need to open the configuration file and modify it to allow the Nagios monitoring server to monitor the Linux host. You can use any text editor to open the file, such as vi, nano, or gedit.

Here is an example of the configuration file with the necessary changes −

# allowed_hosts=127.0.0.1

allowed_hosts=127.0.0.1, Nagios-Server-IP

command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1

In the above configuration file, we have modified the allowed_hosts parameter to include the IP address of the Nagios monitoring server. We have also defined some commands that Nagios will use to monitor the Linux host. In this example, we are monitoring the number of users, system load, and disk usage.

Step 3: Restarting the NRPE Service

After modifying the configuration file, you need to restart the NRPE service for the changes to take effect. You can use the following command to restart the NRPE service −

sudo systemctl restart nagios-nrpe-server

Step 4: Adding the Linux Host to Nagios Monitoring Server

Now that the NRPE plugin is installed and configured on the Linux host, you need to add the host to the Nagios monitoring server.

To do this, you need to modify the Nagios configuration file, which is located at /usr/local/nagios/etc/objects/hosts.cfg.

Here is an example of how to add a Linux host to Nagios −

define host{
   use                     linux-server
   host_name               linux-host
   alias                   Linux Host
   address                 Linux-Host-IP
}

In the above example, we have defined a host named "linux-host" with an alias of "Linux Host". We have also specified the IP address of the Linux host.

The "use" parameter refers to the host template that Nagios will use to monitor the host. You can create your own host template or use one of the predefined templates.

Step 5: Defining Service Checks for the Linux Host

After adding the Linux host to Nagios, the next step is to define service checks for the host. Service checks are commands that Nagios uses to monitor a specific aspect of the host or service.

To define service checks for the Linux host, you need to modify the Nagios configuration file, which is located at /usr/local/nagios/etc/objects/services.cfg.

Here is an example of how to define service checks for the Linux host −

define service{
   use                     generic-service
   host_name               linux-host
   service_description     Current Users
   check_command           check_nrpe!check_users
}
define service{
   use                     generic-service
   host_name               linux-host
   service_description     Current Load
   check_command           check_nrpe!check_load
}

define service{
   use                     generic-service
   host_name               linux-host
   service_description     Disk Space
   check_command           check_nrpe!check_hda1
}

In the above example, we have defined three service checks for the Linux host. The "use" parameter refers to the service template that Nagios will use to monitor the service. We have specified the host name, service description, and check command for each service.

Step 6: Restarting the Nagios Service

After defining the service checks, you need to restart the Nagios service for the changes to take effect. You can use the following command to restart the Nagios service −

sudo systemctl restart nagios

Step 7: Checking the Monitoring Results

After adding the Linux host to Nagios and defining the service checks, you can check the monitoring results on the Nagios web interface.

To access the Nagios web interface, open a web browser and enter the IP address of the Nagios monitoring server followed by /nagios. For example, http://Nagios-Server-IP/nagios.

On the Nagios web interface, you can view the status of the Linux host and the services that are being monitored. You can also configure notifications and alerts for when a service or host goes down or reaches a certain threshold.

There are a few additional considerations to keep in mind when setting up NRPE on your Linux host and Nagios monitoring server.

Security

When configuring NRPE on your Linux host, it is essential to consider security. By default, NRPE listens on port 5666, which can be a security risk if left open to the public internet.

To secure your NRPE service, you can configure your firewall to allow only the Nagios monitoring server's IP address to access port 5666. You can also configure NRPE to use SSL/TLS encryption to secure the communication between the Linux host and Nagios server.

Performance

When defining service checks for your Linux host, it is essential to consider the performance impact of each check. If you have too many service checks, it can result in high CPU usage and slow down the Linux host's performance.

To avoid this issue, you can prioritize the most critical service checks and reduce the frequency of less important checks. You can also configure Nagios to use passive checks, where the Linux host sends the monitoring data to the Nagios server, reducing the load on the host.

Debugging

If you encounter issues with NRPE or Nagios, it is essential to have a method for debugging the problem. You can enable debug mode in the NRPE configuration file by setting debug=1. This will provide detailed logging information that can help you identify the issue.

You can also use the Nagios plugin "check_nrpe" to test the NRPE service on your Linux host from the Nagios monitoring server. For example, you can run the following command on your Nagios server to test the "check_users" service check −

check_nrpe -H Linux-Host-IP -c check_users

This command will execute the "check_users" command on the Linux host and return the monitoring results to the Nagios server.

Conclusion

In this article, we have discussed how to add a Linux host to the Nagios monitoring server using the NRPE plugin. We have covered the steps required to install and configure the NRPE plugin on the Linux host, add the host to Nagios, define service checks, and check the monitoring results on the Nagios web interface.

By following these steps, you can efficiently monitor your Linux hosts and services using Nagios, ensuring the availability and performance of your network resources.

Updated on: 28-Apr-2023

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements