nagios script to check dns servers status
#!/bin/bash
###################################
#Purpose:################################################################
###(a) Monitor if all your name server is online: Status :Done ####
###(b) Monitor if all name server has same zone record : Staus : Ongoing##
###(c) Monitor the Response time of Dns server : Status : Ongoing#
#########################################################################
#Status check variables for nagios script#####
#####################################
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
#####################################
##Declaration of vairables###########
#####################################
declare -rx CMD_HOST="/usr/bin/host";
declare -rx CMD_AWK="/bin/awk"
declare -rx CMD_CAT="/bin/cat"
declare -rx CMD_GREP="/bin/grep"
declare -rx CMD_DIG="/usr/bin/dig"
ZONE=$1; # This value will captuer zone record prvided as parameter from script.
#############################################################
#Command to use : host -t ns fosiul.co.uk | awk '{print $4}'#
#############################################################
NUMBER_OF_DNSSrv=$($CMD_HOST -t ns $ZONE | $CMD_AWK '{print $4}' )
s=0
for i in $NUMBER_OF_DNSSrv
do
###########################################################
###Now Find out if all the name server is running##########
##########################################################
############Command#######################
########dig @dnserver ############
DNS_LIVE_RESULT=$($CMD_DIG @$i | $CMD_GREP -c 'connection timed out')
if [ $DNS_LIVE_RESULT -gt 0 ]
then
OFFLINE_ARRAY[$s]=$i
((s+=1))
fi
done
if [ ${#OFFLINE_ARRAY[*]} -eq 0 ]
then
echo "All servers are online"
exit $STATUS_OK
else
s=0
echo -n "Following servers are offline: "
while [ $s -lt ${#OFFLINE_ARRAY[*]} ]
do
echo -n "${OFFLINE_ARRAY[$s]} "
((s+=1))
done
echo
exit $STATE_CRITICAL
fi
done
This entry was posted
on Monday, June 7th, 2010 at 9:27 am and is filed under Bash Script, Nagios.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.