How To Monitor Remote Linux Systems With Nagios Monitoring Tool

0

In the last article, we discussed the installation of Nagios server on CentOS 7, Ubuntu 16.04, and Debian 9. Here, in this post, we will add Linux host to Nagios Monitoring tool using NRPE plugin.

I’m assuming that you have a working Nagios setup, if not, use any one of the below links and setup Nagios server.

READ: How to Install and Configure Nagios 4.4.x on CentOS 7 / RHEL 7

READ: Install and Configure Nagios 4.4.x on Ubuntu 18.04 & Ubuntu 16.04

READ: How to Install and Configure Nagios 4.4.x on Debian 9

NRPE Plugin

Nagios Remote Plugin Executor (abbreviated as NRPE) plugin allows you to monitor applications and services running on remote Linux / Windows hosts. This NRPE Add-on helps Nagios to monitor local resources like CPU, Memory, Disk, Swap, etc. of the remote host.

On Remote Linux System

Switch to the root user.

sudo su -

Install NRPE Add-on & Nagios Plugins

NRPE and Nagios plugins are not available in the base repository of CentOS 7. So, you need configure EPEL repository on CentOS 7.

READ: How To Configure EPEL Repository On CentOS 7/ RHEL 7

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Use the following command to install NRPE Add-on and Nagios plugins.

### CentOS 7 / RHEL 7 ###

yum install -y nrpe nagios-plugins-all

### Ubuntu 18.04 / 16.04 & Debian 9 ###

apt update
apt install -y nagios-nrpe-server nagios-plugins

Configure NRPE Add-on

Modify the NRPE configuration file to accept the connection from the Nagios server, Edit the /etc/nagios/nrpe.cfg file.

vi /etc/nagios/nrpe.cfg

Add the Nagios servers IP address, separated by comma like below.

allowed_hosts=192.168.1.10

Configure Nagios Checks

The /etc/nagios/nrpe.cfg file contains the basic commands to check the attributes (CPU, Memory, Disk, etc.architecure) and services (HTTP, FTP, etc.) on remote hosts. Below command lines let you monitor attributes with the help of Nagios plugins.

The path to Nagios plugins may change depends on your operating system architecture (i386 or x86_64).

CentOS 7 / RHEL 7

command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_root]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/centos-root
command[check_swap]=/usr/lib64/nagios/plugins/check_swap -w 20% -c 10%
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200

Ubuntu 18.04 / Ubuntu 16.04 & Debian 9

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_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/server--vg-root
command[check_swap]=/usr/lib/nagios/plugins/check_swap -w 20% -c 10%
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
In the above command definition -w stands for warning and -c stands for critical.

Test Nagios Checks

For example, execute the below command in another terminal to see the check result.

Tested on Ubuntu 18.04:

/usr/lib/nagios/plugins/check_procs -w 150 -c 200

Output:

PROCS WARNING: 190 processes | procs=190;150;200;0;

Nagios plugin will count running processes and will warn you when the process count is more than 150, or it will report you critical when the process count is more than 200, and at the same time, the output will state OK if the count is below 150.

You can adjust the alert level as per your requirements. Change warning to 200 and critical to 250 for testing purpose. Now you can see an OK message.

/usr/lib/nagios/plugins/check_procs -w 200 -c 250

Output:

PROCS OK: 189 processes | procs=189;200;250;0;

These command definitions have to be entered on template file on the Nagios server host to enable the monitoring.

Restart the NRPE service.

### CentOS 7 / RHEL 7 ###

systemctl start nrpe
systemctl enable nrpe

### Ubuntu 18.04 / 18.04 & Debian 9 ### 

systemctl restart nagios-nrpe-server

On Nagios Server

NRPE and Nagios plugins are not available in the base repository of CentOS 7. So, you need configure EPEL repository on CentOS 7.

READ: How To Configure EPEL Repository On CentOS 7/ RHEL 7

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install NRPE plugin

Use the following command to install the check_nrpe plugin on your machine.

### CentOS 7 / RHEL 7 ###

yum -y install nagios-plugins-nrpe

### Ubuntu 18.04 / 16.04 & Debian 9 ###

apt -y install nagios-nrpe-plugin

Edit the Nagios configuration file to include all .cfg files inside the /usr/local/nagios/etc/servers directory.

vi /usr/local/nagios/etc/nagios.cfg

Add or uncomment the following line.

cfg_dir=/usr/local/nagios/etc/servers

Create a configuration directory.

mkdir /usr/local/nagios/etc/servers

Configure Nagios Server

Now it’s time to configure the Nagios server to monitor the remote client machine, and You’ll need to create a command definition in Nagios object configuration file to use the check_nrpe plugin. Open the commands.cfg file.

vi /usr/local/nagios/etc/objects/commands.cfg

Add the following Nagios command definition to the file.

### CentOS 7 / RHEL 7 ###

# .check_nrpe. command definition
define command{
command_name check_nrpe
command_line /usr/lib64/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$
}

### Ubuntu 18.04 / 16.04 & Debian 9 ###

# .check_nrpe. command definition
define command{
command_name check_nrpe
command_line /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$
}

Add a Linux host to Nagios server

Create a client configuration file /usr/local/nagios/etc/servers/client.itzgeek.local.cfg to define the host and service definitions of remote Linux host.

vi /usr/local/nagios/etc/servers/client.itzgeek.local.cfg

Copy the below content to the above file.

You can also use the following template and modify it according to your requirement. The following template is for monitoring logged in users, system load, disk usage (/ – partitions), swap, and total process.

define host{
                           
            use                     linux-server            
            host_name               client.itzgeek.local            
            alias                   client.itzgeek.local            
            address                 192.168.1.20
                                    
}                                   
                                    
define hostgroup{                   
                                    
            hostgroup_name          linux-server            
            alias                   Linux Servers            
            members                 client.itzgeek.local
}                                   
                                    
define service{                     
                                    
            use                     local-service            
            host_name               client.itzgeek.local            
            service_description     SWAP Uasge            
            check_command           check_nrpe!check_swap                          
                                    
}                                   
                                    
define service{                     
                                    
            use                     local-service            
            host_name               client.itzgeek.local            
            service_description     Root / Partition            
            check_command           check_nrpe!check_root                          
                                    
}                                   
                                    
define service{                     
                                    
            use                     local-service            
            host_name               client.itzgeek.local            
            service_description     Current Users            
            check_command           check_nrpe!check_users                         
                                    
}                                   
                                    
define service{                     
                                    
            use                     local-service            
            host_name               client.itzgeek.local            
            service_description     Total Processes            
            check_command           check_nrpe!check_total_procs                   
                                    
}                                   
                                    
define service{                     
                                    
            use                     local-service            
            host_name               client.itzgeek.local            
            service_description     Current Load            
            check_command           check_nrpe!check_load

}

Verify Nagios for any errors.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Restart the Nagios server.

systemctl restart nagios

Firewall

Configure the firewall so that the Nagios server can able to reach NRPE server running on remote Linux host. Run these commands on remote Linux machine.

FirewallD

firewall-cmd --permanent --add-port=5666/tcp
firewall-cmd --reload

UFW

ufw allow 5666/tcp
ufw reload
ufw enable

Monitor the remote machine

Go and check the Nagios web interface to view the new services we added just now.

Monitor Remote Linux Systems With Nagios - Hosts List
Monitor Remote Linux Systems With Nagios – Hosts List

Within a minute, you should start seeing status in services page.

Monitor Remote Linux Systems With Nagios - Monitor Services
Monitor Remote Linux Systems With Nagios – Monitor Services

That’s All.

You might also like