#910 implement import of snmpwalk and more robust snapshot handling (#1086)

* initial work

* initial work

* initial work

* some fixes for time and Layer3 weird spec

* store again the snapshot after update for specific

* resolve the enums

* monkeypatch SNMP::translateObj to avoid hardware exception on macOS

* only save cache to db in the late phase worker

* no need to check for cache on transport, can just go ahead and try

* use database only for oidmap instead of netdisco-mibs

* rewrite device snapshot to gather loaded mib leafs only

* remove old walker code from snapshot worker

* allow snmp browser to work without snapshot

* only store snapshot leafs which the device responded on

* refactor to separate snapshot work from snmp transport work

* refactor to separate snapshot work from snmp transport work

* allow typeahead on MIB qualified leafs

* fixes for snmpwalk input after previous refactor

* add the extra stuff SNMP::Info device class uses into snapshot

* better width for snmp search box

* fix css for snmp options

* add spinner while snmp loading

* add spinner while snmp loading

* add spinner while snmp loading

* support SNMP::Info device class or named MIBs as extra on snapshot

* add final tidy and bug fix
This commit is contained in:
Oliver Gorwits
2023-08-10 22:27:02 +01:00
committed by GitHub
parent 7afae0b9b2
commit 9eb537a4c1
12 changed files with 803 additions and 507 deletions

View File

@@ -3,8 +3,10 @@ package App::Netdisco::Util::SNMP;
use Dancer qw/:syntax :script !to_json !from_json/;
use App::Netdisco::Util::DeviceAuth 'get_external_credentials';
use MIME::Base64 'decode_base64';
use Storable 'thaw';
use File::Spec::Functions qw/splitdir catdir catfile/;
use MIME::Base64 qw/decode_base64/;
use Storable qw/thaw/;
use SNMP::Info;
use JSON::PP;
use base 'Exporter';
@@ -12,9 +14,9 @@ our @EXPORT = ();
our @EXPORT_OK = qw/
get_communities
snmp_comm_reindex
sortable_oid
decode_and_munge
%ALL_MUNGERS
decode_and_munge
sortable_oid
/;
our %EXPORT_TAGS = (all => \@EXPORT_OK);
@@ -31,24 +33,6 @@ subroutines.
=head1 EXPORT_OK
=head2 sortable_oid( $oid, $seglen? )
Take an OID and return a version of it which is sortable using C<cmp>
operator. Works by zero-padding the numeric parts all to be length
C<< $seglen >>, which defaults to 6.
=cut
# take oid and make comparable
sub sortable_oid {
my ($oid, $seglen) = @_;
$seglen ||= 6;
return $oid if $oid !~ m/^[0-9.]+$/;
$oid =~ s/^(\.)//; my $leading = $1;
$oid = join '.', map { sprintf("\%0${seglen}d", $_) } (split m/\./, $oid);
return (($leading || '') . $oid);
}
=head2 get_communities( $device, $mode )
Takes the current C<device_auth> setting and pushes onto the front of the list
@@ -247,4 +231,22 @@ sub decode_and_munge {
}
=head2 sortable_oid( $oid, $seglen? )
Take an OID and return a version of it which is sortable using C<cmp>
operator. Works by zero-padding the numeric parts all to be length
C<< $seglen >>, which defaults to 6.
=cut
# take oid and make comparable
sub sortable_oid {
my ($oid, $seglen) = @_;
$seglen ||= 6;
return $oid if $oid !~ m/^[0-9.]+$/;
$oid =~ s/^(\.)//; my $leading = $1;
$oid = join '.', map { sprintf("\%0${seglen}d", $_) } (split m/\./, $oid);
return (($leading || '') . $oid);
}
true;