Nagios Server : Adding Linux hosts for monitoring using NRPE

Last updated on March 12th, 2018 at 09:32 pm

In our earlier tutorials, we installed & configured Nagios Monitoring server & also added Windows host to Nagios Server using NSClient++. In this tutorial, we will learn to add Linux Hosts to Nagios Server with the help of NRPE.

NRPE aka Nagios Remote Plugin Executor, allows us to monitor the local resources of a Linux host on Nagios monitoring server. It needs to be installed on both Linux host & on Nagios server. So let’s start with configuring Linux host first.

(Recommended Read: Easy guide to setup Nagios monitoring using SSH (check_by_ssh))

 

Configuring Linux Host

Before we begin installtion, we will first install Nagios plugin on host

  • Installing required packages

Install the following packages to resolve all dependencies required for installing the plugins ,

$ yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel

 

  • Download the Nagios Plugins

Next, we will download the Nagios plugins from the following url

$ wget https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz

 

  • Installing & Configuring the plugin

Before installing Nagios plugin, we need to add a user “nagios”

$ useradd nagios
$ passwd nagios

after creating user, goto the folder with plugins. We will now extract the plugins

$ tar -xvf nagios-plugins-2.1.4.tar.gz
$ cd nagios-plugins-2.1.4

And now we will compile & install the plugins

$ ./configure –with-nagios-user=nagios
$ make
$ make install

 

  •  Changing the ownership of plugin folder

After the plugins are installed, we will change the ownership of the plugins folders

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

 

  • Downloading & installing NRPE

Now its time we download  the plugin, use the link below

$ wget https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.0.1.tar.gz

then, extract the plugin

$ tar –xvf nrpe-3.0.1.tar.gz
$ cd nrpe-3.0.1

next, we compile & install it

$ ./configure
$ make all
$ make install-plugin
$ make install-daemon                                                                    # Install plugin daemon #
$ make install-daemon-config                 # Install plugin daemon sample config file #
$ make install-xinetd                    # Install plugin daemon as a service under xinetd #

 

  • Making changes to Config file

Now open config file and add the localhost and IP address of the Nagios Monitoring Server.

$ vi /etc/xinet.d/nrpe
only_from = 127.0.0.1 localhost 192.168.1.100

& in /etc/services file , add following line & save it

$ vi /etc/services
nrpe        5666/tcp        NRPE

finally, start xinetd

$ service xinted restart

Note:- xinted is installed on most of the Linux distributions by default, but if that is not the case you install it using

yum install xinetd.

 

  • Verifying connectivity from Nagios to host

Now that the plugin has been installed, we will verify connectivity of host from nagios server by following on Nagios server

$ /usr/local/nagios/libexec/check_nrpe -H 192.168.1.115

where, 192.168.1.115 is IP address of Linux host which is to be monitored.

Note:- NRPE config file (/usr/local/nagios/etc/nrpe.cfg) has some of the commands already written on it, you can modify them as per your needs & can test them by directly running these on terminal.

Next, we move on to Nagios & configure it to receive updates from Linux host.

 

Nagios Server configuration

  • Download & install NRPE

First, we download & install remote plugin on Nagios server , as we did on Linux host

$ tar -xzvf nrpe-3.0.1.tar.gz
$ cd nrpe-3.0.1
$ ./configure
$ make all
$ make install-daemon

 

  • Adding remote Linux host

Create two files named linux_hosts.cfg & linux_services.cfg in folder “/usr/local/nagios/etc/

$ cd /usr/local/nagios/etc/
$ touch linux_hosts.cfg
$ touch linux_services.cfg

then we will edit nagios.cfg & add the following two files in it

$ vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/linux_hosts.cfg
cfg_file=/usr/local/nagios/etc/linux_services.cfg

Now, we will copy the default templates for hosts & services, present in /usr/local/nagios/etc/objects/ to these files & will edit them as per our need

Firstly , open  linux_hosts.cfg & edit it (see screenshot)

$ cd /usr/local/nagios/etc/linux_hosts.cfg

nrpe

then we will add services in linux_services.cfg (see screenshot)

$ cd /usr/local/nagios/etc/linux_services.cfg

nrpe

& lastly, we will add NRPE command definition to /usr/local/nagios/etc/objects/commands.cfg

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

& add the following command definition


###############################################################################
# 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$
}

 

  • Verifying Nagios configuration file


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

If there are any errors, resolve them & then restart the nagios server for changes to take effect.


$ service nagios restart

 

  • Open web-console

Open your web-console, by typing your nagios IP address or FQDN  in your browser & enter credentials for nagios. Once inside the web-console, goto services page & you should see that services for your Linux hosts have added here for monitoring .

 

So, this was our tutorial on how to add Linux hosts to Nagios server for monitoring. If you have any queries or comments, please mention them on the comment box down below.

 

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of you hard earned money:

Linux TechLab is thankful for your continued support.

Shusain

Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

You may also like...

Leave a Reply