????

Your IP : 216.73.217.84


Current Path : /proc/thread-self/root/lib/check_mk_agent/local/
Upload File :
Current File : //proc/thread-self/root/lib/check_mk_agent/local/Status_Dns_Resolve

#!/bin/bash

DOMAIN="google.com"

# Measure latency using default resolver from /etc/resolv.conf
START=$(date +%s%3N)
/usr/bin/dig +time=2 +tries=1 "$DOMAIN" >/dev/null 2>&1
RESULT=$?
END=$(date +%s%3N)

RTT=$((END - START))

# Detect if /etc/resolv.conf is empty
if ! grep -E "nameserver" /etc/resolv.conf >/dev/null; then
    echo "2 Status_Dns_Resolve - No nameserver defined in /etc/resolv.conf"
    exit 0
fi

# Logic state
if [ "$RESULT" -ne 0 ]; then
    STATE=2
    STATUS_MSG="DNS resolve failed"
else
    if [ "$RTT" -ge 2000 ]; then
        STATE=1
        STATUS_MSG="DNS slow (${RTT}ms)"
    else
        STATE=0
        STATUS_MSG="DNS OK (${RTT}ms)"
    fi
fi

# Metric thresholds: WARN >2000ms, CRIT only on fail
echo "$STATE Status_Dns_Resolve rtt=${RTT}ms;2000;5000;; $STATUS_MSG | RTT_MS=$RTT"