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