Zionetrix::Git
Repositories
Help
Report an Issue
check_domain
Code
Commits
Branches
Tags
Search
Tree:
6d8adfe
Branches
Tags
master
check_domain
check_domain
Added specific case for dot es domains (no whois server for this TLD)
Benjamin Renard
commited
6d8adfe
at 2012-05-07 08:50:15
check_domain
Blame
History
Raw
#!/bin/bash WARN=5 CRIT=1 DOMAIN=$1 DEBUG=0 [ "$2" == "-d" ] && DEBUG=1 TLD="`echo $DOMAIN|sed 's/^.*\.\([^\.]*\)$/\1/g'`" [ $DEBUG -eq 1 ] && echo "TLD : $TLD" WHOIS=`whois $DOMAIN` RET=$? [ $DEBUG -eq 1 ] && echo "Whois return :" && echo -e "$WHOIS" if [ $RET -ne 0 ] then echo "UNKNOWN : Impossible to get expiration date." exit 3 fi case $TLD in fr) STATUS="`echo -e "$WHOIS"|grep "^status:"|awk '{print $2}'`" [ $DEBUG -eq 1 ] && echo "Status : $STATUS" ANNIV="`echo -e "$WHOIS"|grep "^anniversary:"|awk '{print $2}'`" [ $DEBUG -eq 1 ] && echo "Anniversary : $ANNIV" if [ "$STATUS" != "ACTIVE" ] then echo "CRITICAL : $DOMAIN status is not ACTIVE (value : $STATUS) - Anniversary : $ANNIV" exit 2 else echo "OK : $DOMAIN anniversary is $ANNIV" exit 0 fi ;; be) STATUS="`echo -e "$WHOIS"|grep "^Status:"|sed 's/Status:[ \t]*//'`" [ $DEBUG -eq 1 ] && echo "Status : $STATUS" SINCE="`echo -e "$WHOIS"|grep "^Registered:"|sed 's/^Registered: *//'`" [ $DEBUG -eq 1 ] && echo "Since : $SINCE" if [ "$STATUS" != "REGISTERED" -a "$STATUS" != "NOT AVAILABLE" ] then echo "CRITICAL : $DOMAIN status is not REGISTERED or NOT AVAILABLE (value : $STATUS)" exit 2 else echo "OK : $DOMAIN registered since $SINCE" exit 0 fi ;; es) echo "UNKNOWN : Dot ES TLD has no whois server. Check domain $DOMAIN is not possible." exit 3 ;; *) EXTXT=`echo -e "$WHOIS"|grep "^expires:"` [ $DEBUG -eq 1 ] && echo "expire result format 1 : $EXTXT" [ ! -n "$EXTXT" ] && EXTXT=`echo -e "$WHOIS"|egrep "([^:]*Expiration Date|Renewal date)"` [ $DEBUG -eq 1 ] && echo "expire result format 2 : $EXTXT" [ $DEBUG -eq 1 ] && echo "Whois expire date : $EXTXT" EXDATE=`echo $EXTXT|sed 's/ *[^:]*: *\(.*\)$/\1/'` [ $DEBUG -eq 1 ] && echo "Expire date : $EXDATE" EXTIME=`date +%s -d"$EXDATE"` [ $DEBUG -eq 1 ] && echo "Expire time : $EXTIME" esac CURTIME=`date +%s` [ $DEBUG -eq 1 ] && echo "Current time : $CURTIME" let DIFF=EXTIME-CURTIME [ $DEBUG -eq 1 ] && echo "Diff time : $DIFF" let nb=DIFF/86400 [ $DEBUG -eq 1 ] && echo "Nb day(s) : $nb" if [ $nb -le $CRIT ] then if [ $nb -lt 0 ] then let nb=nb*-1 echo "CRITICAL : $DOMAIN is expired since $nb day(s) !" else echo "CRITICAL : $DOMAIN expire in $nb day(s) !" fi exit 2 elif [ $nb -le $WARN ] then echo "WARNING : $DOMAIN expire in $nb day(s) !" exit 1 else echo "OK : $DOMAIN expire in $nb day(s)." exit 0 fi