Changeset 159

Show
Ignore:
Timestamp:
04/03/10 23:57:32 (5 months ago)
Author:
mbooth
Message:

Detect dangling PTR record problems and show icons when problems occur.

Location:
trunk/misc
Files:
4 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/misc/dns-o-matic.py

    r158 r159  
    8282                      'status'      : r.header['status'], 
    8383                      'subrecords'  : [], 
     84                      'problems'    : [], 
    8485                      } 
    8586            data.append(answer) 
     
    99100                  'status'      : r.header['status'], 
    100101                  'subrecords'  : [], 
     102                  'problems'    : [], 
    101103                  } 
    102104        data.append(answer) 
     
    130132 
    131133 
    132 def FindValidLoops(data): 
    133     # do a depth-first search for request loops and mark these records as valid 
    134     num = 0 
    135     for result in data['results']: 
    136         new_num = FindValidLoops(result) 
    137         if new_num > num: 
    138             num = new_num 
    139     if not data['status']: 
    140         data['valid'] = True 
    141         return 2 
    142     else: 
    143         if num > 0: 
    144             data['valid'] = True 
    145             return num - 1 
    146         else: 
    147             data['valid'] = False 
    148             return 0 
     134#def FindValidLoops(data): 
     135#   # do a depth-first search for request loops and mark these records as valid 
     136#   num = 0 
     137#   for result in data['results']: 
     138#       new_num = FindValidLoops(result) 
     139#       if new_num > num: 
     140#           num = new_num 
     141#   if not data['status']: 
     142#       data['valid'] = True 
     143#       return 2 
     144#   else: 
     145#       if num > 0: 
     146#           data['valid'] = True 
     147#           return num - 1 
     148#       else: 
     149#           data['valid'] = False 
     150#           return 0 
     151 
     152 
     153def FindDanglingPointers(data): 
     154    for rec in data['subrecords']: 
     155        if rec['status'] == 'NXDOMAIN': 
     156            problem = { 
     157                       'icon':'error', 
     158                       'text':'Dangling pointer (PTR) record detected for %s!\n\n' % data['lookup_of'] + \ 
     159                              'Perhaps it was left behind when the address (A) record for %s was deleted.' % data['resolves_to'], 
     160                       } 
     161            rec['problems'].append(problem) 
    149162 
    150163 
     
    176189    sys.stderr.write("\n") 
    177190 
    178     # iterate through all addresses for which we have results 
    179 #   for address in data['addresses']: 
    180 #       for ns_result in address['results']: 
    181 #           FindValidLoops(ns_result) 
     191    # detect dangling pointers 
     192    for address in data['addresses']: 
     193        for result in address['results']: 
     194            FindDanglingPointers(result) 
    182195    return data 
    183196 
     
    186199    # display the record we're looking up 
    187200    if data['resolves_to'] != '': 
    188         print "    <p style='padding-left:%spx'><span class='record'>%s</span> resolves to: <span class='record'>%s</span></p>" % (`level * 20`, data['lookup_of'], data['resolves_to']) 
     201        print "    <p style='padding-left:%spx'><span class='record'>%s</span> resolves to <span class='record'>%s</span>" % (`level * 20`, data['lookup_of'], data['resolves_to']) 
    189202    else: 
    190         print "    <p style='padding-left:%spx'><span class='record'>%s</span> does not resolve to anything!</p>" % (`level * 20`, data['lookup_of']) 
     203        print "    <p style='padding-left:%spx'><span class='record'>%s</span> does not resolve to anything!" % (`level * 20`, data['lookup_of']) 
     204 
     205    # display any problems associated with the record 
     206    for prob in data['problems']: 
     207        print "      <img src='icons/%s.png' />" % prob['icon'] 
     208    print "    </p>" 
    191209 
    192210    # recursively display subrecords