File: //proc/self/root/lib/check_mk_agent/local/Status_Httpd
#!/bin/bash
# CheckMK Local Check - Status_Httpd (Unified Apache / LiteSpeed)
SERVICE_NAME=""
if systemctl is-active --quiet httpd; then
SERVICE_NAME="httpd"
elif systemctl is-active --quiet lshttpd; then
SERVICE_NAME="lshttpd"
else
echo "3 Status_Httpd - UNKNOWN - No Apache or LiteSpeed service found"
exit 0
fi
# Check service status
if systemctl is-active --quiet "$SERVICE_NAME"; then
STATE_TEXT="RUNNING"
else
echo "2 Status_Httpd status=0;;;; - $SERVICE_NAME is DOWN"
exit 0
fi
# Count active connections on port 80 or 443
CONN_COUNT=$(ss -tan '( sport = :80 or sport = :443 )' | grep ESTAB | wc -l)
# Count worker processes
WORKER_COUNT=$(pgrep -c "$SERVICE_NAME")
# Set thresholds
CONN_WARN=750
CONN_CRIT=1000
WORKER_WARN=150
WORKER_CRIT=250
# Determine status
FINAL_STATE=0
STATUS_MSG="- OK"
if (( CONN_COUNT > CONN_CRIT || WORKER_COUNT > WORKER_CRIT )); then
FINAL_STATE=2
STATUS_MSG="- CRITICAL Load"
elif (( CONN_COUNT > CONN_WARN || WORKER_COUNT > WORKER_WARN )); then
FINAL_STATE=1
STATUS_MSG="- HIGH Load"
fi
# ✅ Output with corrected service name
echo "$FINAL_STATE Status_Httpd connections=${CONN_COUNT};${CONN_WARN};${CONN_CRIT};; workers=${WORKER_COUNT};${WORKER_WARN};${WORKER_CRIT};; - $SERVICE_NAME $STATE_TEXT $STATUS_MSG | CONN=$CONN_COUNT WORKERS=$WORKER_COUNT"