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 June 5, 2018, 4:10 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 until SSL certificate expires
4 # Usage: <PluginDir>/check_ssl_cert -H <HOSTNAME> -P <PORT> -c <CRITICAL> -w <WA RNING>
5
6 PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
7
8 CURRENT_DATE=`date +%y%m%d`
9 HOST="$2"
10 PORT="$4"
11 CRITICAL="$6"
12 WARNING="$8"
13 STATE_OK=0
14 STATE_WARNING=1
15 STATE_CRITICAL=2
16 STATE_UNKNOWN=3
17
18 OUTPUT=`openssl s_client -connect "$HOST":"$PORT" </dev/null 2>/dev/null | opens sl x509 -noout -enddate 2>/dev/null`
mathias 2018/06/05 16:24:19 Please place this in a function() and invoke it to
19
20 if [ ! "$OUTPUT" ]
21 then
22 echo "UNKNOWN - Could not connect to $HOST via port $PORT"
23 exit "$STATE_UNKNOWN"
24 fi
25
26 DAY=`echo "$OUTPUT" | awk '{print $2}'`
27 MONTH=`echo "$OUTPUT" | awk '{print $1}' | cut -c 10-`
28 YEAR=`echo "$OUTPUT" | awk '{print $4}'`
29
30 case "$MONTH" in
31
32 "Jan")
33 MONTH="01"
34 ;;
35 "Feb")
36 MONTH="02"
37 ;;
38 "Mar")
39 MONTH="03"
40 ;;
41 "Apr")
42 MONTH="04"
43 ;;
44 "May")
45 MONTH="05"
46 ;;
47 "Jun")
48 MONTH="06"
49 ;;
50 "Jul")
51 MONTH="07"
52 ;;
53 "Aug")
54 MONTH="08"
55 ;;
56 "Sep")
57 MONTH="09"
58 ;;
59 "Oct")
60 MONTH="10"
61 ;;
62 "Nov")
63 MONTH="11"
64 ;;
65 "Dec")
66 MONTH="12"
67 ;;
68 "*")
69 echo "An error occured"
70 exit 1
71 ;;
72 esac
73
74 EXPIRY_DATE_IN_SEC=`date -d "$YEAR""$MONTH""$DAY" +%s`
mathias 2018/06/05 16:24:19 You can use "$YEAR$MONTH$DAY" or, even better, "${
75 CURRENT_DATE_IN_SEC=`date -d "$CURRENT_DATE" +%s`
76 DIFF=`expr "$EXPIRY_DATE_IN_SEC" - "$CURRENT_DATE_IN_SEC"`
77 DIFF=`expr "$DIFF" / 86400`
78
79 if [ "$DIFF" -le "$CRITICAL" ]
80 then
81 echo "CRITICAL - $HOST: SSL certificate has been expired!"
82 exit "$STATE_CRITICAL"
83 elif [ "$DIFF" -le "$WARNING" ]
84 then
85 echo "WARNING - $HOST: SSL certificate will be expired in $DIFF days!"
86 exit "$STATE_WARNING"
87 elif [ "$DIFF" -gt "$WARNING" ]
88 then
89 echo "OK - $HOST: SSL certificate will be expired in $DIFF days"
90 exit "$STATE_OK"
91 else
92 echo "UNKNOWN - $HOST: Could not retrieve data"
93 exit "$STATE_UNKNOWN"
94 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