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