#!/bin/bash #define the delta limit - difference between previous and current check #this is the difference in drop, not in raise. baddelta="100" #define the bad value limit - the minimum value size we will accept as being #normal - i.e. if the current value is less than $badval then there is an issue. badval="100" ################################################################################ # End user should not need to change anything below this line. ################################################################################ #Lets pull in and define some variables. #The hostname of the machine we will be checking HOST=$1 #The type of machine we're checking - streamer, catalogue TYPE=$2 #The attribute we're checking - anon, sub, cache ATTR=$3 #set default values to avoid if issues delta="0" curdelta="0" value="0" #set our temp file, this file is used for storing the previous $value #one temp file per host per type per attribute - saves confusion. #it will be inherited as $oldval tmp=/tmp/$HOST.$TYPE.$ATTR.jmx.get.tmp #general sanity check if [ -z $HOST ] || [ -z $TYPE ] || [ -z $ATTR ] then echo "Missing Parameters" exit 2 fi #more silly sanity checking touch $tmp #inherit our $oldval from the temp file . $tmp #check what type we're dealing with and assign the correct url dependant on type if [ $TYPE == "streamer" ] then urltype="fm.last.ticketstream.monitor.Status" elif [ $TYPE == "catalogue" ] then urltype="fm.last.catalogue.monitor.Status" fi #same for attribute. if [ $ATTR == "anon" ] then attribute="NumAnon" elif [ $ATTR == "sub" ] then attribute="NumLoggedIn" elif [ $ATTR == "cache" ] then attribute="CacheSizes" else #I don't know, it could happen... echo "OMG, It's a Lion on line 59..." exit 2 fi #sanity check for the $oldval inheritance - first run this won't be set #so we'll set it to zero if that is the case. if [ -z $oldval ] then oldval=0 fi #create our URL. URL="http://gimli.int.last.fm:4041/getattribute?objectname="$HOST""$TYPE":type="$urltype"&attribute="$attribute"" #nitty gritty begins... function getvalue { ##this is the most pointless function ever, but, using a function just in case it gets complicated. #declare only valid for this function, stripping everything but the value out #with cut and passing to a global. value=$(GET "$URL" | grep -o "value=\".*\"" | sed -e 's/\"//g' | cut -d"=" -f2) } #figure out what the delta is. function getdelta { if [ $oldval -lt $value ] then #Because I'm paranoid, and I can. touch $tmp #<= is important, saves hitting line 97 repeatedly elif [ $value -le $oldval ] then delta="$(( $oldval - $value ))" else #it would be thoroughly bad to arrive here, we shouldn't, but, we could. echo "We really shouldn't be on line 97" exit 2 fi } function rotate { #export our oldvalue to the temp file for use next time around echo "oldval=$value" > $tmp } function checkerr { #let the error checking commence if [ $value -lt $badval ] then #if the value is less than our bad value, then this is bad. echo "Value is less than expected - $value" exit 2 elif [ $delta -gt $baddelta ] then #if the delta is out of range, this is also bad. echo "Delta is too large - $delta" exit 2 else #all is good. echo "Value is - $value, Delta is - $delta" exit 0 fi } getvalue getdelta rotate checkerr