HOW TO ADD LINUX HOST TO NAGIOS MONITORING SERVER USING NRPE PLUGIN

HOW TO ADD LINUX HOST TO NAGIOS MONITORING SERVER USING NRPE PLUGIN

In this video, I will show you how to add remote Linux client host and it’s services to Nagios Monitoring Server using NRPE agent.
In my previous video, I demonstrated how to install Nagios server on Centos7. I hope you already have installed Nagios server.
The NRPE is stands for Nagios Remote Plugin Executor. As its says by the name, NRPE allows Nagios server to discover client host resources and their services through the network.

REMOTE CLEINT SIDE CONFIGURATION:

A. INSTALL PREREQUISITES
We need to install required libraries.
[root@cl1 ~]# yum install -y gcc glibc glibc-common openssl openssl-devel perl wget
B. INSTALL LATEST EPEL REPOSITORY AND UPDATE THE SYSTEM.
Install Latest EPEL YUM Repository
[root@cl1 ~]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

[root@cl1 ~]# rpm -Uvh epel-release-latest-7.noarch.rpm

[root@cl1 ~]# yum -y update
C. INSTALL (NRPE V3) NAGIOS REMOTE PLUGIN EXECUTOR
[root@cl1 ~]# yum -y install nrpe
D. UPDATE NRPE CONFIGURATION FILE
Add the private IP address of the Nagios server
**allowed_hosts=**
[root@cl1 ~]# vim /etc/nagios/nrpe.cfg
allowed_hosts=127.0.0.1,172.25.10.50
E. ALLOW NRPE SERVICE PORT THROUGH THE FIREWALL
Allow TCP port 5666 through the firewall to be able to listening through the TCP port 5666
[root@cl1 ~]# firewall-cmd --permanent --add-port=5666/tcp
[root@cl1 ~]# firewall-cmd --reload
F. ENABLE NRPE SERVICE TO START AT BOOT
[root@cl1 ~]# systemctl enable nrpe.service
[root@cl1 ~]# systemctl restart nrpe.service
[root@cl1 ~]# systemctl status -l  nrpe.service

NAGIOS SERVER SIDE CONFIGURATION:

A. CREATE CONFIG A DIRECTORY
Create a directory that will store the configuration files for each server that you will need to monitor.
[root@nagios ~]# sudo mkdir /usr/local/nagios/etc/hosts
B. CREATE HOST DEFINITION FILE
Create a new configuration file for each of the remote hosts that we want to monitor.
In this case I’m going to put all the host and service definitions into a single file.
[root@nagios ~]# vim /usr/local/nagios/etc/hosts/cl1.cfg
# Host configuration file
define host {
        use                          linux-server
        host_name                    cl1
        alias                        Ubuntu Host
        address                      172.25.10.100
        register                     1
}

define service {
      host_name                       cl1
      service_description             PING
      check_command                   check_ping!100.0,20%!500.0,60%
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
}

define service {
      host_name                       cl1
      service_description             PING
      check_command                   check_ping!100.0,20%!500.0,60%
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       cl1
      service_description             Check Users
      check_command           check_local_users!20!50
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       cl1
      service_description             Local Disk
      check_command                   check_local_disk!20%!10%!/
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       cl1
      service_description             Check SSH
      check_command                   check_ssh
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       cl1
      service_description             Total Process
      check_command                   check_local_procs!250!400!RSZDT
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       cl1
      service_description             DNS
      check_command                   check_dns
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}
C. MODIFY NAGIOS MAIN CONFIG
Then, Add “cl1.cfg” config file path into Nagios main configuration file.
[root@nagios ~]# vim /usr/local/nagios/etc/nagios.cfg
# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/hosts/cl1.cfg
D. DEFINE NEW COMMANDS
Edit the file commands.cfg and add the lines below.
Add this command definition config into the bottom of the “commands.cfg” file.
In this case, I’m going to add “check_dns” command into the “commands.cfg” as a new service check command.
[root@nagios ~]# vim /usr/local/nagios/etc/objects/commands.cfg
Here, You can define your own commands that you want to execute on the remote host.
You can add and modify new command definitions by editing this section.
#'check_dns' command definition
define command {
        command_name    check_dns
        command_line       $USER1$/check_dns -H $HOSTADDRESS$ -s $ARG1$ 
}
OR
#'check_dns' command definition
define command {
        command_name    check_dns
        command_line    $USER1$/check_dns -H digitalave.github.io -s 8.8.8.8 -t 15 | sed  -e "s/returns.*//g" 
}
E. VERIFY NRPE DAEMON
Finally verify the configuration that we made.
/usr/local/nagios/libexec/check_nrpe -H <remote_linux_ip_address>
F. VERIFY NAGIOS CONFIGS AND CHECK FOR ERROR
[root@nagios ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Now restart Nagios server to reflect the configuration changes.
[root@nagios ~]# systemctl restart nagios httpd
G. LOG INTO NAGIOS WEB CONSOLE

Comments