From 162925f6eb12a62865e4864ffb1bdc49801952a2 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 8 Aug 2022 20:24:03 +0100 Subject: [PATCH] change for separate uncompressed oid maps in netdisco-mibs --- Build.PL | 1 - lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm | 20 +++++++++++++------- lib/App/Netdisco/Worker/Plugin/Snapshot.pm | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Build.PL b/Build.PL index 8731e767..1b1e7abd 100644 --- a/Build.PL +++ b/Build.PL @@ -51,7 +51,6 @@ Module::Build->new( 'Guard' => '1.022', 'HTML::Parser' => '3.70', 'HTTP::Tiny' => '0.029', - 'IO::Uncompress::Gunzip' => '0', 'IO::Socket::INET6' => '2.72', 'IO::Socket::SSL' => '2.048', 'JSON' => '2.90', diff --git a/lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm b/lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm index 426aba20..a354254c 100644 --- a/lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm +++ b/lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm @@ -6,9 +6,8 @@ use aliased 'App::Netdisco::Worker::Status'; 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 IO::Uncompress::Gunzip qw(gunzip $GunzipError); use File::Temp; # use DDP; @@ -18,18 +17,25 @@ register_worker({ phase => 'main' }, sub { debug "loadmibs - loading netdisco-mibs object cache"; my $home = (setting('mibhome') || catdir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs')); - my $infile = catfile($home, qw(EXTRAS reports all_oids.gz)); - my $outfh = File::Temp->new(); - my $outfile = $outfh->filename; - gunzip $infile => $outfile or die "gunzip failed: $GunzipError\n"; - my @report = read_lines($outfile, '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 @browser = (); my %children = (); + my %seenoid = (); foreach my $line (@report) { my ($oid, $qual_leaf, $type, $access, $index, $status, $enum, $descr) = split m/,/, $line, 8; next unless defined $oid and defined $qual_leaf; + next if ++$seenoid{$oid} > 1; my ($mib, $leaf) = split m/::/, $qual_leaf; my @oid_parts = grep {length} (split m/\./, $oid); diff --git a/lib/App/Netdisco/Worker/Plugin/Snapshot.pm b/lib/App/Netdisco/Worker/Plugin/Snapshot.pm index 4ad43090..b6140d2c 100644 --- a/lib/App/Netdisco/Worker/Plugin/Snapshot.pm +++ b/lib/App/Netdisco/Worker/Plugin/Snapshot.pm @@ -8,7 +8,7 @@ use App::Netdisco::Transport::SNMP; use App::Netdisco::Util::SNMP 'sortable_oid'; 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 File::Slurper qw(read_lines write_text); use File::Path 'make_path'; @@ -101,12 +101,22 @@ sub getoidmap { debug "snapshot $device - loading netdisco-mibs object cache"; 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 = (); foreach my $line (@report) { my ($oid, $qual_leaf, $rest) = split m/,/, $line; next unless defined $oid and defined $qual_leaf; + next if exists $oidmap{$oid}; my ($mib, $leaf) = split m/::/, $qual_leaf; $oidmap{$oid} = $leaf; }