Created
April 11, 2018 18:45
-
-
Save Programie/17baa354236b8a584a5bfcd188703746 to your computer and use it in GitHub Desktop.
Certificate check for Check_MK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
shopt -s nullglob | |
DAYS_WARN=21 | |
DAYS_CRIT=7 | |
for CONF_FILE in /etc/apache2/sites-enabled/*_https.conf; do | |
DOMAIN_NAME=$(grep ServerName ${CONF_FILE} | awk '{print $2}') | |
CERT_FILE=$(grep SSLCertificateFile ${CONF_FILE} | cut -d \" -f 2) | |
EXPIRE_DATE=$(openssl x509 -in ${CERT_FILE} -noout -enddate | cut -d = -f 2) | |
DAYS_LEFT=$(echo "(" $(date -d "${EXPIRE_DATE}" +%s) - $(date +%s) ")" / 86400 | bc) | |
if [ ${DAYS_LEFT} -gt ${DAYS_WARN} ]; then | |
STATUS=0 | |
elif [ ${DAYS_LEFT} -gt ${DAYS_CRIT} ]; then | |
STATUS=1 | |
else | |
STATUS=2 | |
fi | |
echo "${STATUS} Certificate_${DOMAIN_NAME} days=${DAYS_LEFT} Certificate expires in ${DAYS_LEFT} days (${EXPIRE_DATE})" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment