I wrote a small shell script recently for checking dns propagation delay, I whittled this script down to the bare minimum to accomplish what you are wanting to do. In nagios you can configure something like:
define service{
host_name dns_servers
service_description DNS Servers
…
check_command check_dnsservers!4.2.2.1 4.2.2.2
}
Replace the IPs above with a list of your dns servers. You can use IP addresses or f.q.d.n names, or even just ns1 or ns2 if you have /etc/resolv.conf configured to search a default domain
. Then, add:
define command{
command_name check_dnsservers
command_line $USER1$/check_dnsservers.sh $ARG1$
}
And finally for the check_dnsservers.sh script:
#! /bin/bash
serverlist=($*)
servercount=${#serverlist@]}
outtext="Unknown error"
outcode=2
index=0
loopresult=0
badservers=""
while “$index” -lt “$servercount” ]
do
dig @${serverlist$index]} www.yahoo.com A +short 2>&1 > /dev/null
if “$?” = “0” ] ; then
let “loopresult = $loopresult + 1"
else
badservers=”$badservers ${serverlist$index]}"
fi
let “index = $index + 1”
done
if “$loopresult” = “$servercount” ] ; then
outcode=0
outtext="All DNS servers working"
elif “$loopresult” = 0 ] ; then
outcode=2
outtext"No DNS servers working"
else
outcode=1
outtext="DNS servers not responding : ${badservers}"
fi
echo "$outtext"
exit $outcode
I should add that having your primary dns server down is still a bad thing, it can cause poorly written apps/OSs to timeout or hang for some time before moving on to the next dns server. When users start calling complaining that webpages are taking forever to come up, I first start looking for a failed DNS server.
-mike
Edited Fri Jan 06 2006, 06:33PM ]