SSL – Certificate Validity check

The script receives the value, after how many days the certificate expires and sends the values to "Zabbix" via "zabbix-sender".

Script content:

#!/bin/bash

DOMAIN="$(hostname -f)"
DEADLINE="$(echo | openssl s_client -servername $DOMAIN -connect $DOMAIN:443 2>/dev/null | openssl x509 -noout -dates | grep "notAfter" | cut -d "=" -f2)"
SSL_LAST_DAY="$(date +%s -d "$DEADLINE")"
TODAY="$(date +%s)"
let "SSL_LEFT_DAYS = ( $SSL_LAST_DAY - $TODAY ) / 86400"

# WRITE TO LOG OR SEND TO ZABBIX
echo $SSL_LEFT_DAYS > /var/log/ssl_payday

 

You need to make sure that the required domain is set as the FQDN of the host. Or receive it in another way, for example, if you have more than one domain on your host.

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments