SNMP::Class is a Perl module aims to enable snmp-related tasks to be carried out with the best possible ease and expressiveness while at the same time allowing advanced features like subclassing to be used without hassle.
use SNMP::Class;
#create a session to a managed device --
#community will default to public, version will be autoselected from 2,1
my $s = SNMP::Class->new({DestHost => 'myhost'});
#modus operandi #1
#walk the entire table
my $ifTable = $s->walk("ifTable");
#-more compact-
my $ifTable = $s->ifTable;
#get the ifDescr.3
my $if_descr_3 = $ifTable->object("ifDescr")->instance("3");
#more compact
my $if_descr_3 = $ifTable->object(ifDescr).3;
#iterate over interface descriptions -- method senses list context and returns array
for my $descr ($ifTable->object"ifDescr")) {
print $descr->get_value,"\n";
}
#get the speed of the instance for which ifDescr is en0
my $en0_speed = $ifTable->find("ifDescr","en0")->object("ifSpeed")->get_value;
#
#modus operandi #2 - list context
while($s->ifDescr) {
print $_->get_value;
}
Requirements:
· Perl