Zionetrix::Git
Repositories
Help
Report an Issue
check_domain
Code
Commits
Branches
Tags
Search
Tree:
306936a
Branches
Tags
master
check_domain
check_domain
Add filter on the first line matched
Benjamin Renard
commited
306936a
at 2013-11-07 08:35:49
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 ;; eu) if [ ! -n "$2" ] then echo "UNKNOWN : Dot EU TLD not provide expire date in WHOIS result. You can provide manually expiration date in second parameter." exit 3 fi if [ $( echo -e "$WHOIS"|grep -c "AVAILABLE" ) -gt 0 ] then echo "CRITICAL - Domain $DOMAIN not registred !" exit 2 fi EXDATE=$2 EXTIME=$( date +%s --date=$2 ) if [ $? -ne 0 ] then echo "UNKNOWN : Expire date provide not recognized. Ex : YYYYMMDD" fi ;; *) EXTXT=`echo -e "$WHOIS"|grep "^expires:"|tail -n 1` [ $DEBUG -eq 1 ] && echo "expire result format 1 : $EXTXT" [ ! -n "$EXTXT" ] && EXTXT=`echo -e "$WHOIS"|egrep "([^:]*Expiration Date|Renewal date)"|tail -n 1` [ $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