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

Delta Between Two Patch Sets: check_ssl_cert.sh

Issue 29792596: #3298 - SSL monitoring script for icinga (Closed)
Left Patch Set: #3298 - SSL monitoring script for Icinga Created June 20, 2018, 12:29 p.m.
Right Patch Set: #3298 - SSL monitoring script for icinga Created July 4, 2018, 2:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/bin/sh 1 #!/bin/sh
2 2
3 # Icinga plugin that checks how many days are left 3 # Icinga plugin that checks how many days are left
4 # until SSL certificate expires. 4 # until SSL certificate expires.
5 # Usage: 5 # Usage:
6 # $PLUGIN_DIR/check_ssl_cert.sh -H $HOST -P $PORT -c $CRITICAL -w $WARNING 6 # $PLUGIN_DIR/check_ssl_cert.sh -H $HOST -P $PORT -c $CRITICAL -w $WARNING
7 7
8 get_ssl_expiry_date() { 8 get_ssl_expiry_date() {
9 openssl s_client -connect "$1:$2" </dev/null 2>/dev/null \ 9 openssl s_client -connect "$1:$2" </dev/null 2>/dev/null \
10 | openssl x509 -noout -enddate 2>/dev/null 10 | openssl x509 -noout -enddate 2>/dev/null
11 } 11 }
12 12
13 CURRENT_DATE=`date +%y%m%d` 13 CURRENT_DATE=`date +%y%m%d`
14 HOST="$2" 14 HOST="$2"
15 PORT="$4" 15 PORT="$4"
16 CRITICAL="$6" 16 CRITICAL="$6"
17 WARNING="$8" 17 WARNING="$8"
18 STATE_OK=0 18 STATE_OK=0
19 STATE_WARNING=1 19 STATE_WARNING=1
20 STATE_CRITICAL=2 20 STATE_CRITICAL=2
21 STATE_UNKNOWN=3 21 STATE_UNKNOWN=3
22 OUTPUT=`get_ssl_expiry_date "$HOST" "$PORT"` 22 OUTPUT=`get_ssl_expiry_date "$HOST" "$PORT"`
23 23
24 if [ -z "$OUTPUT" ] 24 if [ -z "$OUTPUT" ]
25 then 25 then
26 echo "UNKNOWN - Could not connect to $HOST via port $PORT" 26 echo "UNKNOWN - Could not connect to $HOST via port $PORT"
27 exit "$STATE_UNKNOWN" 27 exit "$STATE_UNKNOWN"
28 fi 28 fi
29 29
30 DAY=`echo "$OUTPUT" | awk '{print $2}'` 30 DAY=`echo "$OUTPUT" | awk '{printf "02d", $2}'`
31 MONTH=`echo "$OUTPUT" | awk '{print $1}' | cut -c 10-` 31 MONTH=`echo "$OUTPUT" | awk '{print $1}' | cut -c 10-`
32 YEAR=`echo "$OUTPUT" | awk '{print $4}'` 32 YEAR=`echo "$OUTPUT" | awk '{print $4}'`
33 33
34 case "$MONTH" in 34 case "$MONTH" in
35 35
36 "Jan") 36 "Jan")
37 MONTH="01" 37 MONTH="01"
38 ;; 38 ;;
39 "Feb") 39 "Feb")
40 MONTH="02" 40 MONTH="02"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 echo "WARNING - $HOST: SSL certificate will be expired in $DIFFERENCE days!" 88 echo "WARNING - $HOST: SSL certificate will be expired in $DIFFERENCE days!"
89 exit "$STATE_WARNING" 89 exit "$STATE_WARNING"
90 elif [ "$DIFFERENCE" -gt "$WARNING" ] 90 elif [ "$DIFFERENCE" -gt "$WARNING" ]
91 then 91 then
92 echo "OK - $HOST: SSL certificate will be expired in $DIFFERENCE days" 92 echo "OK - $HOST: SSL certificate will be expired in $DIFFERENCE days"
93 exit "$STATE_OK" 93 exit "$STATE_OK"
94 else 94 else
95 echo "UNKNOWN - $HOST: Could not retrieve data" 95 echo "UNKNOWN - $HOST: Could not retrieve data"
96 exit "$STATE_UNKNOWN" 96 exit "$STATE_UNKNOWN"
97 fi 97 fi
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld