2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/ssl/ssl-certificate-expiry
Olivier Mehani 21cc6fc458 [ssl-certificate-expiry] Rename from multi_ssl
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
2017-06-20 21:15:17 +10:00

111 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
# -*- sh -*-
: << =cut
=head1 NAME
multi_ssl - Plugin to monitor CERTificate expiration on multiple services and ports
=head1 CONFIGURATION
[multi_ssl]
env.services www.service.tld blah.example.net:PORT
To set warning and critical levels do like this:
[multi_ssl]
env.services ...
env.warning 30:
Alternatively, if you want to monitor hosts separately, you can create multiple symlinks named as follows.
multi_ssl_HOST:PORT
For example:
multi_ssl_www.example.net
multi_ssl_www.example.org_443
multi_ssl_192.0.2.42_636
multi_ssl_2001:0DB8::badc:0fee_485
=head1 AUTHOR
Pactrick Domack (ssl_)
Olivier Mehani (multi_ssl)
Copyright (C) 2013 Patrick Domack <patrickdk@patrickdk.com>
Copyright (C) 2017 Olivier Mehani <shtrom+munin@ssji.net>
=head1 LICENSE
=cut
. "${MUNIN_LIBDIR}/plugins/plugin.sh"
if [ "${MUNIN_DEBUG}" = 1 ]; then
set -x
fi
HOSTPORT=${0##*multi_ssl_}
if [ "${HOSTPORT}" != "${0}" ] \
&& [ ! -z "${HOSTPORT}" ]; then
services="${HOSTPORT}"
fi
case $1 in
config)
echo "graph_title SSL Certificates Expiration"
echo 'graph_args --base 1000'
echo 'graph_vlabel days left'
echo 'graph_category security'
echo "graph_info This graph shows the days left for the certificate"
for service in $services; do
fieldname=$(clean_fieldname "$service")
echo "${fieldname}.label $(echo "${service}" | sed 's/_/:/')"
print_thresholds "${fieldname}"
done
exit 0
;;
esac
get_expire()
{
SITE="$(echo "${1}" | sed 's/_.*//')"
PORT="$(echo "${1}" | sed 's/.*_//')"
VAR="$(clean_fieldname "$1")"
if [ "$PORT" = "$SITE" ]; then
PORT=443
fi
if echo "$SITE" | grep -q ':'; then
SITE="[${SITE}]"
fi
CERT=$(echo "" | openssl s_client -CApath /etc/ssl/certs -servername "${SITE}" -connect "${SITE}:${PORT}" 2>/dev/null);
if echo "${CERT}" | grep -q -- "-----BEGIN CERTIFICATE-----"; then
echo "${CERT}" \
| openssl x509 -noout -enddate \
| awk -F= 'BEGIN {
split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", month, " ");
for (i=1; i<=12; i++)
mdigit[month[i]] = i;
}
/notAfter/ {
split($0,a,"="); split(a[2],b," "); split(b[3],time,":");
datetime=b[4] " " mdigit[b[1]] " " b[2] " " time[1] " " time[2] " " time[3];
days=(mktime(datetime)-systime())/86400;
print "VAR.value " days;
}' \
| sed "s/VAR/${VAR}/g"
fi
}
for service in $services; do
get_expire "$service"
done