How To Monitor Remote Linux Host using Nagios 3.0

Filed Under: Linux    24 Comments

 

Free eBook - Linux 101 Hacks. Get your copy now.

Nagios

In the previous post Nagios 3.0 Jumpstart guide , I explained the overview, installation and configuration of Nagios 3.0 on Red Hat Server. In the following three chapters, I’ll explain how to monitor a remote Linux host and the various services running on the remote host.  Also, please refer to all our Nagios articles.
 
I. Overview

II. 6 steps to install Nagios plugin and NRPE on remote host.

  1. Download Nagios Plugins and NRPE Add-on
  2. Create nagios account
  3. Install Nagios Plugins
  4. Install NRPE
  5. Setup NRPE to run as daemon
  6. Modify the /usr/local/nagios/etc/nrpe.cfg

III. 4 Configuration steps on the Nagios monitoring server to monitor remote host:


  1. Download NRPE Add-on
  2. Install check_nrpe
  3. Create host and service definition for remote host
  4. Restart the nagios service


I. Overview:

.

Following three steps will happen on a very high level when Nagios (installed on the nagios-servers) monitors a service (for e.g. disk space usage) on the remote Linux host.
 

  1. Nagios will execute check_nrpe command on nagios-server and request it to monitor disk usage on remote host using check_disk command.
  2. The check_nrpe on the nagios-server will contact the NRPE daemon on remote host and request it to execute the check_disk on remote host.
  3. The results of the check_disk command will be returned back by NRPE daemon to the check_nrpe on nagios-server.


Following flow summarizes the above explanation:

Nagios Server (check_nrpe) —–> Remote host (NRPE deamon) —–> check_disk

Nagios Server (check_nrpe) <—– Remote host (NRPE deamon) <—– check_disk (returns disk space usage)


II. 7 steps to install Nagios Plugins and NRPE on the remote host

.

1. Download Nagios Plugins and NRPE Add-on

Download following files from Nagios.org and move to /home/downloads:

  • nagios-plugins-1.4.11.tar.gz
  • nrpe-2.12.tar.gz

2. Create nagios account

[remotehost]# useradd nagios
[remotehost]# passwd nagios

3. Install nagios-plugin

[remotehost]# cd /home/downloads
[remotehost]# tar xvfz nagios-plugins-1.4.11.tar.gz
[remotehost]# cd nagios-plugins-1.4.11
[remotehost]# export LDFLAGS=-ldl

[remotehost]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
[remotehost]# make
[remotehost]# make install

[remotehost]# chown nagios.nagios /usr/local/nagios
[remotehost]# chown -R nagios.nagios /usr/local/nagios/libexec/


Note: On Red Hat, For me the ./configure command was hanging with the the message: “checking for redhat spopen problem…”. Add --enable-redhat-pthread-workaround to the ./configure command as a work-around for the above problem.

4. Install NRPE

[remotehost]# cd /home/downloads
[remotehost]# tar xvfz nrpe-2.12.tar.gz
[remotehost]# cd nrpe-2.12

[remotehost]# ./configure
[remotehost]# make all
[remotehost]# make install-plugin
[remotehost]# make install-daemon
[remotehost]# make install-daemon-config
[remotehost]# make install-xinetd

5. Setup NRPE to run as daemon (i.e as part of xinetd):

  • Modify the /etc/xinetd.d/nrpe to add the ip-address of the Nagios monitoring server to the only_from directive. Note that there is a space after the 127.0.0.1 and the nagios monitoring server ip-address (in this example, nagios monitoring server ip-address is: 192.168.1.2)
       only_from       = 127.0.0.1 192.168.1.2
  • Modify the /etc/services and add the following at the end of the file.
       nrpe 5666/tcp # NRPE
  • Start the service
       [remotehost]#service xinetd restart
  • Verify whether NRPE is listening
       [remotehost]# netstat -at | grep nrpe
       tcp 0      0 *:nrpe *:*                         LISTEN
  • Verify to make sure the NRPE is functioning properly
[remotehost]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12

6. Modify the /usr/local/nagios/etc/nrpe.cfg

The nrpe.cfg file located on the remote host contains the commands that are needed to check the services on the remote host. By default the nrpe.cfg comes with few standard check commands as samples. check_users and check_load are shown below as an example.

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


In all the check commands, the “-w” stands for “Warning” and “-c” stands for “Critical”. for e.g. in the check_disk command below, if the available disk space gets to 20% of less, nagios will send warning message. If it gets to 10% or less, nagios will send critical message. Change the value of “-c” and “-w” parameter below depending on your environment.

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1


Note: You can execute any of the commands shown in the nrpe.cfg on the command line on remote host and see the results for yourself. For e.g. When I executed the check_disk command on the command line, it displayed the following:

[remotehost]#/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
DISK CRITICAL - free space: / 6420 MB (10% inode=98%);| /=55032MB;51792;58266;0;64741


In the above example, since the free disk space on /dev/hda1 is only 10% , it is displaying the CRITICAL message, which will be returned to nagios server.


III. 4 Configuration steps on the Nagios monitoring server to monitor remote host:

.

1. Download NRPE Add-on

Download nrpe-2.12.tar.gz from Nagios.org and move to /home/downloads:

2. Install check_nrpe on the nagios monitoring server

[nagios-server]# tar xvfz nrpe-2.12.tar.gz
[nagios-server]# cd nrpe-2.1.2
[nagios-server]# ./configure
[nagios-server]# make all
[nagios-server]# make install-plugin

./configure will give a configuration summary as shown below:

*** Configuration summary for nrpe 2.12 05-31-2008 ***:

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

 

Note: I got the “checking for SSL headers… configure: error: Cannot find ssl headers” error message while performing ./configure. Install openssl-devel as shown below and run the ./configure again to fix the problem.

[nagios-server]# rpm -ivh openssl-devel-0.9.7a-43.16.i386.rpm krb5-devel-1.3.4-47.i386.rpm zlib-devel-1.2.1.2-1.2.i386.rpm e2fsprogs-devel-1.35-12.5.
el4.i386.rpm
warning: openssl-devel-0.9.7a-43.16.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing… ########################################### [100%]
1:e2fsprogs-devel ########################################### [ 25%]
2:krb5-devel ########################################### [ 50%]
3:zlib-devel ########################################### [ 75%]
4:openssl-devel ########################################### [100%]

Verify whether nagios monitoring server can talk to the remotehost.

[nagios-server]#/usr/local/nagios/libexec/check_nrpe -H 192.168.1.3
NRPE v2.12


Note: 192.168.1.3 in the ip-address of the remotehost where the NRPE and nagios plugin was installed as explained in Section II above.

3. Create host and service definition for remotehost

Create a new configuration file /usr/local/nagios/etc/objects/remotehost.cfg to define the host and service definition for this particular remotehost. It is good to take the localhost.cfg and copy it as remotehost.cfg and start modifying it according to your needs.
 

host definition sample:

define host{
use linux-server
host_name remotehost
alias Remote Host
address 192.168.1.3
contact_groups admins
}


Service definition sample:

define service{
use generic-service
service_description Root Partition
contact_groups admins
check_command check_nrpe!check_disk
}

Note: In all the above examples, replace remotehost with the corresponding hostname of your remotehost.

4. Restart the nagios service

Restart the nagios as shown below and login to the nagios web (http://nagios-server/nagios/) to verify the status of the remotehost linux sever that was added to nagios for monitoring.

[nagios-server]# service nagios reload

Recommended Reading

These are the two best books that covers the latest Nagios 3. I strongly recommend that you read both of these books to gain a detailed understanding on Nagios.





Tags: , , ,

24 Responses to “How To Monitor Remote Linux Host using Nagios 3.0”

  1. You may also modify commands.cfg to add check_nrpe that was not by default in that file.
    I find nexts lines in a forum:
    # ‘check_nrpe’ command definition
    define command{
    command_name check_nrpe
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$
    }
    Thanks for this guide!!

  2. Nice article i did everything but still i dnt know hw to monitor the remote host through the nagios server through web interface .
    Can you please help me on this ..?

  3. Jaspreet: you have to edit several file in /usr/local/nagios/etc/ folder. First with nagios.cfg and then each objetc that you wanna monitor.

  4. @David,

    Thanks for your comment about check_nrpe and following up with Jaspreet on his questions.

    @Jaspreet,

    You need to explain little bit more on what configuration you’ve done so far and what exactly the problem you are facing. If you need any additional help send me an email to ramesh (at) thegeekstuff (dot) com , and I’ll help you out.

  5. Great article. Jaspreet, I’m guessing you don’t have the cfg set up right on your host server. I always verify the config as well with the nagios -v [path/to/config.cfg], maybe that would also help.

  6. Now an explanation of the “NRPE” abbreviation would make the whole read less frustrating.

  7. @Simon,

    NRPE stands for “Nagios Remote Plug-Ins Executor”

  8. Hi Ramesh

    i set up nagios server (in singapore) and a client (malaysia) but i got this error when i wanted to see if server talks to client correctly, can you help with this thanks ?

    [root@nagios etc]# /usr/local/nagios/libexec/check_nrpe -H 172.16.1.248
    CHECK_NRPE: Socket timeout after 10 seconds.

  9. According the first message …

    You may also modify commands.cfg to add check_nrpe that was not by default in that file.
    I find nexts lines in a forum:
    # ‘check_nrpe’ command definition
    define command{
    command_name check_nrpe
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$
    }

  10. I couldn’t get the nagios server to monitor the remote host. Do I need to configure the nagios.cfg file with the path of the remothost.cfg file. I did this and I get a config error when I reload nagios. Am I missing something?

  11. Thanks Ramesh good work, one thing though your # “configure …. ” lines will be a bit frustrating for newbies since you have omitted the # “./configure ….. ” and also ” – “instead of ” — ” on your how-to.

    Thanks a mil once again :)

  12. That should have been ” – -”

  13. thank you!

  14. Thanks for your guide. I have got server talking to client (linux) using NRPE. Now there are 4 more other machines but I cannot install any agent on those. Reading through websites, there is a way…can you please suggest me something.

    Thanks in advance.

  15. Mr-lol,

    Yes. It should be “--” in the “./configure”. I’ve fixed it. Thanks for pointing it out.

  16. hi, thank you very much for your help, but now I’ve to ask you some more help because: I carefully followed your instructions for the installation of NREP and the server gives me the following answer when I try to execute the verify on it:

    /usr/local/nagios/libexec/check_nrpe -H 192.168.1.105 (remote linux host ip)
    Connection refused by host

    Do you think it could be the firewall on client? If so, how can I solve the problem?

  17. FYI, Simon… NRPE stands for “Nagios Remote Plug-Ins Executor”

  18. I have installed nagios3 on a linux box. I m tryng to configure a remote linux machine. I m following the above steps as mentioned by you. I have also modified commands.cfg to add check_nrpe

    However i getting following message in web in status information colm
    NRPE: Command ‘check_disk’ not defined

    My check_disk in commands.cfg looks like this
    # ‘check_disk’ command definition
    define command{
    command_name check_disk
    command_line $USER1$/check_disk -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$
    }

  19. Hi,
    I am getting following error when i run this command on nagios server(Fedora8).192.168.1.201 is the ip of remote host (CentOS release 5.2)

    [root@mail nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.201
    CHECK_NRPE: Error – Could not complete SSL handshake.

    Though Openssl is installed in my system

    [root@mail nrpe-2.12]# rpm -qa |grep openssl
    openssl-0.9.8b-17.fc8
    openssl-devel-0.9.8b-17.fc8
    openssl-perl-0.9.8b-17.fc8
    [root@mail nrpe-2.12]#

  20. hi… i have done the following with Nagios 3.0

    1) copied the localhost.cfg file and created a remotehost.cfg file
    2) i have then added a remote linux host to the remotehost.cfg file
    3) how do i see the remote host on the nagios server….?

Discussion Area - Leave a Comment





Enter your email address:

RSS
RSS Subscribe

Sponsors


Password Dragon


Free e-Book


Download Free eBook
Linux 101 Hacks Book
"These useful hacks are concise, well written and easy to read. Well done - I will recommend this eBook to my students."

Prof. Dr. Fritz Mehner
(Author of several Vim plugins)

Categories


pointer Linux pointer Database
pointer Hardware pointer Security
pointer Productivity pointer Java
pointer Software pointer Windows
pointer General



Popular Posts



12 Amazing Linux Books


  • 1. Sed and Awk
  • 2. Learning the Vi and Vim Editors
  • 3. Bash Cookbook
  • 4. SSH, The Secure Shell
  • 5. Essential System Administration
  • 6. Linux Server Hacks, Volume One
  • 7. DNS and BIND
  • 8. Understanding the Linux Kernel
  • 9. Linux Cookbook
  • 10. Linux Firewalls
  • 11. Linux Administration Handbook
  • 12. Beginning Ubuntu Linux
  • Read full review of these 12 books

Community
About TheGeekStuff
Ramesh

My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more