netbox-community / customizations

A collection of community submitted and maintained customizations including reports, scripts, validators and export templates
MIT License
203 stars 55 forks source link

dns-reports.py - AAAA - "NoNameservers: All nameservers failed to answer the query" #109

Open falz opened 1 week ago

falz commented 1 week ago

Odd behaviour running the Check_DNS_AAAA_Record report in Netbox 4.0.10. Check_DNS_A_Record runs just fine.

We get:

NoNameservers: All nameservers failed to answer the query 1ru\032AC\032PDU\032A.

1ru AC PDU A is the device name (1ru\032AC\032PDU\032A is with spacing characters). It has no A nor AAAA nor any IP address at all- yet the script seems to be attempting to resolve it.

The A record (ipv4) report properly logs an info No IP or DNS found. for this. But for AAAA it pukes with:

An exception occurred: NoNameservers: All nameservers failed to answer the query 1ru\032AC\032PDU\032A. IN AAAA: Server Do53:127.0.0.53@53 answered SERVFAIL

Traceback (most recent call last):
  File "/opt/netbox/netbox-4.0.11/netbox/extras/scripts.py", line 662, in _run_script
    script.output = script.run(data, commit)
  File "/opt/netbox/netbox-4.0.11/netbox/extras/scripts.py", line 415, in run
    self.run_tests()
  File "/opt/netbox/netbox-4.0.11/netbox/extras/scripts.py", line 578, in run_tests
    raise e
  File "/opt/netbox/netbox-4.0.11/netbox/extras/scripts.py", line 573, in run_tests
    test_method()
  File "/opt/netbox/netbox-4.0.11/netbox/scripts/dns-reports.py", line 61, in test_dns_aaaa_record
    aaaa = dns.resolver.query(device.name, "AAAA")
  File "/opt/netbox/current/venv/lib/python3.10/site-packages/dns/resolver.py", line 1598, in query
    return resolve(
  File "/opt/netbox/current/venv/lib/python3.10/site-packages/dns/resolver.py", line 1565, in resolve
    return get_default_resolver().resolve(
  File "/opt/netbox/current/venv/lib/python3.10/site-packages/dns/resolver.py", line 1318, in resolve
    (nameserver, tcp, backoff) = resolution.next_nameserver()
  File "/opt/netbox/current/venv/lib/python3.10/site-packages/dns/resolver.py", line 763, in next_nameserver
    raise NoNameservers(request=self.request, errors=self.errors)
dns.resolver.NoNameservers: All nameservers failed to answer the query 1ru\032AC\032PDU\032A. IN AAAA: Server Do53:127.0.0.53@53 answered SERVFAIL

image

falz commented 1 week ago

Did a tcpdump to confirm what's happening - indeed SRVFAIL is true. This is just some ubuntu server with the default local resolver. I suspect there just needs to be better error handling added for NoNameservers (?)

image