All pastes #525768 Raw Edit

Untitled

public shellscript v1 · immutable
#525768 ·published 2007-05-31 14:32 UTC
rendered paste body
#!/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 checkingHOST=$1#The type of machine we are checking - streamer, catalogueTYPE=$2#The attribute we are checking - anon, sub, cacheATTR=$3#set default values to avoid if issuesdelta="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 $oldvaltmp=/tmp/$HOST.$TYPE.$ATTR.jmx.get.tmp#general sanity checkif [ -z $HOST ] || [ -z $TYPE ] || [ -z $ATTR ]then    echo "Missing Parameters"    exit 2fi#more silly sanity checkingtouch $tmp#inherit our $oldval from the temp file. $tmp#check what type we are dealing with and assign the correct url dependant on typeif [ $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 dont know, it could happen...    echo "OMG, Its a Lion on line 59..."    exit 2fi#sanity check for the $oldval inheritance - first run this wont be set#so we will set it to zero if that is the case.if [ -z $oldval ]then    oldval=0fi#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 am 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 shouldnt, but, we could.        echo "We really shouldnt 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}getvaluegetdeltarotatecheckerr