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.

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

22 Comments on “How to add Remote Linux Host on Nagios server to monitor”

  1. Myserver is nagios 4.0.8 client ubuntu. i have installed nrpe plugin using below link.

    http://sharadchhetri.com/2013/06/11/how-to-install-and-configure-nagios-nrpe-client-in-ubuntu-with-apt-get-command/
    I am able to get reply from ubuntu cleint

    [root@localhost objects]# /usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xx.xx
    NRPE v2.15

    and also getting reply cpuload

    [root@localhost objects]# /usr/local/nagios/libexec/check_nrpe -H xxx.xx.xxx.xx -c check_load
    OK – load average: 0.07, 0.13, 0.17|load1=0.070;15.000;30.000;0; load5=0.130;10.000;25.000;0; load15=0.170;5.000;20.000;0;

    We define the command as follows in nagios server

    define command{
    command_name check_nrpe
    command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
    }

    define command{
    command_name check_load
    command_line /usr/local/nagios/libexec/check_load -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
    }

  2. /usr/local/nagios/libexec/check_nrpe -H Remore-host-IP i am getting reply from remote machine as nrpe2.15

  3. I tried in ubuntu desktop but i am getting the error while start the installation

    root@test:~# sudo apt-get install build-essential php5-gd libgd2-xpm libgd2-xpm-dev libapache2-mod-php5 libperl-dev libssl-dev apache2-utils
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package libgd2-xpm

  4. How to attach a screenshot in this website so that you can see what i am getting error on web console. If there is a possibility can you tell where we can attach.

  5. I am able to connect to my remote ubuntu server as followed below command
    [root@localhost nagios]# /usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xx.xxx -c check_load
    OK – load average: 0.03, 0.06, 0.03|load1=0.030;15.000;30.000;0; load5=0.060;10.000;25.000;0; load15=0.030;5.000;20.000;0;

    I am getting reply but it is not displayed on nagios webpage the error is No output on stdout) stderr: execvp(/usr/lib/nagios/plugins/check_nrpe, …) failed. errno is 2: No such file or directory

  6. But i am getting the error as below. I have followed same processor as mentioned above. Only ping is OK is showing on console

    No output on stdout) stderr: execvp(/usr/lib/nagios/plugins/check_nrpe, …) failed. errno is 2: No such file or directory

  7. Shall we do same in ubuntu Client,

    My server nagios in centos6.5. I want monitor ubuntu client how we can monitor

  8. hi, i am getting below error. /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    Nagios Core 4.1.1
    Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
    Copyright (c) 1999-2009 Ethan Galstad
    Last Modified: 08-19-2015
    License: GPL

    Website: https://www.nagios.org
    Reading configuration data…
    Read main config file okay…
    Error: Unexpected start of object definition in file ‘/usr/local/nagios/etc/hosts.cfg’ on line 16. Make sure you close preceding objects before starting a new one.
    Error processing object config files!

    ***> One or more problems was encountered while processing the config files…

    Check your configuration file(s) to ensure that they contain valid
    directives and data defintions. If you are upgrading from a previous
    version of Nagios, you should be aware that some variables/definitions
    may have been removed or modified in this version. Make sure to read
    the HTML documentation regarding the config files, as well as the
    ‘Whats New’ section to find out what has changed.

  9. Hi,
    I am getting below error.I am doing this on the remote host.
    part 1 step 5

    cd ./src/ && make install-plugin
    make[1]: Entering directory `/root/nagios/nrpe-2.15/src’
    /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
    /usr/bin/install -c -m 775 -o nagios -g nagios check_nrpe /usr/local/nagios/libexec
    /usr/bin/install: cannot stat `check_nrpe’: No such file or directory
    make[1]: *** [install-plugin] Error 1
    make[1]: Leaving directory `/root/nagios/nrpe-2.15/src’
    make: *** [install-plugin] Error 2

  10. Successfully i added a host but i do not see any service in that. can you help me to resolve this issue.

  11. Thanks for your guide.
    I have install nagios to monitor Cisco router connected to several branch office.

    But the problem is when a branch router’s wan link face high latency or packet loss its states goes to down node though the node is live.

    Please advice.

Leave a Reply to 2daygeek Cancel reply

Your email address will not be published. Required fields are marked *