Index: check_ssl_cert.sh |
diff --git a/check_ssl_cert.sh b/check_ssl_cert.sh |
new file mode 100755 |
index 0000000000000000000000000000000000000000..388db899d686a3ab352027ac8e25f7d02570587a |
--- /dev/null |
+++ b/check_ssl_cert.sh |
@@ -0,0 +1,97 @@ |
+#!/bin/sh |
+ |
+# Icinga plugin that checks how many days are left |
+# until SSL certificate expires. |
+# Usage: |
+# $PLUGIN_DIR/check_ssl_cert.sh -H $HOST -P $PORT -c $CRITICAL -w $WARNING |
+ |
+get_ssl_expiry_date() { |
+ openssl s_client -connect "$1:$2" </dev/null 2>/dev/null \ |
+ | openssl x509 -noout -enddate 2>/dev/null |
+} |
+ |
+CURRENT_DATE=`date +%y%m%d` |
+HOST="$2" |
+PORT="$4" |
+CRITICAL="$6" |
+WARNING="$8" |
+STATE_OK=0 |
+STATE_WARNING=1 |
+STATE_CRITICAL=2 |
+STATE_UNKNOWN=3 |
+OUTPUT=`get_ssl_expiry_date "$HOST" "$PORT"` |
+ |
+if [ -z "$OUTPUT" ] |
+then |
+ echo "UNKNOWN - Could not connect to $HOST via port $PORT" |
+ exit "$STATE_UNKNOWN" |
+fi |
+ |
+DAY=`echo "$OUTPUT" | awk '{printf "02d", $2}'` |
+MONTH=`echo "$OUTPUT" | awk '{print $1}' | cut -c 10-` |
+YEAR=`echo "$OUTPUT" | awk '{print $4}'` |
+ |
+case "$MONTH" in |
+ |
+ "Jan") |
+ MONTH="01" |
+ ;; |
+ "Feb") |
+ MONTH="02" |
+ ;; |
+ "Mar") |
+ MONTH="03" |
+ ;; |
+ "Apr") |
+ MONTH="04" |
+ ;; |
+ "May") |
+ MONTH="05" |
+ ;; |
+ "Jun") |
+ MONTH="06" |
+ ;; |
+ "Jul") |
+ MONTH="07" |
+ ;; |
+ "Aug") |
+ MONTH="08" |
+ ;; |
+ "Sep") |
+ MONTH="09" |
+ ;; |
+ "Oct") |
+ MONTH="10" |
+ ;; |
+ "Nov") |
+ MONTH="11" |
+ ;; |
+ "Dec") |
+ MONTH="12" |
+ ;; |
+ "*") |
+ echo "An error occured" |
+ exit 1 |
+ ;; |
+esac |
+ |
+EXPIRY_DATE_IN_SEC=`date -d "${YEAR}${MONTH}${DAY}" +%s` |
+CURRENT_DATE_IN_SEC=`date -d "$CURRENT_DATE" +%s` |
+DIFFERENCE=`expr \( "$EXPIRY_DATE_IN_SEC" - "$CURRENT_DATE_IN_SEC" \) / 86400` |
+ |
+if [ "$DIFFERENCE" -le "$CRITICAL" ] |
+then |
+ echo "CRITICAL - $HOST: SSL certificate has been expired!" |
+ exit "$STATE_CRITICAL" |
+elif [ "$DIFFERENCE" -le "$WARNING" ] |
+then |
+ echo "WARNING - $HOST: SSL certificate will be expired in $DIFFERENCE days!" |
+ exit "$STATE_WARNING" |
+elif [ "$DIFFERENCE" -gt "$WARNING" ] |
+then |
+ echo "OK - $HOST: SSL certificate will be expired in $DIFFERENCE days" |
+ exit "$STATE_OK" |
+else |
+ echo "UNKNOWN - $HOST: Could not retrieve data" |
+ exit "$STATE_UNKNOWN" |
+fi |