How to Add Linux Host to Nagios Monitoring Server Using NRPE Plugin
add Remote Linux machine and it’s services to Nagios Monitoring host using NRPE agent.
What is NRPE?
The NRPE ( Nagios Remote Plugin Executor) plugin allows you to monitor any remote Linux/Unix
services or network devices. This NRPE add-on allows Nagios to monitor any local resources like
CPU load, Swap, Memory usage, Online users, etc. on remote Linux machines. After all, these local
resources are not mostly exposed to external machines, an NRPE agent must be installed and configured
on the remote machines.
Installation of NRPE Plugin
To use the NRPE, you will need to do some additional tasks on both the Nagios Monitoring Host and
Remote Linux Host that the NRPE installed on. We will be covering both the installation parts separately.
We assume that you are installing the NRPE on a host that supports TCP wrappers and Xinted daemon
installed on it. Today, most of the modern Linux distributions have these two installed by default. If not,
we will install it later during the installation when required.
On Nagios Monitoring Server
[root@nagios]# cd /tmp
[root@nagios]# wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.tar.gz
[root@nagios]# tar xzf nrpe-3.0.tar.gz
[root@nagios]#cd nrpe-3.0
[root@nagiosnrpe-3.0 ]# ./configure
[root@nagiosnrpe-3.0 ]# make
[root@nagiosnrpe-3.0 ]# make install-plugin
[root@nagiosnrpe-3.0 ]# make install-daemon
Next, open /etc/services file add the following entry for the NRPE daemon at the bottom of the file.
nrpe 5666/tcp NRPE
Step 2: Verify NRPE Daemon Locally
[root@nagiosnrpe-3.0 ]# netstat -at | grep nrpe
Step 3: Verify NRPE Daemon Remotely
[root@nagiosnrpe-3.0 ]# /usr/local/nagios/libexec/check_nrpe -H <remote_linux_ip_address>
RESULT GET PENDING
Step 4: Customize NRPE commands
The default NRPE configuration file that got installed has several command definitions that will be
used to monitor this machine. The sample configuration file located at.
[root@nagiosnrpe-3.0 ]# vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,(Nagios Server IP Addres)
The following are the default command definitions that are located at the bottom of the configuration
file. For the time being, we assume you are using these commands. You can check them by using the
following commands.
[root@nagios nrpe-3.0 ]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
USERS OK- 2 users currently logged in |users=2;5;10;0
[root@nagios nrpe-3.0 ]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
OK- load average: 3.28, 2.95, 2.94|load1=3.280;15.000;30.000;0; load5=2.950;10.000;25.000;0;
load15=2.940;5.000;20.000;0;
[root@nagios nrpe-3.0 ]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_sda1
DISK OK – free space: /boot 154 MB (84% inode=99%);| /boot=29MB;154;173;0;193
[root@nagios nrpe-3.0 ]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs
PROCS OK: 137 processes | procs=137;150;200;0;
[root@nagios nrpe-3.0 ]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs
PROCS OK: 0 processes with STATE = Z | procs=0;5;10;0;
[root@nagios nrpe-3.0 ]# /usr/local/nagios/libexec/check_ping -H localhost -w 100.0,10% -c 200.0,20%
PING OK- Packet loss = 0%, RTA = 0.04 ms|rta=0.040000ms;100.000000;200.000000;0.000000 pl=0%;10;20;0
[root@nagios nrpe-3.0 ]# /usr/local/nagios/libexec/check_ssh -t 4 -r OpenSSH_5.3 -p 22 -H localhost
SSH OK- OpenSSH_5.3 (protocol 2.0) | time=0.010457s;;;0.000000;4.000000
[root@nagios nrpe-3.0 ]# /usr/local/nagios/libexec/check_swap -w 100% -c 90%
SWAP WARNING – 100% free (1023 MB out of 1023 MB) |swap=1023MB;1023;921;0;1023
[root@nagios nrpe-3.0 ]# /usr/local/nagios/libexec/check_procs -w 100% -c 90% -s STATE
PROCS OK: 82 processes with STATE = STATE | procs=82;100%;90%;0;
Adding Remote Linux Host to Nagios Monitoring Server
To add a remote host you need to create a two new files “hosts.cfg” and “services.cfg” under“/usr/local/nagios/etc/” location.
[root@nagios nrpe-3.0 ]# cd /usr/local/nagios/etc/
[root@nagios nrpe-3.0 ]# touch Linux-hosts.cfg
[root@nagios nrpe-3.0 ]# touch Linux-services.cfg
[root@nagios nrpe-3.0 ]# touch Windows-services.cfg
Now add these two files to main Nagios configuration file. Open nagios.cfg file with any editor.
[root@nagios nrpe-3.0 ]# vi /usr/local/nagios/etc/nagios.cfg
# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/Linux-hosts.cfg
cfg_file=/usr/local/nagios/etc/Linux-services.cfg
cfg_file=/usr/local/nagios/etc/Windows-hosts.cfg
(Linux Host)
Now open Linux-hosts.cfg file and add the default host template name and define remote hosts as shown below.
Make sure to replace host_name, alias and address with your remote host server details.
[root@nagios nrpe-3.0 ]# vi /usr/local/nagios/etc/Linux-hosts.cfg
## Default Linux Host Template ##
define host{
name generic ; Name of this template
use generic-host ; Inherit default values
check_period 24×7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24×7
notification_interval 30
notification_options d,r
contact_groups admins
register 0 ; DONT REGISTER THIS – ITS A TEMPLATE
}
## Default
define host{
use generic ; Inherit default values from a template
host_name (Client Name) ; The name we’re giving to this server
alias CentOS 6 ; A longer name for the server
address Client APP Add ; IP address of Remote Linux host
}
Next open Linux-service.cfg file add the following services to be monitored.
define service{
use generic-service
host_name client,
service_description Current Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name client,
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name client1, client2, client
service_description HTTP STATUS
check_command check_nrpe!check_http
}
define service{
use generic-service
host_name client,
service_description PING
check_command check_nrpe!check_ping
}
define service{
use generic-service
host_name client,
service_description Root Partition
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name client,
service_description SSH
check_command check_nrpe!check_ssh
}
define service{
use generic-service
host_name client,
service_description Swap Usage
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name client,
service_description Total Processes
check_command check_nrpe!check_procs
}
Now NRPE command definition needs to be created in commands.cfg file.
[root@nagios nrpe-3.0 ]# vi /usr/local/nagios/etc/objects/commands.cfg
################################################################################
# NOTE: The following ‘check_…’ commands are used to monitor services on
# both local and remote hosts.
################################################################################
# ‘check_ftp’ command definition
define command{
command_name check_ftp
command_line $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
}
# ‘check_hpjd’ command definition
define command{
command_name check_hpjd
command_line $USER1$/check_hpjd -H $HOSTADDRESS$ $ARG1$
}
# ‘check_snmp’ command definition
define command{
command_name check_snmp
command_line $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
}
# ‘check_http’ command definition
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}
# ‘check_ssh’ command definition
define command{
command_name
check_ssh
command_line
$USER1$/check_ssh $ARG1$ $HOSTADDRESS$
}
# ‘check_dhcp’ command definition
define command{
command_name
check_dhcp
command_line
$USER1$/check_dhcp $ARG1$
}
# ‘check_ping’ command definition
define command{
command_name check_ping
command_line $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
}
# ‘check_pop’ command definition
define command{
command_name check_pop
command_line $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$
}
# ‘check_imap’ command definition
define command{
command_name check_imap
command_line $USER1$/check_imap -H $HOSTADDRESS$ $ARG1$
}
# ‘check_smtp’ command definition
define command{
command_name check_smtp
command_line $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$
}
# ‘check_tcp’ command definition
define command{
command_name
check_tcp
command_line
$USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
}
# ‘check_udp’ command definition
define command{
command_name
check_udp
command_line
$USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
}
# ‘check_nt’ command definition
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s password -v $ARG1$ $ARG2$
}
# ‘check_pm2’ command definition
define command {
command_name check_pm2
command_line $USER1$/check_pm2 –host=$HOSTADDRESS$ –name=$1
}
Finally, verify Nagios Configuration files for any errors.
[root@nagios nrpe-3.0 ]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Restart Nagios:
[root@nagios nrpe-3.0 ]# service nagios restart
(Windows Host)
Add Windows Hosts
Open windows-hosts.cfg file for editing with Vi editor
[root@nagios]# /usr/local/nagios/etc/windows-hosts.cfg
###############################################################################
###############################################################################
#
# HOST DEFINITIONS
#
###############################################################################
###############################################################################
# Define a host for the Windows machine we’ll be monitoring
# Change the host_name, alias, and address to fit your situation
define host{
use windows-server ; Inherit default values from a template
host_name [client name] ; The name we’re giving to this host
alias My Windows Server ; A longer name associated with the host
address [client IP] ; IP address of the host
}
Following services are already added and enabled in windows.cfg file. If you wish to add some more
other service definitions that needs to be monitored, you can simple add those definitions to same
configuration file. Make sure to change the host_name for these all services with host_name defined
in the above step.
###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################
# Create a service for monitoring the version of NSCLient++ that is installed
# Change the host_name to match the name of the host you defined above
define service{
use generic-service
host_name client name
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined above
define service{
use generic-service
host_name client name
service_description Uptime
check_command check_nt!UPTIME
}
# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined above
define service{
use generic-service
host_name client name
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
# Create a service for monitoring memory usage
# Change the host_name to match the name of the host you defined above
define service{
use generic-service
host_name client name
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
# Create a service for monitoring C:\ disk usage
# Change the host_name to match the name of the host you defined above
define service{
use generic-service
host_name client name
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
# Create a service for monitoring the W3SVC service
# Change the host_name to match the name of the host you defined above
define service{
use generic-service
host_name client name
service_description W3SVC
check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}
Lastly, uncomment the windows.cfg file in /usr/local/nagios/etc/nagios.cfg.
# Definitions for monitoring a Windows machine
cfg_file=/usr/local/nagios/etc/Windows-host.cfg
Finally, verify the Nagios configuration files for any erros.
[root@nagios# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors: 0
Things look okay – No serious problems were detected during the pre-flight check
If the verification process throws any error messages, fix those errors until the
verification process completes without any error messages. Once’ you fix those
errors, restart the Nagios service.
[root@nagios]# service nagios restart
Running configuration check…done.
Stopping nagios: done.
Starting nagios: done.Check Nagios Monitoring Web interface at
“http://Your-server-IP-address/nagios”
Thanks.