If necessary, run apt-get install nagios-nrpe-plugin
Create a file called check_xenvm and copy the following:
PARM1=$1
WARN=$2
PARM2=$3
CRIT=$4
if [ "$PARM2" != "-c" -o "$CRIT" == "" ]; then
echo "Usage: $0 -w <warning> -c <critical>"
# Nagios exit code 3 = status UNKNOWN = orange
if [ "$PARM1" != "-h" ]; then
exit 3
else
echo ""
echo " -w = Minimum Number of Xen VMs to activate a warning message."
echo " -c = Number of Xen VMs to activate a critical message."
echo " -h = This help message."
exit 3
fi
fi
RUNNING=$(sudo /usr/sbin/xm list | awk '!/[DN]/ {print $1 }')
NBVMS=$(echo $RUNNING | wc -w)
HNAME=$(hostname)
#echo "Xen Running =" $RUNNING
if [ "$NBVMS" -le "$CRIT" ]; then
echo "Critical Xen VMs Usage - Total NB: $NBVMS - detected VMs: $RUNNING"
# Nagios exit code 2 = status CRITICAL = red
exit 2
else if [ "$NBVMS" -le "$WARN" ]; then
echo "Warning Xen VMs Usage - Total NB: $NBVMS - detected VMs: $RUNNING"
# Nagios exit code 1 = status WARNING = yellow
exit 1
else
echo "OK: Xen Hypervisor \"$HNAME\" is running Xen VMs: $RUNNING"
# Nagios exit code 0 = status OK = green
exit 0
fi
fi
Make it into an executable file, chmod +x check_xenvm
Place this file in the /usr/local/nagios/libexec directory
Go to /usr/local/nagios/etc/objects/commands.cfg and add the following:
# added for Xen VM Monitoring
define command{
command_name check_xen_vm
command_line $USER1$/check_xenvm -w $ARG1$ -c $ARG2$
}
Go to linux.cfg and add the following:
define host{
use linux-server
host_name rtpnode01
address 172.16.110.151
}
define service{
use generic-service
host_name rtpnode01
service_description XEN Virtual Machine Monitor
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups dso-admins
notification_options w,u,c,r
notification_interval 960
notification_period 24x7
check_command check_nrpe!check_xen
}
On the host Server run,
Apt-get install nagios-nrpe-plugin
Apt-get install nagios-nrpe-server (needed)
Copy the original check_xenvm executable which was created on the server to /usr/lib/nagios/plugins on the remote server
Go to /etc/nagios/nrpe.cfg and edit the following:
Allowed_host = Nagios Server IP Address
Commands[check_xenvm]=/usr/lib/nagios/plugins/check_xenvm –w 1 –c 0
vi sudoers
nagios ALL=(ALL)NOPASSWD:/usr/sbin/xm list ( allows nagios user to run xm list)
restart nagios-nrpe-server