error message to user to load mibs

This commit is contained in:
Oliver Gorwits
2022-08-08 08:45:36 +01:00
parent 9be1e6c1a3
commit a874882e6e

View File

@@ -34,9 +34,23 @@ ajax '/ajax/data/device/:ip/snmptree/:base' => require_login sub {
my $base = param('base');
$base =~ m/^\.1(\.\d+)*$/ or send_error('Bad OID Base', 404);
my $items = _get_snmp_data($device->ip, $base);
content_type 'application/json';
return to_json [{
text => 'No MIB data. Please run `~/bin/netdisco-do loadmibs`.',
children => \0,
state => { disabled => \1 },
icon => 'icon-search',
}] unless schema('netdisco')->resultset('SNMPObject')->count();
return to_json [{
text => 'No data for this device. You can request a snapshot in the Details tab.',
children => \0,
state => { disabled => \1 },
icon => 'icon-search',
}] unless schema('netdisco')->resultset('DeviceSnapshot')->find($device->ip);
my $items = _get_snmp_data($device->ip, $base);
to_json $items;
};
@@ -123,13 +137,6 @@ sub _get_snmp_data {
my ($ip, $base, $recurse) = @_;
my @parts = grep {length} split m/\./, $base;
return [{
text => 'No data for this device. You can request a snapshot in the Details tab.',
children => \0,
state => { disabled => \1 },
icon => 'icon-search',
}] unless schema('netdisco')->resultset('DeviceSnapshot')->find($ip);
my %meta = map { ('.'. join '.', @{$_->{oid_parts}}) => $_ }
schema('netdisco')->resultset('Virtual::FilteredSNMPObject')
->search({}, { bind => [