Script to monitor bind and related info

i am trying to write a nagios script to monitor bind and zone record, logic is :

it will check if all name server is online or not and they have same zone record. i will add rest of check one by one if i need

here i am not asking for any solution, its rather then how to perform ..


as in another post @tintin said, you can use dig or host command...as nslookup is deprecated .


i wanted to use nslookup like this :(please check the code section)

so if all the zone record return same thing , which means all my name server is online and the zone records are upto date


Now is there any short way to do this .. rather then put all this logic in the script ???

like
host -t soa bbc.co.uk
bbc.co.uk has SOA record ns.bbc.co.uk. hostmaster.bbc.co.uk. 2010042000 1800 600 864000 900

but this only show one soa record, i have tested, if i change any soa record by hand, it will not come here

so here i am here after logic.. rather then how to

thanks


note : i have checked in google, i know there is few nagios script for named check but those are very basic, does not do anything

[root@sandbox nagiosscript]# nslookup
> set type=ns
> bbc.co.uk.
Server:         xx.xx.xx.xx
Address:        xx.xx.xx.xx#53

Non-authoritative answer:
bbc.co.uk       nameserver = ns1.thdo.bbc.co.uk.
bbc.co.uk       nameserver = ns1.thls.bbc.co.uk.
bbc.co.uk       nameserver = ns1.rbsov.bbc.co.uk.
bbc.co.uk       nameserver = ns1.bbc.co.uk.

Authoritative answers can be found from:
ns1.thdo.bbc.co.uk      internet address = 212.58.224.21
ns1.thls.bbc.co.uk      internet address = 132.185.240.21
ns1.rbsov.bbc.co.uk     internet address = 212.58.227.48
> server ns1.bbc.co.uk.
Default server: ns1.bbc.co.uk.
Address: 132.185.132.21#53
> set type=soa
> bbc.co.uk.
Server:         ns1.bbc.co.uk.
Address:        132.185.132.21#53

bbc.co.uk
        origin = ns.bbc.co.uk
        mail addr = hostmaster.bbc.co.uk
        serial = 2010042000
        refresh = 1800
        retry = 600
        expire = 864000
        minimum = 900
> server ns1.rbsov.bbc.co.uk.
Default server: ns1.rbsov.bbc.co.uk.
Address: 212.58.227.48#53
> bbc.co.uk.
Server:         ns1.rbsov.bbc.co.uk.
Address:        212.58.227.48#53

bbc.co.uk
        origin = ns.bbc.co.uk
        mail addr = hostmaster.bbc.co.uk
        serial = 2010042000
        refresh = 1800
        retry = 600
        expire = 864000
        minimum = 900

Open in new window

LVL 29
fosiul01Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RowleyCommented:
Does this not do what you want?
woolmilkporcCommented:
Hi again,
try
host -C bbc.co.uk

Manpage says -
When the -C option is used, host will attempt to display the SOA records for zone name from all the  listed  authorita­
       tive name servers for that zone. The list of name servers is defined by the NS records that are found for the zone.

wmp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fosiul01Author Commented:
@Rowley, i will have a look to that script, i did not come accorss that script before

@woolmilkporc..... I missed that options like that!!!!

i was trying -t..

but host -C .. thats a easy way to do, how much have to separate those value thats all

PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

fosiul01Author Commented:
@Rowley

check_dig yes, its a good tool but what i wanted .. it would not work that way( i guess, I might be wrong, so please correct me)

its giving .. Sireal number of soa record and other but its for individual zone...

suppose i have a domian ..

www.fosiul.com

now i have 2 name server

so i need to check if both name server has same record, if they have same serial number or not .. check_dig is not giving me this customized options

so i guess i need to write one

is not it ??
RowleyCommented:
./check_dig -H 8.8.8.8 -l google.com -T "SOA"

will return the serial in a stripped down manner to that of default dig output. You will, between refreshes. have the serial numbers out of sync. You could write a quick and dirty wrapper for check dig to check both serial numbers. For example:

===========

#!/bin/sh

server1=`check_dig -H 8.8.8.8 -l google.com -T "SOA" | nawk '{print $14}'`
server2=`check_dig -H 8.8.4.4 -l google.com -T "SOA" | nawk '{print $14}'`

if [ "$server1" -eq "server2" ]; then
  echo "DNS OK: Serial match ok"
  exit 0
else
  echo "DNS WARNING: Serial mismatch"  
  exit 0
fi
RowleyCommented:
note, the second exit should exit 1

fosiul01Author Commented:
is there any command to find out Dns response time without using C library or perl add ons ??

any linux command or rpm you can use to find out dns response time ??

thanks


woolmilkporcCommented:
Try dig
dig will give you a report at the end including query time.
dig  @server name type
where name and type can be omitted to get the default output. @server can be omitted also, to use the default nameserver.
wmp
fosiul01Author Commented:
omm yes i saw that .... but i was little bit of confused with check_dig output

./check_dig -l xxxxx.co.uk
DNS OK - 0.008 seconds response time (xxxx.co.uk.  60 IN A xxx.xxx.xxx.xxx)|time=0.007915s;;;0.000000

dig @xx.xx.xx.co.uk

;; Query time: 8 msec


8 msec and 0.0008 second which is same

but what this time=0.007915 ?? i guess its for graph purpose .. is not it ??( 98% sure)

if that true.. then i dont have any doubt

thanks


woolmilkporcCommented:
Well,
I can't telly ou for sure, but since there is only a tiny difference (0.000085 sec) I think that 0.008 is what "dig" says and 0.007915 is what "check_dig" measured by itself.
wmp
fosiul01Author Commented:
yes it is for graph.. i just check one of my nagios script.

anything after that | is for graph

anyway thanks

i will close this question.. will open few more as i decided to go with my own script for learning and for more flexibility
woolmilkporcCommented:
OK,
the things following | are values passed to nagios for e.g. graphing, that's true.
I thought your question was about the difference between the two values ...
Thx for the points!
wmp
fosiul01Author Commented:
hmmm yes its true....

you said, there is a very low difference so that must be same value .

so i took your word!! and its true anything after | is for graph

so you saying they are not the same value ?? then it will put in in doubt!! as that script wrote by C


fosiul01Author Commented:
/usr/local/nagios/libexec/check_dig  -l bbc.co.uk
DNS CRITICAL - 0.004 seconds response time (No ANSWER SECTION found)|time=0.0042                                                                                                  16s;;;0.000000
[root@web nagiosscript]# /usr/local/nagios/libexec/check_dig  -l bbc.co.uk
DNS CRITICAL - 0.005 seconds response time (No ANSWER SECTION found)|time=0.0045                                                                                                  96s;;;0.000000
[root@web nagiosscript]# /usr/local/nagios/libexec/check_dig  -l bbc.co.uk
DNS CRITICAL - 0.008 seconds response time (No ANSWER SECTION found)|time=0.0083                                                                                                  64s;;;0.000000
[root@web nagiosscript]# /usr/local/nagios/libexec/check_dig  -l bbc.co.uk
DNS CRITICAL - 0.005 seconds response time (No ANSWER SECTION found)|time=0.0051                                                                                                  33s;;;0.000000
[root@web nagiosscript]# /usr/local/nagios/libexec/check_dig  -l bbc.co.uk
DNS CRITICAL - 0.006 seconds response time (No ANSWER SECTION found)|time=0.0060                                                                                                  56s;;;0.000000
[root@web nagiosscript]# /usr/local/nagios/libexec/check_dig  -l bbc.co.uk
DNS CRITICAL - 0.004 seconds response time (No ANSWER SECTION found)|time=0.0042                                                                                                  36s;;;0.000000




and digg :
dig bbc.co.uk
all sample value is 1 msec

0.004  is that 4 msec ??


fosiul01Author Commented:
i am confusing my self
let me fix my head first
then i will speak!! right now i am confused my self with this dns time
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.