How to install and configure nagios nrpe client in Ubuntu with apt-get command

A few days back I wrote on how to configure nagios server in Ubuntu 12.04.
In this tutorial we will learn how to monitor the ubuntu machines means we will install nrpe in ubuntu machines so that nagios server can monitor it.

NRPE works on port no. 5666.


Follow the steps to configure nrpe in Ubuntu systems :

note: here # prompt is for root and $ prompt is for non-root user.

Step 1 : Login in to the ubuntu client machine and become a superuser & do “apt-get update”(I prefer to work as root)

$ sudo su -
# apt-get update

Step 2 : Now install nrpe,open-ssl and nagios plugins in ubuntu system

# apt-get install openssl nagios-nrpe-server nagios-plugins nagios-plugins-basic nagios-plugins-standard

Step 3: Take the backup of original nrpe.cfg file

# cp -p  /etc/nagios/nrpe.cfg /etc/nagios/nrpe.cfg.orig

Step 4 : Now edit the /etc/nagios/nrpe.cfg file and in allowed_hosts give the ip address of Nagios Server from which monitoring will be done.

Below is the reference of my Nagios system’s nrpe.cfg file :

root@webserver:/etc/nagios# egrep -v '^#|^$' nrpe.cfg
log_facility=daemon
pid_file=/var/run/nagios/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1,ip-address-of-nagios-server

dont_blame_nrpe=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200 
include=/etc/nagios/nrpe_local.cfg
include_dir=/etc/nagios/nrpe.d/
root@webserver:/etc/nagios#

Step 5 : Now restart the nagios-nrpe-server service in client machine.

/etc/init.d/nagios-nrpe-server restart

Now the given below steps should be done in Nagios Server

Step 6: Login into Nagios Server and do “sudo su – ” means become superuser

sudo su -

Step 7: Create a new file and give the name which must be relevant with your network.for eg. sharad-ec2-hosts.cfg . And add the hostname and its details which you want to monitor.
By doing this you are adding a server to monitor from Nagios Server.

vi /etc/nagios3/conf.d/sharad-ec2-hosts.cfg

define host{
        use                     generic-host; Name of host template to use
        host_name               web.example.com
        alias                   Web Server
        address                 10.10.10.23
        }

Step 8: Now add the service to monitor for your nagios client (web.example.com).
In same file /etc/nagios3/conf.d/sharad-ec2-hosts.cfg add the below given lines.
Now through nrpe the check_disk plugin will check the disk.

vi /etc/nagios3/conf.d/sharad-ec2-hosts.cfg

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       web.example.com
        service_description             Disk Space
        check_command                    check_nrpe!check_disk
        }

Step 9: Restart the following services

/etc/init.d/nagios3 restart

/etc/init.d/apache2 restart

Note:
Question: Why we use check_nrpe!check_disk in check_command ?
answer=> Because check_nrpe is itself a plugin. The symbol ! tells what is the next argument. Here the next argument is check_disk. In nrpe.cfg file in Nagios Client (web.example.com) we are using the given below line and using the command name check_disk
see step 4 (the line command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1)

Hence the nrpe (port no. 5666)from nagios server will communicate to Nagios client at port no. 5666 and will search for argument in /etc/nagios/nrpe.cfg file. Here nrpe found the argumant check_disk.

Similarly you can add other commands to check.
I will recommend you to just explore all config files. Once you understand the concept you can easily play with Nagios server

Read Some More Articles

20 Comments

  1. Hello,
    For Nagios Server I am choosing ” Amazon Linux AMI 2017.03.0 (HVM), SSD Volume Type – ami-c58c1dd3 ”
    And I try to add CentOs, Ubuntu, Windows Servers. It taking only Centos and AWS Linux servers, But I try to ADD Ubuntu And Window Servers, Here I am getting the Error:
    [root@ip-172-31-9-101 nagios]# vim nagios.cfg
    [root@ip-172-31-9-101 nagios]# service nagios restart
    Running configuration check… CONFIG ERROR! Restart aborted. Check your Nagios configuration.
    If I uncomment the Ubuntu Path in Nagios.cfg file (Ubuntu Server :#cfg_file=/etc/nagios/servers/ProdAppEmpi.cfg), It’s Working.
    [root@ip-172-31-9-101 nagios]# vim nagios.cfg
    [root@ip-172-31-9-101 nagios]# service nagios restart
    Running configuration check…done.
    Stopping nagios: done.
    Starting nagios: done.
    Here My question is, does we choosing Centos for Nagios server it Accept only centos Server for Remote monitoring. And If we choose Ubuntu Does it accept only Ubuntu servers.
    We do have any Option to add all types of NRPE (Remote Monitor Servers) to one Nagios Server(either centos r Ubuntu r windows..etc..) ?????

  2. I have Installed successfully. But I dont know how to to open all those plugins. What is the path for SSH and Path for Web Browser ? I mean how can check installed plugins are working or not ?

    1. Hello Raj,

      It seems, you are newly introduced with nagios. Welcome in Nagios Monitoring World.
      The easy approach is, check your Nagios Dashboard. If all alerts are visible it means it is okay.

      There are some other command line troubleshooting we have to take. It seems, I should also write the troubleshooting part in Nagios.
      I assure, I will write a post on it and will update you soon as well.

      Regards
      Sharad

  3. Dude, nice tutorial but I had to disable the favicon feature in Firefox before actually being able to read something on your site.

    That blink-blink is very annoying.

    1. Thanks Ducoci,
      I am happy to hear ,the tutorial helped you.
      Yeah,this blinking favicon,I also do not like.Creating new favicon.Keep reading our blog,there are many nagios and other useful tutorials.

      Regards
      Sharad

  4. Hi, i always get this error in my web-frontent: (Return code of 127 is out of bounds – plugin may be missing)

    Server is a ubuntu 13 remote-host is a debian 7 system.

    What do you think is the problem here?

    1. Hello Matthias,

      Follow the troubleshooting points in nrpe.cfg file

      (1) Check the file nrpe.cfg. In this file the command name has path for plugin for eg. check_disk = /path/of/plugin
      (2) after getting the path of plugin mentioned in nrpe.cfg file, check does the plugin exist in same path if not then make correction in nrpe.cfg file.
      (3) The command name which you have given in Nagios server must have same name in nrpe.cfg in client side with correct plugin path.

      Let me know if problem still exists

      Regards
      Sharad

  5. And I was wondering if we need to install nrpe-server in server as well because, in your server, you just install nagios3 but here you’re saying to restart apache2, nrpe and nagios3.

    Confused

    1. NRPE server in same Nagios Server is not required to install and restart .I will edit this one. I had created another Monitoring Server which was communicating in port no. 5666 to my nagios ,I was doing some hack with port 5666 and nrpe.

  6. Hi there,

    I am sorry again to barge in and say but I would urge you to change what you have written in Step 1.

    Its says server and again step it says do this in server.

    I think it would be more understandable if you differentiate like Ubuntu-Client and Ubuntu-Server.

    Cheers.

    1. yes correct in ubuntu and debian it is apache2.
      In Red Hat base httpd.

      Thanks for informing about typo error

    2. Hola gente una preguna que la verdad no entiendo, donde instalar el server y el plugins.

      tengo una maquina debian y ahi instale nagios y otra pc con debian solo,
      mi pregunta es donde debo instalar en nagios-nrpe-plugin nagios-nrpe-server ?

      yo cuando pongo aptitude search nrpe solo me figuran nagios-nrpe-plugin nagios-nrpe-server.

      muchas gracias

      1. Hola Mariano,

        I am translating your question,so that other readers also know about your question.
        “Hi folks an inquiry that really do not understand where to install the server and plugins.

        I have a debian machine and install nagios there and another pc with debian only,
        my question is where should I install nagios-nrpe-plugin nagios-nrpe-server?

        I get aptitude search when I only include nrpe nagios-nrpe-plugin nagios-nrpe-server.

        thank you very much”

        Answer: You can install nagios-nrpe-plugin nagios-nrpe-server in both server as well as in client.
        NRPE listen on port no. 5666. It depeneds upon system admin for Nagios Server check which method he uses. Because Nagios Server should also be monitored by itself. You can also monitor Nagios Server itself without installing NRPE plugin and service.
        Suggest you to setup Nagios Server and alerts. Explore plugins . Plugins are just a script.
        I hope you understand .

        Translating to Spanish by using Google Translate –
        Hola Mariano
        Puede instalar nagios-plugins-nrpe nagios-nrpe-servidor, tanto en el servidor como en el cliente.
        NRPE escuchar en el puerto no. 5666. Se depeneds a administrador de sistema para el check Nagios servidor qué método se utiliza. Debido Nagios Server también debe ser monitoreada por sí mismo. También puede supervisar Nagios propio servidor sin necesidad de instalar NRPE plugin y servicio.
        Usted sugiere configurar Nagios Server y alertas. Explora plugins. Los plugins son sólo una secuencia de comandos.
        Espero que lo entiendas.
        saludos
        Sharad

        1. Muchas gracias por la respuesta.

          me da error zetian es la maquina que quiero chequear, me fije en services y le agrege el puerto 5666 en las dos maquinas, pero en nagios tengo ping hacia la maquina que quiero chequear pero con el comando de nagios me pone es localhost
          Debian GNU/Linux
          Current Load
          OK 2014-06-23 12:00:49 17d 21h 7m 58s 1/4 OK – load average: 0.08, 0.21, 0.22
          Current Users
          OK 2014-06-23 11:58:16 17d 21h 7m 8s 1/4 USERS OK – 2 users currently logged in
          Disk Space
          OK 2014-06-23 11:59:12 17d 21h 6m 18s 1/4 DISK OK
          HTTP
          OK 2014-06-23 11:58:19 17d 21h 5m 28s 1/4 HTTP OK: HTTP/1.1 200 OK – 454 bytes in 0.001 second response time
          SSH
          OK 2014-06-23 12:01:22 17d 21h 4m 38s 1/4 SSH OK – OpenSSH_6.0p1 Debian-4+deb7u1 (protocol 2.0)
          Total Processes
          OK 2014-06-23 12:00:50 17d 21h 3m 48s 1/4 PROCS OK: 167 processes
          zetian
          Disk Space
          UNKNOWN 2014-06-23 11:58:38 3d 23h 27m 21s 4/4 (No output returned from plugin)
          … muchas gracias igual.

        2. Hello thank you very much for the reply, install the plugins and server in (nagios server and the terminal). nagios UNKNOWN in me. I put in service protocol 5666, which may be doing wrong? thank you very much

        3. Hi folks thanks for the reply, I did everything but it gives me error says, this is what shows nagios.
          Disk Space
          UNKNOWN 2014-06-23 13:53:38 4d 1h 18m 29s 4/4 (No output returned from plugin)

          1. Ok, it seem the plugin is not working properly.
            In this case, we have to do some troubleshooting with nagios plugin.
            Go to client server where you have installed nagios plugin.
            Search the nagios plugin, regular name is check_disk .
            Change to nagios plugin directory and run the command ./check_disk –help. It will show you available parameter.
            Use those parameter. also run command df -h to check which disk you are about to check with check_disk script.
            If result is same as Error you got.It means we have to check the script or check the parameters which you have given. Kindly let me know what is the result

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.