2013-08-11 07:55:19 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
ssl_ - Plugin to monitor certificate expiration
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
This plugin does not normally require configuration.
|
|
|
|
|
|
|
|
To set warning and critical levels do like this:
|
|
|
|
|
|
|
|
[ssl_*]
|
|
|
|
env.warning 30:
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Pactrick Domack
|
|
|
|
|
|
|
|
Copyright (C) 2013 Patrick Domack <patrickdk@patrickdk.com>
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2017-06-16 12:46:12 +02:00
|
|
|
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
2013-08-11 07:55:19 +02:00
|
|
|
|
2016-08-05 05:13:28 +02:00
|
|
|
ARGS=${0##*ssl_}
|
2016-08-05 06:04:42 +02:00
|
|
|
SITE=${ARGS/_*/}
|
|
|
|
PORT=${ARGS##*_}
|
2016-08-05 05:13:28 +02:00
|
|
|
if [ "$PORT" = "$SITE" ]; then
|
|
|
|
PORT=443
|
|
|
|
fi
|
2013-08-11 07:55:19 +02:00
|
|
|
|
|
|
|
case $1 in
|
|
|
|
config)
|
|
|
|
|
|
|
|
echo "graph_title $SITE SSL Certificate Expire"
|
|
|
|
echo 'graph_args --base 1000'
|
|
|
|
echo 'graph_vlabel days left'
|
2017-02-23 15:31:40 +01:00
|
|
|
echo 'graph_category security'
|
2013-08-11 07:55:19 +02:00
|
|
|
echo "graph_info This graph shows the days left for the certificate being served by $SITE"
|
|
|
|
echo 'expire.label days'
|
|
|
|
print_warning expire
|
|
|
|
print_critical expire
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2016-08-05 05:13:28 +02:00
|
|
|
cert=$(echo "" | openssl s_client -CApath /etc/ssl/certs -servername "${SITE}" -connect "${SITE}:${PORT}" 2>/dev/null);
|
2013-08-11 07:55:19 +02:00
|
|
|
|
|
|
|
if [[ "${cert}" = *"-----BEGIN CERTIFICATE-----"* ]]; then
|
2017-06-16 12:46:12 +02:00
|
|
|
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 "expire.value " days;
|
|
|
|
}'
|
2013-08-11 07:55:19 +02:00
|
|
|
fi
|