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: Created May 28, 2018, 2:54 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 export PATH
8 PROGNAME=`basename $0`
9 PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
10
11 . $PROGPATH/utils.sh
12
13 CURRENT_DATE=`date +%y%m%d`
14 HOST=$2
15 PORT=$4
16 CRITICAL=$6
17 WARNING=$8
18
19 DAY=`echo | openssl s_client -connect "$HOST":$PORT 2>/dev/null | openssl x509 - noout -enddate 2>/dev/null | awk '{print $2}'`
20
21 if [ ! $DAY ]
22 then
23 echo "UNKNOWN - Could not connect to $HOST via port $PORT"
24 exit $STATE_UNKNOWN
25 fi
26
27 MONTH=`echo | openssl s_client -connect "$HOST":$PORT 2>/dev/null | openssl x509 -noout -enddate | awk '{print $1}'`
28 MONTH=`echo ${MONTH#*=}`
29 YEAR=`echo | openssl s_client -connect "$HOST":$PORT 2>/dev/null | openssl x509 -noout -enddate | awk '{print $4}'`
30
31 case $MONTH in
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 esac
70
71 DIFF=$(( ($(date --date="$YEAR$MONTH$DAY" +%s) - $(date --date="$CURRENT_DATE" + %s) )/(60*60*24) ))
72
73 if [ $DIFF -le $CRITICAL ]
74 then
75 echo "CRITICAL - $HOST: SSL certificate has been expired!"
76 exit $STATE_CRITICAL
77 elif [ $DIFF -le $WARNING ] && [ $DIFF -gt $CRITICAL ]
78 then
79 echo "WARNING - $HOST: SSL certificate will be expired in $DIFF days!"
80 exit $STATE_WARNING
81 elif [ $DIFF -gt $WARNING ]
82 then
83 echo "OK - $HOST: SSL certificate will be expired in $DIFF days"
84 exit $STATE_OK
85 else
86 echo "UNKNOWN - $HOST: Could not retrieve data"
87 exit $STATE_UNKNOWN
88 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