pjs/tools/tinderbox-configs/monitoring/check_tinderbox_status

125 строки
2.8 KiB
Bash
Executable File

#! /bin/bash
#
# Checks to see if tinderbox tree state has changed.
#
# Copyright 2006 Mozilla
# Initial Author: Robert Helmer <robert@roberthelmer.com>
# Contributor(s): Nick Thomas <nrthomas@gmail.com>
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
NAGIOS_PLUGIN_PATH='/usr/lib/nagios/plugins'
REVISION=`echo '$Revision 1.4 $' | sed -e 's/[^0-9.]//g'`
. $NAGIOS_PLUGIN_PATH/utils.sh
while getopts "t:" options
do
case "$options" in
t)
# tree name to compare
TREE=$OPTARG
;;
esac
done
URL="http://tinderbox.mozilla.org/${TREE}/quickparse.txt"
OLD_STATE="/var/tmp/tinderbox-${TREE}-old.state"
NEW_STATE="/var/tmp/tinderbox-${TREE}-new.state"
TEMP_STATE="/var/tmp/tinderbox-${TREE}.temp"
TIMEOUT=7 # should be less than 10 seconds so curl gives up before nagios
STATUS=0
print_usage() {
echo "Usage: $PROGNAME -t <tree_to_check>"
}
print_help() {
print_revision $PROGNAME $REVISION
echo ""
print_usage
echo ""
echo "This plugin checks to see if a Tinderbox tree changes state."
echo ""
support
exit 0
}
case "$1" in
--help)
print_help
exit 0
;;
-h)
print_help
exit 0
;;
--version)
print_revision $PROGNAME $REVISION
exit 0
;;
-V)
print_revision $PROGNAME $REVISION
exit 0
;;
*)
if test -z $TREE
then
print_usage
exit 1
fi
if [ -f "$OLD_STATE" ]
then
curl -s -m $TIMEOUT "$URL" > $TEMP_STATE
if [ $? -eq 0 ]
then
grep -v 'State|' $TEMP_STATE | awk -F\| '{print $3}' > $NEW_STATE
else
echo "Error retrieving status from tinderbox server"
echo
exit 0
fi
added=`diff "$OLD_STATE" "$NEW_STATE" | grep '^> ' | sed 's/^> //' | tr '\n' ',' | sed 's/,$//' | sed 's/,/, /'`
removed=`diff "$OLD_STATE" "$NEW_STATE" | grep '^< ' | sed 's/^< //' | tr '\n' ',' | sed 's/,$//' | sed 's/,/, /'`
# restore state
if [ -f "$NEW_STATE" ]
then
mv "$NEW_STATE" "$OLD_STATE"
fi
if [ -n "$added" ]
then
message="ADDED: $added"
STATUS=1
fi
if [ -n "$removed" ]
then
message="$message =-=-= REMOVED: $removed"
STATUS=2
fi
if [ -z "$message" ]
then
message="OK: No changes"
fi
else
# initialize old state
curl -s -m $TIMEOUT "$URL" > $TEMP_STATE
if [ $? -eq 0 ]
then
grep -v 'State|' $TEMP_STATE | awk -F\| '{print $3}' > "$OLD_STATE"
message="Initialized old state."
STATUS=0
else
message="Error retrieving status from tinderbox server"
STATUS=0
fi
fi
echo $message
echo
exit $STATUS
;;
esac