Changeset 645


Ignore:
Timestamp:
06/11/14 17:46:24 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Extend mergerecs with --detail option; now it defaults to only logging
a single generic entry for the actions taken rather than logging each
record merge separately. Also print the log messages to the console.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mergerecs

    r643 r645  
    3535
    3636sub usage {
    37   die qq(usage:  mergerecs zone [domain]
    38     zone  The zone to walk for PTR or A/AAAA records to try to merge.
    39           Using a reverse zone (either CIDR or in-addr.arpa) will
    40           likely behave more consistently.
     37  die qq(usage:  mergerecs zone [domain] [--detail]
     38    zone  The zone to walk for PTR records to try to merge.
    4139  domain  Optionally restrict record merges to a specified domain as well.
    42           Ignored if zone is a domain.
     40 --detail Optional argument to add one log entry for each A+PTR pair merged
     41          instead of a single generic entry.
    4342);
    4443}
    4544
    46 my $pzone = $ARGV[0];
    47 my $matchdom = $ARGV[1] || '';
     45my $logdetail = 0;
     46my $matchdom = '';
     47
     48my $pzone = shift @ARGV;
     49if (@ARGV) {
     50  if ($ARGV[0] eq '--detail') {
     51    $logdetail = 1;
     52  } else {
     53    $matchdom = shift @ARGV;
     54    $logdetail = 1 if @ARGV && $ARGV[0] eq '--detail';
     55  }
     56}
    4857
    4958my $dnsdb = new DNSDB or die "Couldn't create DNSDB object: ".$DNSDB::errstr."\n";
     
    124133        $mergesth->execute($erdns, $ettl, $etype, $id);
    125134        $delsth->execute($erid);
    126         $dnsdb->_log(group_id => $group, domain_id => $zid, rdns_id => $erdns, entry => $logentry);
    127       }
     135        if ($logdetail) {
     136          $dnsdb->_log(group_id => $group, domain_id => $zid, rdns_id => $erdns, entry => $logentry);
     137          print "$logentry\n";
     138        }
     139      }
     140      $nrecs++;
     141    } # while
     142    if (!$logdetail) {
     143      $dnsdb->_log(group_id => $group, domain_id => $zid,
     144        entry => "Merged $nrecs A and AAAA records in $pzone with matching PTRs");
    128145    }
     146    print "Merged $nrecs A and AAAA records in $pzone with matching PTRs\n";
    129147
    130148  } else {
    131     # merge records in a forward zone
     149    # merge records in a reverse zone
    132150    my $reclist = $dbh->prepare("SELECT host,val,type,record_id,ttl,location FROM records ".
    133151        "WHERE type=12 AND rdns_id = ?");
     
    159177        $mergesth->execute($edid, $ettl, $ntype, $id);
    160178        $delsth->execute($erid);
    161         $dnsdb->_log(group_id => $group, domain_id => $edid, rdns_id => $zid, entry => $logentry);
    162       }
     179        if ($logdetail) {
     180          $dnsdb->_log(group_id => $group, domain_id => $edid, rdns_id => $zid, entry => $logentry);
     181          print "$logentry\n";
     182        }
     183      }
     184      $nrecs++;
    163185    } # while
     186    my $entry = "Merged $nrecs PTR records in $pzone with matching A or AAAA records".($fzid ? " in $matchdom" : '');
     187    if (!$logdetail) {
     188      if ($fzid) {
     189        $dnsdb->_log(group_id => $group, domain_id => $fzid, rdns_id => $zid, entry => $entry);
     190      } else {
     191        $dnsdb->_log(group_id => $group, rdns_id => $zid, entry => $entry);
     192      }
     193    }
     194    print "$entry\n";
    164195  } # else
    165196  $dbh->commit;
Note: See TracChangeset for help on using the changeset viewer.