In my previous article we had discovered how to install Nagios Server on Ubuntu 16 LTS 64 bit, now we need to understand how to monitor a remote host using Nagios server. Firstly, to be able to monitor remote host server we need to NRPE daemon over an (optionally) SSL-protected connection that will be contacted by check_nrpe executed on the nagios server to run the appropriate Nagios plugin.
Prerequisites
– Ubuntu 16.04 LTS – 64bit server
– A superuser Privilege
– A Nagios Server Monitor, you can take a look to this article : How To Install Nagios core 4 on Ubuntu 16 LTS
What we will do in this tutorial:
– Install NRPE service from a repository.
– Configure NRPE to allow Nagios server to execute checks.
– Add a host file configuration on the Nagios server.
Let’s start our tutorial.
1./ Install NRPE Daemon and Nagios Plugins
NRPE is available under default apt repositories of Ubuntu systems. Execute the following command to install it
# apt install nagios-nrpe-server nagios-plugins
2./ Configure NRPE Daemon
To allow our Nagios server to execute checks plugins in our remote host:
– First we need to edit the /etc/nagios/nrpe.cfg file and add the IP address of the monitoring server to the allowed_hosts directive and modify dont_blame_nrpe value from 0 to 1 to allow command arguments.
# vi /etc/nagios/nrpe.cfg
allowed_hosts=127.0.0.1, 192.168.1.17 # add your nagios_ip_address dont_blame_nrpe=1
– Second,we need to add the following entry nrpe 5666/tcp # NRPE for the NRPE daemon to the /etc/services file.
# vi /etc/services nrpe 5666/tcp # NRPE
finally, we need to restart our NRPE Daemon, open firewall rules and make some checks to verify if every things work properly.
# firewall-cmd --permanent --add-port=5666/tcp # firewall-cmd --reload
# systemctl restart nagios-nrpe-server
# netstat -at | grep nrpe tcp 0 0 *:nrpe *:* LISTEN tcp6 0 0 [::]:nrpe [::]:* LISTEN
3./Add Check Commands in NRPE
By default after the installation of NRPE daemon in the file /etc/nagios/nrpe.cfg it will be created a few commands like below.
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20 command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1 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
Here i’ll add more commands
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10 command[check_sda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1 command[check_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200 -s RSZDT command[check_disk_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p / command[check_swap]=/usr/lib/nagios/plugins/check_swap -w 20% -c 10%
Each time we make any changes in configuration file we need to restart the nrpe service.
# systemctl restart nagios-nrpe-server
4./ Add a remote host to the monitoring Nagios server
Let’s move to our monitoring nagios server.
i.)Create a Command Definition
First, to be able to use check_nrpe plugin we need to create a command definition in the commands.cfg file.
# vi /usr/local/nagios/etc/commands.cfg
and add the following definition to the file:
define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
ii.)Organizing Nagios Configuration
-open nagios file configuration:
# sudo vi /usr/local/nagios/etc/nagios.cfg
-uncomment this line
cfg_dir=/usr/local/nagios/etc/servers
-create servers directory where we’ll store the configuration file for each server that we will monitor
# sudo mkdir /usr/local/nagios/etc/servers # chown -R nagios.nagios /usr/local/nagios
iii.)Configure Nagios Contacts
# sudo vi /usr/local/nagios/etc/objects/contacts.cfg email nagios@localhost ; # CHANGE THIS TO YOUR EMAIL ADDRESS
iiii.)Create host and service definitions
-Create a new remote host file configuration under the directory /usr/local/nagios/servers/ and add the host definition and the services definition that you want to be monitored.
# vi /usr/local/nagios/etc/servers/node01.cfg
############################################################################### ############################################################################### # # HOST DEFINITION # ############################################################################### ############################################################################### define host{ use linux-server host_name node01 #PUT HERE YOUR HOSTNAME REMOTE SERVER alias node01 #PUT HERE THE ALIAS OF YOUR REMOTE SERVER address 192.168.1.55 #PUT HERE THE IP ADDRESS OF YOUR REMOTE SERVER max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 } ############################################################################### ############################################################################### # # HOST SERVICES DEFINITION # ############################################################################### ############################################################################### define service{ use generic-service host_name node01 service_description PING check_command check_ping!100.0,20%!500.0,60% } define service { use generic-service host_name node01 service_description SSH check_command check_ssh notifications_enabled 0 } # for free disk SDA1 define service{ use generic-service host_name node01 service_description SDA1 Disk check_command check_nrpe!check_sda1 } # for free Root Partition define service{ use generic-service host_name node01 service_description Root Partition check_command check_nrpe!check_disk_root } # for current users define service{ use generic-service host_name node01 service_description Current Users check_command check_nrpe!check_users } # for total processes define service{ use generic-service host_name node01 service_description Total Processes check_command check_nrpe!check_procs } # for current load define service{ use generic-service host_name node01 service_description Current Load check_command check_nrpe!check_load }
-Verify nagios configuration files using this command
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-Restart nagios
# systemctl restart nagios
-Finally open the nagios web interface to check if the remote host is added properly.
1 comment
Im getting this error.Could you please rectify this issue
Read main config file okay…
Error: Could not find any host matching ‘node01’ (config file ‘/usr/local/nagios/e tc/servers/node01.cfg’, starting on line 67)
Error: Failed to expand host list ‘node01’ for service ‘Current Load’ (/usr/local/ nagios/etc/servers/node01.cfg:67)
Error processing object config files!
***> One or more problems was encountered while processing the config files…
Check your configuration file(s) to ensure that they contain valid
directives and data definitions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
‘Whats New’ section to find out what has changed.