Subject: | Fetch first entry bug |
Hello Sébastien,
I'm using your module in pass persist mode through this kind of config.
pass_persist .1.3.6.1.4.1.2021.51 /etc/snmp/test.pl
The tree I need to get with a walk is of kind
'.1.3.6.1.4.1.2021.51.1',
'.1.3.6.1.4.1.2021.51.2.1',
'.1.3.6.1.4.1.2021.51.2.2',
'.1.3.6.1.4.1.2021.51.4'
Without any change the first OID I get with a walk to
".1.3.6.1.4.1.2021.51" is the 51.2.1 node. It should be "51.1".
I corrected it changing the code block
# prefix match of the requested entry
$curr_entry_idx = $i - 1
if index($entries->[$i], $req_oid) >= 0 and $curr_entry_idx
== -1;
by
# prefix match of the requested entry
$curr_entry_idx = $i - 1
if index($entries->[$i], $req_oid) >= 0 and $curr_entry_idx
== -1 and $i == 0;
Anmyway, in my case the module should return the first entry of the
sorted tree and I'm sure it could be done in the code in any other way.
BR
Aymeric BLAZY
test.pl:
#!/usr/bin/perl
use strict;
use warnings;
use SNMP::Extension::PassPersist;
my $extsnmp = SNMP::Extension::PassPersist->new(
backend_collect => \&update_tree,
idle_count => 10, # no more than 10 idle cycles
refresh => 10, # refresh every 10 sec
);
my $oid = ".1.3.6.1.4.1.2021.51.";
sub update_tree {
$extsnmp->add_oid_entry($oid."1", "string", "TEST");
$extsnmp->add_oid_entry($oid."2.1", "string", "2.1");
$extsnmp->add_oid_entry($oid."2.2", "string", "2.2");
$extsnmp->add_oid_entry($oid."4", "integer", 1);
}
# run the program
$extsnmp->run;