1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

ssl-certificate-expiry: add support for FreeBSD's "date"

Thanks to oz42

Closes: #1038
This commit is contained in:
Lars Kruse 2020-01-25 01:22:11 +01:00
parent 70f565c503
commit 292cfb955a

View file

@ -94,9 +94,15 @@ parse_valid_days_from_certificate() {
valid_until_string=$(echo "$input_data" | openssl x509 -noout -enddate \
| grep "^notAfter=" | cut -f 2 -d "=")
if [ -n "$valid_until_string" ]; then
valid_until_epoch=$(date --date="$valid_until_string" +%s)
if [ -n "$valid_until_epoch" ]; then
# FreeBSD requires special arguments for "date"
if uname | grep -q ^FreeBSD; then
valid_until_epoch=$(date -j -f '%b %e %T %Y %Z' "$valid_until_string" +%s)
now_epoch=$(date -j +%s)
else
valid_until_epoch=$(date --date="$valid_until_string" +%s)
now_epoch=$(date +%s)
fi
if [ -n "$valid_until_epoch" ]; then
# calculate the number of days left
echo "$valid_until_epoch" "$now_epoch" | awk '{ print(($1 - $2) / (24 * 3600)); }'
fi