App-Netdisco
view release on metacpan or search on metacpan
lib/App/Netdisco/Web/Plugin/Device/SNMP.pm view on Meta::CPAN
my $object = schema(vars->{'tenant'})->resultset('SNMPObject')
->find({'me.oid' => $oid},
{join => ['snmp_filter'], prefetch => ['snmp_filter']})
or send_error('Bad OID', 404);
my $munge = (param('munge') ||
($object->snmp_filter ? $object->snmp_filter->subname : undef));
#Â this is a bit lazy, could be a join on above with some effort
my $value = schema(vars->{'tenant'})->resultset('DeviceBrowser')
->search({-and => [-bool => \q{ array_length(oid_parts, 1) IS NOT NULL },
-bool => \q{ jsonb_typeof(value) = 'array' }]})
->find({'me.oid' => $oid, 'me.ip' => $device});
my %data = (
$object->get_columns,
snmp_object => { $object->get_columns },
value => ( defined $value ? decode_and_munge( $munge, $value->value ) : undef ),
);
my @mungers = schema(vars->{'tenant'})->resultset('SNMPFilter')
->search({},{ distinct => 1, order_by => 'subname' })
->get_column('subname')->all;
template 'ajax/device/snmpnode.tt',
{ node => \%data, munge => $munge, mungers => \@mungers },
{ layout => 'noop' };
};
sub _get_snmp_data {
my ($ip, $base, $recurse) = @_;
my @parts = grep {length} split m/\./, $base;
my %meta = map { ('.'. join '.', @{$_->{oid_parts}}) => $_ }
schema(vars->{'tenant'})->resultset('Virtual::FilteredSNMPObject')
->search({}, { bind => [
$ip,
(scalar @parts + 1),
(scalar @parts + 1),
$base,
] })->hri->all;
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] .')'),
has_value => $meta{$_}->{browser},
($meta{$_}->{browser} ? (icon => 'icon-folder-close text-info')
: (icon => 'icon-folder-close-alt muted')),
(scalar @{$meta{$_}->{index}}
? (icon => 'icon-th'.($meta{$_}->{browser} ? ' text-info' : ' muted')) : ()),
(($meta{$_}->{num_children} == 0 and ($meta{$_}->{type}
or $meta{$_}->{access} =~ m/^(?:read|write)/
or $meta{$_}->{oid_parts}->[-1] == 0))
? (icon => 'icon-leaf'.($meta{$_}->{browser} ? ' text-info' : ' muted')) : ()),
# jstree will async call to expand these, and while it's possible
# for us to prefetch by calling _get_snmp_data() and passing to
#Â children, it's much slower UX. async is better for search especially
children => ($meta{$_}->{num_children} ? \1 : \0),
# and set the display to open to show the single child
#Â but only if there is data below
state => { opened => (($meta{$_}->{browser} and $meta{$_}->{num_children} == 1) ? \1 : \0 ) },
}} sort {$meta{$a}->{oid_parts}->[-1] <=> $meta{$b}->{oid_parts}->[-1]} keys %meta;
return \@items;
}
true;
( run in 0.605 second using v1.01-cache-2.11-cpan-5623c5533a1 )