'snmp_community' => { 'label'=>'Community', 'default'=>'public' },
'snmp_timeout' => { label=>'Timeout (seconds)', 'default'=>1 },
'snmp_oid' => { label=>'Object ID', multiple=>1 },
+ 'snmp_oid_name' => { label=>'Object Name', multiple=>1 },
;
%info = (
my $vers = $self->option('snmp_version');
my $time = ($self->option('snmp_timeout') || 1) * 1000000;
my @oids = split("\n", $self->option('snmp_oid'));
+ my @oidnames = split("\n", $self->option('snmp_oid_name'));
my %connect = (
'DestHost' => $host,
'Community' => $comm,
return { 'error' => 'Error creating SNMP session' } unless $snmp;
return { 'error' => $snmp->{'ErrorStr'} } if $snmp->{'ErrorStr'};
my @out;
- foreach my $oid (@oids) {
+ for (my $i=0; $i <= $#oids; $i++) {
+ my $oid = $oids[$i];
+ my $oidname = $oidnames[$i];
$oid = $SNMP::MIB{$oid}->{'objectID'} if $SNMP::MIB{$oid};
my @values;
if ($vers eq '1') {
my $varbind = new SNMP::Varbind [$oid];
my $max = 1000; #sanity check
- while ($max > 0 and $snmp->getnext($varbind)) {
+ while ($max > 0 and defined($snmp->getnext($varbind))) {
last if $snmp->{'ErrorStr'};
last unless $SNMP::MIB{$varbind->[0]}; # does this happen?
my $nextoid = $SNMP::MIB{$varbind->[0]}->{'objectID'};
last unless $nextoid =~ /^$oid/;
$max--;
- push @values, new SNMP::Varbind [ @$varbind ];
+ push @values, [ @$varbind ];
}
} else {
# not clear on what max-repeaters (25) does, plucked value from example code
# but based on testing, it isn't capping number of returned values
- @values = $snmp->bulkwalk(0,25,$oid);
+ my ($values) = $snmp->bulkwalk(0,25,$oid);
+ @values = @$values if $values;
}
if ($snmp->{'ErrorStr'} || !@values) {
push @out, { 'error' => $snmp->{'ErrorStr'} || 'No values retrieved' };
next;
}
my %result = map { $_ => $SNMP::MIB{$oid}{$_} } qw( objectID label );
+ $result{'name'} = $oidname;
# unbless @values, for ease of JSON encoding
$result{'values'} = [];
foreach my $value (@values) {