How to add Linux hosts to Nagios server for monitoring
Nagios is free and open source application that is used for monitoring the complete It infrastructure i.e. computers, firewalls, printers, networks etc. It provides real time updates of usage of various resources like ram, hdd or cpu usage of the systems & also provides alerts when things go wrong like CPU limit exceeds, ram over utilizations etc. In our earlier tutorial, we created a nagios server but that was only monitoring services of localhost. In this tutorial, we will discuss complete process to add a Linux machine for monitoring on Nagios server & we use NRPE plugin to achieve it.
NRPE or Nagios Remote Plugin Executor the utility that allows us to monitor the local resources of a Linux host on Nagios monitoring server. It allows us to remotely execute the plugins on a Linux machine and it can also communicate with some of the Windows but for the purpose of this tutorial, we will only be using it on Linux machines. NRPE will installed on both nagios server & Linux client machine.
Pre-requisites
- A working nagios server.
We have already created a nagios server from our previous tutorial, with an IP address 192.168.1.100
- A Linux client machine
We will need a Linux client machine, we will be using a machine with CentOS 6 installed with an IP address 192.168.1.115 but you can also use other Linux versions. Process will remain the same.
- Required packages installed on client machine
Like we did with nagios server, we need to install some packages before we can actually install NRPE on client machine. To install these packages, run
$ yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel
Now we will start with installing & configuring the NRPE & nagios plugins on client machine first & then will install NRPE on nagios server.
Linux client machine configuration
Step 1- Download the Nagios Plugins
We will firstly need to download nagios plugins on client machine. To obtain the nagios plugins, use the link below
$ wget https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz
Step 2- Installing & Configuring the plugin
We will now configure a user for nagios with the name ‘nagios’. To add a user “nagios”, run
$ useradd nagios
$ passwd nagios
Next we will install the plugins, goto the folder with plugins & extract them
$ cd /home/dan
$ tar -xvf nagios-plugins-2.1.4.tar.gz
$ cd nagios-plugins-2.1.4
Then compile & install the plugin
$ ./configure –with-nagios-user=nagios
$ make
$ make install
Step 3- Changing the ownership of plugin folder
We need to change the ownership of the plugins folders, after we have installed them on the client machine. To change ownership of the folder, run
$ chown nagios.nagios /usr/local/nagios
$ chown -R nagios.nagios /usr/local/nagios/libexec
Step 4 – Downloading & installing NRPE
After we have installed the nagios plugins on the machine, we will now download & install NRPE on client machine. Download NRPE from 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
& now compile & install the package
$ ./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 #
Step 5 – Configuring NRPE
After installation of NRPE, we will make some changes to the configuration to the NRPE config file i.e. /etc/xinet.d/nrpe. Open configuration file and add edit the ‘only_from’ parameter to add ‘localhost’ & ‘IP address of nagios server’
$ vi /etc/xinet.d/nrpe
only_from = 127.0.0.1 localhost 192.168.1.100
Than open the file /etc/services file to add nrpe as service, & add following line
$ vi /etc/services
nrpe 5666/tcp NRPE
Save the file & exit. Then start xinetd service
$ service xinted restart
Step 6- Verifying connectivity from Nagios server to client
Most of the configurations on client machine are now complete, we just need to make sure that client machine is actually able to connect from nagios server. To check the connectivity from Nagios server to client machine, run the following command on terminal of nagios server
$ /usr/local/nagios/libexec/check_nrpe -H 192.168.1.115
192.168.1.115 is the IP of Linux client machine. If there is no problem in connectivity between nagios server and client, we should get nrpe version as output of successful execution of the command.
Nagios Server configuration
Step 1- Download & install NRPE
Similarly as we did on Linux client machine, we will install NRPE on nagios server as well. So download the NRPE package, extract it & then install it,
$ tar -xzvf nrpe-3.0.1.tar.gz
$ cd nrpe-3.0.1
$ ./configure
$ make all
$ make install-daemon
Step 2 – Adding remote Linux host
We will now add the Linux client machine on nagios server, to do that we need to create two files, named ‘linuxhosts.cfg’ for adding Linux client host information & linuxservices.cfg for adding services that will run on Linux client host, in folder “/usr/local/nagios/etc/”
$ cd /usr/local/nagios/etc/
$ touch linuxhosts.cfg
$ touch linuxservices.cfg
Now we need to edit nagios.cfg to add these to files location for nagios to read
$ vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/linuxhosts.cfg
cfg_file=/usr/local/nagios/etc/linuxservices.cfg
Both the files linuxhosts.cfg & linuxservices.cfg are empty but there are default templates for hosts & services that we can use. These templates are located in /usr/local/nagios/etc/objects/, we now copy these templetes to these two files & edit them as per our need. Firstly , open linuxhosts.cfg & edit it
$ vi /usr/local/nagios/etc/linuxhosts.cfg
Next, add services in linuxservices.cfg
$ vi /usr/local/nagios/etc/linuxservices.cfg
& lastly, we will add NRPE command definition to /usr/local/nagios/etc/objects/commands.cfg. Open the file & add the following
$ vi /usr/local/nagios/etc/objects/commands.cfg
###############################################################################
# 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$
}
Save file & exit.
Step 3 – Verifying Nagios configuration file
After all the changes have been made, we will now verify the nagios configurations against a sample nagios configuration file,
$ /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
After output of the above commands returns with no-errors, restart the nagios service to implement all the changes we have made.
$ service nagios restart
Step 4 – Checking services on web-console
We will now check the status of Linux client services on web console. Open nagios web-console,
http://192.168.1.100
Once logged in, goto ‘services’ page & all the services for the client along with localhost should be listed here.
difficult to cut and paste from image files :)
$ make install-daemon-config # Install plugin daemon sample config file #
$ make install-xinetd # Install plugin daemon as a service under xinetd #
These steps are not working.
[root@localhost nrpe-3.2.1]# make install-daemon-config
make: *** No rule to make target `install-daemon-config’. Stop.
[root@localhost nrpe-3.2.1]# make install-xinetd
make: *** No rule to make target `install-xinetd’. Stop.
[root@localhost nrpe-3.2.1]#