Changeset 645 for trunk/mergerecs
- Timestamp:
- 06/11/14 17:46:24 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mergerecs
r643 r645 35 35 36 36 sub 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. 41 39 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. 43 42 ); 44 43 } 45 44 46 my $pzone = $ARGV[0]; 47 my $matchdom = $ARGV[1] || ''; 45 my $logdetail = 0; 46 my $matchdom = ''; 47 48 my $pzone = shift @ARGV; 49 if (@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 } 48 57 49 58 my $dnsdb = new DNSDB or die "Couldn't create DNSDB object: ".$DNSDB::errstr."\n"; … … 124 133 $mergesth->execute($erdns, $ettl, $etype, $id); 125 134 $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"); 128 145 } 146 print "Merged $nrecs A and AAAA records in $pzone with matching PTRs\n"; 129 147 130 148 } else { 131 # merge records in a forwardzone149 # merge records in a reverse zone 132 150 my $reclist = $dbh->prepare("SELECT host,val,type,record_id,ttl,location FROM records ". 133 151 "WHERE type=12 AND rdns_id = ?"); … … 159 177 $mergesth->execute($edid, $ettl, $ntype, $id); 160 178 $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++; 163 185 } # 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"; 164 195 } # else 165 196 $dbh->commit;
Note:
See TracChangeset
for help on using the changeset viewer.