Menu

#1644 SNMP.pm RetryNoSuch doesn't work as documented

linux
open
nobody
perl (81)
5
2018-04-23
2006-08-01
No

The SNMP.pm perldoc (and
http://www.net-snmp.org/docs/perl-SNMP-README.html\) has:

RetryNoSuch

default '0', if enabled NOSUCH errors in 'get' pdus will be
repaired, removing the varbind in error, and resent - undef will be
returned for all NOSUCH varbinds, when set to '0' this feature is
disabled and the entire get request will fail on any NOSUCH error
applies to v1 only)

However, this is not true. If 3 varbinds are supplied
where the second replies with NOSUCH, exactly two
values are returned, (val1, val3), not (val1, undef,
val2). Also the supplied $varbind is mangled
accordingly, as the next example shows.

The consequence is that one needs to keep a deep copy
of the VarList, and then compare the OID after the get,
to find which ones have a value and which are undef.

At the very least, this is contrary to the
documentation. After having read that, I expected to
see values like (val1, undef, val3).

---------------- Reproducing script ---------

use Data::Dumper;
use SNMP;

my $sess = new SNMP::Session\(DestHost => 'localhost', 
                 Community => public,
                 Version=>1,
                 RetryNoSuch=>1,
                \);

my $vars = new SNMP::VarList \( \['ifInOctets','1'\], 
                   \['ifInOctets','2745523'\], 
                   \['ifInOctets','2'\]        \);

printf "perl Version is: %vd\n", $^V;  \# Perl's version
print "SNMP Version is: $SNMP::VERSION\n";

print Dumper\($vars\);
my @vals = $sess->get\($vars\);
print Dumper\($vars, \@vals\);

Discussion

  • Peter Valdemar Mørch

    Logged In: YES
    user_id=740837

    Forgot to supply the output:

    perl Version is: 5.8.8
    SNMP Version is: 5.2.2
    $VAR1 = bless( [
    bless( [
    'ifInOctets',
    '1'
    ], 'SNMP::Varbind' ),
    bless( [
    'ifInOctets',
    '2745523'
    ], 'SNMP::Varbind' ),
    bless( [
    'ifInOctets',
    '2'
    ], 'SNMP::Varbind' )
    ], 'SNMP::VarList' );
    $VAR1 = bless( [
    bless( [
    'ifInOctets',
    '1',
    '3480446094',
    'COUNTER'
    ], 'SNMP::Varbind' ),
    bless( [
    'ifInOctets',
    '2',
    '1787504796',
    'COUNTER'
    ], 'SNMP::Varbind' ),
    bless( [
    'ifInOctets',
    '2'
    ], 'SNMP::Varbind' )
    ], 'SNMP::VarList' );
    $VAR2 = [
    '3480446094',
    '1787504796'
    ];

     
  • Peter Valdemar Mørch

    Logged In: YES
    user_id=740837

    # And here is a workaround sub
    # (for others with the same problem)
    # It illustrates what I hoped was going to happen
    #
    sub snmpGetRetryNoSuch {
    my ($sess, $varlist) = @_;

    #
    # Version=>1 is the only version with this problem
    #
    if ($sess->{Version} ne '1') {
    return $sess->get($varlist);
    }

    die 'Please dont use $sess->{RetryNoSuch}'
    if $$sess{RetryNoSuch};

    # Make a deep copy of the supplied varlist - SNMP.pm will
    mangle
    # that copy... (Faster way to do this, anyone?)
    require Data::Dumper;
    my $d = Data::Dumper->new([$varlist], ['varlistCopy']);
    $d->Deepcopy(1);
    my $varlistCopy;
    eval $d->Dump();
    die $@
    if $@;

    # Keep track of what indices in $varlistCopy are the same
    entries as
    # the ones in $varlist. Initially $varlist->[N] and
    # $varlistCopy->[N] point the to the same objects, but
    that won't be
    # true once we start splicing in $varlistCopy.
    my @origIndices = (0..scalar(@$varlist)-1);
    my $continueDoWhileLoop = 1;
    while ($continueDoWhileLoop) {
    $sess->get($varlistCopy);
    if ($sess->{ErrorStr} =~ /^\(noSuchName\)/) {
    splice @$varlistCopy, $sess->{ErrorInd}-1,1;
    splice @origIndices, $sess->{ErrorInd}-1,1;
    } else {
    $continueDoWhileLoop = 0;
    }
    }
    # Now, $varlistCopy may have had some entries removed, whereas
    # $varlist will have all of them, just without the values.
    Lets put
    # the values back in varlist.
    foreach my $i (0..$#origIndices) {
    $$varlist[$origIndices[$i]] = $$varlistCopy[$i];
    }
    # Now lets create a proper return value with undefs where they
    # belong.
    my @retvals;
    foreach (@$varlist) {
    push @retvals, $_->[2];
    }
    return @retvals;
    }

     
  • Peter Valdemar Mørch

    Really? Sourceforge has "improved" its website and as a consequence, all code in comments has lost all formatting? For real?

     

    Last edit: Peter Valdemar Mørch 2018-04-19
  • Bill Fenner

    Bill Fenner - 2018-04-23
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -4,12 +4,9 @@
     RetryNoSuch
    
     default '0', if enabled NOSUCH errors in 'get' pdus will be
    -repaired, removing the varbind in error, and resent -
    -undef will be
    -returned for all NOSUCH varbinds, when set to '0' this
    -feature is
    -disabled and the entire get request will fail on any
    -NOSUCH error
    +repaired, removing the varbind in error, and resent - undef will be
    +returned for all NOSUCH varbinds, when set to '0' this feature is
    +disabled and the entire get request will fail on any NOSUCH error
     applies to v1 only\)
    
     However, this is not true. If 3 varbinds are supplied
    @@ -28,6 +25,8 @@
    
     \---------------- Reproducing script ---------
    
    +
    +~~~perl
     use Data::Dumper;
     use SNMP;
    
    @@ -47,3 +46,4 @@
     print Dumper\($vars\);
     my @vals = $sess->get\($vars\);
     print Dumper\($vars, \@vals\);
    +~~~
    
     
  • Bill Fenner

    Bill Fenner - 2018-04-23

    Reformat per "improved" SourceForge formatting

     
  • Peter Valdemar Mørch

    I appreciate the effort, Bill. Thanks.

    Don't bother reformatting this, but: The problem seems to be that there has been a bulk reformat of all descriptions and comments. Now, in the "improved" description, every ( and ) is backslashed (and the code therefore is filled with syntax errors), and I'm 100% certain they weren't like that when I posted them way back when. And my comments (including a workaround) are also garbage-formatted now. Without even giving me, the author, a chance to fix the bad formatting.

    Does the net-snmp team have any plans to ditch SourceForge for something better? A tool that doesn't so carelessly degrade the quality of project history?

     

    Last edit: Peter Valdemar Mørch 2018-04-23

Log in to post a comment.