here's my basic code:
guru> cat test #!/opt/local/bin/perl
use strict; use warnings; use Data::Dumper; use SNMP;
my $obj = "sysDescr"; my $read = "public"; my ($sess, $val, $vb);
my %esx = ( "10.10.22.8" => "b2-esx",
"10.10.16.8" => "a1-esx",
"10.10.18.8" => "a2-esx",
"10.10.20.8" => "a3-esx",
);for my $addr (keys %esx) {
print "Processing $addr\n";
$sess = new SNMP::Session ( Community => $read,
DestHost => $addr,
);
$vb = new SNMP::Varbind([$obj]);
$val = $sess->bulkwalk('0', '10000', $vb);
($val) = $sess->bulkwalk('0', '10000', $obj);
print Dumper($val);
print "Finished $addr\n";
}
guru>
guru> ./test
Processing 10.10.18.8
$VAR1 = [
'10.10.18.8',
'10.10.22.8',
'10.10.20.8',
'10.10.16.8',
bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' )
];
Finished 10.10.18.8
Processing 10.10.22.8
$VAR1 = [
bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' )
];
Finished 10.10.22.8
Use of freed value in iteration at ./test line 27.
guru>so this, produces a weird data structure on the first pass, and then Perl dies with the 'Use of freed value in iteration' error.
ok, so if i change the hash to an array:
#!/opt/local/bin/perl
use strict; use warnings; use Data::Dumper; use SNMP;
my $obj = "sysDescr"; my $read = "public"; my ($sess, $val, $vb);
my @esx = qw /10.10.16.8 10.10.18.8 10.10.20.8 10.10.22.8/;
for my $esx (@esx) {
my $addr = $esx;
print "Processing $addr\n";
$sess = new SNMP::Session ( Community => $read,
DestHost => $addr,
);
$vb = new SNMP::Varbind([$obj]);
$val = $sess->bulkwalk('0', '10000', $vb);
print Dumper($val);
}
guru>
guru> ./test-array
Processing 10.10.16.8
$VAR1 = [
'1',
bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' )
];
Processing 10.10.18.8
$VAR1 = [
bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' )
];
Processing 10.10.20.8
$VAR1 = [
bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' )
];
Processing 10.10.22.8
$VAR1 = [
bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' )
];
guru>then the very first data structure is weird ... notice the '1' part:
$VAR1 = [
'1',
bless( [but the rest of the data structures seem normal to me, and Perl doesn't encounter in the 'freed value' problem.
if i invoke bulkwalk on a simple scalar, rather than on a Varbind, the issue goes away entirely:
#!/opt/local/bin/perl
use strict; use warnings; use Data::Dumper; use SNMP;
my $obj = "sysDescr"; my $read = "public"; my ($sess, $val, $vb);
my %esx = ( "10.10.22.8" => "b2-esx",
"10.10.16.8" => "a1-esx",
"10.10.18.8" => "a2-esx",
"10.10.20.8" => "a3-esx",
);for my $addr (keys %esx) {
print "Processing $addr\n";
$sess = new SNMP::Session ( Community => $read,
DestHost => $addr,
);
# $vb = new SNMP::Varbind([$obj]);
# $val = $sess->bulkwalk('0', '10000', $vb);
($val) = $sess->bulkwalk('0', '10000', $obj);
print Dumper($val);
print "Finished $addr\n";
}
guru>
guru> ./test
Processing 10.10.18.8
$VAR1 = bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' );
Finished 10.10.18.8
Processing 10.10.22.8
$VAR1 = bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' );
Finished 10.10.22.8
Processing 10.10.20.8
$VAR1 = bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' );
Finished 10.10.20.8
Processing 10.10.16.8
$VAR1 = bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' );
Finished 10.10.16.8
guru>the data structures are well-formed, and Perl doesn't encounter the 'freed value' issue.
however, this only works under net-snmp-5.0.9. under net-snmp-5.1.2.rc2, Dumper tells me that $VAR1 is undefined for every instance.
now then, let's say that i pretend that bulkwalk is returning two arrays, not one:
guru> cat test #!/opt/local/bin/perl
use strict; use warnings; use Data::Dumper; use SNMP;
my $obj = "sysDescr"; my $read = "public"; my ($sess, $val1, $val2, $vb);
my %esx = ( "10.10.22.8" => "b2-esx",
"10.10.16.8" => "a1-esx",
"10.10.18.8" => "a2-esx",
"10.10.20.8" => "a3-esx",
);for my $addr (keys %esx) {
print "Processing $addr\n";
$sess = new SNMP::Session ( Community => $read,
DestHost => $addr,
);
$vb = new SNMP::Varbind([$obj]);
($val1, $val2) = $sess->bulkwalk('0', '10000', $vb);
# ($val) = $sess->bulkwalk('0', '10000', $obj);
print "Dumping val1\n";
print Dumper($val1);
print "Dumping val2\n";
print Dumper($val2);
print "Finished $addr\n";
}
guru> ./test
Processing 10.10.18.8
Dumping val1
$VAR1 = bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' );
Dumping val2
$VAR1 = undef;
Finished 10.10.18.8
Processing 10.10.22.8
Dumping val1
$VAR1 = bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' );
Dumping val2
$VAR1 = undef;
Finished 10.10.22.8
Processing 10.10.20.8
Dumping val1
$VAR1 = bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' );
Dumping val2
$VAR1 = undef;
Finished 10.10.20.8
Processing 10.10.16.8
Dumping val1
$VAR1 = bless( [
bless( [
'sysDescr',
'0',
'Cisco Systems, Inc. WS-C4006
Cisco Catalyst Operating System Software, Version 7.6(7)
Copyright (c) 1995-2004 by Cisco Systems, Inc.
',
'OCTETSTR'
], 'SNMP::Varbind' )
], 'SNMP::VarList' );
Dumping val2
$VAR1 = undef;
Finished 10.10.16.8
guru>
then, things start working as i expect them to.
-i don't understand why the bulkwalk method will take a simple scalar ... i thought it required a Varbind ... i don't understand what a Varbind is ... but hey, thus far, until now, if i handed one to bulkwalk, i got back what i want.
-i don't understand why bulkwalk is returning two 'things' to me ... is it supposed to? and what would i do with $val2 ... if it did contain something?
insights appreciated.
--sk
stuart kendrick fhcrc
------------------------------------------------------- This SF.Net email is sponsored by OSTG. Have you noticed the changes on Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, one more big change to announce. We are now OSTG- Open Source Technology Group. Come see the changes on the new OSTG site. www.ostg.com _______________________________________________ Net-snmp-users mailing list [EMAIL PROTECTED] Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users
