Nagios plugin sample for Xen Enterprise

I’ve been experimenting with Nagios recently and one of the BioTeam services I really want to keep an eye on is our Xen Enterprise virtualization platform. We have 2 licensed servers running the Xen Enterprise 4 hypervisor and since they share a common storage pool “resource” we are able to do live migration of VMs between physical servers. Nothing fancy but it gives us more administrative flexibility as well as reliability for the more important VMs we instantiate.

A quick google search for Nagios plugins designed to monitor Xen instances turns up a script from Novell that seems to be intended for the open-source version of Xen in that it only runs the command “xm list” in order to generate output.

The “xm” binary does not exist on our Xen Enterprise 4 hypervisors — the related command on our system seems to be “xe” which takes a heck of a lot more command-line arguments it seems than “xm“.

With a bit of hacking around, this is the command I want to run on our hypervisors – it simply lists the name of every detected VM that has a power-state switch set to “running”:
# xe vm-list params=name-label power-state=running

Nothing fancy, all I want to do is count the number of running VMs across both hypervisors and set a warning or critical Nagios alert if the number of “powered on” VMs goes below a certain threshold.

Using one of the standard plugin scripts, a sample script that does what I need would look something like this:



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
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

RUNNING=$(xe vm-list params=name-label power-state=running | awk '/:/{print $5}')
NBVMS=$(echo $RUNNING | wc -w)
SHORT=$(echo $RUNNING | awk '{sub(/$/," ");print}' )

#echo "Xen Running ="$NBVMS
#echo "SHORT =" $SHORT

if [ "$NBVMS" -le "$CRIT" ]; then
echo "Critical Xen VMs Usage - Only $NBVMS VMs in running state: $SHORT "
# Nagios exit code 2 = status CRITICAL = red
exit 2
else if [ "$NBVMS" -le "$WARN" ]; then
echo "Warning Xen VMs Usage - Only $NBVMS Vms in running state: $SHORT "
# Nagios exit code 1 = status WARNING = yellow
exit 1
echo "OK: Xen Enterprise - $NBVMS (power-state='running') VMs across all hypervisors.
Running VM list: $SHORT "
# Nagios exit code 0 = status OK = green
exit 0



Get updates from BioTeam in your inbox.

Trends from the Trenches eBook January 2022

The eBook of BioTeam and Bio-IT World's Most Trending Articles