How to Add Linux Host to Nagios Monitoring Server

In the first article, we have explained how to install and configure Nagios core on Amazon Linux Server. In this blog, we will show you how to add Linux host to Nagios monitoring server using nrpe plugin. Assuming you have already installed Nagios Server and running properly, if not please check Step By Step method for installing Nagios in Amazon Linux Once you have setup/installed Nagios Monitoring Server. Now you are ready to add remote Linux host for monitoring. Steps on Remote Linux Host which you want to monitor in Nagios monitoring server.

Install NRPE Add-on and Nagios Plugins on remote Linux host:

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum install -y nrpe nagios-plugins-all

Add Nagios servers IP address, separated by a comma as mention below.

vim /etc/nagios/nrpe.cfg                         
allowed_hosts=127.0.0.1,Nagios_Server_IP

Configure Nagios Monitoring Checks:

How to monitor CPU usage, disk usage and total process in Nagios monitoring server. In this example, we will monitor Root Partition, Another disk usage like /mnt (additional disk), CPU load, User logged in, Total processes Login to your Linux host and edit nrpe.cfg file

vi /etc/nagios/nrpe.cfg
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_disk]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
command[check_mnt_disk]=/usr/lib64/nagios/plugins/check_mnt_disk -w 20% -c 10% -p /dev/xvdf
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200

#Note: In the above command definition -w stands for warning and -c stands for critical

Verify Nagios plugin:

/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
Output 
PROCS WARNING: 190 processes | procs=190;150;200;0;

Command to start nrpe service on Linux host:

service nrpe start/restart/stop

Auto start nrpe service after reboot on Linux host:

chkconfig nrpe on

Steps to be done on Nagios Monitoring Server Login to your Nagios Monitoring Server.

Steps to Install NRPE Plugins on Nagios Server

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum install -y nrpe nagios-plugins-all

Verify NRPE plugins can communicate with your remote Linux host

/usr/lib64/nagios/plugins/check_nrpe -H 
---Output----
NRPE v2.15

You will get output with NRPE version which is installed on a remote Linux host Tip:

  • Make sure your firewall allows the communication between remote Linux host and Nagios monitoring host (vice versa)
  • Check NRPE plugins installed properly with all dependency

How to add remote Linux host to Nagios Monitoring Server

Login to your Nagios monitoring server

Step 1: Uncomment below the line in “nagios.cfg” file

Here we specify the location of all your remote host file.

vi /usr/local/nagios/etc/nagios.cfg
...
#Uncomment below the line
cfg_dir=/usr/local/nagios/etc/servers
...

Step 2:  Update/Add host definition in “templates.cfg”

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

# Linux host definition template - This is NOT a real host, just a template!
define host{
name                            linux-server    ; The name of this host template
use                             generic-host    ; This template inherits other values from the generic-host template
check_period                    24x7            ; By default, Linux hosts are checked round the clock
check_interval                  5               ; Actively check the host every 5 minutes
retry_interval                  1               ; Schedule host check retries at 1 minute intervals
max_check_attempts              10              ; Check each Linux host 10 times (max)
check_command                   check-host-alive ; Default command to check Linux hosts
notification_period             workhours       ; Linux admins hate to be woken up, so we only notify during the day
; Note that the notification_period variable is being overridden from
; the value that is inherited from the generic-host template!
notification_interval           120             ; Resend notifications every 2 hours
notification_options            d,u,r           ; Only send notifications for specific host states
contact_groups                  admins          ; Notifications get sent to the admins by default
register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}

# Local service definition template - This is NOT a real service, just a template!
define service{
name                            local-service           ; The name of this service template
use                             generic-service         ; Inherit default values from the generic-service definition
max_check_attempts              4                       ; Re-check the service up to 4 times in order to determine its final (hard) state
check_interval                  10                      ; Check the service every 5 minutes under normal conditions
retry_interval                  1                       ; Re-check the service every minute until a hard state can be determined
register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
notification_interval           60
notification_period             24x7
notification_options            c,u,r,w
contact_groups                  admins
}

Step 3: Create service file in “/usr/local/nagios/etc/servers/” and add below lines in that.

Eg: Monitor Linux host with CPU load, Users, process, disk usage.

define host{
use                     linux-server
host_name               enter-your-host-name
alias                   enter-your-host-name
address                 IP-address
hostgroups              LinuxServers
}

define service{
use                             local-service
host_name                       enter-your-host-name
service_description             Root / Partition
check_command                   check_nrpe!check_disk
}

define service{
use                             local-service
host_name                       enter-your-host-name
service_description             /mnt Partition
check_command                   check_nrpe!check_mnt_disk
}

define service{
use                             local-service
host_name                       enter-your-host-name
service_description             Current Users
check_command                   check_nrpe!check_users
}

define service{
use                             local-service
host_name                       enter-your-host-name
service_description             Total Processes
check_command                   check_nrpe!check_total_procs
}

define service{
use                             local-service
host_name                       enter-your-host-name
service_description             Current Load
check_command                   check_nrpe!check_load
}

NRPE Command definition needs to add in “command.cfg” file

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

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

Now test/verify Nagios configuration file for any errors in Nagios Server:

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

Total Warnings: 0
Total Errors:   0

Now reload your Nagios configuration.

Commands to restart or reload Nagios service

service nagios reload
Or
service nagios restart

From all these steps you have added a remote Linux host in the Nagios monitoring server. Now goto Nagios monitoring web interface at http://<ipaddress>/nagios and provide username and password and check now the Linux host added, and it is monitoring in Nagios Monitoring Server. This is how to add a Linux host to Nagios monitoring server using nrpe plugin.

Read this also:

Simple Steps for Installing Munin Monitoring Tool

Steps to install Nagios in Amazon linux

Add remote server in Nagios