SNMP: The Object-Oriented Way
The SNMP::Info Perl package was developed at the University of California, Santa Cruz. The official web site for this package is http://snmp-info.sourceforge.net.
SNMP::Info is based on the Net-SNMP Perl module. It allows you to obtain various information from a device without having to know any OIDs, MIBs, etc., and it does so with object orientation (OO). How does it do this? It supports a well-developed list of MIBs, and it can discover the type of device you are trying to query. If it knows about the device, you can use predefined methods to get interface information and other things. Here's an example script that gathers information about interfaces on a switch:
#!/usr/bin/perl use SNMP::Info; my $info = new SNMP::Info( # Auto Discover more specific Device Class AutoSpecify => 1, Debug => 0, # The rest is passed to SNMP::Session DestHost => '192.168.0.148', 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; $name = $info->name(); $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}; ...
Get Essential SNMP, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.