Changeset 744 for trunk/mergerecs
- Timestamp:
- 08/29/16 16:16:13 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mergerecs
r662 r744 36 36 sub usage { 37 37 die qq(usage: mergerecs zone [domain] [--detail] 38 zone The zone to walk for PTR records to try to merge. 39 domain Optionally restrict record merges to a specified domain as well. 38 zone The primary zone to walk for records to try to merge. May be either 39 a reverse zone or a domain. 40 domain Optionally restrict record merges in a reverse zone to a specific 41 domain. 40 42 --detail Optional argument to add one log entry for each A+PTR pair merged 41 43 instead of a single generic entry. … … 82 84 } 83 85 die "$pzone is not a valid reverse zone specification\n" if !$npzone; 84 $zid = $dnsdb->revID($npzone );86 $zid = $dnsdb->revID($npzone, ''); 85 87 } else { 86 88 $rev = 'n'; 87 $zid = $dnsdb->domainID($pzone );88 } 89 die "$pzone is not a zone in the database \n" if !$zid;89 $zid = $dnsdb->domainID($pzone, ''); 90 } 91 die "$pzone is not a zone in the database (".$dnsdb->errstr.")\n" if !$zid; 90 92 91 93 # check the second arg. 92 my $fzid = $dnsdb->domainID($matchdom );94 my $fzid = $dnsdb->domainID($matchdom, ''); 93 95 die "$matchdom is not a domain in the database\n" if $matchdom && !$fzid; 94 96 … … 116 118 $reclist->execute($zid); 117 119 my $nrecs = 0; 120 my @cloglist; 118 121 while (my ($host,$val,$type,$id,$ttl,$loc) = $reclist->fetchrow_array) { 119 122 my $etype = 12; … … 134 137 $delsth->execute($erid); 135 138 if ($logdetail) { 136 $dnsdb->_log(group_id => $group, domain_id => $zid, rdns_id => $erdns, entry => $logentry); 139 my $lid = $dnsdb->_log(group_id => $group, domain_id => $zid, rdns_id => $erdns, entry => $logentry); 140 push @cloglist, $lid; 137 141 print "$logentry\n"; 138 142 } … … 140 144 } 141 145 } # while 142 if (!$logdetail) { 143 $dnsdb->_log(group_id => $group, domain_id => $zid, 146 my $lpid = $dnsdb->_log(group_id => $group, domain_id => $zid, 144 147 entry => "Merged $nrecs A and AAAA records in $pzone with matching PTRs"); 148 # since unlike in most other operations, we only "know" the parent log entry *after* 149 # we're done entering all the child entries, we have to update the children with the parent ID 150 my $assoc = $dbh->prepare("UPDATE log SET logparent = ? WHERE log_id = ?"); 151 for my $lcid (@cloglist) { 152 $assoc->execute($lpid, $lcid); 145 153 } 146 154 print "Merged $nrecs A and AAAA records in $pzone with matching PTRs\n"; … … 157 165 $reclist->execute($zid); 158 166 my $nrecs = 0; 167 my @cloglist; 159 168 while (my ($host,$val,$type,$id,$ttl,$loc) = $reclist->fetchrow_array) { 160 169 if ($matchdom) { … … 178 187 $delsth->execute($erid); 179 188 if ($logdetail) { 180 $dnsdb->_log(group_id => $group, domain_id => $edid, rdns_id => $zid, entry => $logentry); 181 print "$logentry\n"; 189 my $lid = $dnsdb->_log(group_id => $group, domain_id => $edid, rdns_id => $zid, entry => $logentry); 190 push @cloglist, $lid; 191 print "$lid: $logentry\n"; 182 192 } 183 193 $nrecs++; … … 185 195 } # while 186 196 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 } 197 my $lpid; 198 if ($fzid) { 199 $lpid = $dnsdb->_log(group_id => $group, domain_id => $fzid, rdns_id => $zid, entry => $entry); 200 } else { 201 $lpid = $dnsdb->_log(group_id => $group, rdns_id => $zid, entry => $entry); 202 } 203 # since unlike in most other operations, we only "know" the parent log entry *after* 204 # we're done entering all the child entries, we have to update the children with the parent ID 205 my $assoc = $dbh->prepare("UPDATE log SET logparent = ? WHERE log_id = ?"); 206 for my $lcid (@cloglist) { 207 $assoc->execute($lpid, $lcid); 193 208 } 194 209 print "$entry\n"; 195 } # else 210 } 211 196 212 $dbh->commit; 197 213 };
Note:
See TracChangeset
for help on using the changeset viewer.