Script to send email, if DNS resolution fails
by james000 from LinuxQuestions.org on (#581WS)
Hi,
Few days ago, DNS forwarding was broken between two datacenters and one of the URL was broken. At that time, when I did "nslookup gemprov.clc.prdv51.com", it failed. Below is description, how it works.
The webserver/application server of this website is on servers hosted in Raleigh/Dallas. Any query goes to this URL, reached to DNS servers of Raleigh/Dallas. prdv512.com zone is not available on Raleigh/Dallas DNS servers, so there is a forwarder set, which send this query to Seattle/Phoenix (4 in numbers) DNS servers and then it will be resolved.
As a custom solution of monitoring, I want to setup something like, we should get email if the resolution doesn't work and fails. One way I can think is, setup a cronjob like below. Can it work?
Code:dig gemprov.clc.prdv51.com | grep NOERROR 1>/dev/null || echo "DNS lookup fail from clc" | mail -s "DNS lookup of gemprov.clc.prdv51.com fails" abc_group@prdv51.comFor testing, if I make typo in domain, then only it works.
Code:[root@lin-32serv ~]# dig gemprov123.clc.prdv51.com | grep NOERROR
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57436
[root@lin-32serv ~]# dig gemprov.clc.comtech911.com | grep NOERROR
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56694
[root@lin-32serv ~]# dig gemprov.clc.prdv51123.com | grep NOERROR
[root@lin-32serv ~]#What would be best way to achieve it?
Advice, please
Thanks


Few days ago, DNS forwarding was broken between two datacenters and one of the URL was broken. At that time, when I did "nslookup gemprov.clc.prdv51.com", it failed. Below is description, how it works.
The webserver/application server of this website is on servers hosted in Raleigh/Dallas. Any query goes to this URL, reached to DNS servers of Raleigh/Dallas. prdv512.com zone is not available on Raleigh/Dallas DNS servers, so there is a forwarder set, which send this query to Seattle/Phoenix (4 in numbers) DNS servers and then it will be resolved.
As a custom solution of monitoring, I want to setup something like, we should get email if the resolution doesn't work and fails. One way I can think is, setup a cronjob like below. Can it work?
Code:dig gemprov.clc.prdv51.com | grep NOERROR 1>/dev/null || echo "DNS lookup fail from clc" | mail -s "DNS lookup of gemprov.clc.prdv51.com fails" abc_group@prdv51.comFor testing, if I make typo in domain, then only it works.
Code:[root@lin-32serv ~]# dig gemprov123.clc.prdv51.com | grep NOERROR
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57436
[root@lin-32serv ~]# dig gemprov.clc.comtech911.com | grep NOERROR
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56694
[root@lin-32serv ~]# dig gemprov.clc.prdv51123.com | grep NOERROR
[root@lin-32serv ~]#What would be best way to achieve it?
Advice, please
Thanks