Adding a remote Linux machine
Use the NRPE daemon to execute Nagios plugins on the remote server and report back to the monitoring host server.
Create Nagios user account on remote server to be monitored:
# useradd nagios
# passwd nagios
Download and Install Nagios Plugins
[root@xone /]# yum install nagios.i386 nagios-plugins.i386 nagios-plugins-nrpe.i386 nagios-nrpe.i386
You need the openssl-devel package installed to compile plugins with ssl support. **
yum -y install openssl-devel
Edit the file xinetd
nano /etc/xinetd.d/nrpe
change “only_from” and add the IP of the Nagios server – Remember to change disable = no
# default: off
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
type = UNLISTED
port = 5666
socket_type = stream
wait = no
user = nagios
group = nagios
server = /usr/sbin/nrpe
server_args = -c /etc/nagios/nrpe.cfg –inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 192.168.2.65
}
Specify the Nagios server 192.168.2.65
Add the nrpe to services
nano /etc/services
nrpe 5666/tcp # NRPE
service xinetd restart
Run = netstat -at |grep nrpe – this shows the host is listening for the requests
[root@xone /]# netstat -at |grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
Then run = /usr/lib/nagios/plugins/check_nrpe -H localhost
Should look like =
[root@xone /]# /usr/lib/nagios/plugins/check_nrpe -H localhost
NRPE v2.12
============================
Open Port 5666 on Firewall
============================
Now setup the Nagios server config for the remote host
Make sure the plugins are installed –
yum install nagios-plugins-nrpe.i386 nagios-nrpe.i386
then run /usr/lib/nagios/plugins/check_nrpe -H 192.168.2.66
If all is ok you should get the output = NRPE v2.12
[root@mampi /]# /usr/lib/nagios/plugins/check_nrpe -H 192.168.2.66
NRPE v2.12
Create NRPE Command Definition
nano /etc/nagios/objects/commands.cfg
Add the following:
###############################################################################
# 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$
}
Create Linux Object template
In order to be able to add the remote linux machine to Nagios we need to create an object template file adn add some object definitions.
Create new linux-box-remote object template file: linux-box-remote.cfg
/etc/nagios/objects/linux-box-remote.cfg
Here we add all the necessary’s – If there’s already a host then its not defined here, the example below is using xone host template defined else where, the is a host template that’s commented out “xeno-r”
define host{
name linux-box-remote ; 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
}
#
#define host{
# use linux-box-remote ; Inherit default values from a template
# host_name xeno-r ; The name we’re giving to this server
# alias xeno-r ; A longer name for the server
# address 192.168.2.66 ; IP address of the server
# }
define service{
use generic-service
host_name xone
service_description CPU Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name xone
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name xone
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}
define service{
use generic-service
host_name xone
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use generic-service
host_name xone
service_description Zombie Processes
check_command check_nrpe!check_zombie_procs
}
Lastly add the new cfg created to the nagios config file so it knows to load it up –
nano /etc/nagios/nagios.cfg
# Definitions for monitoring the local (Linux) host
cfg_file=/etc/nagios/objects/linux-box-remote.cfg
cfg_file=/etc/nagios/objects/linux-box-remote-swift.cfg
How to monitor a remote process on a remote linux host parsing the commands using nrpe
Ok the commands are defined in the nrpe.cfg file on the remote machine
So
command[check_john]=/usr/lib/nagios/plugins/check_procs -c 1:30 -C john
Then on the Nagios server machine define the check
define service{
use generic-service
host_name swift
service_description Check John
check_command check_nrpe!check_john
}
nagios -v /etc/nagios/nagios.cfg
service nagios restart