Filippo Zanardo's Blog

to blog or not to blog

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

4 Responses

Subscribe to comments with RSS.

  1. Loving it. Using it.

    Your calculation is off by one day though: You need to change line 44 to this:

    dayDiff=`echo \($timeStampOfPast – $timeStampToday\) / $secondsInDay – 1 | bc`


    October 19, 2010 at 08:32

    • thanks very much i modify the post.


      October 19, 2010 at 09:26

      • Since I was at it I also changed line 48 to this:

        OUTPUT=”$dayDiff days remaining – expires on `date +%Y-%m-%d -d $DEX`”

        to include the expiration date in the plugin output as well.


        October 19, 2010 at 11:05

  2. This is very useful, I think this will come in handy for me at work

    live xenserver backup

    May 20, 2011 at 12:43

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: