change for separate uncompressed oid maps in netdisco-mibs

This commit is contained in:
Oliver Gorwits
2022-08-08 20:24:03 +01:00
parent 5d5e36b5fd
commit 162925f6eb
3 changed files with 25 additions and 10 deletions

View File

@@ -51,7 +51,6 @@ Module::Build->new(
'Guard' => '1.022', 'Guard' => '1.022',
'HTML::Parser' => '3.70', 'HTML::Parser' => '3.70',
'HTTP::Tiny' => '0.029', 'HTTP::Tiny' => '0.029',
'IO::Uncompress::Gunzip' => '0',
'IO::Socket::INET6' => '2.72', 'IO::Socket::INET6' => '2.72',
'IO::Socket::SSL' => '2.048', 'IO::Socket::SSL' => '2.048',
'JSON' => '2.90', 'JSON' => '2.90',

View File

@@ -6,9 +6,8 @@ use aliased 'App::Netdisco::Worker::Status';
use Dancer::Plugin::DBIC 'schema'; use Dancer::Plugin::DBIC 'schema';
use File::Spec::Functions qw(catdir catfile); use File::Spec::Functions qw(splitdir catfile catdir);
use File::Slurper qw(read_lines write_text); use File::Slurper qw(read_lines write_text);
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
use File::Temp; use File::Temp;
# use DDP; # use DDP;
@@ -18,18 +17,25 @@ register_worker({ phase => 'main' }, sub {
debug "loadmibs - loading netdisco-mibs object cache"; debug "loadmibs - loading netdisco-mibs object cache";
my $home = (setting('mibhome') || catdir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs')); my $home = (setting('mibhome') || catdir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs'));
my $infile = catfile($home, qw(EXTRAS reports all_oids.gz)); my $reports = catdir( $home, 'EXTRAS', 'reports' );
my $outfh = File::Temp->new(); my @maps = map { (splitdir($_))[-1] }
my $outfile = $outfh->filename; grep { ! m/^(?:EXTRAS)$/ }
gunzip $infile => $outfile or die "gunzip failed: $GunzipError\n"; grep { ! m/\./ }
my @report = read_lines($outfile, 'latin-1'); grep { -f }
glob (catfile( $reports, '*_oids' ));
my @report = ();
push @report, read_lines( catfile( $reports, $_ ), 'latin-1' )
for (qw(rfc_oids net-snmp_oids cisco_oids), @maps);
my @browser = (); my @browser = ();
my %children = (); my %children = ();
my %seenoid = ();
foreach my $line (@report) { foreach my $line (@report) {
my ($oid, $qual_leaf, $type, $access, $index, $status, $enum, $descr) = split m/,/, $line, 8; my ($oid, $qual_leaf, $type, $access, $index, $status, $enum, $descr) = split m/,/, $line, 8;
next unless defined $oid and defined $qual_leaf; next unless defined $oid and defined $qual_leaf;
next if ++$seenoid{$oid} > 1;
my ($mib, $leaf) = split m/::/, $qual_leaf; my ($mib, $leaf) = split m/::/, $qual_leaf;
my @oid_parts = grep {length} (split m/\./, $oid); my @oid_parts = grep {length} (split m/\./, $oid);

View File

@@ -8,7 +8,7 @@ use App::Netdisco::Transport::SNMP;
use App::Netdisco::Util::SNMP 'sortable_oid'; use App::Netdisco::Util::SNMP 'sortable_oid';
use Dancer::Plugin::DBIC 'schema'; use Dancer::Plugin::DBIC 'schema';
use File::Spec::Functions qw(catdir catfile); use File::Spec::Functions qw(splitdir catdir catfile);
use MIME::Base64 'encode_base64'; use MIME::Base64 'encode_base64';
use File::Slurper qw(read_lines write_text); use File::Slurper qw(read_lines write_text);
use File::Path 'make_path'; use File::Path 'make_path';
@@ -101,12 +101,22 @@ sub getoidmap {
debug "snapshot $device - loading netdisco-mibs object cache"; debug "snapshot $device - loading netdisco-mibs object cache";
my $home = (setting('mibhome') || catdir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs')); my $home = (setting('mibhome') || catdir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs'));
my @report = read_lines(catfile($home, qw(EXTRAS reports all_oids)), 'latin-1'); my $reports = catdir( $home, 'EXTRAS', 'reports' );
my @maps = map { (splitdir($_))[-1] }
grep { ! m/^(?:EXTRAS)$/ }
grep { ! m/\./ }
grep { -f }
glob (catfile( $reports, '*_oids' ));
my @report = ();
push @report, read_lines( catfile( $reports, $_ ), 'latin-1' )
for (qw(rfc_oids net-snmp_oids cisco_oids), @maps);
my %oidmap = (); my %oidmap = ();
foreach my $line (@report) { foreach my $line (@report) {
my ($oid, $qual_leaf, $rest) = split m/,/, $line; my ($oid, $qual_leaf, $rest) = split m/,/, $line;
next unless defined $oid and defined $qual_leaf; next unless defined $oid and defined $qual_leaf;
next if exists $oidmap{$oid};
my ($mib, $leaf) = split m/::/, $qual_leaf; my ($mib, $leaf) = split m/::/, $qual_leaf;
$oidmap{$oid} = $leaf; $oidmap{$oid} = $leaf;
} }