App-Netdisco
view release on metacpan or search on metacpan
lib/App/Netdisco/Util/Snapshot.pm view on Meta::CPAN
Cache => $info,
Session => {},
MibDirs => [ get_mibdirs() ],
AutoSpecify => 0,
IgnoreNetSNMPConf => 1,
Debug => ($ENV{INFO_TRACE} || 0),
DebugSNMP => ($ENV{SNMP_TRACE} || 0),
});
}
my %globals = %{ $info->globals };
my %funcs = %{ $info->funcs };
while (my ($alias, $leaf) = each %globals) {
next if $leaf =~ m/\.\d+$/;
$info->_cache($alias, $info->$leaf) if $info->$leaf;
}
while (my ($alias, $leaf) = each %funcs) {
$info->_cache($alias, dclone $info->$leaf) if ref q{} ne ref $info->$leaf;
}
# SNMP::Info::Layer3 has some weird structures we can try to fix here
my %propfix = (
chassisId => 'serial1',
ospfRouterId => 'router_ip',
bgpIdentifier => 'bgp_id',
bgpLocalAs => 'bgp_local_as',
ifPhysAddress => 'mac',
qw(
model model
serial serial
os_ver os_ver
os os
),
);
foreach my $prop (keys %propfix) {
my $val = $info->$prop;
$val = [values %$val]->[0] if ref $val eq 'HASH';
$info->_cache($propfix{$prop}, $val);
}
#Â netdisco will try uptime or hrSystemUptime or sysUptime (but not sysUptimeInstance)
if (defined $info->sysUpTimeInstance) {
my $uptime = (ref {} eq ref $info->sysUpTimeInstance)
? ($info->sysUpTimeInstance->{0} || $info->sysUpTimeInstance->{''})
: $info->sysUpTimeInstance;
if (!defined $info->uptime) {
$info->_cache('uptime', $uptime);
}
if (!defined $info->sysUpTime) {
$info->_cache('sysUpTime', $uptime);
}
}
# now for any other SNMP::Info method in GLOBALS or FUNCS which Netdisco
# might call, but will not have data, we fake a cache entry to avoid
# throwing errors
while (my $method = <DATA>) {
$method =~ s/\s//g;
next unless length $method and not $info->$method;
$info->_cache($method, '') if exists $globals{$method};
$info->_cache($method, {}) if exists $funcs{$method};
}
#Â debug sprintf "add_snmpinfo_aliases: cache size: %d", scalar keys %{ $info->cache };
return $info->cache;
}
=head2 fixup_browser_from_aliases( $device_instance, $snmp_info_instance )
Now we have a solid SNMP::Info cache, if there are any fixups of browser
data they can happen here.
=cut
sub fixup_browser_from_aliases {
my $device = shift or return;
my $info = shift or return;
my $e_type = $info->e_type;
if (scalar keys %$e_type) {
my $row = $device->oids->find({ oid => '.1.3.6.1.2.1.47.1.1.1.1.3' });
$row->update({ value =>
to_json([{ map {($_ => encode_base64(trim($e_type->{$_}), ''))} keys %{ $e_type } }]) });
}
}
true;
__DATA__
agg_ports
at_paddr
bgp_peer_addr
bp_index
c_cap
c_id
c_if
c_ip
c_platform
c_port
cd11_mac
cd11_port
cd11_rateset
cd11_rxbyte
cd11_rxpkt
cd11_sigqual
cd11_sigstrength
cd11_ssid
cd11_txbyte
cd11_txpkt
cd11_txrate
cd11_uptime
class
contact
docs_if_cmts_cm_status_inet_address
( run in 1.362 second using v1.01-cache-2.11-cpan-39bf76dae61 )