Skip to content

Commit

Permalink
New DNS reports: PTR zombie and duplicated PTRs (#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurek committed Feb 23, 2017
1 parent 235a2c4 commit 00f5b65
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/ralph/dns/management/commands/dns_find_inconsistencies.py
Expand Up @@ -155,6 +155,26 @@ def check_ralph_ptrs(self, ips, dns, dns_rev):
if ptr not in dns['PTR'] or hostname not in dns['PTR'][ptr]:
yield (ip, hostname, dns['PTR'].get(ptr))

def get_zombie_ptrs(self, ips, dns, dns_rev):
"""
Return pairs of (ip, hostname) which has not properly configured PTR
records.
"""
for hostname, ptrs in dns_rev['PTR'].items():
for ptr in ptrs:
ip = '.'.join(ptr.split('.')[3::-1])
if hostname not in dns['A'] or ip not in dns['A'][hostname]:
yield ptr, hostname

def get_duplicated_ptrs(self, ips, dns, dns_rev):
"""
Return pairs of (ip, hostname) which has not properly configured PTR
records.
"""
for ptr, hostnames in dns['PTR'].items():
if len(hostnames) > 1:
yield ptr, hostnames

def handle(self, **options):
dns, dns_rev = self._fetch_dns_records()
ips = self._get_ips()
Expand All @@ -179,6 +199,16 @@ def handle(self, **options):
['IP', 'ralph hostname', 'PTR content'],
'Missing or wrong PTR records'
),
(
self.get_zombie_ptrs,
['PTR', 'hostname (content)'],
'Zombie PTR records'
),
(
self.get_duplicated_ptrs,
['PTR', 'hostnames'],
'Duplicated PTR records'
),
]:
result = func(ips, dns, dns_rev)
self.stdout.write(TEMPLATE.format(
Expand Down

0 comments on commit 00f5b65

Please sign in to comment.