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.

# /usr/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

no acceptable c compiler found in $PATH

When I gave the ./configure command i got this error saying: no acceptable c compiler found in $PATH and then it stops.

After a quick google search I found a topic saying that i needed to install gcc so i entered:

yum install gcc glibc glibc-common gd gd-devel

(thanks to AgentOOX)

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
Fabio Milano has written 79 articles for us. Fabio Milano is a certified RHCE, MCP, and CFOI. He runs an IT consulting and services company called RDS Support inc. Website:http://www.rdssupport.com
The information provided is for educational purposes only. All content including links and comments is provided "as is" with no warranty, expressed or implied. Use is at your own risk and you are solely responsible for what you do with it.

43 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…….

  11. [...] openssl-devel While I would like to take credit for solving this, I found the solution here: http://www.kernelhardware.org/nagios-nrpe-to-monitor-remote-linux-server/ Share this [...]

  12. titino on March 17th, 2010

    i am running the command : “/usr/local/nagios/libexec/check_nrpe -H localhost” and i am getting “CHECK_NRPE: Error – Could not complete SSL handshake.” and i don’t think that /etc/hosts.allow and /etc/hosts.deny files are involved since i am testing on Localhost!Can you help please! thanks

  13. Fabio Milano on March 17th, 2010

    Did you add

    only_from = 127.0.0.1

    to /etc/xinetd.d/nrpe

  14. titino on March 18th, 2010

    Yes !

  15. Ciprian on March 27th, 2010

    Thanks!!!

  16. Einar on April 7th, 2010

    Hi.

    I get error when configue.

    <…..
    prime, generator 2
    This is going to take a long time
    ………………….. …………… ..

    checking for Kerberos include files… could not find include files
    checking for perl… /usr/bin/perl
    configure: creating ./config.status
    config.status: creating Makefile
    config.status: creating src/Makefile
    config.status: creating subst
    config.status: creating include/config.h
    config.status: include/config.h is unchanged

  17. Mathieu Dreo on June 7th, 2010

    There is a small thing missing in this tuto.

    On the client, you have to configure the nrpe.cfg:
    vim /usr/local/nagios/etc/nrpe.cfg (on CentOs).

    And add the command :
    command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p

    By doing that the server will be able to launch the Disk space service remotely otherwise you will get an error.

  18. Masaiah on June 16th, 2010

    Hi i have installed nagios.,plugin.,and nrpe
    after starting the process im not getting the MAP
    its showing below error.in other options i colud see localhost status and all but GUI is not proper
    Would appreciate anyone help me at the earliest..

    This error (HTTP 404 Not Found) means that Internet Explorer was able to connect to the website, but the page you wanted was not found. It’s possible that the webpage is temporarily unavailable. Alternatively, the website might have changed or removed the webpage.

    For more information about HTTP errors, see Help

  19. Agent00X on August 25th, 2010

    When I gave the ./configure command i got this error saying: no acceptable c compiler found in $PATH and then it stops.

    After a quick google search I found a topic saying that i needed to install gcc so i entered:

    yum install gcc glibc glibc-common gd gd-devel

    (which is mentioned in the how-to install nagios on CentOS 5 manual (http://www.kernelhardware.org/install-nagios-on-centos-5/))

    After that it installed just fine. it also explains why in wasn’t working on my BlueOnyx 5.5 ,same error.

    Maybe you can add a note about that as well Fabio or someone. I think it would help a lot of people.

  20. Fabio Milano on August 25th, 2010

    thanks Agent00X

    I updated the post

  21. Mats on August 26th, 2010

    Spelling error:
    # /user/local/nagios/libexec/check_nrpe -H

    should be:
    # /usr/local/nagios/libexec/check_nrpe -H

  22. Fabio Milano on August 27th, 2010

    thanks Mats. I fixed the spelling mistake

  23. Fros on September 14th, 2010

    Hi Fabio,
    Thanks for the tutorial.

    Could you help me on the modification that I need to made on the remote client. I’m confused.

    Here’s what I’ve done.
    Server is up and running and monitoring itself only.
    I’ve installed the nrpe software on remote machine and no problem doing check_nrpe from remote host to nagios server.

    I’m confused with the command and host templates.
    Where are they .It’s on the server side or remote client side. From the remote side ,there’s no object folder. My objective is to be able to add remote host as I can only see the server itself.
    Thanks.

  24. 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…….

  25. Rajan on November 14th, 2010

    Hi,

    I have observing the following 2 errors. Please give me the solution.
    1.CHECK_NRPE: Error receiving data from daemon.
    2.NRPE: Command ‘check_load’ not defined.

    Thanks,
    G.Rajan
    rajangurusamy@gmail.com
    9578925920

  26. anand on December 10th, 2010

    Hi

    hey hi i have configured nagios as per the above configuration,but only problem is that,i am unable to get nagios in /usr/local/nagios/bin/.

    Kindly do the needful.
    Anand

  27. somewhere-lost on December 17th, 2010

    So, I installed nagios plugin and the NRPE for the client side. But, I’m getting “CHECK_NRPE: Error – Could not complete SSL handshake.” when running /usr/local/nagios/libexec/check_nrpe -H localhost (or using the ip address of the client side).

    I checked the following:
    - made sure that /etc/xinetd.d/nrpe, on the line “only_from = ‘nagios server ip address only’

    - made sure that I have added nrpe 5666/tcp # NRPE to /etc/services and have restarted the xinetd. And, have not problem with running netstat.

    - checked hosts.deny, this is the only thing that’s in the file:
    #
    # hosts.deny This file describes the names of the hosts which are
    # *not* allowed to use the local INET services, as decided
    # by the ‘/usr/sbin/tcpd’ server.
    #
    # The portmap line is redundant, but it is left to remind you that
    # the new secure portmap uses hosts.deny and hosts.allow. In particular
    # you should know that NFS uses portmap!

    - the hosts.allow only has this:

    # hosts.allow This file describes the names of the hosts which are
    # allowed to use the local INET services, as decided
    # by the ‘/usr/sbin/tcpd’ server.

    But, I can run “/usr/local/nagios/libexec/check_nrpe -H ‘ip address of client’ from nagios server and get NRPE v2.12 on one of my test system and I get different error on the second system ‘Connection refused or timed out’

    Please help. thx.

  28. Confluence: PA 3 Space on December 22nd, 2010

    1. Installation guide…

    1. ?? ? ?? ???? Apache PHP GCC compiler GD development libraries OpenSSL development libraries Apache? PHP? ?? plugin ? server??? ?? source ??? ????, GCC compiler? GD tool? cpu?? ? package? version dependency ??? ?? ??? yum install? ?????…….

  29. anon on January 7th, 2011

    thx 4 this great walkthrough! worked like a charm for me

  30. [...] Here is the step by step guide to get NRPE to work with Nagios NRPE-Guide [...]

  31. Ashish Sood on January 18th, 2011

    i install nagios using rpm on my rhel 5 machine, so there is not check_nrpe plugins install, i m also facing a problem my problem is that i can sucessfully monitor a remote ssh service using check_ssh but when i try to monitor remote disk space and then restart nagios service i got Configuration validation failed error message but problem monitory ssh serverice.

    my plugins dir is
    /usr/lib/nagios/plugins

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

    Nagios Core 3.2.3
    Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
    Copyright (c) 1999-2009 Ethan Galstad
    Last Modified: 10-03-2010
    License: GPL

    Website: http://www.nagios.org
    Reading configuration data…
    Read main config file okay…
    Processing object config file ‘/etc/nagios/objects/commands.cfg’…
    Processing object config file ‘/etc/nagios/objects/contacts.cfg’…
    Processing object config file ‘/etc/nagios/objects/timeperiods.cfg’…
    Processing object config file ‘/etc/nagios/objects/templates.cfg’…
    Processing object config file ‘/etc/nagios/objects/remote.cfg’…
    Processing object config file ‘/etc/nagios/objects/localhost.cfg’…
    Read object config files okay…

    Running pre-flight check on configuration data…

    Checking services…
    Error: Service check command ‘check_users’ specified in service ‘check_mem’ for host ‘station10′ not defined anywhere!
    Checked 10 services.
    Checking hosts…
    Checked 2 hosts.
    Checking host groups…
    Checked 1 host groups.
    Checking service groups…
    Checked 0 service groups.
    Checking contacts…
    Checked 1 contacts.
    Checking contact groups…
    Checked 1 contact groups.
    Checking service escalations…
    Checked 0 service escalations.
    Checking service dependencies…
    Checked 0 service dependencies.
    Checking host escalations…
    Checked 0 host escalations.
    Checking host dependencies…
    Checked 0 host dependencies.
    Checking commands…
    Checked 24 commands.
    Checking time periods…
    Checked 5 time periods.
    Checking for circular paths between hosts…
    Checking for circular host and service dependencies…
    Checking global event handlers…
    Checking obsessive compulsive processor commands…
    Checking misc settings…

    Total Warnings: 0
    Total Errors: 1

    ***> One or more problems was encountered while running the pre-flight check…

    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.

  32. Amit on June 10th, 2011

    Ashish, you probably figured this out by now by now but in case you haven’t or if someone else has the same problem as you: I think the most likely source of error is that you did not add a definition for the command “check_users” in the /etc/nagios/objects/commands.cfg file.

  33. Patches on June 28th, 2011

    Thanks for this simple, straight-forward how-to.

  34. Confluence: JIRA Department on July 19th, 2011

    Monitoring…

    Na této stránce budou popsána ?ešení pro monitoring sítí. Jako zajímavá ?ešení se jeví Nagios, Centreon a Zenoss. Zajímavé porovnání se nachází v ?lánku Open Source Management Solutions…

  35. JIRA: KION TDM on September 8th, 2011

    [STILLTDM-1630] Automatisches Monitoring der zentralen Variante verbessern…

    Zwecks Monitoring muss Nagios in den JBoss integriert werden. Die Zeiten werden dann auf “Feldtestserver” gebucht. Als Info dazu eine Mail von Bernd Schymanski an Torsten Fink: Hallo Herr Fink, um den jboss zu überwachen benötigen wir ein Pl……

  36. puggy on September 15th, 2011

    thank you!

  37. Mohit on November 1st, 2011

    My one of the script is giving output in other file and through NRPE check we are running that script , but everytime i run the nrpe plugin manually. It is showing the value 0 in the file. If i run stat command on both script and file. Both time stamps changes but the output file is not taking any output. I’ve set permission 777 on both output file and script.. I am not getting any logs for this.. Any help please…

  38. Gonzalo Valenzuela on November 8th, 2011

    Perfect in CentOS 6.0 x86_64, without errors!!!

  39. somesh on January 4th, 2012

    Hi!!
    I have problem in using “check_mysql_health” command, if i run in command line it is getting executed properly but in Nagios core it is returning “Status Information” as (null). Can anyone tell me how to avoid this?

    Thanks
    Somesh

  40. Poon on January 5th, 2012

    Hi, When I run this command on the server, is pop up the error below.

    /usr/local/nagios/libexec/check_nrpe -H 10.1.1.1
    CHECK_NRPE: Error – Could not complete SSL handshake.

    The another way when I run this command on the server,
    /usr/local/nagios/libexec/check_nrpe -H localhost
    Connection refused by host

    as you mention above, if saw this errors, have to look into these files..
    /etc/xinetd.d/nrpe
    /etc/hosts.allow
    /etc/hosts.deny

    But I do not find any problem inside the files…

    Please advice.

  41. ben on January 18th, 2012

    Make sure iptables is not blocking your traffic and also make sure selinux is not interfering.

  42. app88n on January 27th, 2012

    Poon run:

    #service nrpe stop
    #service xinetd restart

    That worked for me.

  43. [...] Nagios plugins on the remote server and report back to the monitoring host server. [read more @http://www.kernelhardware.org/nagios-nrpe-to-monitor-remote-linux-server/] Advertisement GA_googleAddAttr("AdOpt", "1"); GA_googleAddAttr("Origin", "other"); [...]

Leave a reply