Subject: | Options parameter not working with gettable |
Date: | Wed, 25 Mar 2015 18:13:52 +0000 |
To: | bug-SNMP [...] rt.cpan.org |
From: | Sean <seanb99 [...] gmail.com> |
Hi,
I'm running:
SNMP 5.05
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Perl v5.10.1 (*) built for x86_64-linux-thread-multi
Running gettable with <OPTIONS> I get the following error:
Odd number of elements in anonymous hash at
/usr/lib64/perl5/vendor_perl/SNMP.pm line 684.
E.g. using the following to get the storage table (where the arguments are
hosts):
#!/usr/bin/perl
use SNMP;
use Data::Dumper;
foreach (@ARGV) {
my $session = new SNMP::Session ('DestHost' => $_,
'Community' => 'public',
'Version' => 1);
my $result = $session->gettable('hrStorageTable',
{ 'columns' => ['hrStorageDescr', 'hrStorageType'] } );
print Dumper($result);
}
Gives the following output (truncated):
$ ./testsnmp.pl hostname
Odd number of elements in anonymous hash at
/usr/lib64/perl5/vendor_perl/SNMP.pm line 684.
$VAR1 = {
'6' => {
'hrStorageSize' => '65528',
'hrStorageAllocationUnits' => '65536',
'hrStorageUsed' => '22584',
'hrStorageAllocationFailures' => '0',
'hrStorageDescr' => 'Physical Memory',
'hrStorageIndex' => '6',
'hrStorageType' => 'hrStorageRam'
},
This returns all fields, so is ignoring the <OPTIONS> parameter.
Running without the <OPTIONS> parameter, I don't get the error.
Looking at line 684 in SNMP.pm, it looks like this is because it's
expecting an array instead of a hash, although the documentation states
that <OPTIONS> should be a hash.
Looking at the current version on CPAN, this is line 670. My suggested fix
is as follows:
$ diff SNMP.pm SNMP-new.pm
669,670c669,670
< my ($this, $root_oid, @options) = @_;
< $state->{'options'} = {@options};
---
Show quoted text
> my ($this, $root_oid, $options) = @_;
> $state->{'options'} = $options;
This fix gives the expected results - i.e. it honours the 'columns' option
when set.
Not sure if this is right fix, but it works for me.
Sean.