Add NRPE host to Nagios

NRPE (Nagios Remote Plugin Executor) is a Nagios agent witch allows for remote  system monitoring by executing scripts on a remote system allowing monitoring of disk usage, system’s load or number of users currently logged in and much more. Normally Nagios can only monitor public services such as HTTP & FTP. This is great if you only want to monitor public servers, however I bet that most people want to monitor their own servers and have access to private information, that’s were NRPE comes in. It works on a client server basis, you install a daemon on the machine you  want to monitor, then setup your Nagios server to connect to the remote daemon to gather information



So how do we set this up, well first we need to be running a Nagios server.Once you have a Nagios server setup you’ll need to download and install the NRPE daemon on the remote machine.

So lets get started first SSH into your remote machine and enter:

/usr/sbin/useradd nagios
passwd nagios

this will setup a new Nagios user, now we need to install some plugins:

tar -xzf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make
sudo make install

This will download and install the Nagios plugins required for NRPE to run, now we need to give the plugins access via the new Nagios user:

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

NRPE require you install xinetd and libssl-dev so we’ll do that now

apt-get install xinetd
sudo apt-get install libssl-dev

Now that done its time to install the NRPE daemon itself:

cd ~/
tar xzf nrpe-2.12.tar.gz
cd nrpe-2.12
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd

now we need to configure the daemon so it will talk to our Nagios server, well do this buy editing /etc/xinetd.d/nrpe and adding our monitoring servers address:

nano /etc/xinetd.d/nrpe
Should Look Like:
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
        flags           = REUSE
        socket_type     = stream
        port            = 5666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = [NAGIOS SERVER ADDRESS]

Then add “nrpe 5666/tcp # NRPE” to /etc/services:

nano /etc/services
nrpe 5666/tcp # NRPE

you can check this all been configured probably by typing:

netstat -at | grep nrpe

this should show something like

(tcp        0      0 *:nrpe                  *:*                     LISTEN)

If that worked correctly its time to setup your Nagios server to monitor your remote host, so ssh into your Nagios server. Now we are going to add separate host file for the new host so we need to edit the nano “nagios.cfg” file:

nano /usr/local/nagios/etc/nagios.cfg
add lines:

Now we need to create the Host1.cfg:

nano /usr/local/nagios/etc/objects/host1.cfg

and enter the following code:

define host{
        use linux-server ; Inherit default values from a template
        host_name remotehost ; The name we're giving to this server
        alias Fedora Core 6 ; A longer name for the server
        address; IP address of the server

define service{
        use generic-service
        host_name remotehost
        service_description CPU Load
        check_command check_nrpe!check_load

define service{
        use generic-service
        host_name remotehost
        service_description Current Users
        check_command check_nrpe!check_users

define service{
        use generic-service
        host_name remotehost
        service_description /dev/hda1 Free Space
        check_command check_nrpe!check_sda1

define service{
        use generic-service
        host_name remotehost
        service_description Total Processes
        check_command check_nrpe!check_total_procs

define service{
        use generic-service
        host_name remotehost
        service_description Zombie Processes
        check_command check_nrpe!check_zombie_procs

Run the nagios config check then restart nagios:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios restart

And hay presto you Nagios should now be monitoring your remote host, don’t worry if it says pending it can take up to 5 minutes for the information to come through.

If you want to add more hosts repeat the above steps and use host2.cfg instead of host1.cfg.


the critical in the above screen dump is because I had disabled ICMP on the remote server.


Installing Nagios on Ubuntu

Nagios is the Industry Standard Network Monitoring Engine. OK great so whats that mean, well nagios is a server that monitors your hosts and services and will inform you if something goes wrong and when it is fixed again. It can monitor network services, host resources and even network probes such as temperature and moisture.

These features as well as many more make nagios, by far, the most complete Network Monitoring tool on the market, however with all these features comes complexity and nagios has obviously been designed with the experienced Network Administrator in mind. But don’t worry too much, its not that difficult to learn as long as you take it one step at a time, and in today’s tutorial we’re going to look at the first step, actually getting it installed


First of all you will need a server running the LAMP Stack. Then you will need to setup a special user account and group for nagios, this allows nagios to have some rights over the server without giving it full root access, to do this first type:

sudo useradd -m -s /bin/bash nagios

to add the new user and group, then you’ll need to set the password, use:

sudo passwd nagios

Now create the ‘nagcmd’ group to allow external commands to be run, then add the nagios user and the apache user to the group:

sudo /usr/sbin/groupadd nagcmd
sudo /usr/sbin/usermod -a -G nagcmd nagios
sudo /usr/sbin/usermod -a -G nagcmd www-data

Now that’s all out of the way you’ll need to download Nagios (I recommend downloading it to its own directory, eg. ~/nagios-install):


then extract the source code form the tar file and navigate into the new folder:

tar -xzf nagios-3.4.3.tar.gz
cd nagios-3.2.1

now we just need to download gcc, the c++ compiler,

sudo apt-get install gcc

Now its time to install nagios, we are going to do this buy compiling the source code, this can seem a little confusing the first time you do it, but don’t worry you don’t relay have to understand it yet (that comes when you start to make your own programs) just follow the lines and you will be ok:

./configure --with-command-group=nagcmd
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode

Now we just need to configure the contacts .cfg file so nagious can email us the report:

sudo vim /usr/local/nagios/etc/objects/contacts.cfg

and change the email field to your email address.

Because the installer thinks Apache is installed in /etc/httpd/ witch it isn’t, we need to make a symlink to /etc/apache2/. A symlink is a file or folder that contains reference to another folder/file, so when the installer thinks its installing into /etc/httpd its actually installing into apache2, to do this type:

sudo mkdir /etc/httpd
sudo ln -s /etc/apache2/* /etc/httpd/
sudo make install-webconf

now we need to add the password to login to our nagios site, remember this password you will need it later:

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

restart apache

sudo /etc/init.d/apache2 reload

You don’t need to do the next step, however its extremely useful to install the base plug in pack to provide some extra functionality for nagios, to do this

cd ~/
tar -xzf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make
sudo make install

Configure Nagios to automatically start when the system boots.

sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the sample Nagios configuration files.

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, start Nagios.

sudo /etc/init.d/nagios start

now you can login to Nagios buy going to http://your_ip/nagios/ in your web browser and using the details:

password:[the password you set earler]

And that’s about it you should now have a nagios server set-up that is monitoring the local host

You may need to update nagios to its latest version, to do this type:

cd /usr/local/src
sudo wget
sudo tar xvzf nagios-3.2.2.tar.gz
cd nagios-3.2.2
sudo ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd --enable-nanosleep --enable-event-broker
sudo make all
sudo make install
sudo make install-init
sudo make install-commandmode
sudo make install-config
sudo update-rc.d -f nagios defaults
cd ..