1

I have a script that executes rndc reload <zone_name> in <view_name> on secondary (slave) servers on the zones that are modified. This command returns success if the reload is queued successfully.

I wanted to know if there is a way I can get the status of the actual zone transfer without going through the logs itself. I want to be able to automatically handle the case when bind reload failed based on the error itself. Currently, I have to parse the logs to get the status of the zone transfer after executing rndc reload.

Can someone help me figure out how I can get the status of the zone transfer after executing rndc reload <zone_name> which is better than parsing the logs itself.

NOTE [to add more clarity]: I know notify can be used for master to communicate to the slave about a change. My question is about knowing if there is any way to get notified when the zone transfer initiated by the slave failed due to any reason without parsing the logs.

E.g. May be after notifying the slave, the master server died due to some reason. In this case, when the slave initiates a zone transfer, it would fail on getting the SOA record from the master. I want to get notified for these kind of errors that can happen during zone transfer without actually parsing the logs.

Let me know if more information is needed.

  • 2
    Compare the SOA serial number on both the primary and the slave? – HBruijn Apr 07 '17 at 06:48
  • @HBruijn How do I get any error status from comparing the SOA serial number? At most, I will know if the transfer succeeded or not but no information in the case it didn't succeed. Can you please elaborate? – unrealsoul007 Apr 07 '17 at 07:43
  • Why are you doing it like this? What you are asking about is based around doing things in clearly strange way. Is there any point to not just doing the usual notifies from the master side when changes happen? – Håkan Lindqvist Apr 09 '17 at 11:35
  • @HåkanLindqvist Even when using notify when the master tells the slave about a change, what if the zone transfer failed due to some reason? I want to get notified of this change without reading/parsing the logs manually. And further, I want to be able to take some action based on the failure message. I hope that adds clarity to what I want to achieve here. – unrealsoul007 Apr 10 '17 at 02:31

3 Answers3

2

The (error) log file is the only place where Bind will log such errors, so if you don't want to parse the log files for specific errors, (although you can use something like Splunk to automate such parsing and generating relevant alerts) you need to something else.

From a monitoring perspective I think your focus on getting notified on errors during zone transfers misses the point slightly. It's not really the errors that matter so much, it is the fact such errors indicate a reduced, failed or erroneous service. Instead focus on the service.

A correctly configured monitoring solution will detect such changed service state and alert you. Then your engineer/operator can easily search the log file for the relevant cause of that service reduction/failure...

In a master-slave scenario your monitoring needs to ensure that:

  • all slave and the master name-servers respond and return zone data
  • all slaves return data that is consistent with the master

A good DNS record to monitor for a zone would be the SOA record, as that is something that each name server should always be able to return for every zone.

Second the serial number in the SOA record should tell you if the slave is sync with the master. If there is difference in serial numbers that can be caused by the slave having missed a NOTIFY message, but if that difference is present longer than the SOA refresh interval a more serious issue is at hand.

HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • I do agree that this can be viewed from the monitoring perspective. In that case, can you help me identify what will be good solutions for automatically parsing the logs? We already have a central log system which can also generate alerts. – unrealsoul007 Apr 10 '17 at 18:08
2

Create a script slave.sh with:

#!/bin/sh

ns1="yourfirstdnsserver"
ns2="yourslavednsserver" 
serial='grep SOA |cut -d " " -f7'
domain=$1

rndc reload $domain

a=`host -t SOA $domain $ns1 |grep SOA |cut -d " " -f7`
b=`host -t SOA $domain $ns2 |grep SOA |cut -d " " -f7`

if [ $a = $b ];
        then echo "$domain : synchro ok";
        else "$domain : Error";
fi;

Simply use ./slave.sh yourdomain.com.

Enjoy!

Tombart
  • 2,143
  • 3
  • 27
  • 48
  • 1
    From what I understand, all this is doing is getting the SOA from the slave and master and comparing it if they are same or not. However this is done almost immediately after executing `rndc reload $domain` and since rndc reload is an asynchronous command, it is possible that SOA serial number may not be same immediately. Also this does try to identify if there was an error but doesn't say anything about what kind of error might have happened. Please correct me if I am wrong. – unrealsoul007 Apr 10 '17 at 18:01
  • So why don't you then add `sleep 20` after `rndc reload`? – Esa Jokinen Apr 14 '17 at 11:50
  • And yes, this doesn't tell you what's wrong if zone transfer fails. It just lets you know whether it went ok, which is most likely the normal condition. The rest can be found from logs, or you could modify this script to do something like `else tail -n 10 /var/log/named/xfer-out.log;` – Esa Jokinen Apr 14 '17 at 11:59
0
a=`host -t SOA yourdomain.com yourns1.com |grep SOA |cut -d " " -f7` && b=`host -t SOA yourdomain.com yourns2.com |grep SOA |cut -d " " -f7` && if [ $a = $b ]; then echo "synchro ok"; else "Error"; fi;
jscott
  • 24,484
  • 8
  • 79
  • 100
  • Let me minutes i'll write a script for you for doing this with simplicity. – Christophe Casalegno Apr 10 '17 at 15:08
  • 3
    Whilst this may theoretically answer the question, please [provide context around scripts](http://serverfault.com/help/how-to-answer) so others will have some idea what it is supposed to do why it’s there. e.g. *" I would script a simple comparison of the SOA serial numbers returned by each of your name servers"* ;) – HBruijn Apr 10 '17 at 15:23