mirror of
https://git.dn42.dev/dn42/registry.git
synced 2025-05-10 06:35:22 +08:00
[validate-dns] print the error if an unknown error occurs,
so that the script doesn't completely exit upon such errors - add warning after summary if at least one 'error' occured - align line beginnings
This commit is contained in:
parent
d3de73d1f3
commit
bb37cb9223
1 changed files with 52 additions and 40 deletions
|
@ -249,6 +249,19 @@ def get_domain_by_mntner(mntner):
|
|||
return domains
|
||||
|
||||
|
||||
# if an unknown error occurs: notify the user
|
||||
def _handle_unknown_error(e: Exception, nserver: str, domain_name: str):
|
||||
global errors
|
||||
print(f"-----------------")
|
||||
print(f"Error: unknown/unexpected error occured while querying {nserver} for {domain_name}")
|
||||
print(f"Error: '{e.__class__.__module__}.{e.__class__.__name__}': '{str(e)}'")
|
||||
print(f"Note: please check your nameserver, your network and any related configuration")
|
||||
print(f"-----------------")
|
||||
errors += 1
|
||||
time.sleep(3)
|
||||
return False
|
||||
|
||||
|
||||
def get_soa(domain_name, nserver):
|
||||
"""query dns server for SOA"""
|
||||
global errors, summary
|
||||
|
@ -270,11 +283,7 @@ def get_soa(domain_name, nserver):
|
|||
summary[domain_name][SUMMARY.SERVFAIL] += 1
|
||||
return False
|
||||
except Exception as e:
|
||||
print(
|
||||
f"ERROR: unknown error occured while querying {nserver} for {domain_name}: '{e}'")
|
||||
errors += 1
|
||||
time.sleep(3)
|
||||
return False
|
||||
return _handle_unknown_error(e)
|
||||
# raise e
|
||||
if response[0].rcode() != 0:
|
||||
# HANDLE QUERY FAILED (SERVER ERROR OR NO SOA RECORD)
|
||||
|
@ -330,6 +339,8 @@ def get_ns(domain_name, nserver):
|
|||
f"ERROR: server replied with different different ip than requested: error: {e}")
|
||||
errors += 1
|
||||
return False
|
||||
except Exception as e:
|
||||
return _handle_unknown_error(e, nserver=nserver, domain_name=domain_name)
|
||||
if response[0].rcode() != 0:
|
||||
# HANDLE QUERY FAILED (SERVER ERROR OR NO NS RECORD)
|
||||
print(
|
||||
|
@ -390,6 +401,8 @@ def get_dnskey(domain_name, nserver):
|
|||
summary[domain_name][SUMMARY.REFUSED] += 1
|
||||
errors += 1
|
||||
return False
|
||||
except Exception as e:
|
||||
return _handle_unknown_error(e, nserver=nserver, domain_name=domain_name )
|
||||
|
||||
if response[0].rcode() != 0:
|
||||
# HANDLE QUERY FAILED (SERVER ERROR OR NO DNSKEY RECORD)
|
||||
|
@ -515,6 +528,9 @@ def check_dnssec(domain_name, domain_data):
|
|||
f"WARN: querying {nserver} ({nsaddr}) for {domain_name} timed out")
|
||||
summary[domain_name][SUMMARY.TIMEOUT] += 1
|
||||
continue
|
||||
except Exception as e:
|
||||
_handle_unknown_error(e, nserver=f"{nserver} ({nsaddr})", domain_name=domain_name)
|
||||
continue
|
||||
|
||||
if no_ds_rdatas:
|
||||
print(
|
||||
|
@ -581,16 +597,9 @@ def main(mntner):
|
|||
# get all domains/inet(6)nums of the mntner
|
||||
domains = get_domain_by_mntner(mntner=mntner)
|
||||
|
||||
# global _tmp_continue, _tmp_found
|
||||
# _tmp_found = False
|
||||
# _tmp_continue = "10.in-addr.arpa"
|
||||
def check_dns(domain_name):
|
||||
global errors, summary
|
||||
# global _tmp_found, _tmp_continue
|
||||
# if domain_name == _tmp_continue:
|
||||
# _tmp_found = True
|
||||
# if not _tmp_found:
|
||||
# return
|
||||
|
||||
summary[domain_name] = [0, 0, 0, 0, 0, 0, 0, 0]
|
||||
# check if the domain doesn't have DS data
|
||||
if domains[domain_name]["ds-rdata"] == []:
|
||||
|
@ -736,12 +745,15 @@ def main(mntner):
|
|||
if len(_domain) > _max_domain_length:
|
||||
_max_domain_length = len(_domain)
|
||||
|
||||
print("\n\nSummary:\n")
|
||||
print("```\n\nSummary:\n")
|
||||
print(f"{'domain name'.ljust(_max_domain_length)} | success | dnssec fail | wrong NS | wrong SOA | NXDOMAIN | REFUSED | SERVFAIL | timeout")
|
||||
print(f"-{'-'.rjust(_max_domain_length, '-') }-|---------|-------------|----------|-----------|----------|---------| -------- | -------")
|
||||
for domain in summary:
|
||||
print(f" {domain.rjust(1).ljust(_max_domain_length)} | {str(summary[domain][SUMMARY.SUCCESS]).rjust(7)} | {str(summary[domain][SUMMARY.DNSSEC_FAIL]).rjust(11)} | {str(summary[domain][SUMMARY.WRONG_NS]).rjust(8)} | {str(summary[domain][SUMMARY.WRONG_SOA]).rjust(9)} | {str(summary[domain][SUMMARY.NXDOMAIN]).rjust(8)} | {str(summary[domain][SUMMARY.REFUSED]).rjust(7)} | {str(summary[domain][SUMMARY.SERVFAIL]).rjust(8)} | {str(summary[domain][SUMMARY.TIMEOUT]).rjust(7)}")
|
||||
|
||||
print("```\n")
|
||||
if errors > 0:
|
||||
print("WARN: at least one 'error' occured while checking. check the table and output above")
|
||||
# print(summary)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue