Benjamin Renard commited on 2011-01-04 13:47:13
Showing 1 changed files, with 79 additions and 0 deletions.
... | ... |
@@ -0,0 +1,79 @@ |
1 |
+#!/bin/bash |
|
2 |
+ |
|
3 |
+WARN=5 |
|
4 |
+CRIT=1 |
|
5 |
+DOMAIN=$1 |
|
6 |
+DEBUG=0 |
|
7 |
+[ "$2" == "-d" ] && DEBUG=1 |
|
8 |
+ |
|
9 |
+TLD="`echo $DOMAIN|sed 's/^.*\.\([^\.]*\)$/\1/g'`" |
|
10 |
+[ $DEBUG -eq 1 ] && echo "TLD : $TLD" |
|
11 |
+ |
|
12 |
+WHOIS=`whois $DOMAIN` |
|
13 |
+RET=$? |
|
14 |
+ |
|
15 |
+[ $DEBUG -eq 1 ] && echo "Whois return :" && echo -e "$WHOIS" |
|
16 |
+ |
|
17 |
+if [ $RET -ne 0 ] |
|
18 |
+then |
|
19 |
+ echo "UNKNOWN : Impossible to get expiration date." |
|
20 |
+ exit 3 |
|
21 |
+fi |
|
22 |
+ |
|
23 |
+case $TLD in |
|
24 |
+ fr) |
|
25 |
+ STATUS="`echo -e "$WHOIS"|grep "^status:"|awk '{print $2}'`" |
|
26 |
+ [ $DEBUG -eq 1 ] && echo "Status : $STATUS" |
|
27 |
+ ANNIV="`echo -e "$WHOIS"|grep "^anniversary:"|awk '{print $2}'`" |
|
28 |
+ [ $DEBUG -eq 1 ] && echo "Anniversary : $ANNIV" |
|
29 |
+ if [ "$STATUS" != "ACTIVE" ] |
|
30 |
+ then |
|
31 |
+ echo "CRITICAL : $DOMAIN status is not ACTIVE (value : $STATUS) - Anniversary : $ANNIV" |
|
32 |
+ exit 2 |
|
33 |
+ else |
|
34 |
+ echo "OK : $DOMAIN anniversary is $ANNIV" |
|
35 |
+ exit 0 |
|
36 |
+ fi |
|
37 |
+ ;; |
|
38 |
+ *) |
|
39 |
+ EXTXT=`echo -e "$WHOIS"|grep "^expires:"` |
|
40 |
+ [ $DEBUG -eq 1 ] && echo "expire result format 1 : $EXTXT" |
|
41 |
+ [ ! -n "$EXTXT" ] && EXTXT=`echo -e "$WHOIS"|egrep "([^:]*Expiration Date|Renewal date)"` |
|
42 |
+ [ $DEBUG -eq 1 ] && echo "expire result format 2 : $EXTXT" |
|
43 |
+ |
|
44 |
+ [ $DEBUG -eq 1 ] && echo "Whois expire date : $EXTXT" |
|
45 |
+ |
|
46 |
+ |
|
47 |
+ |
|
48 |
+ EXDATE=`echo $EXTXT|sed 's/ *[^:]*: *\(.*\)$/\1/'` |
|
49 |
+ [ $DEBUG -eq 1 ] && echo "Expire date : $EXDATE" |
|
50 |
+ EXTIME=`date +%s -d"$EXDATE"` |
|
51 |
+ [ $DEBUG -eq 1 ] && echo "Expire time : $EXTIME" |
|
52 |
+esac |
|
53 |
+ |
|
54 |
+CURTIME=`date +%s` |
|
55 |
+[ $DEBUG -eq 1 ] && echo "Current time : $CURTIME" |
|
56 |
+ |
|
57 |
+let DIFF=EXTIME-CURTIME |
|
58 |
+[ $DEBUG -eq 1 ] && echo "Diff time : $DIFF" |
|
59 |
+let nb=DIFF/86400 |
|
60 |
+[ $DEBUG -eq 1 ] && echo "Nb day(s) : $nb" |
|
61 |
+ |
|
62 |
+if [ $nb -le $CRIT ] |
|
63 |
+then |
|
64 |
+ if [ $nb -lt 0 ] |
|
65 |
+ then |
|
66 |
+ let nb=nb*-1 |
|
67 |
+ echo "CRITICAL : $DOMAIN is expired since $nb day(s) !" |
|
68 |
+ else |
|
69 |
+ echo "CRITICAL : $DOMAIN expire in $nb day(s) !" |
|
70 |
+ fi |
|
71 |
+ exit 2 |
|
72 |
+elif [ $nb -le $WARN ] |
|
73 |
+then |
|
74 |
+ echo "WARNING : $DOMAIN expire in $nb day(s) !" |
|
75 |
+ exit 1 |
|
76 |
+else |
|
77 |
+ echo "OK : $DOMAIN expire in $nb day(s)." |
|
78 |
+ exit 0 |
|
79 |
+fi |
|
0 | 80 |