2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

[ssl_/multi_ssl] More legible cert-parsing code

Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
Olivier Mehani 2017-06-16 20:46:12 +10:00
parent a4c308081c
commit 91fe427bfc
2 changed files with 29 additions and 4 deletions

View File

@ -47,7 +47,7 @@ case $1 in
for service in $services; do
fieldname=$(clean_fieldname "$service")
echo "${fieldname}.label ${service/_/:}"
print_thresholds ${fieldname}
print_thresholds "${fieldname}"
done
exit 0
@ -66,7 +66,20 @@ function get_expire()
CERT=$(echo "" | openssl s_client -CApath /etc/ssl/certs -servername "${SITE}" -connect "${SITE}:${PORT}" 2>/dev/null);
if [[ "${CERT}" = *"-----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"
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
}

View File

@ -26,7 +26,7 @@ Copyright (C) 2013 Patrick Domack <patrickdk@patrickdk.com>
=cut
. $MUNIN_LIBDIR/plugins/plugin.sh
. "$MUNIN_LIBDIR/plugins/plugin.sh"
ARGS=${0##*ssl_}
SITE=${ARGS/_*/}
@ -54,5 +54,17 @@ esac
cert=$(echo "" | openssl s_client -CApath /etc/ssl/certs -servername "${SITE}" -connect "${SITE}:${PORT}" 2>/dev/null);
if [[ "${cert}" = *"-----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 "expire.value " days; }'
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;
}'
fi