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

Side by Side Diff: check_ssl_cert.sh

Issue 29793559: #3298 - SSL monitoring script for icinga (Closed)
Patch Set: Created May 29, 2018, 1:28 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}' | cut -c 10-`
28 YEAR=`echo | openssl s_client -connect "$HOST":$PORT 2>/dev/null | openssl x509 -noout -enddate | 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`
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 ] && [ $DIFF -gt $CRITICAL ]
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