Filippo Zanardo's Blog

to blog or not to blog

Archive for the ‘Nagios’ Category

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

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 http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/yum-priorities-1.1.16-13.el5.centos.noarch.rpm
wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

then install it

rpm –import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
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

basically:

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 = 127.0.0.1 192.168.0.100 #this is the ip of the nagios machine

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

nagios ALL=(ALL) NOPASSWD: ALL

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

check_nrpe|check_raid

Cheers!

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