Nagios NRPE to Monitor Remote Linux Server

Scenario / Question:

How do I monitor a remote linux system using Nagios

Solution / Answer:

Use th NRPE daemon to execute Nagios plugins on the remote server and report back to the monitoring host server.

NRPE Remote Server Installation and Setup

Create Nagios user account on remote server to be monitored:

# useradd nagios
# passwd nagios

Download and Install Nagios Plugins:

# mkdir -p /opt/Nagios/Nagios_Plugins
# cd /opt/Nagios/Nagios_Plugins

Save file to directory /opt/Nagios

http://www.nagios.org/download/download.php

As of this writing Nagios 3.0.6 (Stable) and Nagios Plugins 1.4.13 (Stable)

Extract Files:

# tar xzf nagios-plugins-1.4.13.tar.gz

# cd nagios-plugins-1.4.13

Compile and Configure Nagios Plugins

** You need the openssl-devel package installed to compile plugins with ssl support. **

# yum -y install openssl-devel

Instal Plugins:

# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install

The permissions on the plugin directory and the plugins will need to be changed to nagios user

# chown nagios.nagios /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/libexec

Package xinted is needed

# yum install xinetd

Downlad and Install NRPE Daemon

# mkdir -p /opt/Nagios/Nagios_NRPE
# cd /opt/Nagios/Nagios_NRPE

Save file to directory /opt/Nagios

http://www.nagios.org/download/download.php

As of this writing NRPE 2.12 (Stable)

Extract the Files:

# tar -xzf nrpe-2.12.tar.gz
# cd nrpe-2.12

Compile and Configure NRPE

** You need the openssl-devel package installed to compile NRPE with ssl support. **

# yum -y install openssl-devel

Install NRPE:

# ./configure 

General Options:
 -------------------------
 NRPE port:    5666
 NRPE user:    nagios
 NRPE group:   nagios
 Nagios user:  nagios
 Nagios group: nagios

# make all

# make install-plugin

# make install-daemon

# make install-daemon-config

# make install-xinetd

Post NRPE Configuration

Edit Xinetd NRPE entry:

Add Nagios Monitoring server to the “only_from” directive

# vi /etc/xinetd.d/nrpe

only_from = 127.0.0.1 <nagios_ip_address>

Edit services file entry:

Add entry for nrpe daemon

# vi /etc/services

nrpe      5666/tcp    # NRPE

Restart Xinetd and Set to start at boot:

# chkconfig xinetd on

# service xinetd restart

Test NRPE Daemon Install

Check NRPE daemon is running and listening on port 5666:

# netstat -at |grep nrpe

Output should be:

tcp    0    0 *:nrpe    *.*    LISTEN

Check NRPE daemon is functioning:

# /usr/local/nagios/libexec/check_nrpe -H localhost

Output should be NRPE version:

NRPE v2.12

Open Port 5666 on Firewall

Make sure to open port 5666 on the firewall of the remote server so that the Nagios monitoring server can access the NRPE daemon.

Nagios Monitoring Host Server Setup

Downlad and Install NRPE Plugin

# mkdir -p /opt/Nagios/Nagios_NRPE
# cd /opt/Nagios/Nagios_NRPE

Save file to directory /opt/Nagios

http://www.nagios.org/download/download.php

As of this writing NRPE 2.12 (Stable)

Extract the Files:

# tar -xzf nrpe-2.12.tar.gz
# cd nrpe-2.12

Compile and Configure NRPE

# ./configure 

# make all

# make install-plugin

Test Connection to NRPE daemon on Remote Server

Lets now make sure that the NRPE on our Nagios server can talk to the NRPE daemon on the remote server we want to monitor. Replace “<IP of Remote Server>” with the remote servers IP address.

# /user/local/nagios/libexec/check_nrpe -H <IP of Remote Server>
NRPE v2.12

Create NRPE Command Definition

A command definition needs to be created in order for the check_nrpe plugin to be used by nagios.

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

Add the following:

###############################################################################
# NRPE CHECK COMMAND
#
# Command to use NRPE to check remote host systems
###############################################################################

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

Create Linux Object template

In order to be able to add the remote linux machine to Nagios we need to create an object template file adn add some object definitions.

Create new linux-box-remote object template file:

# vi /usr/local/nagios/etc/objects/linux-box-remote.cfg

Add the following and replace the values “host_name” “alias” “address” with the values that match your setup:

** The “host_name” you set for the “define_host” section must match the “host_name” in the “define_service” section **

define host{
          name                  linux-box-remote             ; Name of this template
          use                   generic-host          ; Inherit default values
          check_period          24x7
          check_interval        5
          retry_interval        1
          max_check_attempts    10
          check_command         check-host-alive
          notification_period   24x7
          notification_interval 30
          notification_options  d,r
          contact_groups        admins
          register              0          ; DONT REGISTER THIS - ITS A TEMPLATE
          }

define host{
          use       linux-box-remote     ; Inherit default values from a template
          host_name Centos5    ; The name we're giving to this server
          alias     Centos5 ; A longer name for the server
          address   192.168.0.5   ; IP address of the server
          }

define service{
          use                 generic-service
          host_name           Centos5
          service_description CPU Load
          check_command       check_nrpe!check_load
          }
define service{
          use                 generic-service
          host_name           Centos5
          service_description Current Users
          check_command       check_nrpe!check_users
          }
define service{
          use                 generic-service
          host_name           Centos5
          service_description /dev/hda1 Free Space
          check_command       check_nrpe!check_hda1
          }
define service{
          use                 generic-service
          host_name           Centos5
          service_description Total Processes
          check_command       check_nrpe!check_total_procs
          }
define service{
          use                 generic-service
          host_name           Centos5
          service_description Zombie Processes
          check_command       check_nrpe!check_zombie_procs
          }

Activate the linux-box-remote.cfg template:

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

And add:

# Definitions for monitoring remote Linux machine
cfg_file=/usr/local/nagios/etc/objects/linux-box-remote.cfg

Verify Nagios Configuration Files:

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors:   0

Restart Nagios:

# service nagios restart

Check Nagios Monitoring server that the remote linux box was added and is being monitored !

TroubleShooting

NRPE ./configure error:

checking for SSL headers… configure: error: Cannot find ssl headers

Solution:

You need to install the openssl-devel package

# yum -y install openssl-devel

CHECK_NRPE: Error – Could not complete SSL handshake

Solution:

This is most likely not a probem with SSL but rather with Xinetd access restrictions.

Check the following files:

/etc/xinetd.d/nrpe

/etc/hosts.allow

/etc/hosts.deny

10 Comments so far

  1. Diger on June 25th, 2009

    why not using check_by_ssh ?

  2. Fabio Milano on June 25th, 2009

    Diger

    check_by_ssh can be used as well. However, when monitoring 100’s of servers check_by_ssh can place high load on your Nagios server due to all the open ssh connections.

    Feel free to use which ever check method that suits your environment. That is why there is two different methods.

  3. djill on July 3rd, 2009

    Hi !

    I have a problem with check_procs and NRPE, when I execute the check_procs plugin to check some process, It works:
    /usr/local/nagios/libexec/check_procs -a vsftpd
    PROCS OK: 1 processus avec args ‘vsftpd’

    But when I use the same check_procs command with NRPE, it doesn’t work.
    /usr/local/nagios/libexec/check_nrpe -H localhost -c vsftpd
    (with vsftpd command into nrpe.cfg: command[vsftpd]=/usr/local/nagios/libexec/check_nrpe -H localhost -c vsftpd)
    NRPE output is ‘PROCS CRITIQUE: 0 processus’

    I execute both commands on localhost.
    Others plugins works correctly, for example check_load, check_users
    I don’t understand.

    Any help would be appreciate

    Thanks.

  4. Fabio Milano on July 3rd, 2009

    Djill

    The nrpe “command” that is set in nrpe.cfg should be written as if you were running the check_plugin directly.

    Change:

    command[vsftpd]=/usr/local/nagios/libexec/check_nrpe -H localhost -c vsftpd

    To:

    command[check_vsftpd]=/usr/local/nagios/libexec/check_procs -a vsftpd

    Run:

    /usr/local/nagios/libexec/check_nrpe -H localhost -c check_vsftpd

  5. djill on July 3rd, 2009

    Sorry, but I made a mistake with the NRPE command;

    I want to say ‘(with vsftpd command into nrpe.cfg: command[vsftpd]=/usr/local/nagios/libexec/check_procs -a vsftpd)’ not ‘(with vsftpd command into nrpe.cfg: command[vsftpd]=/usr/local/nagios/libexec/check_nrpe -H localhost -c vsftpd)’…

    The exact command is:

    command[vsftpd]=/usr/local/nagios/libexec/check_procs –argument-array=”/usr/sbin/vsftpd” -c 1:

    When I launch this command:

    /usr/local/nagios/libexec/check_procs -a vsftpd

    I have this output:

    PROCS OK: 1 processus avec args ‘vsftpd’

    But when I launch this command:

    /usr/local/nagios/libexec/check_nrpe -H localhost -c vsftpd

    I have this output:

    PROCS OK: 0 processus avec args ‘vsftpd’

  6. Fabio Milano on July 3rd, 2009

    djill

    In the line

    /usr/local/nagios/libexec/check_procs –argument-array=”/usr/sbin/vsftpd” -c 1:

    I don’t believe -argument-array is a valid option. -argument-array is the type of data that should be supplied to the -a option.

    I usually structure my check_procs as follows for monitoring a service:

    /usr/local/nagios/libexec/check_procs -c 1: -C vsftpd

  7. Dario on July 4th, 2009

    the check_nrpe worked ok by command line, but on web interface I can see “No output returned from plugin” only, Why?.

  8. Fabio Milano on July 4th, 2009

    Dario

    Could you paste:

    nrpe.cfg plugin command on the remote host

    service setting on the Nagios server

  9. djill on July 6th, 2009

    I have the same problem with this command into my nrpe.cfg:

    command[vsftpd]=/usr/local/nagios/libexec/check_procs -c 1: -C vsftpd

  10. Central Monitoring and Logging…

    Introduction This document outlines the centralized logging and monitoring infrastructure setup for Xcal DS. System The FRESNEL.CHALYBS.NET system hosts the central logging and monitoring…….

Leave a reply