SNMP::Info(3pm) | User Contributed Perl Documentation | SNMP::Info(3pm) |
SNMP::Info - OO Interface to Network devices and MIBs through SNMP
SNMP::Info - Version 3.95
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 <https://github.com/netdisco/snmp-info/> for the most up-to-date list of developers.
SNMP::Info was originally created at UCSC for the Netdisco project <http://netdisco.org> by Max Baker.
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).
use SNMP::Info; my $info = SNMP::Info->new({ # Auto Discover your Device Class (Cisco, Juniper, etc ...) AutoSpecify => 1, Debug => 1, # The rest is passed to SNMP::Session DestHost => 'router', Community => 'public', Version => 2 # Parameter reference for SNMPv3 # Version => 3 # SecLevel => 'authPriv', # authPriv|authNoPriv|noAuthNoPriv # SecName => 'myuser', # AuthProto => 'MD5', # MD5|SHA # AuthPass => 'authp4ss', # PrivProto => 'DES', # DES|AES # PrivPass => 'pr1vp4ss', }); my $err = $info->error(); die $err if defined $err; # usually a wrong DestHost or Community or Version if you have trouble here 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"; }
Please direct all support, help, and bug requests to the snmp-info-users Mailing List at <http://lists.sourceforge.net/lists/listinfo/snmp-info-users>.
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.
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 "SNMP" is found inside the net-snmp distribution. Go to the perl/ directory of the distribution to install it, or run "./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.
Redhat Users: Some versions that come with certain versions of Redhat/Fedora don't have the Perl library installed. Uninstall the RPM and install by hand.
If you are using SNMP::Info separate from Netdisco, download the Netdisco MIB package at <https://github.com/netdisco/netdisco-mibs/releases/latest/>
Make sure that your snmp.conf is updated to point to your MIB directory and that the MIBs are world-readable.
For example SNMP::Info has an entry in its %GLOBALS hash for ``sysName'' instead of 1.3.6.1.2.1.1.5.
For Example instead of looking up 1.3.6.1.2.1.2.2.1.3 and getting back 23
SNMP::Info will ask for "RFC1213-MIB::ifType" and will get back "ppp".
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.
These are the subclasses that implement MIBs and support devices:
Required MIBs not included in the install instructions above are noted here.
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 "perldoc" on any of the following module names.
Requires the ADSL-LINE-MIB, down loadable from Cisco.
See documentation in SNMP::Info::AdslLine for details.
See documentation in SNMP::Info::Aggregate for details.
See documentation in SNMP::Info::Airespace for details.
See documentation in SNMP::Info::AMAP for details.
See documentation in SNMP::Info::Bridge for details.
See documentation in SNMP::Info::CDP for details.
See documentation in SNMP::Info::CiscoAgg for details.
See documentation in SNMP::Info::CiscoBGP for details.
See documentation in SNMP::Info::CiscoConfig for details.
See documentation in SNMP::Info::CiscoPortSecurity for details.
See documentation in SNMP::Info::CiscoPower for details.
See documentation in SNMP::Info::CiscoQOS for details.
See documentation in SNMP::Info::CiscoRTT for details.
See documentation in SNMP::Info::CiscoStack for details.
See documentation in SNMP::Info::CiscoStats for details.
See documentation in SNMP::Info::CiscoStpExtensions for details.
See documentation in SNMP::Info::CiscoVTP for details.
See documentation in SNMP::Info::DocsisCM for details.
See documentation in SNMP::Info::DocsisHE for details.
See documentation in SNMP::Info::EDP for details.
See documentation in SNMP::Info::Entity for details.
See documentation in SNMP::Info::EtherLike for details.
See documentation in SNMP::Info::FDP for details.
See documentation in SNMP::Info::IEEE802_Bridge for details.
See documentation in SNMP::Info::IEEE802dot11 for details.
See documentation in SNMP::Info::IEEE802dot3ad for details.
See documentation in SNMP::Info::IPv6 for details.
See documentation in SNMP::Info::LLDP for details.
See documentation in SNMP::Info::MAU for details.
See documentation in SNMP::Info::MRO for details.
See documentation in SNMP::Info::NortelStack for details.
See documentation in SNMP::Info::PortAccessEntity for details.
See documentation in SNMP::Info::PowerEthernet for details.
See documentation in SNMP::Info::RapidCity for details.
See documentation in SNMP::Info::SONMP for details.
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).
See documentation in SNMP::Info::Layer1 for details.
Requires ATI-MIB
See documentation in SNMP::Info::Layer1::Allied for details.
Requires ASANTE-HUB1012-MIB
See documentation in SNMP::Info::Layer1::Asante for details.
See documentation in SNMP::Info::Layer1::Bayhub for details.
See documentation in SNMP::Info::Layer1::Cyclades for details.
See documentation in SNMP::Info::Layer1::S3000 for details.
See documentation in SNMP::Info::Layer2 for details.
See documentation in SNMP::Info::Layer2::3Com for details.
See documentation in SNMP::Info::Layer2::Adtran for details.
See documentation in SNMP::Info::Layer2::Aerohive for details.
See documentation in SNMP::Info::Layer2::Airespace for details.
See documentation in SNMP::Info::Layer2::Aironet for details.
See documentation in SNMP::Info::Layer2::Allied for details.
See documentation in SNMP::Info::Layer2::Atmedia for details.
See documentation in SNMP::Info::Layer2::Baystack for details.
See documentation in SNMP::Info::Layer2::C1900 for details.
See documentation in SNMP::Info::Layer2::C2900 for details.
See documentation in SNMP::Info::Layer2::Catalyst for details.
See documentation in SNMP::Info::Layer2::Centillion for details.
See documentation in SNMP::Info::Layer2::Cisco for details.
See documentation in SNMP::Info::Layer2::CiscoSB for details.
See documentation in SNMP::Info::Layer2::Exinda for details.
See documentation in SNMP::Info::Layer2::Hirschmann for details.
Requires HP-ICF-OID and ENTITY-MIB downloaded from HP.
See documentation in SNMP::Info::Layer2::HP for details.
Requires HP-ICF-OID and ENTITY-MIB downloaded from HP.
See documentation in SNMP::Info::Layer2::HP4000 for details.
See documentation in SNMP::Info::Layer2::HPVC for details.
See documentation in SNMP::Info::Layer2::Kentrox for details.
See documentation in SNMP::Info::Layer2::N2270 for details.
See documentation in SNMP::Info::Layer2::NAP222x for details.
See documentation in SNMP::Info::Layer2::Netgear for details.
See documentation in SNMP::Info::Layer2::Nexans for details.
See documentation in SNMP::Info::Layer2::NWSS2300 for details.
See documentation in SNMP::Info::Layer2::Orinoco for details.
See documentation in SNMP::Info::Layer2::Trapeze for details.
See documentation in SNMP::Info::Layer2::Sixnet for details.
See documentation in SNMP::Info::Layer2::Ubiquiti for details.
See documentation in SNMP::Info::Layer2::ZyXEL_DSLAM for details.
See documentation in SNMP::Info::Layer3 for details.
Note SNMP::Info::Layer2::Aironet
See documentation in SNMP::Info::Layer3::Aironet for details.
See documentation in SNMP::Info::Layer3::AlcatelLucent for details.
See documentation in SNMP::Info::Layer3::AlteonAD for details.
See documentation in SNMP::Info::Layer3::Aruba for details.
See documentation in SNMP::Info::Layer3::ArubaCX for details.
See documentation in SNMP::Info::Layer3::BayRS for details.
See documentation in SNMP::Info::Layer3::BlueCoatSG for details.
See documentation in SNMP::Info::Layer3::C3550 for details.
See documentation in SNMP::Info::Layer3::C4000 for details.
See documentation in SNMP::Info::Layer3::C6500 for details.
See documentation in SNMP::Info::Layer3::CheckPoint for details.
See documentation in SNMP::Info::Layer3::Ciena for details.
See documentation in SNMP::Info::Layer3::Cisco for details.
See documentation in SNMP::Info::Layer3::CiscoASA for details.
See documentation in SNMP::Info::Layer3::CiscoFWSM for details.
See documentation in SNMP::Info::Layer3::Contivity for details.
See documentation in SNMP::Info::Layer3::Cumulus for details.
See documentation in SNMP::Info::Layer3::Dell for details.
See documentation in SNMP::Info::Layer3::DLink for details.
See documentation in SNMP::Info::Layer3::Enterasys for details.
See documentation in SNMP::Info::Layer3::ERX for details.
See documentation in SNMP::Info::Layer3::Extreme for details.
See documentation in SNMP::Info::Layer3::F5 for details.
See documentation in SNMP::Info::Layer3::Force10 for details.
See documentation in SNMP::Info::Layer3::Fortinet for details.
See documentation in SNMP::Info::Layer3::Foundry for details.
See documentation in SNMP::Info::Layer3::Genua for details.
See documentation in SNMP::Info::Layer3::H3C for details.
See documentation in SNMP::Info::Layer3::HP9300 for details.
See documentation in SNMP::Info::Layer3::Huawei for details.
See documentation in SNMP::Info::Layer3::IBMGbTor for details.
See documentation in SNMP::Info::Layer3::Juniper for details.
See documentation in SNMP::Info::Layer3::Lantronix for details.
See documentation in SNMP::Info::Layer3::Lenovo for details.
See documentation in SNMP::Info::Layer3::Microsoft for details.
See documentation in SNMP::Info::Layer3::Mikrotik for details.
See documentation in SNMP::Info::Layer3::N1600 for details.
See documentation in SNMP::Info::Layer3::Netonix for details.
See documentation in SNMP::Info::Layer3::NetSNMP for details.
See documentation in SNMP::Info::Layer3::Netscreen for details.
See documentation in SNMP::Info::Layer3::Nexus for details.
See documentation in SNMP::Info::Layer3::OneAccess for details.
See documentation in SNMP::Info::Layer3::PacketFront for details.
See documentation in SNMP::Info::Layer3::PaloAlto for details.
See documentation in SNMP::Info::Layer3::Passport for details.
See documentation in SNMP::Info::Layer3::Pf for details.
See documentation in SNMP::Info::Layer3::Pica8 for details.
See documentation in SNMP::Info::Layer3::Redlion for details.
See documentation in SNMP::Info::Layer3::Scalance for details.
See documentation in SNMP::Info::Layer3::SonicWALL for details.
See documentation in SNMP::Info::Layer3::Steelfusion for details.
See documentation in SNMP::Info::Layer3::Steelhead for details.
See documentation in SNMP::Info::Layer3::SteelheadEx for details.
See documentation in SNMP::Info::Layer3::Sun for details.
See documentation in SNMP::Info::Layer3::Tasman for details.
See documentation in SNMP::Info::Layer3::Teltonika for details.
See documentation in SNMP::Info::Layer3::Timetra for details.
See documentation in SNMP::Info::Layer3::VyOS for details.
See documentation in SNMP::Info::Layer3::VMware for details.
See documentation in SNMP::Info::Layer3::Whiterabbit for details.
See documentation in SNMP::Info::Layer7 for details.
See documentation in SNMP::Info::Layer7::APC for details.
See documentation in SNMP::Info::Layer7::Arbor for details.
See documentation in SNMP::Info::Layer7::CiscoIPS for details.
See documentation in SNMP::Info::Layer7::Gigamon for details.
See documentation in SNMP::Info::Layer7::HWGroup for details.
See documentation in SNMP::Info::Layer7::Liebert for details.
See documentation in SNMP::Info::Layer7::Neoteris for details.
See documentation in SNMP::Info::Layer7::Netscaler for details.
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!
Always returns an SNMP::Info instance, and you should always check for error() as in SYNOPSIS above to be sure of success.
Will take a bare list of key/value options but we recommend a HASH ref as in the example below and SYNOPSIS, to catch syntax errors.
my $info = SNMP::Info->({ 'Debug' => 1, 'AutoSpecify' => 1, 'BigInt' => 1, 'BulkWalk' => 1, 'BulkRepeaters' => 20, 'LoopDetect' => 1, 'IgnoreNetSNMPConf' => 1, 'DestHost' => 'myrouter', 'Community' => 'public', 'Version' => 2, 'MibDirs' => ['dir1','dir2','dir3'], });
SNMP::Info Specific Arguments :
(default 0, which means "off")
(default 0, which means "off")
Note that BULKWALK is turned off for Net-SNMP versions 5.1.x because of a bug.
(default 1, which means "on")
(default 20)
Set to 0 to turn off loop detection.
(default 1, which means "on")
Set to 1 "on" to ignore Net-SNMP configuration files by overriding the "SNMPCONFPATH" 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")
(default 0, which means "off")
See SNMP for more details.
(default use net-snmp settings only)
(default 1, which means "on")
(default creates session automatically)
(default 0, which means "online")
See SNMP::Session for a list of other possible arguments.
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.
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., "sysObjectID", "sysDescr") that we use to identify the device.
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 "Offline" option.
These are for package related data, not directly supplied from SNMP.
Optionally sets the Offline parameter.
Optionally sets the cache parameters if passed a HashRef.
Optionally sets the bulkwalk parameter.
Optionally sets the loopdetect parameter.
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.
Reading the error will clear the error unless you set the no_clear flag.
Returns if the device doesn't support the layers() call.
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.
See <ftp://ftp.cisco.com/pub/mibs/supportlists/wsc5000/wsc5000-communityIndexing.html>
These are methods to return scalar data from RFC1213.
Some subset of these is probably available for any network device that speaks SNMP.
("sysUpTime")
eg: 01000010 means layers 2 (physical) and 7 (Application) are served.
Note: This string is 8 digits long.
See $info->has_layer()
("sysServices")
Not too useful as the number of SNMP interfaces usually does not correspond with the number of physical ports
("ifNumber")
Returns either forwarding or not-forwarding
("ipForwarding")
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.
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 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.
Ignored interfaces are ones that are usually not physical ports or Virtual Lans (VLANs) such as the Loopback interface, or the CPU interface.
("ifIndex")
("ifDescr")
("ifType")
("ifMtu")
("ifSpeed", "ifHighSpeed" if necessary)
("ifSpeed", "ifHighSpeed" if necessary)
("ifHighSpeed")
("ifPhysAddress")
("ifOperStatus")
("ifAdminStatus")
("ifLastChange")
("ifName")
("ifAlias")
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.
("ifInOctets") ("ifOutOctets") ("ifHCInOctets") ("ifHCOutOctets")
("ifInErrors") ("ifOutErrors")
64 bit version may not exist on all devices.
("ifInUcastPkts") ("ifOutUcastPkts") ("ifHCInUcastPkts") ("ifHCOutUcastPkts")
These methods are deprecated by i_pkts_multi_in() and i_pkts_bcast_in() according to "IF-MIB". Actual device usage may vary.
("ifInNUcastPkts") ("ifOutNUcastPkts")
64 bit version may not exist on all devices.
("ifInMulticastPkts") ("ifOutMulticastPkts") ("ifHCInMulticastPkts") ("ifHCOutMulticastPkts")
64 bit version may not exist on all devices.
("ifInBroadcastPkts") ("ifOutBroadcastPkts") ("ifHCInBroadcastPkts") ("ifHCOutBroadcastPkts")
("ifInDiscards") ("ifOutDiscards")
("ifInUnknownProtos")
("ifOutQLen")
("ifSpecific")
Each entry in this table is an IPv4 address in use on this device. Usually this is implemented in Layer3 Devices. These methods try the deprecated IPv4 address table "IP-MIB::ipAddrTable" first due to its prevalence and will try the current "IP-MIB::ipAddressTable" if it doesn't return any results. "IP-MIB::ipAddressTable" results are filtered to only return IPv4 unicast addresses and modified to match the return format of the older table for backwards compatibility.
See documentation in SNMP::Info::IPv6 for IPv6 Address Table.
("ipAdEntIfIndex") or filtered and index modified ("ipAddressIfIndex")
("ipAdEntAddr") or address extracted from ("ipAddressIfIndex")
("ipAdEntNetMask") or netmask calculated from ("ipAddressPrefix")
("ipAdEntBcastAddr"), there is no equivalent from the "IP-MIB::ipAddressTable"
("ipRouteDest")
("ipRouteIfIndex")
("ipRouteMetric1")
("ipRouteMetric2")
"The IP address of the next hop of this route. (In the case of a route bound to an interface which is realized via a broadcast media, the value of this field is the agent's IP address on that interface.)"
("ipRouteNextHop")
other(1), -- none of the following invalid(2), -- an invalidated route -- route to directly direct(3), -- connected (sub-)network -- route to a non-local indirect(4) -- host/network/sub-network "The type of route. Note that the values direct(3) and indirect(4) refer to the notion of direct and indirect routing in the IP architecture. Setting this object to the value invalid(2) has the effect of invalidating the corresponding entry in the ipRouteTable object. That is, it effectively disassociates the destination identified with said entry from the route identified with said entry. It is an implementation-specific matter as to whether the agent removes an invalidated entry from the table. Accordingly, management stations must be prepared to receive tabular information from agents that corresponds to entries not currently in use. Proper interpretation of such entries requires examination of the relevant ipRouteType object."
("ipRouteType")
other(1), -- none of the following -- non-protocol information, -- e.g., manually configured local(2), -- entries -- set via a network netmgmt(3), -- management protocol -- obtained via ICMP, icmp(4), -- e.g., Redirect -- the remaining values are -- all gateway routing -- protocols egp(5), ggp(6), hello(7), rip(8), is-is(9), es-is(10), ciscoIgrp(11), bbnSpfIgp(12), ospf(13), bgp(14)
("ipRouteProto")
("ipRouteAge")
("ipRouteMask")
("ipRouteInfo")
Based upon the manufacturer and software version devices may support some combination of Layer 2 topology protocol information. SNMP::Info supports querying Link Layer Discovery Protocol (LLDP), Cisco Discovery Protocol (CDP), SynOptics/Bay/Nortel/Avaya Network Management Protocol (SONMP), Foundry/Brocade Discovery Protocol (FDP), Extreme Discovery Protocol (EDP), and Alcatel Mapping Adjacency Protocol (AMAP).
For protocol specific information and implementation:
Topology Capabilities
Returns either a reference to an array of protocols, possible values being: "lldp", "cdp", "sonmp", "fdp", "edp", "amap" or "undef" if no protocols are supported or running.
Common Topology Table Information
The common topology table methods below will query the device for information from the specified topology protocols and return a single hash combining all information. As a result, there may be identical topology information returned from the two protocols causing duplicate entries. It is the calling program's responsibility to identify any duplicate entries and remove duplicates if necessary. If it is necessary to understand which protocol provided the information, utilize the protocol specific methods directly rather than the generic methods.
The methods support partial table fetches by providing a partial as the first argument.
If a reference to an array is provided as the second argument, those protocols will be queried for information. The supported array values are: "lldp", "cdp", "sonmp", "fdp", "edp", "amap".
If nothing is passed in as the second argument, the methods will call has_topo() to determine supported and running topology protocols on the device.
If multiple entries exist with the same local port, c_if(), with the same IPv4 address, c_ip(), it may be a duplicate entry.
If multiple entries exist with the same local port, c_if(), with different IPv4 addresses, c_ip(), there is either a device in between two or more devices utilizing a different topology protocol or multiple devices which are not directly connected.
Use the protocol specific methods to dig deeper.
Note: SONMP does not return this information.
Note: EDP does not provide this information. LLDP uses ("lldpRemSysDesc") or "lldp_rem_sysname" as the closest match.
Note: Only CDP and LLDP support this method.
This section explains how to use SNMP::Info to do SNMP Set operations.
Returns if failed, or the return value from SNMP::Session::set() (snmp_errno)
$info->set_location("Here!");
Returns if failed, or the return value from SNMP::Session::set() (snmp_errno)
# Disable a port administratively my %if_map = reverse %{$info->interfaces()} $info->set_i_up_admin('down', $if_map{'FastEthernet0/0'}) or die "Couldn't disable the port. ",$info->error(1);
NOTE: You must be connected to your device with a "ReadWrite" community string in order for set operations to work.
NOTE: This will only set data listed in %FUNCS and %GLOBALS. For data acquired from overridden methods (subroutines) specific set_METHOD() subroutines will need to be added if they haven't been already.
SNMP::Info will not chirp anything to STDOUT unless there is a serious error (in which case it will probably die).
To get lots of debug info, set the Debug flag when calling new() or call $info->debug(1);
When calling a method check the return value. If the return value is undef then check $info->error()
Beware, calling $info->error() clears the error.
my $name = $info->name() or die "Couldn't get sysName!" . $name->error();
To support a new class (vendor or platform) of device, add a Perl package with the data structures and methods listed below.
If this seems a little scary, then the SNMP::Info developers are usually happy to accept the SNMP data from your device and make an attempt at the class themselves. Usually a "beta" release will go to CPAN for you to verify the implementation.
The preference is to open a pull request in the github project. This allows all developers to have visibility into the request. Please include pointers to the applicable platform MIBs. For development we will need an "snmpwalk" of the device. There is a tool now included in the SNMP::Info distribution to help with this task, although you'll most likely need to download the distribution from CPAN as it's included in the ""contrib/util"" directory.
The utility is named "make_snmpdata.pl". Run it with a command line like:
./make_snmpdata.pl -c community -i -d device_ip \ -m /home/netdisco-mibs/rfc:/home/netdisco-mibs/net-snmp:/home/netdisco-mibs/dir3 \ SNMPv2-MIB IF-MIB EtherLike-MIB BRIDGE-MIB Q-BRIDGE-MIB ENTITY-MIB \ POWER-ETHERNET-MIB IPV6-MIB LLDP-MIB DEVICE-SPECIFIC-MIB-NAME(s) > output.txt
This will print to the file every MIB entry with data in a format that the developers can use to emulate read operations without needing access to the device. Preference would be to mask any sensitive data in the output, zip the file, and attach it to the github pull request. However, if you do not feel comfortable uploading the output to the tracker you could e-mail it to the developer that has claimed the ticket.
A class inheriting this class must implement these data structures :
To resolve MIB leaf name conflicts between private MIBs, you may prefix the leaf name with the MIB replacing each - (dash) and : (colon) with an _ (underscore). For example, ALTEON_TIGON_SWITCH_MIB__agSoftwareVersion would be used as the hash value instead of the net-snmp notation ALTEON-TIGON-SWITCH-MIB::agSoftwareVersion.
When choosing the name for the methods, be aware that other new Sub Modules might inherit this one to get it's features. Try to choose a prefix for methods that will give it's own name space inside the SNMP::Info methods.
To resolve MIB leaf name conflicts between private MIBs, you may prefix the leaf name with the MIB replacing each - (dash) and : (colon) with an _ (underscore). For example, ALTEON_TS_PHYSICAL_MIB__agPortCurCfgPortName would be used as the hash value instead of the net-snmp notation ALTEON-TS-PHYSICAL-MIB::agPortCurCfgPortName.
('MIB-NAME' => 'itemToTestForPresence')
The value for each entry should be a MIB object to check for to make sure that the MIB is present and has loaded correctly.
$info->init() will throw an exception if a MIB does not load.
Sample %MUNGE:
(my_ip => \&munge_ip, my_mac => \&munge_mac, my_layers => \&munge_dec2bin )
Let's make a sample Layer 2 Device subclass. This class will inherit the Cisco Vlan module as an example.
----------------------- snip --------------------------------
# SNMP::Info::Layer2::Sample package SNMP::Info::Layer2::Sample; $VERSION = 0.1; use strict; use warnings; use Exporter; use SNMP::Info::Layer2; use SNMP::Info::CiscoVTP; @SNMP::Info::Layer2::Sample::ISA = qw/SNMP::Info::Layer2 SNMP::Info::CiscoVTP Exporter/; @SNMP::Info::Layer2::Sample::EXPORT_OK = qw//; our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE, $AUTOLOAD, $INIT, $DEBUG); %MIBS = (%SNMP::Info::Layer2::MIBS, %SNMP::Info::CiscoVTP::MIBS, 'SUPER-DOOPER-MIB' => 'supermibobject', ); %GLOBALS = (%SNMP::Info::Layer2::GLOBALS, %SNMP::Info::CiscoVTP::GLOBALS, 'name' => 'supermib_supername', 'favorite_color' => 'supermib_fav_color_object', 'favorite_movie' => 'supermib_fav_movie_val', ); %FUNCS = (%SNMP::Info::Layer2::FUNCS, %SNMP::Info::CiscoVTP::FUNCS, # Super Dooper MIB - Super Hero Table 'super_hero_index' => 'SuperHeroIfIndex', 'super_hero_name' => 'SuperHeroIfName', 'super_hero_powers' => 'SuperHeroIfPowers', ); %MUNGE = (%SNMP::Info::Layer2::MUNGE, %SNMP::Info::CiscoVTP::MUNGE, 'super_hero_powers' => \&munge_powers, ); # Override uptime() method from %SNMP::Info::GLOBALS sub uptime { my $sample = shift; my $name = $sample->name(); # this is silly but you get the idea return '600' if defined $name ; } # Create our own munge function sub munge_powers { my $power = shift; # Take the returned obscure value and return something useful. return 'Fire' if $power =~ /reallyhot/i; return 'Ice' if $power =~ /reallycold/i; # Else return $power; } # Copious Documentation here!!! =head1 NAME =head1 AUTHOR =head1 SYNOPSIS =head1 DESCRIPTION =head2 Inherited Classes =head2 Required MIBs =head1 GLOBALS =head2 Overrides =head1 TABLE METHODS =head2 Overrides =cut 1; # don't forget this line ----------------------- snip --------------------------------
Internal data is stored with bareword keys. For example $info->{debug}
SNMP Data is stored or marked cached with keys starting with an underscore. For example $info->{_name} is the cache for $info->name().
Cached Table data is stored in $info->store() and marked cached per above.
These set the default value for an object upon creation.
%SPEED_MAP = ( '56000' => '56 kbps', '64000' => '64 kbps', '115000' => '115 kbps', '1500000' => '1.5 Mbps', '1536000' => 'T1', '1544000' => 'T1', '2000000' => '2.0 Mbps', '2048000' => '2.048 Mbps', '3072000' => 'Dual T1', '3088000' => 'Dual T1', '4000000' => '4.0 Mbps', '10000000' => '10 Mbps', '11000000' => '11 Mbps', '16000000' => '16 Mbps', '16777216' => '16 Mbps', '20000000' => '20 Mbps', '44210000' => 'T3', '44736000' => 'T3', '45000000' => '45 Mbps', '45045000' => 'DS3', '46359642' => 'DS3', '51850000' => 'OC-1', '54000000' => '54 Mbps', '64000000' => '64 Mbps', '100000000' => '100 Mbps', '149760000' => 'ATM on OC-3', '155000000' => 'OC-3', '155519000' => 'OC-3', '155520000' => 'OC-3', '200000000' => '200 Mbps', '400000000' => '400 Mbps', '599040000' => 'ATM on OC-12', '622000000' => 'OC-12', '622080000' => 'OC-12', '1000000000' => '1.0 Gbps', '2000000000' => '2.0 Gbps', '2488000000' => 'OC-48', '2500000000' => '2.5 Gbps', )
Note: high speed interfaces (usually 1 Gbps or faster) have their link speed in "ifHighSpeed". i_speed() automatically determines whether to use "ifSpeed" or "ifHighSpeed"; if the latter is used, the value is munged by munge_highspeed(). SNMP::Info can return speeds up to terabit levels this way.
TODO: Get the precedence of MIBs and overriding of MIB data in Net-SNMP figured out. Hierarchy/precedence of MIBS in SNMP::Info.
If the element has a value of '1', then that port is included in the set of ports; the port is not included if it has a value of '0'.
If $info->debug() is true, then the error message is carped too.
Store is a hash reference in this format :
$info->store = { attribute => { iid => value , iid2 => value2, ... } };
Example: $info->name() on the first call dispatches to AUTOLOAD() which calls $info->_global('name') creating the method name().
These methods return data as a scalar.
Attr can be passed as either a scalar or a reference to an array or array of arrays when used with set_multi().
Example: $info->set_name('dog',3) uses autoload to resolve to $info->_set('name','dog',3);
Example: $info->set_name('dog',3) dispatches to autoload to resolve to $info->_set('name','dog',3) and _make_setter creates the set_name() method.
Pass either a reference to a 4 element array [<obj>, <iid>, <val>, <type>] or a reference to an array of 4 element arrays to specify multiple values.
<obj> - One of the following forms: 1) leaf identifier (e.g., C<'sysContact'>) 2) An entry in either %FUNCS, %GLOBALS (e.g., 'contact') <iid> - The dotted-decimal, instance identifier. For scalar MIB objects use '0' <val> - The SNMP data value being set (e.g., 'netdisco') <type> - Optional as the MIB should be loaded.
If one of the set assignments is invalid, then the request will be rejected without applying any of the new values - regardless of the order they appear in the list.
Example:
my $vlan_set = [
['qb_v_untagged',"$old_vlan_id","$old_untagged_portlist"],
['qb_v_egress',"$new_vlan_id","$new_egress_portlist"],
['qb_v_egress',"$old_vlan_id","$old_egress_portlist"],
['qb_v_untagged',"$new_vlan_id","$new_untagged_portlist"],
['qb_i_vlan',"$port","$new_vlan_id"],
];
$info->set_multi($vlan_set);
Runs $info->load_METHOD() for each entry in $info->funcs();
Returns $info->store() -- See store() entry.
Note return value has changed since version 0.3
Use $info->load_all() to reload the data.
Note return value has changed since version 0.3
Supports partial table fetches and single instance table fetches. See "Partial Table Fetches" in SNMP::Info.
These methods return data as a reference to a hash.
Accepts the leaf and value (scalar, or hashref for a table). Does not return anything useful.
Accepts the leaf and value (scalar, or hashref for a table) and returns the raw or the munged data, as appropriate. That is, you do not need to know whether MUNGE is installed, and it's safe to call this method regardless.
Calls parent can() first to see if method exists, if not validates that a method should be created then dispatches to the appropriate internal method for creation.
Returns undef if the method does not exist and can not be created.
Each entry in either %FUNCS, %GLOBALS, or MIB Leaf node names present in loaded MIBs are used by AUTOLOAD() to create dynamic methods.
Override any dynamic method listed in %GLOBALS, %FUNCS, or MIB Leaf node name a by creating a subroutine with the same name.
For example to override $info->name() create `` sub name {...}'' in your subclass.
Changes from SNMP::Info Version 0.7 and on are: Copyright (c) 2003-2010 Max Baker and SNMP::Info Developers All rights reserved.
Original Code is: Copyright (c) 2002-2003, Regents of the University of California All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the University of California, Santa Cruz nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2023-09-30 | perl v5.36.0 |