Filippo Zanardo's Blog

to blog or not to blog

Posts Tagged ‘xenserver 5.5

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

0 downtime snapshot based XENServer 5.5 backup script

with 19 comments

Check this new better version of the script

Ok guys based on this script i made mine with some more features.
Basically i split the configuration file out of the script and added some new features:

automount: if set to true script try to mount the backupdir specified in mountcommand at start and umount at end, else no action taken and u have to mount dir manually

subfolder: Set to true to create a subfolder in the store for each backup based on vm name

versioning: Set to true to let the script manage to delete the backup older than a certain day or number or hours

and i rewrite the message so they are now more “human” readeable.

The usage it’s the same except u have to pass the path to the config file to the script like:

perl /path/to/ /path/to/config.txt

U can download the file here

Unzip in a folder and read and modify the configuration file (basic explanation is written in), i put also in the config file message’s string so it’s easy to translate in your preferred language, i added also the elapsed minute time of each backup.

Next remember to modify the SendEmail script changing the “server” line at line 65, to send notification mail.

## Network
“server” =>’’,
“port” => 25, ## Default port
“alarm” => ”, ## Default timeout for connects and reads, this gets set from $opt{‘timeout’}

and at line 54 hostname:

“hostname” => ‘’, ## Used in printmsg() for all output, and in SMTP EHLO.

Next call in a cron job or manually the script and enjoy.

Remember to put in the skip variable the uuid of the control domain on host and other vm that don’t need to backed up!

Don’t remove the “\” near @ cause it’s needed for the sendEmail script, so the string should looks like “mymail\”

Comments for bug, wish feature etc etc…

Based on todo list on the main page i will add other feature when i have time!


Check this new better version of the script

Written by pipposan

December 9, 2009 at 17:38