HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //lib64/nagios/plugins/check_a2_whm_ssl
#!/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