Simple script to check if the varnish daemon has been restarted latelly

Here is the code:

#!/bin/bash
#Get current varnish uptime
#Version 1.0
#By Felipe Ferreira Set 2013
#Variables
CRIT=900
#Check arguments print help
if [ $# -lt 1 ]; then
	echo "Usage: $0  [ uptime(sec)]"
	exit 3
else
	CRIT=$1
fi
function show_time () {
    num=$1
    min=0
    hour=0
    day=0
    if((num>59));then
        ((sec=num%60))
        ((num=num/60))
        if((num>59));then
            ((min=num%60))
            ((num=num/60))
            if((num>23));then
                ((hour=num%24))
                ((day=num/24))
            else
                ((hour=num))
            fi
        else
            ((min=num))
        fi
    else
        ((sec=num))
    fi
    echo "$day"d "$hour"h "$min"m "$sec"s
}
###################################### MAIN ################################
result=`varnishstat -1 |grep uptime |awk '{print $2}'`
uptime=`show_time $result`
MSG="Uptime $uptime , $result seg.|uptime=$result"
if [ $result -lt $CRIT ]; then
        OUTPUT="CRITICAL - $MSG"
        exitstatus=2
fi
if [ $result -gt $CRIT ];then
   OUTPUT="OK - $MSG"
   exitstatus=0
fi
echo $OUTPUT
exit $exitstatus
Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *