Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: check_ssl_cert.sh

Issue 29792596: #3298 - SSL monitoring script for icinga (Closed)
Patch Set: #3298 - SSL monitoring script for icinga Created July 4, 2018, 2:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/sh
2
3 # Icinga plugin that checks how many days are left
4 # until SSL certificate expires.
5 # Usage:
6 # $PLUGIN_DIR/check_ssl_cert.sh -H $HOST -P $PORT -c $CRITICAL -w $WARNING
7
8 get_ssl_expiry_date() {
9 openssl s_client -connect "$1:$2" </dev/null 2>/dev/null \
10 | openssl x509 -noout -enddate 2>/dev/null
11 }
12
13 CURRENT_DATE=`date +%y%m%d`
14 HOST="$2"
15 PORT="$4"
16 CRITICAL="$6"
17 WARNING="$8"
18 STATE_OK=0
19 STATE_WARNING=1
20 STATE_CRITICAL=2
21 STATE_UNKNOWN=3
22 OUTPUT=`get_ssl_expiry_date "$HOST" "$PORT"`
23
24 if [ -z "$OUTPUT" ]
25 then
26 echo "UNKNOWN - Could not connect to $HOST via port $PORT"
27 exit "$STATE_UNKNOWN"
28 fi
29
30 DAY=`echo "$OUTPUT" | awk '{print $2}'`
31 MONTH=`echo "$OUTPUT" | awk '{print $1}' | cut -c 10-`
32 YEAR=`echo "$OUTPUT" | awk '{print $4}'`
33
34 if [ "$DAY" -lt 10 ]
35 then
36 DAY="0$DAY"
37 fi
Fred 2018/07/04 14:24:10 That should work. But you could also use awk's pri
38
39 case "$MONTH" in
40
41 "Jan")
42 MONTH="01"
43 ;;
44 "Feb")
45 MONTH="02"
46 ;;
47 "Mar")
48 MONTH="03"
49 ;;
50 "Apr")
51 MONTH="04"
52 ;;
53 "May")
54 MONTH="05"
55 ;;
56 "Jun")
57 MONTH="06"
58 ;;
59 "Jul")
60 MONTH="07"
61 ;;
62 "Aug")
63 MONTH="08"
64 ;;
65 "Sep")
66 MONTH="09"
67 ;;
68 "Oct")
69 MONTH="10"
70 ;;
71 "Nov")
72 MONTH="11"
73 ;;
74 "Dec")
75 MONTH="12"
76 ;;
77 "*")
78 echo "An error occured"
79 exit 1
80 ;;
81 esac
82
83 EXPIRY_DATE_IN_SEC=`date -d "${YEAR}${MONTH}${DAY}" +%s`
84 CURRENT_DATE_IN_SEC=`date -d "$CURRENT_DATE" +%s`
85 DIFFERENCE=`expr \( "$EXPIRY_DATE_IN_SEC" - "$CURRENT_DATE_IN_SEC" \) / 86400`
86
87 if [ "$DIFFERENCE" -le "$CRITICAL" ]
88 then
89 echo "CRITICAL - $HOST: SSL certificate has been expired!"
90 exit "$STATE_CRITICAL"
91 elif [ "$DIFFERENCE" -le "$WARNING" ]
92 then
93 echo "WARNING - $HOST: SSL certificate will be expired in $DIFFERENCE days!"
94 exit "$STATE_WARNING"
95 elif [ "$DIFFERENCE" -gt "$WARNING" ]
96 then
97 echo "OK - $HOST: SSL certificate will be expired in $DIFFERENCE days"
98 exit "$STATE_OK"
99 else
100 echo "UNKNOWN - $HOST: Could not retrieve data"
101 exit "$STATE_UNKNOWN"
102 fi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld