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:

#!/bin/bash
#
# 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”;;
esac
done

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

syntax:

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

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

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

today=`date +%Y%m%d`
timeStampToday=`date +%s -d $today`
timeStampOfPast=`date +%s -d $DEX`
secondsInDay=86400
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

err=0

if (( $dayDiff <= $int_warn )); then
err=1
elif (( $dayDiff <= $int_crit )); then
err=2
fi

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"

fi

else

echo -n "no output from plugin"
exit 3

fi
exit

just copy it save with some name for example check_xenlicense.sh in the nagios plugins directory and configure to use for example with nrpe.
basic usage is:

check_xenlicense.sh -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.

Cheers
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


DEPRECATED
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/backup.pl /path/to/config.txt

U can download the file here

http://xenbackup.googlecode.com/files/xenbackup.zip

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” =>’mysmtp.server.com’,
“port” => 25, ## Default port
“alarm” => ”, ## Default timeout for connects and reads, this gets set from $opt{‘timeout’}

and at line 54 hostname:

“hostname” => ‘backup.csinet.ca’, ## 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\@mydomain.com”

Comments for bug, wish feature etc etc…

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

Cheers!
Filippo

DEPRECATED
Check this new better version of the script

Written by pipposan

December 9, 2009 at 17:38