# SNMP::Info
#
# Copyright (c) 2003-2012 Max Baker and SNMP::Info Developers
# All rights reserved.
#
# Portions Copyright (c) 2002-2003, Regents of the University of California
# All rights reserved.
#
# See COPYRIGHT at bottom
package SNMP::Info;
use warnings;
use strict;
use Exporter;
use SNMP;
use Carp;
use Math::BigInt;
use NetAddr::IP::Lite ':lower';
@SNMP::Info::ISA = qw/Exporter/;
@SNMP::Info::EXPORT_OK = qw//;
our
($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE, $AUTOLOAD, $INIT, $DEBUG, %SPEED_MAP,
$NOSUCH, $BIGINT, $REPEATERS);
$VERSION = '3.81';
=head1 NAME
SNMP::Info - OO Interface to Network devices and MIBs through SNMP
=head1 VERSION
SNMP::Info - Version 3.81
=head1 AUTHOR
SNMP::Info is maintained by team of Open Source authors headed by Eric Miller,
Bill Fenner, Max Baker, Jeroen van Ingen and Oliver Gorwits.
Please visit L for the most up-to-date
list of developers.
SNMP::Info was originally created at UCSC for the Netdisco project L
by Max Baker.
=head1 DEVICES SUPPORTED
There are now generic classes for most types of device and so the authors
recommend loading SNMP::Info with AutoSpecify, and then reporting to the mail
list any missing functionality (such as neighbor discovery tables).
=head1 SYNOPSIS
use SNMP::Info;
my $info = new SNMP::Info(
# Auto Discover more specific Device Class
AutoSpecify => 1,
Debug => 1,
# The rest is passed to SNMP::Session
DestHost => 'router',
Community => 'public',
Version => 2
) or die "Can't connect to device.\n";
my $err = $info->error();
die "SNMP Community or Version probably wrong connecting to device. $err\n" if defined $err;
my $name = $info->name();
my $class = $info->class();
print "SNMP::Info is using this device class : $class\n";
# Find out the Duplex status for the ports
my $interfaces = $info->interfaces();
my $i_duplex = $info->i_duplex();
# Get CDP Neighbor info
my $c_if = $info->c_if();
my $c_ip = $info->c_ip();
my $c_port = $info->c_port();
# Print out data per port
foreach my $iid (keys %$interfaces){
my $duplex = $i_duplex->{$iid};
# Print out physical port name, not snmp iid
my $port = $interfaces->{$iid};
print "$port: ";
print "$duplex duplex" if defined $duplex;
# The CDP Table has table entries different than the interface tables.
# So we use c_if to get the map from cdp table to interface table.
my %c_map = reverse %$c_if;
my $c_key = $c_map{$iid};
unless (defined $c_key) {
print "\n\n";
next;
}
my $neighbor_ip = $c_ip->{$c_key};
my $neighbor_port = $c_port->{$c_key};
print " connected to $neighbor_ip / $neighbor_port\n" if defined $neighbor_ip;
print "\n";
}
=head1 SUPPORT
Please direct all support, help, and bug requests to the snmp-info-users
Mailing List at L.
=head1 DESCRIPTION
SNMP::Info gives an object oriented interface to information obtained through
SNMP.
This module is geared towards network devices. Subclasses exist for a number
of network devices and common MIBs.
The idea behind this module is to give a common interface to data from network
devices, leaving the device-specific hacks behind the scenes in subclasses.
In the SYNOPSIS example we fetch the name of all the ports on the device and
the duplex setting for that port with two methods -- interfaces() and
i_duplex().
The information may be coming from any number of MIB files and is very vendor
specific. SNMP::Info provides you a common method for all supported devices.
Adding support for your own device is easy, and takes little SNMP knowledge.
The module is not limited to network devices. Any MIB or device can be given
an objected oriented front-end by making a module that consists of a couple
hashes. See EXTENDING SNMP::INFO.
=head1 REQUIREMENTS
=over
=item 1. Net-SNMP
To use this module, you must have Net-SNMP installed on your system.
More specifically you need the Perl modules that come with it.
DO NOT INSTALL SNMP:: or Net::SNMP from CPAN!
The SNMP module is matched to an install of net-snmp, and must be installed
from the net-snmp source tree.
The Perl module C is found inside the net-snmp distribution. Go to the
F directory of the distribution to install it, or run
C<./configure --with-perl-modules> from the top directory of the net-snmp
distribution.
Net-SNMP can be found at http://net-snmp.sourceforge.net
Version 5.3.2 or greater is recommended.
Versions 5.0.1, 5.0301 and 5.0203 have issues with bulkwalk and are not supported.
B: Some versions that come with certain versions of
Redhat/Fedora don't have the Perl library installed. Uninstall the RPM and
install by hand.
=item 2. MIBS
SNMP::Info operates on textual descriptors found in MIBs.
If you are using SNMP::Info separate from Netdisco,
download the Netdisco MIB package at L
Make sure that your snmp.conf is updated to point to your MIB directory
and that the MIBs are world-readable.
=back
=head1 DESIGN GOALS
=over
=item 1. Use of textual MIB leaf identifier and enumerated values
=over
=item * All values are retrieved via MIB Leaf node names
For example SNMP::Info has an entry in its %GLOBALS hash for ``sysName''
instead of 1.3.6.1.2.1.1.5.
=item * Data returned is in the enumerated value form.
For Example instead of looking up 1.3.6.1.2.1.2.2.1.3 and getting back C<23>
SNMP::Info will ask for C and will get back C.
=back
=item 2. SNMP::Info is easily extended to new devices
You can create a new subclass for a device by providing four hashes :
%GLOBALS, %MIBS, %FUNCS, and %MUNGE.
Or you can override any existing methods from a parent class by making a short
subroutine.
See the section EXTENDING SNMP::INFO for more details.
When you make a new subclass for a device, please be sure to send it back
to the developers (via a github pull request or the mailing list) for inclusion
in the next version.
=back
=head1 SUBCLASSES
These are the subclasses that implement MIBs and support devices:
Required MIBs not included in the install instructions above are noted here.
=head2 MIB Subclasses
These subclasses implement method to access one or more MIBs. These are not
used directly, but rather inherited from device subclasses.
For more info run C on any of the following module names.
=over
=item SNMP::Info::AdslLine
SNMP Interface to the ADSL-LINE-MIB for ADSL interfaces.
Requires the F, down loadable from Cisco.
See documentation in L for details.
=item SNMP::Info::Aggregate
SNMP Interface to F C Aggregated Links
See documentation in L for details.
=item SNMP::Info::Airespace
F and F. Inherited by
devices based on the Airespace wireless platform.
See documentation in L for details.
=item SNMP::Info::AMAP
F. Alcatel Mapping Adjacency
Protocol (AMAP) Support.
See documentation in L for details.
=item SNMP::Info::Bridge
F (RFC1286). F. Inherited by devices with Layer2
support.
See documentation in L for details.
=item SNMP::Info::CDP
F. Cisco Discovery Protocol (CDP) Support. Inherited by
Cisco, Enterasys, and HP devices.
See documentation in L for details.
=item SNMP::Info::CiscoAgg
SNMP Interface to Cisco Aggregated Links
See documentation in L for details.
=item SNMP::Info::CiscoConfig
F, F, and F.
These OIDs facilitate the writing of configuration files.
See documentation in L for details.
=item SNMP::Info::CiscoPortSecurity
F and F.
See documentation in L for details.
=item SNMP::Info::CiscoPower
F.
See documentation in L for details.
=item SNMP::Info::CiscoQOS
F. A collection of OIDs providing information about
a Cisco device's QOS config.
See documentation in L for details.
=item SNMP::Info::CiscoRTT
F. A collection of OIDs providing information about a Cisco
device's RTT values.
See documentation in L for details.
=item SNMP::Info::CiscoStack
F.
See documentation in L for details.
=item SNMP::Info::CiscoStats
F, F, and F.
Provides common interfaces for memory, cpu, and os statistics for Cisco
devices.
See documentation in L for details.
=item SNMP::Info::CiscoStpExtensions
F
See documentation in L for details.
=item SNMP::Info::CiscoVTP
F, F,
F
See documentation in L for details.
=item SNMP::Info::DocsisCM
SNMP Interface for DOCSIS Cable Modems
See documentation in L for details.
=item SNMP::Info::DocsisHE
SNMP Interface for DOCSIS CMTS
See documentation in L for details.
=item SNMP::Info::EDP
Extreme Discovery Protocol. F
See documentation in L for details.
=item SNMP::Info::Entity
F. Used for device info in Cisco and other vendors.
See documentation in L for details.
=item SNMP::Info::EtherLike
F (RFC1398) - Some Layer3 devices implement this MIB, as well
as some Aironet Layer 2 devices (non Cisco).
See documentation in L for details.
=item SNMP::Info::FDP
Foundry (Brocade) Discovery Protocol. F
See documentation in L for details.
=item SNMP::Info::IEEE802_Bridge
SNMP Interface to data available through the F
See documentation in L for details.
=item SNMP::Info::IEEE802dot11
F. A collection of OIDs providing information about
standards based 802.11 wireless devices.
See documentation in L for details.
=item SNMP::Info::IEEE802dot3ad
SNMP Interface to IEEE Aggregated Links. F
See documentation in L for details.
=item SNMP::Info::IPv6
SNMP Interface for obtaining configured IPv6 addresses and mapping IPv6
addresses to MAC addresses and interfaces, using information from F,
F and/or F.
See documentation in L for details.
=item SNMP::Info::LLDP
F, F, and F. Link Layer
Discovery Protocol (LLDP) Support.
See documentation in L for details.
=item SNMP::Info::MAU
F (RFC2668). Some Layer2 devices use this for extended Ethernet
(Medium Attachment Unit) interface information.
See documentation in L for details.
=item SNMP::Info::MRO
Method resolution introspection for SNMP::Info
See documentation in L for details.
=item SNMP::Info::NortelStack
F, F.
See documentation in L for details.
=item SNMP::Info::PowerEthernet
F
See documentation in L for details.
=item SNMP::Info::RapidCity
F. Inherited by Avaya switches for duplex and VLAN information.
See documentation in L for details.
=item SNMP::Info::SONMP
SynOptics Network Management Protocol (SONMP) F,
F. Inherited by
Avaya/Nortel/Bay/Synoptics switches and hubs.
See documentation in L for details.
=back
=head2 Device Subclasses
These subclasses inherit from one or more classes to provide a common
interface to data obtainable from network devices.
All the required MIB files are included in the netdisco-mib package.
(See Above).
=over 4
=item SNMP::Info::Layer1
Generic Layer1 Device subclass.
See documentation in L for details.
=over 4
=item SNMP::Info::Layer1::Allied
Subclass for Allied Telesis Repeaters / Hubs.
Requires F
See documentation in L for details.
=item SNMP::Info::Layer1::Asante
Subclass for Asante 1012 Hubs.
Requires F
See documentation in L for details.
=item SNMP::Info::Layer1::Bayhub
Subclass for Nortel/Bay hubs. This includes System 5000, 100 series,
200 series, and probably more.
See documentation in L for details.
=item SNMP::Info::Layer1::Cyclades
Subclass for Cyclades/Avocent terminal servers.
See documentation in L for details.
=item SNMP::Info::Layer1::S3000
Subclass for Bay/Synoptics hubs. This includes System 3000, 281X, and
probably more.
See documentation in L for details.
=back
=item SNMP::Info::Layer2
Generic Layer2 Device subclass.
See documentation in L for details.
=over
=item SNMP::Info::Layer2::3Com
Subclass for L2 3Com Switches.
See documentation in L for details.
=item SNMP::Info::Layer2::Adtran
Subclass for Adtran devices.
See documentation in L for details.
=item SNMP::Info::Layer2::Aerohive
Subclass for Aerohive / Extreme access points.
See documentation in L for details.
=item SNMP::Info::Layer2::Airespace
Subclass for Cisco (Airespace) wireless controllers.
See documentation in L for details.
=item SNMP::Info::Layer2::Aironet
Class for Cisco Aironet wireless devices that run IOS. See also
L for Aironet devices that don't run IOS.
See documentation in L for details.
=item SNMP::Info::Layer2::Allied
Allied Telesis switches.
See documentation in L for details.
=item SNMP::Info::Layer2::Atmedia
Subclass for atmedia encryptors.
See documentation in L for details.
=item SNMP::Info::Layer2::Baystack
Subclass for Avaya/Nortel/Bay Ethernet Switch/Baystack switches. This
includes 303, 304, 350, 380, 410, 420, 425, 450, 460, 470 series,
2500 series, 4000 series, 5000 series, Business Ethernet Switch (BES),
Business Policy Switch (BPS), VSP 7000 series, and probably others.
See documentation in L for details.
=item SNMP::Info::Layer2::C1900
Subclass for Cisco Catalyst 1900 and 1900c Devices running CatOS.
See documentation in L for details.
=item SNMP::Info::Layer2::C2900
Subclass for Cisco Catalyst 2900, 2950, 3500XL, and 3548 devices running IOS.
See documentation in L for details.
=item SNMP::Info::Layer2::Catalyst
Subclass for Cisco Catalyst switches running CatOS. These switches usually
report a model number that starts with C. Note that this class
does not support everything that has the name Catalyst.
See documentation in L for details.
=item SNMP::Info::Layer2::Centillion
Subclass for Nortel/Bay Centillion and 5000BH ATM switches.
See documentation in L for details.
=item SNMP::Info::Layer2::Cisco
Generic Cisco subclass for layer 2 devices that are not yet supported
in more specific subclasses and the base layer 2 Cisco class for
other device specific layer 2 Cisco classes.
See documentation in L for details.
=item SNMP::Info::Layer2::CiscoSB
Subclass for Cisco's "Small Business" product line, acquired from
Linksys. This currently comprises the Sx300/500 line of switches.
See documentation in L for details.
=item SNMP::Info::Layer2::Exinda
Subclass for Exinda / GFI Network Orchestrator traffic shapers.
See documentation in L for details.
=item SNMP::Info::Layer2::HP
Subclass for more recent HP Procurve Switches.
Requires F and F downloaded from HP.
See documentation in L for details.
=item SNMP::Info::Layer2::HP4000
Subclass for older HP Procurve Switches
Requires F and F downloaded from HP.
See documentation in L for details.
=item SNMP::Info::Layer2::HPVC
Subclass for HP Virtual Connect Switches
See documentation in L for details.
=item SNMP::Info::Layer2::Kentrox
Class for Kentrox DataSMART DSU/CSU.
See documentation in L for details.
=item SNMP::Info::Layer2::N2270
Subclass for Nortel 2270 wireless switches.
See documentation in L for details.
=item SNMP::Info::Layer2::NAP222x
Subclass for Nortel 222x series wireless access points.
See documentation in L for details.
=item SNMP::Info::Layer2::Netgear
Subclass for Netgear switches
See documentation in L for details.
=item SNMP::Info::Layer2::Nexans
Subclass for Nexans switches
See documentation in L for details.
=item SNMP::Info::Layer2::NWSS2300
SNMP Interface to Avaya (Trapeze) Wireless Controllers
See documentation in L for details.
=item SNMP::Info::Layer2::Orinoco
Subclass for Orinoco/Proxim wireless access points.
See documentation in L for details.
=item SNMP::Info::Layer2::Trapeze
SNMP Interface to Juniper (Trapeze) Wireless Controllers
See documentation in L for details.
=item SNMP::Info::Layer2::Sixnet
SNMP Interface to Sixnet industrial switches
See documentation in L for details.
=item SNMP::Info::Layer2::Ubiquiti
SNMP Interface to Ubiquiti Access Points and other devices
See documentation in L for details.
=item SNMP::Info::Layer2::ZyXEL_DSLAM
Zyxel DSLAMs. Need I say more?
See documentation in L for details.
=back
=item SNMP::Info::Layer3
Generic Layer3 and Layer2+3 Device subclass.
See documentation in L for details.
=over
=item SNMP::Info::Layer3::Aironet
Subclass for Cisco Aironet wireless access points (AP) not running IOS. These
are usually older devices.
Note L
See documentation in L for details.
=item SNMP::Info::Layer3::AlcatelLucent
Alcatel-Lucent OmniSwitch Class.
See documentation in L for details.
=item SNMP::Info::Layer3::AlteonAD
Subclass for Radware Alteon Series ADC switches and Nortel BladeCenter
Layer2-3 GbE Switch Modules.
See documentation in L for details.
=item SNMP::Info::Layer3::Altiga
See documentation in L for details.
=item SNMP::Info::Layer3::Arista
See documentation in L for details.
=item SNMP::Info::Layer3::Aruba
Subclass for Aruba wireless switches.
See documentation in L for details.
=item SNMP::Info::Layer3::ArubaCX
SNMP Interface to L3 Devices running ArubaOS-CX
See documentation in L for details.
=item SNMP::Info::Layer3::BayRS
Subclass for Avaya/Nortel/Bay Multiprotocol/BayRS routers. This includes
BCN, BLN, ASN, ARN, AN, 2430, and 5430 routers.
See documentation in L for details.
=item SNMP::Info::Layer3::BlueCoatSG
Subclass for BlueCoat SG series proxy devices.
See documentation in L for details.
=item SNMP::Info::Layer3::C3550
Subclass for Cisco Catalyst 3550,3540,3560 2/3 switches running IOS.
See documentation in L for details.
=item SNMP::Info::Layer3::C4000
This class covers Catalyst 4000s and 4500s.
See documentation in L for details.
=item SNMP::Info::Layer3::C6500
This class covers Catalyst 6500 series running CatOS or IOS, as well as
Catalyst 2960, 2970, 3750 and 3850 series, including blade switches
CBS30x0 and CBS31x0 series, all running IOS.
See documentation in L for details.
=item SNMP::Info::Layer3::CheckPoint
Subclass for CheckPoint devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Ciena
Subclass for Ciena devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Cisco
This is a simple wrapper around layer 3 for IOS devices and the base layer 3
Cisco class for other device specific layer 3 Cisco classes.
See documentation in L for details.
=item SNMP::Info::Layer3::CiscoASA
Subclass for Cisco Adaptive Security Appliances.
See documentation in L for details.
=item SNMP::Info::Layer3::CiscoFWSM
Subclass for Cisco Firewall Services Modules.
See documentation in L for details.
=item SNMP::Info::Layer3::CiscoSwitch
Base class for L3 Cisco switches. See documentation in
L for details.
=item SNMP::Info::Layer3::Contivity
Subclass for Avaya/Nortel Contivity/VPN Routers.
See documentation in L for details.
=item SNMP::Info::Layer3::Cumulus
Subclass for Cumulus Networks Routers.
See documentation in L for details.
=item SNMP::Info::Layer3::Dell
Subclass for Dell PowerConnect switches. The IBM BladeCenter
Gigabit Ethernet Switch Module and some Linksys switches
also use this module based upon MIB support.
See documentation in L for details.
=item SNMP::Info::Layer3::DLink
Subclass for DLink devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Enterasys
Subclass for Enterasys devices.
See documentation in L for details.
=item SNMP::Info::Layer3::ERX
Subclass for Juniper ERX switches.
See documentation in L for details.
=item SNMP::Info::Layer3::Extreme
Subclass for Extreme Networks switches.
See documentation in L for details.
=item SNMP::Info::Layer3::F5
Subclass for F5 devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Force10
Subclass for Force10 devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Fortinet
Subclass for Fortinet devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Foundry
Subclass for Brocade (Foundry) Network devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Genua
Subclass for Genua security devices.
See documentation in L for details.
=item SNMP::Info::Layer3::H3C
SNMP Interface to Layer 3 Devices, H3C & HP A-series.
See documentation in L for details.
=item SNMP::Info::Layer3::HP9300
Subclass for HP network devices which Foundry Networks was the
Original Equipment Manufacturer (OEM) such as the HP ProCurve 9300 and 6300 series.
See documentation in L for details.
=item SNMP::Info::Layer3::Huawei
SNMP Interface to Huawei Layer 3 switches and routers.
See documentation in L for details.
=item SNMP::Info::Layer3::IBMGbTor
SNMP Interface to IBM Rackswitch (formerly Blade Network Technologies)
network devices. Lenovo acquired these from IBM and is now selling
them under the Lenovo brand.
See documentation in L for details.
=item SNMP::Info::Layer3::Juniper
Subclass for Juniper devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Lantronix
Subclass for Lantronix devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Lenovo
Subclass for Lenovo switches running CNOS.
See documentation in L for details.
=item SNMP::Info::Layer3::Microsoft
Subclass for Generic Microsoft Routers running Microsoft Windows OS.
See documentation in L for details.
=item SNMP::Info::Layer3::Mikrotik
Subclass for Mikrotik devices running RouterOS.
See documentation in L for details.
=item SNMP::Info::Layer3::N1600
Subclass for Avaya/Nortel Ethernet Routing Switch 1600 series.
See documentation in L for details.
=item SNMP::Info::Layer3::NetSNMP
Subclass for host systems running Net-SNMP.
See documentation in L for details.
=item SNMP::Info::Layer3::Netscreen
Subclass for Juniper NetScreen.
See documentation in L for details.
=item SNMP::Info::Layer3::Nexus
Subclass for Cisco Nexus devices running NX-OS.
See documentation in L for details.
=item SNMP::Info::Layer3::OneAccess
Subclass for OneAccess routers.
See documentation in L for details.
=item SNMP::Info::Layer3::PacketFront
Subclass for PacketFront DRG series CPE.
See documentation in L for details.
=item SNMP::Info::Layer3::PaloAlto
Subclass for Palo Alto firewalls.
See documentation in L for details.
=item SNMP::Info::Layer3::Passport
Subclass for Avaya/Nortel Ethernet Routing Switch/Passport 8000 series,
Accelar, and VSP 9000 series switches.
See documentation in L for details.
=item SNMP::Info::Layer3::Pf
Subclass for FreeBSD-Based Firewalls using Pf /Pf Sense
See documentation in L for details.
=item SNMP::Info::Layer3::Pica8
Subclass for Pica8 devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Redlion
Subclass for redlion routers.
See documentation in L for details.
=item SNMP::Info::Layer3::Scalance
Subclass for Siemens Scalance devices.
See documentation in L for details.
=item SNMP::Info::Layer3::SonicWALL
Subclass for generic SonicWALL devices.
See documentation in L for details.
=item SNMP::Info::Layer3::Steelfusion
Subclass for Riverbed Steelfusion WAN optimization appliances.
See documentation in L for details.
=item SNMP::Info::Layer3::Steelhead
Subclass for Riverbed Steelhead WAN optimization appliances.
See documentation in L for details.
=item SNMP::Info::Layer3::SteelheadEx
Subclass for Riverbed SteelheadEx WAN optimization appliances.
See documentation in L for details.
=item SNMP::Info::Layer3::Sun
Subclass for Generic Sun Routers running SunOS.
See documentation in L for details.
=item SNMP::Info::Layer3::Tasman
Subclass for Avaya Secure Routers.
See documentation in L for details.
=item SNMP::Info::Layer3::Teltonika
Subclass for Teltonika RUT9xx series routers.
See documentation in L for details.
=item SNMP::Info::Layer3::Timetra
Alcatel-Lucent SR Class.
See documentation in L for details.
=item SNMP::Info::Layer3::VyOS
Subclass for VyOS routers.
See documentation in L for details.
=item SNMP::Info::Layer3::VMware
Subclass for VMware ESXi hosts.
See documentation in L for details.
=item SNMP::Info::Layer3::Whiterabbit
Subclass for whiterabbit devices.
See documentation in L for details.
=back
=back
=over 4
=item SNMP::Info::Layer7
Generic Layer7 Devices.
See documentation in L for details.
=over 4
=item SNMP::Info::Layer7::APC
Subclass for APC UPS devices.
See documentation in L for details.
=item SNMP::Info::Layer7::Arbor
Subclass for Arbor appliances.
See documentation in L for details.
=item SNMP::Info::Layer7::CiscoIPS
Subclass for Cisco IPS devices.
See documentation in L for details.
=item SNMP::Info::Layer7::Gigamon
Subclass for Gigamon devices.
See documentation in L for details.
=item SNMP::Info::Layer7::Liebert
Subclass for Liebert devices.
See documentation in L for details.
=item SNMP::Info::Layer7::Neoteris
Subclass for Pulse Secure / Juniper SSL VPN appliances.
See documentation in L for details.
=item SNMP::Info::Layer7::Netscaler
Subclass for Citrix Netscaler appliances.
See documentation in L for details.
=back
=back
=head1 Thanks
Thanks for testing and coding help (in no particular order) to :
Alexander Barthel, Andy Ford, Alexander Hartmaier, Andrew Herrick, Alex
Kramarov, Bernhard Augenstein, Bradley Baetz, Brian Chow, Brian Wilson,
Carlos Vicente, Dana Watanabe, David Pinkoski, David Sieborger, Douglas
McKeown, Greg King, Ivan Auger, Jean-Philippe Luiggi, Jeroen van Ingen,
Justin Hunter, Kent Hamilton, Matthew Tuttle, Michael Robbert, Mike Hunter,
Nicolai Petri, Ralf Gross, Robert Kerr, Nick Nauwelaerts and people listed
on the Netdisco README!
=head1 USAGE
=head2 Constructor
=over
=item new()
Creates a new object and connects via SNMP::Session.
my $info = new SNMP::Info( 'Debug' => 1,
'AutoSpecify' => 1,
'BigInt' => 1,
'BulkWalk' => 1,
'BulkRepeaters' => 20,
'IgnoreNetSNMPConf' => 1,
'LoopDetect' => 1,
'DestHost' => 'myrouter',
'Community' => 'public',
'Version' => 2,
'MibDirs' => ['dir1','dir2','dir3'],
) or die;
SNMP::Info Specific Arguments :
=over
=item AutoSpecify
Returns an object of a more specific device class
(default 0, which means "off")
=item BigInt
Return Math::BigInt objects for 64 bit counters. Sets on a global scope,
not object.
(default 0, which means "off")
=item BulkWalk
Set to C<0> to turn off BULKWALK commands for SNMPv2 connections.
Note that BULKWALK is turned off for Net-SNMP versions 5.1.x because of a bug.
(default 1, which means "on")
=item BulkRepeaters
Set number of MaxRepeaters for BULKWALK operation. See
C -> bulkwalk() for more info.
(default 20)
=item LoopDetect
Detects looping during getnext table column walks by comparing IIDs for each
instance. A loop is detected if the same IID is seen more than once and the
walk is aborted. Note: This will not detect loops during a bulkwalk
operation, Net-SNMP's internal bulkwalk function must detect the loop.
Set to C<0> to turn off loop detection.
(default 1, which means "on")
=item IgnoreNetSNMPConf
Net-SNMP version 5.0 and higher read configuration files, snmp.conf or
snmp.local.conf, from /etc/snmp, /usr/share/snmp, /usr/lib(64)/snmp, or
$HOME/.snmp and uses those settings to automatically parse MIB files, etc.
Set to C<1> "on" to ignore Net-SNMP configuration files by overriding the
C environmental variable during object initialization. Note:
MibDirs must be defined or Net-SNMP will not be able to load MIBs and
initialize the object.
(default 0, which means "off")
=item Debug
Prints Lots of debugging messages.
Pass 2 to print even more debugging messages.
(default 0, which means "off")
=item DebugSNMP
Set $SNMP::debugging level for Net-SNMP.
See F for more details.
=item MibDirs
Array ref to list of directories in which to look for MIBs. Note this will
be in addition to the ones setup in snmp.conf at the system level.
(default use net-snmp settings only)
=item RetryNoSuch
When using SNMP Version 1, try reading values even if they come back as "no
such variable in this MIB". Set to false if so desired. This feature lets
you read SNMPv2 data from an SNMP version 1 connection, and should probably
be left on.
(default 1, which means "on")
=item Session
SNMP::Session object to use instead of connecting on own.
(default creates session automatically)
=item Offline
Causes SNMP::Info to avoid network activity and return data only from its
cache. If you ask for something not in the cache, an error is thrown. See
also the C and C methods.
(default 0, which means "online")
=item Cache
Pass in a HashRef to prime the cache of retrieved data. Useful for creating an
instance in C mode from a previously dumped cache. See also the
C method to retrieve a cache after running actial queries.
=item OTHER
All other arguments are passed to SNMP::Session.
See SNMP::Session for a list of other possible arguments.
=back
A Note about the wrong Community string or wrong SNMP Version:
If a connection is using the wrong community string or the wrong SNMP version,
the creation of the object will not fail. The device still answers the call
on the SNMP port, but will not return information. Check the error() method
after you create the device object to see if there was a problem in
connecting.
A note about SNMP Versions :
Some older devices don't support SNMP version 2, and will not return anything
when a connection under Version 2 is attempted.
Some newer devices will support Version 1, but will not return all the data
they might have if you had connected under Version 1.
When trying to get info from a new device, you may have to try version 2 and
then fallback to version 1.
=cut
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = @_;
my %sess_args = %args;
my $new_obj = {};
bless $new_obj, $class;
$new_obj->{class} = $class;
# load references to all the subclass data structures
{
no strict 'refs'; ## no critic (ProhibitNoStrict ProhibitProlongedStrictureOverride)
$new_obj->{init} = \${ $class . '::INIT' };
$new_obj->{mibs} = \%{ $class . '::MIBS' };
$new_obj->{globals} = \%{ $class . '::GLOBALS' };
$new_obj->{funcs} = \%{ $class . '::FUNCS' };
$new_obj->{munge} = \%{ $class . '::MUNGE' };
}
# SNMP::Info specific args :
if ( defined $args{Debug} ) {
$new_obj->debug( $args{Debug} );
delete $sess_args{Debug};
}
else {
$new_obj->debug( defined $DEBUG ? $DEBUG : 0 );
}
if ( defined $args{DebugSNMP} ) {
$SNMP::debugging = $args{DebugSNMP};
delete $sess_args{DebugSNMP};
}
my $auto_specific = 0;
if ( defined $args{AutoSpecify} ) {
$auto_specific = $args{AutoSpecify} || 0;
delete $sess_args{AutoSpecify};
}
if ( defined $args{BulkRepeaters} ) {
$new_obj->{BulkRepeaters} = $args{BulkRepeaters};
delete $sess_args{BulkRepeaters};
}
if ( defined $args{BulkWalk} ) {
$new_obj->{BulkWalk} = $args{BulkWalk};
delete $sess_args{BulkWalk};
}
if ( defined $args{LoopDetect} ) {
$new_obj->{LoopDetect} = $args{LoopDetect};
delete $sess_args{LoopDetect};
}
if ( defined $args{IgnoreNetSNMPConf} ) {
$new_obj->{IgnoreNetSNMPConf} = $args{IgnoreNetSNMPConf} || 0;
delete $sess_args{IgnoreNetSNMPConf};
}
if ( defined $args{Offline} ) {
$new_obj->{Offline} = $args{Offline} || 0;
delete $sess_args{Offline};
}
if ( defined $args{Cache} and ref {} eq ref $args{Cache} ) {
$new_obj->{$_} = $args{Cache}->{$_} for keys %{$args{Cache}};
delete $sess_args{Cache};
}
my $sess = undef;
if ( defined $args{Session} ) {
$sess = $args{Session};
delete $sess_args{Session};
}
if ( defined $args{BigInt} ) {
$BIGINT = $args{BigInt};
delete $sess_args{BigInt};
}
if ( defined $args{MibDirs} ) {
$new_obj->{mibdirs} = $args{MibDirs};
delete $sess_args{MibDirs};
}
# For IPv6 hosts set transport
if ( defined $sess_args{DestHost} ) {
$sess_args{DestHost} = resolve_desthost($sess_args{DestHost});
}
$new_obj->{nosuch} = $args{RetryNoSuch} || $NOSUCH;
# Initialize mibs if not done
my $init_ref = $new_obj->{init};
unless ( defined $$init_ref and $$init_ref ) {
$new_obj->init();
$$init_ref = 1;
}
# Connects to device unless open session is provided.
$sess = SNMP::Session->new(
'UseEnums' => 1,
%sess_args, 'RetryNoSuch' => $new_obj->{nosuch}
) unless defined $sess;
# No session object created
unless ( defined $sess ) {
$new_obj->error_throw("SNMP::Info::new() Failed to Create Session. ");
return;
}
# Session object created but SNMP connection failed.
my $sess_err = $sess->{ErrorStr} || '';
if ($sess_err) {
$new_obj->error_throw(
"SNMP::Info::new() Net-SNMP session creation failed. $sess_err");
return;
}
# Save Args for later
$new_obj->{store} ||= {};
$new_obj->{sess} = $sess;
$new_obj->{args} = \%args;
$new_obj->{snmp_ver} = $sess->{Version} || $args{Version} || 2;
$new_obj->{snmp_comm} = $sess->{Community} || $args{Community} || 'public';
$new_obj->{snmp_user} = $sess->{SecName} || $args{SecName} || 'initial';
my $info = $auto_specific ? $new_obj->specify() : $new_obj;
if (defined $info and ($info->debug() > 1)) {
require mro;
print STDERR (ref $info) ." has resolution order: \n";
print STDERR " $_\n" foreach @{ mro::get_linear_isa( ref $info ) };
}
return $info;
}
=item update()
Replace the existing session with a new one with updated values,
without re-identifying the device. The only supported changes are
to Community or Context.
Clears the object cache.
This is useful, e.g., when a device supports multiple contexts
(via changes to the Community string, or via the SNMPv3 Context
parameter), but a context that you want to access does not support
the objects (e.g., C, C) that we use to identify
the device.
=cut
sub update {
my $obj = shift;
my %update_args = @_;
my %sess_args = ( %{ $obj->{args} }, %update_args );
# silently only update "the right" args
delete $sess_args{Debug};
delete $sess_args{DebugSNMP};
delete $sess_args{AutoSpecify};
delete $sess_args{BulkRepeaters};
delete $sess_args{BulkWalk};
delete $sess_args{LoopDetect};
delete $sess_args{IgnoreNetSNMPConf};
delete $sess_args{BigInt};
delete $sess_args{MibDirs};
my $sess = SNMP::Session->new(
'UseEnums' => 1,
%sess_args, 'RetryNoSuch' => $obj->{nosuch}
);
unless ( defined $sess ) {
$obj->error_throw(
"SNMP::Info::update() Failed to Create new Session. ");
return;
}
# Session object created but SNMP connection failed.
my $sess_err = $sess->{ErrorStr} || '';
if ($sess_err) {
$obj->error_throw(
"SNMP::Info::update() Net-SNMP session creation failed. $sess_err"
);
return;
}
$obj->clear_cache();
return $obj->session($sess);
}
=back
=head2 Data is Cached
Methods and subroutines requesting data from a device will only load the data
once, and then return cached versions of that data.
Run $info->load_METHOD() where method is something like 'i_name' to reload
data from a method.
Run $info->clear_cache() to clear the cache to allow reload of both globals
and table methods.
The cache can be retrieved or set using the $info->cache() method. This works
together with the C option.
=head2 Object Scalar Methods
These are for package related data, not directly supplied
from SNMP.
=over
=item $info->clear_cache()
Clears the cached data. This includes GLOBALS data and TABLE METHOD data.
=cut
sub clear_cache {
my $self = shift;
print "SNMP::Info::clear_cache() - Cache Cleared.\n" if $self->debug();
# Clear cached global values and table method flag for being cached
foreach my $key ( keys %$self ) {
next unless defined $key;
next unless $key =~ /^_/;
delete $self->{$key};
}
# Clear store for tables
return $self->store( {} );
}
=item $info->debug(1)
Returns current debug status, and optionally toggles debugging info for this
object.
=cut
sub debug {
my $self = shift;
my $debug = shift;
if ( defined $debug ) {
$self->{debug} = $debug;
}
return $self->{debug};
}
=item $info->offline([1|0])
Returns if offline mode is currently turned on for this object.
Optionally sets the Offline parameter.
=cut
sub offline {
my $self = shift;
my $ol = shift;
if ( defined $ol ) {
$self->{Offline} = $ol;
}
return $self->{Offline};
}
=item $info->cache([new_cache])
Returns a HashRef of all cached data in this object. There will be a C
key for table data and then one key for each leaf.
Optionally sets the cache parameters if passed a HashRef.
=cut
sub cache {
my $self = shift;
my $data = shift;
if ( defined $data and ref {} eq ref $data ) {
$self->{$_} = $data->{$_} for keys %$data;
}
my $cache = { store => $self->{store} };
foreach my $key ( keys %$self ) {
next unless defined $key;
next unless $key =~ /^_/;
$cache->{$key} = $self->{$key};
}
return $cache;
}
=item $info->bulkwalk([1|0])
Returns if bulkwalk is currently turned on for this object.
Optionally sets the bulkwalk parameter.
=cut
sub bulkwalk {
my $self = shift;
my $bw = shift;
if ( defined $bw ) {
$self->{BulkWalk} = $bw;
}
return $self->{BulkWalk};
}
=item $info->loopdetect([1|0])
Returns if loopdetect is currently turned on for this object.
Optionally sets the loopdetect parameter.
=cut
sub loopdetect {
my $self = shift;
my $ld = shift;
if ( defined $ld ) {
$self->{LoopDetect} = $ld;
}
return $self->{LoopDetect};
}
=item $info->device_type()
Returns the Subclass name for this device. C is returned if no
more specific class is available.
First the device is checked for Layer 3 support and a specific subclass,
then Layer 2 support and subclasses are checked.
This means that Layer 2 / 3 switches and routers will fall under the
SNMP::Info::Layer3 subclasses.
If the device still can be connected to via SNMP::Info, then
SNMP::Info is returned.
=cut
sub device_type {
my $info = shift;
my $objtype = "SNMP::Info";
my $layers = $info->layers() || '00000000';
my $desc = $info->description() || 'undef';
$desc =~ s/[\r\n\l]+/ /g;
# Some devices don't implement sysServices, but do return a description.
# In that case, log a warning and continue.
if ( $layers eq '00000000' ) {
if ($desc ne 'undef') {
carp("Device doesn't implement sysServices but did return sysDescr. Might give unexpected results.\n") if $info->debug();
} else {
# No sysServices, no sysDescr
return;
}
}
my $id = $info->id() || 'undef';
my $soid = $id;
# Hash for generic fallback to a device class if unable to determine using
# the sysDescr regex.
my %l3sysoidmap = (
9 => 'SNMP::Info::Layer3::CiscoSwitch',
11 => 'SNMP::Info::Layer2::HP',
18 => 'SNMP::Info::Layer3::BayRS',
42 => 'SNMP::Info::Layer3::Sun',
43 => 'SNMP::Info::Layer2::3Com',
45 => 'SNMP::Info::Layer2::Baystack',
96 => 'SNMP::Info::Layer3::Whiterabbit',
171 => 'SNMP::Info::Layer3::DLink',
244 => 'SNMP::Info::Layer3::Lantronix',
311 => 'SNMP::Info::Layer3::Microsoft',
664 => 'SNMP::Info::Layer2::Adtran',
674 => 'SNMP::Info::Layer3::Dell',
1588 => 'SNMP::Info::Layer3::Foundry',
1872 => 'SNMP::Info::Layer3::AlteonAD',
1890 => 'SNMP::Info::Layer3::Redlion',
1916 => 'SNMP::Info::Layer3::Extreme',
1991 => 'SNMP::Info::Layer3::Foundry',
2011 => 'SNMP::Info::Layer3::Huawei',
2021 => 'SNMP::Info::Layer3::NetSNMP',
2272 => 'SNMP::Info::Layer3::Passport',
2620 => 'SNMP::Info::Layer3::CheckPoint',
2636 => 'SNMP::Info::Layer3::Juniper',
2925 => 'SNMP::Info::Layer1::Cyclades',
3076 => 'SNMP::Info::Layer3::Altiga',
3224 => 'SNMP::Info::Layer3::Netscreen',
3375 => 'SNMP::Info::Layer3::F5',
3417 => 'SNMP::Info::Layer3::BlueCoatSG',
3717 => 'SNMP::Info::Layer3::Genua',
4413 => 'SNMP::Info::Layer2::Ubiquiti',
4526 => 'SNMP::Info::Layer2::Netgear',
4874 => 'SNMP::Info::Layer3::ERX',
5624 => 'SNMP::Info::Layer3::Enterasys',
6027 => 'SNMP::Info::Layer3::Force10',
6141 => 'SNMP::Info::Layer3::Ciena',
6486 => 'SNMP::Info::Layer3::AlcatelLucent',
6527 => 'SNMP::Info::Layer3::Timetra',
6876 => 'SNMP::Info::Layer3::VMware',
8072 => 'SNMP::Info::Layer3::NetSNMP',
9303 => 'SNMP::Info::Layer3::PacketFront',
10002 => 'SNMP::Info::Layer2::Ubiquiti',
10418 => 'SNMP::Info::Layer1::Cyclades',
12325 => 'SNMP::Info::Layer3::Pf',
12356 => 'SNMP::Info::Layer3::Fortinet',
13191 => 'SNMP::Info::Layer3::OneAccess',
14179 => 'SNMP::Info::Layer2::Airespace',
14525 => 'SNMP::Info::Layer2::Trapeze',
14823 => 'SNMP::Info::Layer3::Aruba',
14988 => 'SNMP::Info::Layer3::Mikrotik',
17163 => 'SNMP::Info::Layer3::Steelhead',
19046 => 'SNMP::Info::Layer3::Lenovo',
21091 => 'SNMP::Info::Layer2::Exinda',
25461 => 'SNMP::Info::Layer3::PaloAlto',
25506 => 'SNMP::Info::Layer3::H3C',
26543 => 'SNMP::Info::Layer3::IBMGbTor',
26928 => 'SNMP::Info::Layer2::Aerohive',
30065 => 'SNMP::Info::Layer3::Arista',
30803 => 'SNMP::Info::Layer3::VyOS',
35098 => 'SNMP::Info::Layer3::Pica8',
40310 => 'SNMP::Info::Layer3::Cumulus',
41112 => 'SNMP::Info::Layer2::Ubiquiti',
44641 => 'SNMP::Info::Layer3::VyOS',
47196 => 'SNMP::Info::Layer3::ArubaCX',
48690 => 'SNMP::Info::Layer3::Teltonika',
);
my %l2sysoidmap = (
9 => 'SNMP::Info::Layer2::Cisco',
11 => 'SNMP::Info::Layer2::HP',
43 => 'SNMP::Info::Layer2::3Com',
45 => 'SNMP::Info::Layer2::Baystack',
96 => 'SNMP::Info::Layer3::Whiterabbit',
171 => 'SNMP::Info::Layer3::DLink',
207 => 'SNMP::Info::Layer2::Allied',
266 => 'SNMP::Info::Layer2::Nexans',
664 => 'SNMP::Info::Layer2::Adtran',
674 => 'SNMP::Info::Layer3::Dell',
1872 => 'SNMP::Info::Layer3::AlteonAD',
1890 => 'SNMP::Info::Layer3::Redlion',
1916 => 'SNMP::Info::Layer3::Extreme',
1991 => 'SNMP::Info::Layer3::Foundry',
2011 => 'SNMP::Info::Layer3::Huawei',
2272 => 'SNMP::Info::Layer3::Passport',
2925 => 'SNMP::Info::Layer1::Cyclades',
3224 => 'SNMP::Info::Layer3::Netscreen',
3375 => 'SNMP::Info::Layer3::F5',
4526 => 'SNMP::Info::Layer2::Netgear',
5624 => 'SNMP::Info::Layer3::Enterasys',
6141 => 'SNMP::Info::Layer3::Ciena',
6486 => 'SNMP::Info::Layer3::AlcatelLucent',
9303 => 'SNMP::Info::Layer3::PacketFront',
10418 => 'SNMP::Info::Layer1::Cyclades',
11898 => 'SNMP::Info::Layer2::Orinoco',
13458 => 'SNMP::Info::Layer2::Atmedia',
14179 => 'SNMP::Info::Layer2::Airespace',
14525 => 'SNMP::Info::Layer2::Trapeze',
14823 => 'SNMP::Info::Layer3::Aruba',
17163 => 'SNMP::Info::Layer3::Steelhead',
20540 => 'SNMP::Info::Layer2::Sixnet',
21091 => 'SNMP::Info::Layer2::Exinda',
26543 => 'SNMP::Info::Layer3::IBMGbTor',
26928 => 'SNMP::Info::Layer2::Aerohive',
47196 => 'SNMP::Info::Layer3::ArubaCX',
48690 => 'SNMP::Info::Layer3::Teltonika',
);
my %l1sysoidmap = (
2925 => 'SNMP::Info::Layer1::Cyclades',
10418 => 'SNMP::Info::Layer1::Cyclades',
);
my %l7sysoidmap = (
318 => 'SNMP::Info::Layer7::APC',
476 => 'SNMP::Info::Layer7::Liebert',
5951 => 'SNMP::Info::Layer7::Netscaler',
9694 => 'SNMP::Info::Layer7::Arbor',
12532 => 'SNMP::Info::Layer7::Neoteris',
14525 => 'SNMP::Info::Layer2::Trapeze',
26866 => 'SNMP::Info::Layer7::Gigamon',
);
# Get just the enterprise number for generic mapping
$id = $1 if ( defined($id) && $id =~ /^\.1\.3\.6\.1\.4\.1\.(\d+)/ );
if ($info->debug()) {
print "SNMP::Info $VERSION\n";
print "SNMP::Info::device_type() layers:$layers id:$id sysDescr:\"$desc\"\n";
}
# Layer 3 Supported
# (usually has layer2 as well, so we check for 3 first)
if ( $info->has_layer(3) ) {
$objtype = 'SNMP::Info::Layer3';
# Device Type Overrides
return $objtype unless ( defined $desc and length($desc) );
$objtype = 'SNMP::Info::Layer3::C3550' if $desc =~ /(C3550|C3560)/;
$objtype = 'SNMP::Info::Layer3::C4000' if $desc =~ /Catalyst 4[05]00/;
$objtype = 'SNMP::Info::Layer3::Foundry' if $desc =~ /foundry/i;
$objtype = 'SNMP::Info::Layer3::ERX' if $desc =~ /erx/i;
# Aironet - older non-IOS
$objtype = 'SNMP::Info::Layer3::Aironet'
if ($desc =~ /Cisco/
and $desc =~ /\D(CAP340|AP340|CAP350|350|1200)\D/ );
$objtype = 'SNMP::Info::Layer3::Aironet'
if ( $desc =~ /Aironet/ and $desc =~ /\D(AP4800)\D/ );
# Override voice gateway device (VG350) showing up as Aironet
$objtype = 'SNMP::Info::Layer3::Cisco' if $desc =~ /VG350/;
# Cat6k with older SUPs (hybrid CatOS/IOS?)
$objtype = 'SNMP::Info::Layer3::C6500' if $desc =~ /(c6sup2|c6sup1)/;
# Cat6k with Sup720, Sup720 or Sup2T (and Sup2 running native IOS?)
$objtype = 'SNMP::Info::Layer3::C6500'
if $desc =~ /(s72033_rp|s3223_rp|s32p3_rp|s222_rp|s2t54)/;
# Next one untested. Reported working by DA
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /cisco/i and $desc =~ /3750/ );
# IOS 15.x on Catalyst 3850
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /cisco/i and $desc =~ /CAT3K/ );
# Cisco 2970
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /(C2970|C2960)/ );
# Cisco 3400 w/ Layer3 capable image
$objtype = 'SNMP::Info::Layer3::C3550'
if ( $desc =~ /(ME340x)/ );
# Various Cisco blade switches, CBS30x0 and CBS31x0 models
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /cisco/i and $desc =~ /CBS3[0-9A-Za-z]{3}/ );
# Cisco Nexus running NX-OS
$objtype = 'SNMP::Info::Layer3::Nexus'
if ( $desc =~ /^Cisco\s+NX-OS/ );
# HP, older ProCurve models (1600, 2400, 2424m, 4000, 8000)
$objtype = 'SNMP::Info::Layer2::HP4000'
if $desc =~ /\b(J4093A|J4110A|J4120A|J4121A|J4122A|J4122B)\b/;
# HP, Foundry OEM
$objtype = 'SNMP::Info::Layer3::HP9300'
if $desc =~ /\b(J4874A|J4138A|J4139A|J4840A|J4841A)\b/;
# Nortel ERS (Passport) 1600 Series < version 2.1
$objtype = 'SNMP::Info::Layer3::N1600'
if $desc =~ /(Passport|Ethernet\s+Routing\s+Switch)-16/i;
# ERS - BayStack Numbered
$objtype = 'SNMP::Info::Layer2::Baystack'
if ( $desc
=~ /^(BayStack|Ethernet\s+Routing\s+Switch)\s[2345](\d){2,3}/i );
# Nortel Contivity
$objtype = 'SNMP::Info::Layer3::Contivity'
if $desc =~ /(\bCES\b|\bNVR\sV\d)/
and (!defined $id or !defined $l3sysoidmap{$id});
# SonicWALL
$objtype = 'SNMP::Info::Layer3::SonicWALL' if $desc =~ /SonicWALL/i;
# Allied Telesis Layer2 managed switches. They report they have L3 support
$objtype = 'SNMP::Info::Layer2::Allied'
if ( $desc =~ /Allied.*AT-80\d{2}\S*/i );
# Cisco ASA, newer versions which report layer 3 functionality
# version >= 8.2 are known to do this
$objtype = 'SNMP::Info::Layer3::CiscoASA'
if ( $desc =~ /Cisco Adaptive Security Appliance/i );
# Cisco FTD includes an ASA running as lina process
$objtype = 'SNMP::Info::Layer3::CiscoASA'
if ( $desc =~ /Cisco Firepower Threat Defense/i );
# Cisco FWSM
$objtype = 'SNMP::Info::Layer3::CiscoFWSM'
if ( $desc =~ /Cisco Firewall Services Module/i );
# Cisco Small Business (300 500) series override
# This is for enterprises(1).cisco(9).otherEnterprises(6).ciscosb(1)
$objtype = 'SNMP::Info::Layer2::CiscoSB'
if ( $soid =~ /^\.?1\.3\.6\.1\.4\.1\.9\.6\.1/ );
# Avaya Secure Router
$objtype = 'SNMP::Info::Layer3::Tasman'
if ( $desc =~ /^(avaya|nortel)\s+(SR|secure\srouter)\s+\d{4}/i );
# HP Virtual Connect blade switches
$objtype = 'SNMP::Info::Layer2::HPVC'
if ( $desc =~ /HP\sVC\s/ );
# Aironet - IOS
# Starting with IOS 15, Aironet reports sysServices 6, even though
# it still is the same layer2 access point.
$objtype = 'SNMP::Info::Layer2::Aironet'
if ($desc =~ /\b(C1100|C1130|C1140|AP1200|C350|C1200|C1240|C1250|C2700|C3700)\b/
and $desc =~ /\bIOS\b/ );
# Airespace (WLC) Module
$objtype = 'SNMP::Info::Layer2::Airespace'
if ( $desc =~ /^Cisco Controller$/ );
#Nortel 2270
$objtype = 'SNMP::Info::Layer2::N2270'
if (
$desc =~ /Nortel\s+(Networks\s+)??WLAN\s+-\s+Security\s+Switch/ );
# Nortel (Trapeze) WSS 2300 Series
$objtype = 'SNMP::Info::Layer2::NWSS2300'
if (
$desc =~ /^(Nortel\s)??Wireless\sSecurity\sSwitch\s23[568][012]\b/);
# Siemens Simatic Scalance
# Scalance overwrites layers later,
# so if we don't add it here (layer3) and at other
# it would flip/flop between those
$objtype = 'SNMP::Info::Layer3::Scalance'
if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.4329\.6\.1\.2/i );
# Aruba wireless switches (issue #403)
$objtype = 'SNMP::Info::Layer3::Aruba'
if ( $desc =~ /ArubaOS/ );
# Teltonika RUT9xx Series
$objtype = 'SNMP::Info::Layer3::Teltonika'
if (
$desc =~ /\bTeltonika.*RUT9\d{2}\b/);
# Riverbed Steelfusion
$objtype = 'SNMP::Info::Layer3::SteelheadEx'
if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.17163\.1\.51/i );
$objtype = 'SNMP::Info::Layer3::Steelfusion'
if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.17163\.1\.52/i );
# Whiterabbit Timing
$objtype = 'SNMP::Info::Layer3::Whiterabbit'
if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.96\.100\.1000/i );
# Generic device classification based upon sysObjectID
if ( ( $objtype eq 'SNMP::Info::Layer3' )
and ( defined($id) )
and ( exists( $l3sysoidmap{$id} ) ) )
{
$objtype = $l3sysoidmap{$id};
}
# Layer 2 Supported
}
elsif ( $info->has_layer(2) ) {
$objtype = 'SNMP::Info::Layer2';
return $objtype unless ( defined $desc and $desc !~ /^\s*$/ );
# Device Type Overrides
# Bay Hub (Needed here for layers override)
$objtype = 'SNMP::Info::Layer1::Bayhub'
if ( $desc =~ /\bNMM.*Agent/ );
$objtype = 'SNMP::Info::Layer1::Bayhub'
if ( $desc =~ /\bBay\s*Stack.*Hub/i );
# Synoptics Hub (Needed here for layers override)
# This will override Bay Hub only for specific devices supported
# by this class
$objtype = 'SNMP::Info::Layer1::S3000'
if ( $desc =~ /\bNMM\s+(281|3000|3030)/i );
# Catalyst 1900 series override
$objtype = 'SNMP::Info::Layer2::C1900'
if ( $desc =~ /catalyst/i and $desc =~ /\D19\d{2}/ );
# Catalyst 2900 and 3500XL (IOS) series override
$objtype = 'SNMP::Info::Layer2::C2900'
if ( $desc =~ /(C2900XL|C2950|C3500XL|C2940|CGESM|CIGESM)/i );
# Catalyst WS-C series override 2926,4k,5k,6k in Hybrid
$objtype = 'SNMP::Info::Layer2::Catalyst' if ( $desc =~ /WS-C\d{4}/ );
# Catalyst 3550 / 3548 Layer2 only switches
# Cisco 3400 w/ MetroBase Image
$objtype = 'SNMP::Info::Layer3::C3550'
if ( $desc =~ /(C3550|ME340x)/ );
# Cisco blade switches, CBS30x0 and CBS31x0 models with L2 only
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /cisco/i and $desc =~ /CBS3[0-9A-Za-z]{3}/ );
# Cisco 2970
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /(C2970|C2960)/ );
# Cisco Small Business (300 500) series override
# This is for enterprises(1).cisco(9).otherEnterprises(6).ciscosb(1)
$objtype = 'SNMP::Info::Layer2::CiscoSB'
if ( $soid =~ /^\.1\.3\.6\.1\.4\.1\.9\.6\.1/ );
# HP, older ProCurve models (1600, 2400, 2424m, 4000, 8000)
$objtype = 'SNMP::Info::Layer2::HP4000'
if $desc =~ /\b(J4093A|J4110A|J4120A|J4121A|J4122A|J4122B)\b/;
# HP, Foundry OEM
$objtype = 'SNMP::Info::Layer3::HP9300'
if $desc =~ /\b(J4874A|J4138A|J4139A|J4840A|J4841A)\b/;
# IBM BladeCenter 4-Port GB Ethernet Switch Module
$objtype = 'SNMP::Info::Layer3::Dell'
if ( $desc =~ /^IBM Gigabit Ethernet Switch Module$/ );
# Linksys 2024/2048
$objtype = 'SNMP::Info::Layer3::Dell'
if (
$desc =~ /^(24|48)-Port 10\/100\/1000 Gigabit Switch (with |w\/)WebView$/ );
# Centillion ATM
$objtype = 'SNMP::Info::Layer2::Centillion' if ( $desc =~ /MCP/ );
# BPS
$objtype = 'SNMP::Info::Layer2::Baystack'
if ( $desc =~ /Business\sPolicy\sSwitch/i );
# BayStack Numbered
$objtype = 'SNMP::Info::Layer2::Baystack'
if ( $desc
=~ /^(BayStack|Ethernet\s+(Routing\s+)??Switch)\s[2345](\d){2,3}/i
);
# Kentrox DataSMART DSU/CSU
$objtype = 'SNMP::Info::Layer2::Kentrox'
if ( $desc =~ /^DataSMART/i );
# Nortel Business Ethernet Switch
$objtype = 'SNMP::Info::Layer2::Baystack'
if ( $desc =~ /^Business Ethernet Switch\s[12]\d\d/i );
# Nortel AP 222X
$objtype = 'SNMP::Info::Layer2::NAP222x'
if ( $desc =~ /Access\s+Point\s+222/ );
# Orinoco
$objtype = 'SNMP::Info::Layer2::Orinoco'
if ( $desc =~ /(AP-\d{3}|WavePOINT)/ );
# Aironet - IOS
$objtype = 'SNMP::Info::Layer2::Aironet'
if ($desc =~ /\b(C1100|C1130|C1140|AP1200|C350|C1200|C1240|C1250)\b/
and $desc =~ /\bIOS\b/ );
# Aironet - non IOS
$objtype = 'SNMP::Info::Layer3::Aironet'
if ( $desc =~ /Cisco/ and $desc =~ /\D(BR500)\D/ );
# Airespace (WLC) Module
$objtype = 'SNMP::Info::Layer2::Airespace'
if ( $desc =~ /^Cisco Controller$/ );
#Nortel 2270
$objtype = 'SNMP::Info::Layer2::N2270'
if (
$desc =~ /Nortel\s+(Networks\s+)??WLAN\s+-\s+Security\s+Switch/ );
# HP Virtual Connect blade switches
$objtype = 'SNMP::Info::Layer2::HPVC'
if ( $desc =~ /HP\sVC\s/ );
$objtype = 'SNMP::Info::Layer2::ZyXEL_DSLAM'
if ( $desc =~ /8-port .DSL Module\(Annex .\)/i );
# Generic DOCSIS Cable Modem override
# If sysDesc follows the DOCSIS standard
$objtype = 'SNMP::Info::DocsisCM'
if ( $desc =~ /<>/i);
# Generic device classification based upon sysObjectID
if ( ( $objtype eq 'SNMP::Info::Layer2' )
and ( defined($id) )
and ( exists( $l2sysoidmap{$id} ) ) )
{
$objtype = $l2sysoidmap{$id};
}
}
elsif ( $info->has_layer(1) ) {
$objtype = 'SNMP::Info::Layer1';
# Allied crap-o-hub
$objtype = 'SNMP::Info::Layer1::Allied' if ( $desc =~ /allied/i );
$objtype = 'SNMP::Info::Layer1::Asante' if ( $desc =~ /asante/i );
# Bay Hub
$objtype = 'SNMP::Info::Layer1::Bayhub'
if ( $desc =~ /\bNMM.*Agent/ );
$objtype = 'SNMP::Info::Layer1::Bayhub'
if ( $desc =~ /\bBay\s*Stack.*Hub/i );
# Synoptics Hub
# This will override Bay Hub only for specific devices supported
# by this class
$objtype = 'SNMP::Info::Layer1::S3000'
if ( $desc =~ /\bNMM\s+(281|3000|3030)/i );
# Generic device classification based upon sysObjectID
if ( ( $objtype eq 'SNMP::Info::Layer1' )
and ( defined($id) )
and ( exists( $l1sysoidmap{$id} ) ) )
{
$objtype = $l1sysoidmap{$id};
}
}
# These devices don't claim to have Layer1-3 but we like em anyways.
else {
$objtype = 'SNMP::Info::Layer2::ZyXEL_DSLAM'
if ( $desc =~ /8-port .DSL Module\(Annex .\)/i );
# Aruba wireless switches
$objtype = 'SNMP::Info::Layer3::Aruba'
if ( $desc =~ /(ArubaOS|AirOS)/ );
# Alcatel-Lucent branded Aruba
$objtype = 'SNMP::Info::Layer3::Aruba'
if ( $desc =~ /^AOS-W/ );
# Cisco PIX
$objtype = 'SNMP::Info::Layer3::Cisco'
if ( $desc =~ /Cisco PIX Security Appliance/i );
# Cisco ASA, older version which doesn't report layer 3 functionality
$objtype = 'SNMP::Info::Layer3::CiscoASA'
if ( $desc =~ /Cisco Adaptive Security Appliance/i );
# HP Virtual Connect blade switches
$objtype = 'SNMP::Info::Layer2::HPVC'
if ( $desc =~ /HP\sVC\s/ );
# Nortel (Trapeze) WSS 2300 Series
$objtype = 'SNMP::Info::Layer2::NWSS2300'
if (
$desc =~ /^(Nortel\s)??Wireless\sSecurity\sSwitch\s23[568][012]\b/);
# Cisco IPS, older version which doesn't report layer 3 functionality
$objtype = 'SNMP::Info::Layer7::CiscoIPS'
if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.9\.1\.1545/i );
# Siemens Simatic Scalance
# Scalance overwrites layers later,
# so if we don't add it here (layer3) and at other
# it would flip/flop between those
$objtype = 'SNMP::Info::Layer3::Scalance'
if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.4329\.6\.1\.2/i );
# Whiterabbit Timing
$objtype = 'SNMP::Info::Layer3::Whiterabbit'
if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.96\.100\.1000/i );
# Teltonika RUT9xx Series
$objtype = 'SNMP::Info::Layer3::Teltonika'
if (
$desc =~ /\bTeltonika.*RUT9\d{2}\b/);
# Generic device classification based upon sysObjectID
if ( defined($id) and $objtype eq 'SNMP::Info') {
if ( defined $l3sysoidmap{$id} ) {
$objtype = $l3sysoidmap{$id};
} elsif ( defined $l2sysoidmap{$id}) {
$objtype = $l2sysoidmap{$id};
} elsif ( defined $l7sysoidmap{$id}) {
$objtype = $l7sysoidmap{$id};
} elsif ($info->has_layer(7)) {
$objtype = 'SNMP::Info::Layer7'
}
}
}
return $objtype;
}
=item $info->error(no_clear)
Returns Error message if there is an error, or undef if there is not.
Reading the error will clear the error unless you set the no_clear flag.
=cut
sub error {
my $self = shift;
my $no_clear = shift;
my $err = $self->{error};
$self->{error} = undef unless defined $no_clear and $no_clear;
return $err;
}
=item $info->has_layer(3)
Returns non-zero if the device has the supplied layer in the OSI Model
Returns if the device doesn't support the layers() call.
=cut
sub has_layer {
my $self = shift;
my $check_for = shift;
my $layers = $self->layers();
return unless defined $layers;
return unless length($layers);
return substr( $layers, 8 - $check_for, 1 );
}
=item $info->snmp_comm()
Returns SNMP Community string used in connection.
=cut
sub snmp_comm {
my $self = shift;
if ( $self->{snmp_ver} == 3 ) {
return $self->{snmp_user};
}
else {
return $self->{snmp_comm};
}
}
=item $info->snmp_ver()
Returns SNMP Version used for this connection
=cut
sub snmp_ver {
my $self = shift;
return $self->{snmp_ver};
}
=item $info->specify()
Returns an object of a more-specific subclass.
my $info = new SNMP::Info(...);
# Returns more specific object type
my $specific = $info->specify();
Usually this method is called internally from new(AutoSpecify => 1)
See device_type() entry for how a subclass is chosen.
=cut
sub specify {
my $self = shift;
my $device_type = $self->device_type();
unless ( defined $device_type ) {
$self->error_throw(
"SNMP::Info::specify() - Could not get info from device");
return;
}
return $self if $device_type eq 'SNMP::Info';
# Load Subclass
# By evaling a string the contents of device_type now becomes a bareword.
eval "require $device_type;"; ## no critic
if ($@) {
croak "SNMP::Info::specify() Loading $device_type Failed. $@\n";
}
my $args = $self->args();
my $session = $self->session();
my $sub_obj = $device_type->new(
%$args,
'Session' => $session,
'AutoSpecify' => 0
);
unless ( defined $sub_obj ) {
$self->error_throw(
"SNMP::Info::specify() - Could not connect with new class ($device_type)"
);
return $self;
}
$self->debug()
and print "SNMP::Info::specify() - Changed Class to $device_type.\n";
return $sub_obj;
}
=item $info->cisco_comm_indexing()
Returns 0. Is an overridable method used for vlan indexing for
snmp calls on certain Cisco devices.
See L
=cut
sub cisco_comm_indexing {
return 0;
}
=back
=head2 GLOBALS (Scalar Methods)
These are methods to return scalar data from RFC1213.
Some subset of these is probably available for any network device that speaks
SNMP.
=over
=item $info->uptime()
Uptime in hundredths of seconds since device became available.
(C)
=item $info->contact()
(C)
=item $info->name()
(C)
=item $info->location()
(C)
=item $info->layers()
This returns a binary encoded string where each
digit represents a layer of the OSI model served
by the device.
eg: 01000010 means layers 2 (physical) and 7 (Application)
are served.
Note: This string is 8 digits long.
See $info->has_layer()
(C)
=item $info->ports()
Number of interfaces available on this device.
Not too useful as the number of SNMP interfaces usually does not
correspond with the number of physical ports
(C)
=item $info->ipforwarding()
The indication of whether the entity is acting as an IP gateway
Returns either forwarding or not-forwarding
(C)
=back
=head2 Table Methods
Each of these methods returns a hash_reference to a hash keyed on the
interface index in SNMP.
Example : $info->interfaces() might return
{ '1.12' => 'FastEthernet/0',
'2.15' => 'FastEthernet/1',
'9.99' => 'FastEthernet/2'
}
The key is what you would see if you were to do an snmpwalk, and in some cases
changes between reboots of the network device.
=head2 Partial Table Fetches
If you want to get only a part of an SNMP table or a single instance from the
table and you know the IID for the part of the table that you want, you can
specify it in the call:
$local_routes = $info->ipr_route('192.168.0');
This will only fetch entries in the table that start with C<192.168.0>, which
in this case are routes on the local network.
Remember that you must supply the partial IID (a numeric OID).
Partial table results are not cached.
=head2 Interface Information
=over
=item $info->interfaces()
This methods is overridden in each subclass to provide a
mapping between the Interface Table Index (iid) and the physical port name.
=item $info->if_ignore()
Returns a reference to a hash where key values that exist are
interfaces to ignore.
Ignored interfaces are ones that are usually not physical ports or Virtual
Lans (VLANs) such as the Loopback interface, or the CPU interface.
=cut
sub if_ignore {
my %nothing;
return \%nothing;
}
=item $info->bulkwalk_no()
Returns 0. Is an overridable method used for turn off bulkwalk for the
device class.
=cut
sub bulkwalk_no {
return 0;
}
=item $info->i_index()
Default SNMP IID to Interface index.
(C)
=item $info->i_description()
Description of the interface. Usually a little longer single word name that is
both human and machine friendly. Not always.
(C)
=item $info->i_type()
Interface type, such as Vlan, Ethernet, Serial
(C)
=item $info->i_mtu()
INTEGER. Interface MTU value.
(C)
=item $info->i_speed()
Speed of the link, human format. See munge_speed() later in document for
details.
(C, C if necessary)
=cut
sub i_speed {
my $info = shift;
my $partial = shift;
my $i_speed = $info->orig_i_speed($partial);
my $i_speed_high = undef;
foreach my $i ( keys %$i_speed ) {
if ( $i_speed->{$i} eq "4294967295" ) {
$i_speed_high = $info->i_speed_high($partial)
unless defined($i_speed_high);
$i_speed->{$i} = $i_speed_high->{$i} if ( $i_speed_high->{$i} );
}
}
return $i_speed;
}
=item $info->i_speed_raw()
Speed of the link in bits per second without munging.
If i_speed_high is available it will be used and multiplied by 1_000_000.
(C, C if necessary)
=cut
sub i_speed_raw {
my $info = shift;
my $partial = shift;
# remove the speed formating
my $munge_i_speed = delete $info->{munge}{i_speed};
# also for highspeed interfaces e.g. TenGigabitEthernet
my $munge_i_speed_high = delete $info->{munge}{i_speed_high};
my $i_speed_raw = $info->orig_i_speed($partial);
my $i_speed_high = undef;
foreach my $i ( keys %$i_speed_raw ) {
if ( $i_speed_raw->{$i} eq "4294967295" ) {
$i_speed_high = $info->i_speed_high($partial)
unless defined($i_speed_high);
$i_speed_raw->{$i} = ( $i_speed_high->{$i} * 1_000_000 )
if ( $i_speed_high->{$i} );
}
}
# restore the speed formating
$info->{munge}{i_speed} = $munge_i_speed;
$info->{munge}{i_speed_high} = $munge_i_speed_high;
return $i_speed_raw;
}
=item $info->i_speed_high()
Speed of a high-speed link, human format. See munge_highspeed() later in
document for details. You should not need to call this directly, as
i_speed() will call it if it needs to.
(C)
=item $info->i_mac()
MAC address of the interface. Note this is just the MAC of the port, not
anything connected to it.
(C)
=item $info->i_up()
Link Status of the interface. Typical values are 'up' and 'down'.
(C)
=item $info->i_up_admin()
Administrative status of the port. Typical values are 'enabled' and 'disabled'.
(C)
=item $info->i_lastchange()
The value of C when this port last changed states (up,down).
(C)
=item $info->i_name()
Interface Name field. Supported by a smaller subset of devices, this fields
is often human set.
(C)
=item $info->i_alias()
Interface Name field. For certain devices this is a more human friendly form
of i_description(). For others it is a human set field like i_name().
(C)
=back
=head2 Interface Statistics
=over
=item $info->i_octet_in(), $info->i_octets_out(),
$info->i_octet_in64(), $info->i_octets_out64()
Bandwidth.
Number of octets sent/received on the interface including framing characters.
64 bit version may not exist on all devices.
NOTE: To manipulate 64 bit counters you need to use Math::BigInt, since the
values are too large for a normal Perl scalar. Set the global
$SNMP::Info::BIGINT to 1 , or pass the BigInt value to new() if you want
SNMP::Info to do it for you.
(C) (C)
(C) (C)
=item $info->i_errors_in(), $info->i_errors_out()
Number of packets that contained an error preventing delivery. See C
for more info.
(C) (C)
=item $info->i_pkts_ucast_in(), $info->i_pkts_ucast_out(),
$info->i_pkts_ucast_in64(), $info->i_pkts_ucast_out64()
Number of packets not sent to a multicast or broadcast address.
64 bit version may not exist on all devices.
(C) (C)
(C) (C)
=item $info->i_pkts_nucast_in(), $info->i_pkts_nucast_out(),
Number of packets sent to a multicast or broadcast address.
These methods are deprecated by i_pkts_multi_in() and i_pkts_bcast_in()
according to C. Actual device usage may vary.
(C) (C)
=item $info->i_pkts_multi_in() $info->i_pkts_multi_out(),
$info->i_pkts_multi_in64(), $info->i_pkts_multi_out64()
Number of packets sent to a multicast address.
64 bit version may not exist on all devices.
(C) (C)
(C