auto expand SNMP browser more now the perf is good

This commit is contained in:
Oliver Gorwits
2022-08-03 17:57:54 +01:00
parent 94c43fcc33
commit 24b94d3092
2 changed files with 5 additions and 7 deletions

View File

@@ -31,11 +31,10 @@ ajax '/ajax/data/device/:ip/snmptree/:base' => require_login sub {
->find( param('ip') ) }
or send_error('Bad Device', 404);
my $recurse = ((param('recurse') and param('recurse') eq 'on') ? 0 : 1);
my $base = param('base');
$base =~ m/^\.1(\.\d+)*$/ or send_error('Bad OID Base', 404);
my $items = _get_snmp_data($device->ip, $base, $recurse);
my $items = _get_snmp_data($device->ip, $base);
content_type 'application/json';
to_json $items;
@@ -121,7 +120,6 @@ ajax '/ajax/content/device/:ip/snmpnode/:oid' => require_login sub {
sub _get_snmp_data {
my ($ip, $base, $recurse) = @_;
my @parts = grep {length} split m/\./, $base;
++$recurse;
# psql cannot cope with bind params and group by array element
# so we build a static query instead.
@@ -169,12 +167,12 @@ QUERY
text => ($meta{$_}->{leaf} .' ('. $kids{$_}->{part} .')'),
# for nodes with only one child, recurse to prefetch...
children => ( ($recurse < 2 and $kids{$_}->{children} == 1)
? _get_snmp_data($ip, ("${base}.". $kids{$_}->{part}), $recurse)
children => (($kids{$_}->{children} == 1)
? _get_snmp_data($ip, ("${base}.". $kids{$_}->{part}), 1)
: ($kids{$_}->{children} ? \1 : \0)),
# and set the display to open to show the single child
state => { opened => ( ($recurse < 2 and $kids{$_}->{children} == 1)
state => { opened => ( ($recurse or $kids{$_}->{children} == 1)
? \1
: \0 ) },

View File

@@ -84,7 +84,7 @@
'data' : {
'url' : function (node) {
return ('[% uri_base | none %]/ajax/data/device/[% device %]/snmptree/'
+ (node.id === '#' ? '.1' : node.id) + '?recurse=on');
+ (node.id === '#' ? '.1' : node.id));
}
}
},