
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
#!/bin/bash

# Get the hostname and construct the domain
HOSTNAME=$(hostname)
DOMAIN="www${HOSTNAME}"
PORT=2087

# Get certificate expiration date in epoch format
EXPIRY_DATE=$(openssl s_client -connect ${DOMAIN}:${PORT} -servername ${DOMAIN} </dev/null 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2)
EXPIRY_EPOCH=$(date -d "${EXPIRY_DATE}" +%s)
CURRENT_EPOCH=$(date +%s)

# Calculate days remaining
DAYS_REMAINING=$(( (EXPIRY_EPOCH - CURRENT_EPOCH) / 86400 ))

# Check expiration thresholds
if [ "$DAYS_REMAINING" -le 14 ]; then
    echo "CRITICAL - SSL certificate for ${DOMAIN} expires in ${DAYS_REMAINING} days"
    exit 2
elif [ "$DAYS_REMAINING" -le 30 ]; then
    echo "WARNING - SSL certificate for ${DOMAIN} expires in ${DAYS_REMAINING} days"
    exit 1
else
    echo "OK - SSL certificate for ${DOMAIN} expires in ${DAYS_REMAINING} days"
    exit 0
fi

