Changeset 791 for trunk


Ignore:
Timestamp:
09/27/19 11:21:32 (5 years ago)
Author:
Kris Deugau
Message:

/trunk

Revise tiny-import.pl to log a per-file summary count of the records handled

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tiny-import.pl

    r777 r791  
    122122$dnsdb->{logusername} = $dnsdb->{logusername}."/tiny-import.pl";
    123123$dnsdb->{logfullname} = $dnsdb->{logusername} if !$dnsdb->{logfullname};
     124$dnsdb->{logfullname} = $dnsdb->{logfullname}."/tiny-import.pl";
    124125
    125126$dbh->{AutoCommit} = 0;
     
    132133
    133134foreach my $file (@ARGV) {
     135  my %filecount;
     136  my $logentry = "Import records from $file: ";
    134137  eval {
    135     import(file => $file);
    136 #    import(file => $file, nosoa => 1);
     138    import(file => $file, cnt => \%filecount);
     139    if (%filecount) {
     140      foreach (sort keys %filecount) {
     141        $logentry .= "$_ $filecount{$_}, ";
     142        $cnt{$_} += $filecount{$_};
     143      }
     144      $logentry =~ s/[\s,]+$//;
     145      $dnsdb->_log(group_id => $importcfg{group}, entry => $logentry);
     146    }
    137147    $dbh->rollback if $importcfg{trial};
    138148    $dbh->commit unless $importcfg{trial};
     
    146156
    147157# print summary count of record types encountered
    148 foreach (keys %cnt) {
     158foreach (sort keys %cnt) {
    149159  print " $_    $cnt{$_}\n";
    150160}
     
    155165  our %args = @_;
    156166  my $flatfile = $args{file};
     167  my $filecnt = $args{cnt};
    157168  my @fpath = split '/', $flatfile;
    158169  $fpath[$#fpath] = ".$fpath[$#fpath]";
     
    186197    chomp;
    187198    s/\s*$//;
    188     my $recstat = recslurp($_);
     199    my $recstat = recslurp($_, $filecnt);
    189200    $ok++ if $recstat;
    190201    if ($importcfg{rw}) {
     
    322333  sub recslurp {
    323334    my $rec = shift;
     335    my $filecnt = shift;
    324336    my $nodefer = shift || 0;
    325337    my $impok = 1;
     
    329341
    330342    if ($rec =~ /^=/) {
    331       $cnt{APTR}++;
     343      $filecnt->{'A+PTR'}++;
    332344
    333345##fixme:  do checks like this for all types
     
    384396
    385397    } elsif ($rec =~ /^C/) {
    386       $cnt{CNAME}++;
     398      $filecnt->{CNAME}++;
    387399
    388400      my ($host,$targ,$ttl,$stamp,$loc) = split /:/, $rec, 5;
     
    429441
    430442    } elsif ($rec =~ /^\&/) {
    431       $cnt{NS}++;
     443      $filecnt->{NS}++;
    432444
    433445      my ($zone,$ip,$ns,$ttl,$stamp,$loc) = split /:/, $rec, 6;
     
    471483
    472484    } elsif ($rec =~ /^\^/) {
    473       $cnt{PTR}++;
     485      $filecnt->{PTR}++;
    474486
    475487      my ($rip,$host,$ttl,$stamp,$loc) = split /:/, $rec, 5;
     
    521533
    522534    } elsif ($rec =~ /^\+/) {
    523       $cnt{A}++;
     535      $filecnt->{A}++;
    524536
    525537      my ($host,$ip,$ttl,$stamp,$loc) = split /:/, $rec, 5;
     
    558570
    559571    } elsif ($rec =~ /^Z/) {
    560       $cnt{SOA}++;
     572      $filecnt->{SOA}++;
    561573
    562574      my ($zone,$master,$contact,$serial,$refresh,$retry,$expire,$minttl,$ttl,$stamp,$loc) = split /:/, $rec, 11;
     
    610622
    611623    } elsif ($rec =~ /^\@/) {
    612       $cnt{MX}++;
     624      $filecnt->{MX}++;
    613625
    614626      my ($zone,$ip,$host,$dist,$ttl,$stamp,$loc) = split /:/, $rec, 7;
     
    641653
    642654    } elsif ($rec =~ /^'/) {
    643       $cnt{TXT}++;
     655      $filecnt->{TXT}++;
    644656
    645657      my ($fqdn, $rdata, $ttl, $stamp, $loc) = split /:/, $rec, 5;
     
    672684
    673685    } elsif ($rec =~ /^\./) {
    674       $cnt{NSASOA}++;
     686      $filecnt->{NSASOA}++;
    675687
    676688      my ($fqdn, $ip, $ns, $ttl, $stamp, $loc) = split /:/, $rec, 6;
     
    746758
    747759    } elsif ($rec =~ /^\%/) {
    748       $cnt{VIEWS}++;
     760      $filecnt->{VIEWS}++;
    749761
    750762      # unfortunate that we don't have a guaranteed way to get a description on these.  :/
     
    765777
    766778    } elsif ($rec =~ /^:/) {
    767       $cnt{NCUST}++;
     779      $filecnt->{NCUST}++;
    768780# Big section.  Since tinydns can publish anything you can encode properly, but only provides official
    769781# recognition and handling for the core common types, this must deal with the leftovers.
     
    930942
    931943    } else {
    932       $cnt{other}++;
     944      $filecnt->{other}++;
    933945      print " $_\n";
    934946    }
Note: See TracChangeset for help on using the changeset viewer.