#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

@@ -41,7 +41,7 @@ ajax '/ajax/data/device/:ip/snmptree/:base' => require_login sub {
children => \0,
state => { disabled => \1 },
icon => 'icon-search',
}] unless schema(vars->{'tenant'})->resultset('DeviceSnapshot')->find($device->ip);
}] unless $device->oids->count;
return to_json [{
text => 'No MIB data. Please run `~/bin/netdisco-do loadmibs`.',
@@ -62,12 +62,19 @@ ajax '/ajax/data/snmp/typeahead' => require_login sub {
my $table = ($deviceonly ? 'DeviceBrowser' : 'SNMPObject');
my @found = schema(vars->{'tenant'})->resultset($table)
->search({ -or => [ oid => $term,
oid => { -like => ($term .'.%') },
leaf => { -ilike => ('%'. $term .'%') } ],
->search({ -or => [ 'me.oid' => $term,
'me.oid' => { -like => ($term .'.%') },
'me.leaf' => { -ilike => ('%'. $term .'%') } ],
(($deviceonly and $device) ? (ip => $device) : ()), },
{ rows => 25, columns => 'leaf', order_by => 'oid_parts' })
->get_column('leaf')->all;
{ select => [
(($deviceonly and $device) ? \q{ oid_fields.mib || '::' || me.leaf }
: \q{ me.mib || '::' || me.leaf }),
],
as => ['qleaf'],
(($deviceonly and $device) ? (join => 'oid_fields') : ()),
rows => 25, order_by => 'me.oid_parts' })
->get_column('qleaf')->all;
return to_json [] unless scalar @found;
content_type 'application/json';
@@ -87,10 +94,12 @@ ajax '/ajax/data/snmp/nodesearch' => require_login sub {
{ rows => 1, order_by => 'oid_parts' })->first;
}
else {
my ($mib, $leaf) = split m/::/, $to_match;
$found = schema(vars->{'tenant'})->resultset('SNMPObject')
->search({ -or => [ oid => $to_match,
leaf => $to_match ] },
{ rows => 1, order_by => 'oid_parts' })->first;
->search({
(($mib and $leaf) ? (-and => [mib => $mib, leaf => $leaf])
: (-or => [oid => $to_match, leaf => { -ilike => $to_match }])),
},{ rows => 1, order_by => 'oid_parts' })->first;
}
return to_json [] unless $found;
@@ -148,6 +157,8 @@ sub _get_snmp_data {
my @items = map {{
id => $_,
mib => $meta{$_}->{mib}, # accessed via node.original.mib
leaf => $meta{$_}->{leaf}, # accessed via node.original.leaf
text => ($meta{$_}->{leaf} .' ('. $meta{$_}->{oid_parts}->[-1] .')'),
($meta{$_}->{browser} ? (icon => 'icon-folder-close text-info')