How to add Remote Linux Host on Nagios server to monitor

We have already covered in our previous article, Nagios installation on RPM based systems such as CentOS & RHEL and Nagios installation on DEB based systems such as Debian, Ubuntu & Mint, also refer Adding Nagios Remote Windows Host. For Monitoring Linux/Windows hosts in Nagios Server, you need to install NRPE & nagios-plugins in your remote Linux/Windows systems.

What is NRPE ?

NRPE stands for Nagios Remote Plugin Executor. NRPE allows you to remotely execute Nagios plugins on other Linux/Unix & windows machines. This allows you to monitor remote machine metrics (disk usage, CPU load, webserver usage, database server usage, etc…,).

What nagios-plugins doing ?

Nagios Plugins monitor hosts, devices, services, protocols, and applications with Nagios and give the report to NRPE. NRPE send those reports to Nagios server based on Nagios server request. So, Nagios & NRPE can perform all the process only with Nagios-plugins.

Two parts of installation is required to monitor the remote host in Nagios server.

  • Remote Host System : NRPE plugin & nagios-plugins
  • Nagios Server System : NRPE plugin

Part-1 : Host system configuration.

1) Prerequisites for Nagios

Make sure you should install LAMP stack and also install below dependency packages on your system before proceeding Nagios installation.

# CentOS/RHEL/Fedora systems (Use dnf instead of yum, if you are using Fedora 21 & later systems #
# yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel

# Ubuntu/LinuxMint/Debian systems #
$ sudo apt-get install build-essential php5-gd libgd2-xpm libgd2-xpm-dev libapache2-mod-php5 libperl-dev libssl-dev apache2-utils

2) Create Nagios User

Create new user account for nagios.

# useradd nagios
# passwd nagios

3) Download Nagios-Plugins & NRPE add-on

Navigate to /opt directory and download latest version of Nagios-Plugins & NRPE add-on.

# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

4) Compile and Install the Nagios-Plugins

Follow the below steps to Install latest nagios plugin in your system.

# tar -xzvf nagios-plugins-2.0.3.tar.gz
# cd nagios-plugins-2.0.3
# ./configure --with-nagios-user=nagios
# make
# make install
# chown nagios.nagios /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/libexec

5) Compile and Install the NRPE add-on

Follow the below steps to Install NRPE add-on in your system.

# tar -xzvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure
# make all
# make install-plugin

# Install NRPE daemon #
# make install-daemon

# Install NRPE daemon sample confi file #
# make install-daemon-config

# Install NRPE daemon as a service under xinetd (Note : Most of the system by defult installed with xineted) #
# make install-xinetd

6) Making changes in NRPE file

Make below changes in NRPE file and check NRPE service status. Adding Nagios server IP to NRPE file. Make sure, you need to add the Nagios server IP without comma, like below

# nano /etc/xinetd.d/nrpe

only_from = 127.0.0.1 

# Add NRPE port number to service file #
# nano /etc/services

nrpe 5666/tcp # NRPE

# Restart the xinetd service #
# service xinetd restart
# systemctl restart xinetd.service

# Check NRPE service status #
# netstat -at | grep nrpe
tcp        0      0 *:nrpe                      *:*                         LISTEN

# Adding NRPE port to firewall, If you are using any other firewall (CSF, ASF, etc..) except iptables you need to add the NRPE port to firewall allowed ports #
# iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT

# Saving IPtables new rules to take effect #
# service iptables save

# Check whether NRPE is working properly or not in localhost #
# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.15

7) Making changes in nrpe.cfg file

By default /usr/local/nagios/etc/nrpe.cfg file comes with standard rules to check service and hardware status. You can directly run the below command on your terminal to check whether its working or not and you can customize as per your requirment once it starts working.

# Standard rules which is defined by nagios team #
# nano /usr/local/nagios/etc/nrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

Part-2 : Nagis Server configuration.

1) Compile and Install the NRPE add-on

Follow the below steps to Install same NRPE add-on in your server which you installed in remote host.

# tar -xzvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure
# make all
# make install-daemon

# Check whether NRPE is working properly or not with remote host #
# /usr/local/nagios/libexec/check_nrpe -H Remore-host-IP
NRPE v2.15

2) Adding Linux host to Nagios server to monitor

Create two files inside “/usr/local/nagios/etc/“ to define host and services.

# Navigate to directory #
# cd /usr/local/nagios/etc/

# Create host file, I'm creating linux-hosts.cfg for clarification #
# touch linux-hosts.cfg

# Create service file #
# touch linux-services.cfg

# Add both files to end of the nagios.cfg file with below format #
# nano /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/linux-hosts.cfg
cfg_file=/usr/local/nagios/etc/linux-services.cfg

3) Add/Define new linux host

We don’t know how to define and configure hosts. So, don’t worry because default templates available at /usr/local/nagios/etc/objects/ just copy and past it into your host file.

# Adding contents to linux-hosts.cfg file from (localhost.cfg & templates.cfg) file #
# nano /usr/local/nagios/etc/linux-hosts.cfg
###############################################################################
#
# HOST DEFINITION
#
###############################################################################

# Define a host for the remote machine

define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               linux.2daygeek.com
        alias                   CentOS 6.5
        address                 192.168.0.130
        }

# Linux host definition 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!
        }

4) Add/Define service for linux host

We don’t know how to define and configure service for linux hosts. So, don’t worry because default templates available at /usr/local/nagios/etc/objects/ just copy and past it into your service file.

# Adding contents to linux-service.cfg file from (localhost.cfg) file #
# nano /usr/local/nagios/etc/linux-service.cfg
###############################################################################
# SERVICE DEFINITIONS
###############################################################################

# Define a service to "ping" the remote machine

define service{
        use                             generic-service         
        host_name                       linux.2daygeek.com
        service_description             PING
	        check_command                   check_ping!100.0,20%!500.0,60%
        }

define service{
        use                             generic-service         
        host_name                       linux.2daygeek.com
        service_description             Root Partition
	check_command			check_local_disk!20%!10%!/
        }

define service{
        use                             generic-service         
        host_name                       linux.2daygeek.com
        service_description             Current Users
	check_command			check_local_users!20!50
        }

define service{
        use                             generic-service         
        host_name                       linux.2daygeek.com
        service_description             Total Processes
	check_command			check_local_procs!250!400!RSZDT
        }

define service{
        use                             generic-service         
        host_name                       linux.2daygeek.com
        service_description             Current Load
	check_command			check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        }

define service{
        use                             generic-service         
        host_name                       linux.2daygeek.com
        service_description             Swap Usage
	check_command			check_local_swap!20!10
        }

define service{
        use                             generic-service         
        host_name                       linux.2daygeek.com
        service_description             SSH
	check_command			check_ssh
	notifications_enabled		0
        }

define service{
        use                             generic-service         
        host_name                       linux.2daygeek.com
        service_description             HTTP
	check_command			check_http
	notifications_enabled		0
        }

5) Add/Define NRPE commands for linux host

We don’t know how to define and configure NRPE commands to communicate with remote server. So, don’t worry because default templates available at /usr/local/nagios/etc/objects/ just copy and past it at the end of your commands.cfg file.

# Adding NRPE commands to commands.cfg file from (commands.cfg) file #
# nano /usr/local/nagios/etc/commands.cfg

define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

6) Verifying Nagios.cfg file

After madking all the above changes, verify the Nagios.cfg file whether it throws any errors.

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

7) Restart Nagios service

Finally restart the Nagios service to take effect.

# service nagios restart                    # [For SysVinit Systems]
# systemctl restart nagios.service          # [For systemd Systems]

8) Access Nagios Web Interface

Navigate your browser to http://localhost/nagios or http://IP-Address/nagios or http://Domain-Name/nagios and enter the Username and Password then click “Hosts”, Here you can see the new linux host which has been added by you.
linux-host-nagios-server-monitor-linux-host
Stay tune with us. Will show you, how to add windows host in Nagios server in our next article.

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...

Shares
Close
Please support the site
By clicking any of these buttons you help our site to get better