Nagios is an open source software that monitors systems, networks and infrastructure. In our previous tutorial, we explained how to install and configure the latest Nagios Core on CentOS 7. In this tutorial, you will learn how to add Remote CentOS Machine and it’s services into Nagios Monitoring host using NRPE Agent.
Know about NRPE?
NRPE (Nagios Remote Plugin Executor) plugin allows nagios to monitor any local resources like Memory usage, CPU load, Swap, logged-in users, etc. on remote Linux/Unix services or network devices . Since, these local resources are not mostly exposed to external machines, an NRPE agent should be installed and configured on the remote machines.
Prerequisite
- Nagios Server
- Remote Linux Host (CentOS)
Installation of NRPE Plugin On Remote Linux Host
- Prerequisite of Nagios
Please use below step by step instructions to install nagios plugin and NRPE daemon on Remote CentOS Host. Make sure you have LAMP Stack installed and execute below commands to install required dependencies on remote machine.
# yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel wget curl -y
- Create Nagios User
You have to create a new nagios user and set the password for it.
# useradd nagios
# passwd nagios
- Download & Configure Nagios-Plugin
Now create a directory for nagios plugin installation and download the latest nagios plugin.
# mkdir /nagios ; cd /nagios
# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
After this execute the below tar command to extract latest nagios plugin source code.
# tar -xvf nagios-plugins-2.2.1.tar.gz
# ls -l
total 2672
drwxr-xr-x. 15 root root 4096 Apr 19 2017 nagios-plugins-2.2.1
-rw-r--r--. 1 root root 2728818 Apr 19 2017 nagios-plugins-2.2.1.tar.gz
Next, compile and install using the below commands.
# cd nagios-plugins-2.2.1
# ./configure --with-nagios-user=nagios
# make
# make install
set the permission for nagios installation files.
# chown nagios.nagios /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/libexec
- Download and Configure NRPE add-on
Please follow the below steps to Install NRPE add on in your system.
# cd /nagios # wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-3.2.1.tar.gz
Unpack the NRPE add on source code tarball using tar command.
# tar xzf nrpe.tar.gz
# cd nrpe-nrpe-3.2.1
Now compile and install the NRPE addon.
# ./configure --enable-command-args
# make all
Next, install the binaries & configuration files.
# make install
# make install-config
Next, open /etc/services file add the “nrpe 5666/tcp NRPE” entry for the NRPE daemon at the bottom of the file. Then restart the xinetd service.
# echo >> /etc/services
# echo '# Nagios services' >> /etc/services
# echo 'nrpe 5666/tcp' >> /etc/services
- Install Service / Daemon
This installs the service or daemon files.
# make install-init
# systemctl enable nrpe.service
- Configure Firewall
Port 5666 is used by NRPE and must be opened on the local firewall.
- CentOS 6/ RHEL 6
# iptables -I INPUT -p tcp --destination-port 5666 -j ACCEPT
# service iptables save
# ip6tables -I INPUT -p tcp --destination-port 5666 -j ACCEPT
# service ip6tables save
2. CentOS 7/ RHEL 7
# firewall-cmd --zone=public --add-port=5666/tcp
# firewall-cmd --zone=public --add-port=5666/tcp --permanent
# firewall-cmd --reload
- Update Configuration File
The file nrpe.cfg must be updated with the nagios server ip address.
# vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1, <Nagios_Server_IP_Addr>
dont_blame_nrpe=1
Next start the nrpe service.
# systemctl start nrpe.service
- Verify NRPE Daemon
Run the following command to verify the NRPE daemon working correctly under xinetd.
# netstat -at | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
If you get output similar to above, means it working correctly. If not, make sure to check the following things.
- Check you’ve added nrpe entry correctly in /etc/services file
- The only_from contains an entry for “nagios_ip_address” in the /etc/xinetd.d/nrpe file.
- The xinetd service must be installed and started.
- Check errors in system log files about xinetd or nrpe and fix problems.
Next, verify the NRPE daemon is functioning properly. Run the “check_nrpe” command that was installed earlier for testing purposes. You will get a following string on the screen, it shows you what version of NRPE is installed.
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v3.2.1
- Making changes in NRPE Configuration file
So your are good to customize the nrpe configuration files as per your requirement once it starts working.
# vim /usr/local/nagios/etc/nrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1 or /dev/sda
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
You can edit and add more command definitions by editing the NRPE config file. Hence, you’ve successfully installed and configured NRPE agent on the Remote Linux Host. After making changes you have to restart the nrpe service.
# systemctl restart nrpe.service
On Nagios Monitoring Server
Next login into your Nagios Monitoring Server. Here you need to follow the below steps:
- Download and Install check_nrpe plugin.
- Create a Nagios command definition using the check_nrpe plugin.
- Create Nagios host and add service definitions to monitor the remote Linux host
- Download and Install NRPE Plugin
Go to the nagios download directory and download the latest NRPE add on using wget command.
# cd /nagios
# wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-3.2.1.tar.gz
Extract the NRPE source code tarball.
# tar xzf nrpe.tar.gz
# cd nrpe-nrpe-3.2.1
You need to compile and install the NRPE add-on.
# ./configure --enable-command-args # make all # make install # make install-config
- Verify NRPE Daemon
Please be sure that the check_nrpe plugin must communicate with the NRPE daemon on the remote host.
# /usr/local/nagios/libexec/check_nrpe -H <Remote-host-IP>
NRPE v3.2.1
If you get plugin time-out error, then please check the below things.
- Be sure firewall isn’t blocking the communication between the remote host and the monitoring server.
- Be sure NRPE daemon is installed properly under xinetd.
- Be sure the remote host firewall rules blocking the monitoring server from communicating to the NRPE daemon.
Adding Remote Linux Host to Nagios Monitoring Server
While adding a linux remote host you need to create a two new files “hosts.cfg” and “services.cfg” under “/usr/local/nagios/etc/” location. As we are adding centos remote host to nagios server so we will be creating centos-host.cfg and centos-services.cfg for better understanding.
# cd /usr/local/nagios/etc/
# touch centos-hosts.cfg
# touch centos-services.cfg
Now add these two files in the end of main Nagios configuration file. Open nagios.cfg file with your favourite editor.
# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/centos-hosts.cfg
cfg_file=/usr/local/nagios/etc/centos-services.cfg
- Define New Linux Host (CentOS)
We have no idea how to define and configure hosts. So, let’s not worried because default templates available at /usr/local/nagios/etc/objects/ just copy and paste it into your host file.
# vim /usr/local/nagios/etc/centos-hosts.cfg
######################################################################### HOST TEMPLATES ######################################################################### # Define a host for the remote machine define host{ use linux-server ; Name of host template to use ; This host definition will inherit all variables that are defined ; in (or inherited by) the linux-server host template definition. host_name thecodecloud.in alias CentOS 7 address 192.168.0.6 } # Linux host definition template # This is NOT a real host, just a template! define host { name linux-server ; The name of this host template use generic-host ; This template inherits other values from the generic-host template check_period 24x7 ; By default, Linux hosts are checked round the clock check_interval 5 ; Actively check the host every 5 minutes retry_interval 1 ; Schedule host check retries at 1 minute intervals max_check_attempts 10 ; Check each Linux host 10 times (max) check_command check-host-alive ; Default command to check Linux hosts notification_period 24x7 ; Linux admins hate to be woken up, so we only notify during the day notification_interval 30 ; Resend notifications every 2 hours notification_options d,r ; Only send notifications for specific host states contact_groups admins ; Notifications get sent to the admins by default register 0 ; DON'T REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE! }
- Define service for Remote Linux Host
Next open services.cfg file and add the following services to be monitored.
# vim /usr/local/nagios/etc/centos-services.cfg
##########################################################################
SERVICE DEFINITIONS ########################################################################## # Define a service to "ping" the remote machine define service{ use generic-service host_name thecodecloud.in service_description PING check_command check_ping!100.0,20%!500.0,60% } define service{ use generic-service host_name thecodecloud.in service_description Root Partition check_command check_local_disk!20%!10%!/ } define service{ use generic-service host_name thecodecloud.in service_description Current Users check_command check_local_users!20!50 } define service{ use generic-service host_name thecodecloud.in service_description Total Processes check_command check_local_procs!250!400!RSZDT } define service{ use generic-service host_name thecodecloud.in service_description Current Load check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0 } define service{ use generic-service host_name thecodecloud.in service_description Swap Usage check_command check_local_swap!20!10 } define service{ use generic-service host_name thecodecloud.in service_description SSH check_command check_ssh notifications_enabled 0 } define service{ use generic-service host_name thecodecloud.in service_description HTTP check_command check_http notifications_enabled 0 }
- Define NRPE Commands for Linux Host
NRPE command definition should be created in commands.cfg file.
# vim /usr/local/nagios/etc/objects/commands.cfg
Now add the following NRPE command definition in the end of the file.
#Command to use NRPE to check remote host systems define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
- Verify Nagios Configuration Files
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors: 0
- Restart Nagios Service
# systemctl restart nagios.service
- Accessing Nagios Web Interface
Try to access nagios web console via your browser to http://localhost/nagios or http://IP-Address/nagios or http://Domain-Name/nagios and enter the Username and Password then click “Hosts”, Here you can see the new linux hosts which have been added by you.




That’s it! for now, in our next article we will show you how to add Windows host to Nagios monitoring Server.
Conclusion
Hence, you have learned How to Add Remote Linux Host to Nagios Monitoring Server. I hope I helped.. Thanks !!
Read Also: How to Setup and Configure Nagios Core on CentOS 7