Filippo Zanardo's Blog

to blog or not to blog

Posts Tagged ‘nagios xenserver

Nagios Plugin To Check XenServer License

with 4 comments

Hi guys,
since xenserver license is active for 1 year, happens sometimes that i forgot to reactivate the license, and then if u shut down the vm machine they don’t start up if license is expired, i create a nagios plugin to check the days remaining for the license.

here’s the script updated thanks to Martin:

# retrieve remaining day for xenserver license
# Date: 2010-04-15
# Author: Filippo Zanardo

# get arguments

while getopts ‘w:c:hp’ OPT; do
case $OPT in
w) int_warn=$OPTARG;;
c) int_crit=$OPTARG;;
h) hlp=”yes”;;
*) unknown=”yes”;;

# usage
usage: $0 [ -w value -c value -h ]


-w –> Warning integer value
-c –> Critical integer value
-h –> print this help screen

if [ “$hlp” = “yes” -o $# -lt 1 ]; then
echo “$HELP”
exit 0

# get license expiry date
EX=`xe host-license-view |grep expiry | awk ‘{ print $2; }’`

today=`date +%Y%m%d`
timeStampToday=`date +%s -d $today`
timeStampOfPast=`date +%s -d $DEX`
dayDiff=`echo \($timeStampOfPast – $timeStampToday\) / $secondsInDay – 1 | bc`

#dayDiff is the day remaining

OUTPUT=”$dayDiff days remaining”

if [ -n “$int_warn” -a -n “$int_crit” ]; then


if (( $dayDiff <= $int_warn )); then
elif (( $dayDiff <= $int_crit )); then

if (( $err == 0 )); then

echo -n "OK – $OUTPUT"
exit "$err"

elif (( $err == 1 )); then
echo -n "WARNING – $OUTPUT"
exit "$err"

elif (( $err == 2 )); then

echo -n "CRITICAL – $OUTPUT"
exit "$err"



echo -n "no output from plugin"
exit 3


just copy it save with some name for example in the nagios plugins directory and configure to use for example with nrpe.
basic usage is: -w 15 -c 5

where “w” is the days remaining for a warning message and “c” is the days remaining for a critical message

if you don’t use nagios you can use as a simple script in a cron job or whatever.

Maybe if someone find this useful i will add the ability to send an email notification.

Post for suggestion comment etc etc


Written by pipposan

April 15, 2010 at 12:11

Nagios XenServer

with 4 comments

I use nagios to check my server, and most of the time i use xenserver 5.5 on them, so i have to trick up the machine to work with nagios and i use an example to check hardware raid on it.

Let’s start first of all execute this command, this download yum priorities and the rpm needed by rpmforge:

wget -c

then install it

rpm –import
rpm -i rpmforge-release-0.3.6-1.el5.rf.*.rpm

Then install some lib needed for nagios, and finally install nagios-plugins nrpe and xinetd.

yum -y install compat-libstdc++-296 compat-libstdc++-33
yum install nagios-plugins nagios-nrpe xinetd

i use a central nagios server and i check raid via nrpe, if u don’t know what is nrpe read this:
nrpe documentation


NRPE allows you to remotely execute Nagios plugins on other Linux/Unix machines. This allows you to monitor remote machine metrics (disk usage, CPU load, etc.). NRPE can also communicate with Windows agent addons like NSClient++, so you can check metrics on remote Windows machines as well.

next modify the file /etc/xinet.d/nrpe updating this line:

disable = no
only_from = #this is the ip of the nagios machine

allow nagios to run some script modify /etc/sudoers like:


this is not so secure on remote machine, modify to suit your needs, i use on lan machine.

next let xinetd start on startup

chkconfig xinetd on
service xinetd start

For example i sue hp prolaint server, so i explain how i check hardware raid on them, first install this rpm:

hp rpm

next i use this plugin to check raid:

raid check

modify nrpe config file (/etc/nagios/nrpe.cfg) adding this line:

command[check_raid]=/usr/lib/nagios/libexec/check_cciss -v

Finally we done set up the machine, and we can check his hardware raid on nagios central server, with the nrpe-plugin, my command on central nagios is:

$user1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

and i use it in a service with



p.s. if someone is interested in nagios or in a particular argument related, post your wish and later i can blog on this.

Written by pipposan

December 1, 2009 at 19:11

Posted in Nagios, XenServer

Tagged with , ,