instantiate helper SNMP::Info instances with better defaults
This commit is contained in:
@@ -3,7 +3,7 @@ package App::Netdisco::Transport::SNMP;
|
|||||||
use Dancer qw/:syntax :script/;
|
use Dancer qw/:syntax :script/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
use App::Netdisco::Util::SNMP 'get_communities';
|
use App::Netdisco::Util::SNMP qw/get_communities get_mibdirs/;
|
||||||
use App::Netdisco::Util::Device 'get_device';
|
use App::Netdisco::Util::Device 'get_device';
|
||||||
use App::Netdisco::Util::Permission 'acl_matches';
|
use App::Netdisco::Util::Permission 'acl_matches';
|
||||||
use App::Netdisco::Util::Snapshot qw/load_cache_for_device add_snmpinfo_aliases/;
|
use App::Netdisco::Util::Snapshot qw/load_cache_for_device add_snmpinfo_aliases/;
|
||||||
@@ -11,7 +11,6 @@ use App::Netdisco::Util::Snapshot qw/load_cache_for_device add_snmpinfo_aliases/
|
|||||||
use SNMP::Info;
|
use SNMP::Info;
|
||||||
use Try::Tiny;
|
use Try::Tiny;
|
||||||
use Module::Load ();
|
use Module::Load ();
|
||||||
use Path::Class 'dir';
|
|
||||||
use NetAddr::IP::Lite ':lower';
|
use NetAddr::IP::Lite ':lower';
|
||||||
use List::Util qw/pairkeys pairfirst/;
|
use List::Util qw/pairkeys pairfirst/;
|
||||||
|
|
||||||
@@ -136,7 +135,7 @@ sub _snmp_connect_generic {
|
|||||||
BulkWalk => ((defined setting('bulkwalk_off') && setting('bulkwalk_off'))
|
BulkWalk => ((defined setting('bulkwalk_off') && setting('bulkwalk_off'))
|
||||||
? 0 : 1),
|
? 0 : 1),
|
||||||
BulkRepeaters => (setting('bulkwalk_repeaters') || 20),
|
BulkRepeaters => (setting('bulkwalk_repeaters') || 20),
|
||||||
MibDirs => [ _build_mibdirs() ],
|
MibDirs => [ get_mibdirs() ],
|
||||||
IgnoreNetSNMPConf => 1,
|
IgnoreNetSNMPConf => 1,
|
||||||
Debug => ($ENV{INFO_TRACE} || 0),
|
Debug => ($ENV{INFO_TRACE} || 0),
|
||||||
DebugSNMP => ($ENV{SNMP_TRACE} || 0),
|
DebugSNMP => ($ENV{SNMP_TRACE} || 0),
|
||||||
@@ -372,16 +371,4 @@ sub _mk_info_commargs {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _build_mibdirs {
|
|
||||||
my $home = (setting('mibhome') || dir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs'));
|
|
||||||
return map { dir($home, $_)->stringify }
|
|
||||||
@{ setting('mibdirs') || _get_mibdirs_content($home) };
|
|
||||||
}
|
|
||||||
|
|
||||||
sub _get_mibdirs_content {
|
|
||||||
my $home = shift;
|
|
||||||
my @list = map {s|$home/||; $_} grep { m|/[a-z0-9-]+$| } grep {-d} glob("$home/*");
|
|
||||||
return \@list;
|
|
||||||
}
|
|
||||||
|
|
||||||
true;
|
true;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package App::Netdisco::Util::SNMP;
|
|||||||
use Dancer qw/:syntax :script !to_json !from_json/;
|
use Dancer qw/:syntax :script !to_json !from_json/;
|
||||||
use App::Netdisco::Util::DeviceAuth 'get_external_credentials';
|
use App::Netdisco::Util::DeviceAuth 'get_external_credentials';
|
||||||
|
|
||||||
|
use Path::Class 'dir';
|
||||||
use File::Spec::Functions qw/splitdir catdir catfile/;
|
use File::Spec::Functions qw/splitdir catdir catfile/;
|
||||||
use MIME::Base64 qw/decode_base64/;
|
use MIME::Base64 qw/decode_base64/;
|
||||||
use Storable qw/thaw/;
|
use Storable qw/thaw/;
|
||||||
@@ -14,6 +15,7 @@ our @EXPORT = ();
|
|||||||
our @EXPORT_OK = qw/
|
our @EXPORT_OK = qw/
|
||||||
get_communities
|
get_communities
|
||||||
snmp_comm_reindex
|
snmp_comm_reindex
|
||||||
|
get_mibdirs
|
||||||
%ALL_MUNGERS
|
%ALL_MUNGERS
|
||||||
decode_and_munge
|
decode_and_munge
|
||||||
sortable_oid
|
sortable_oid
|
||||||
@@ -142,6 +144,24 @@ sub snmp_comm_reindex {
|
|||||||
return $snmp;
|
return $snmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head2 get_mibdirs
|
||||||
|
|
||||||
|
Return a list of directories in the `netdisco-mibs` folder.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub get_mibdirs {
|
||||||
|
my $home = (setting('mibhome') || dir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs'));
|
||||||
|
return map { dir($home, $_)->stringify }
|
||||||
|
@{ setting('mibdirs') || _get_mibdirs_content($home) };
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _get_mibdirs_content {
|
||||||
|
my $home = shift;
|
||||||
|
my @list = map {s|$home/||; $_} grep { m|/[a-z0-9-]+$| } grep {-d} glob("$home/*");
|
||||||
|
return \@list;
|
||||||
|
}
|
||||||
|
|
||||||
our %ALL_MUNGERS = (
|
our %ALL_MUNGERS = (
|
||||||
'SNMP::Info::munge_speed' => \&SNMP::Info::munge_speed,
|
'SNMP::Info::munge_speed' => \&SNMP::Info::munge_speed,
|
||||||
'SNMP::Info::munge_highspeed' => \&SNMP::Info::munge_highspeed,
|
'SNMP::Info::munge_highspeed' => \&SNMP::Info::munge_highspeed,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package App::Netdisco::Util::Snapshot;
|
|||||||
use Dancer qw/:syntax :script !to_json !from_json/;
|
use Dancer qw/:syntax :script !to_json !from_json/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
use App::Netdisco::Util::SNMP 'sortable_oid';
|
use App::Netdisco::Util::SNMP qw/get_mibdirs sortable_oid/;
|
||||||
|
|
||||||
use File::Spec::Functions qw/splitdir catdir catfile/;
|
use File::Spec::Functions qw/splitdir catdir catfile/;
|
||||||
use MIME::Base64 qw/encode_base64 decode_base64/;
|
use MIME::Base64 qw/encode_base64 decode_base64/;
|
||||||
@@ -150,8 +150,12 @@ sub snmpwalk_to_cache {
|
|||||||
my $info = SNMP::Info->new({
|
my $info = SNMP::Info->new({
|
||||||
Offline => 1,
|
Offline => 1,
|
||||||
Cache => {},
|
Cache => {},
|
||||||
AutoSpecify => 0,
|
|
||||||
Session => {},
|
Session => {},
|
||||||
|
MibDirs => [ get_mibdirs() ],
|
||||||
|
AutoSpecify => 0,
|
||||||
|
IgnoreNetSNMPConf => 1,
|
||||||
|
Debug => ($ENV{INFO_TRACE} || 0),
|
||||||
|
DebugSNMP => ($ENV{SNMP_TRACE} || 0),
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach my $attr (keys %leaves) {
|
foreach my $attr (keys %leaves) {
|
||||||
@@ -318,8 +322,12 @@ sub add_snmpinfo_aliases {
|
|||||||
$info = SNMP::Info->new({
|
$info = SNMP::Info->new({
|
||||||
Offline => 1,
|
Offline => 1,
|
||||||
Cache => $info,
|
Cache => $info,
|
||||||
AutoSpecify => 0,
|
|
||||||
Session => {},
|
Session => {},
|
||||||
|
MibDirs => [ get_mibdirs() ],
|
||||||
|
AutoSpecify => 0,
|
||||||
|
IgnoreNetSNMPConf => 1,
|
||||||
|
Debug => ($ENV{INFO_TRACE} || 0),
|
||||||
|
DebugSNMP => ($ENV{SNMP_TRACE} || 0),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user