thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:

While I was implementing a simple program I came accross with the following error:

Problem with session get request: The OBJECT IDENTIFIER value "ARRAY(0 +x942c50)" is expected in dotted decimal notation.

I tried to find online the reason that appears but not successfully. It is like no one has ever encounter this problem. Or maybe I can not find a relevant report at least.

The program is a very simple Net::SNMP->session request

my @info = split(/:/, $IP); # initiate snmp session ($session, $error) = Net::SNMP->session( -hostname => $info[0], -port => $info[1], -nonblocking => $boolean, -version => $version, -domain => $domain, -timeout => $seconds, -retries => $count, -maxmsgsize => $octets, -translate => $translate, -community => $community, ); if (!defined ($session)) { printf "Problem: %s.\n", $error; exit 1; } print Dumper(\$session);

I printed the $session with Dumper in order to possibly detect the error and I came across with something strange:

$VAR1 = \bless( { '_translate' => 0, '_security' => bless( { '_error' => undef, '_community' => 'public', '_version' => 0 }, 'Net::SNMP::Security::Comm +unity' ), '_transport_argv' => [ '-retries', '2', '-hostname', '127.0.0.1', '-port', '161', '-maxmsgsize', '1472', '-domain', 'udp/ipv4', '-timeout', '3' ], '_pdu' => undef, '_callback' => undef, '_nonblocking' => 0, '_version' => 0, '_transport' => bless( { '_dest_name' => '� +', '_max_msg_size' => 1472, '_sock_name' => '', '_timeout' => 3, '_error' => undef, '_sock_hostname' => '', '_dest_hostname' => '127.0 +.0.1', '_socket' => bless( \*Symb +ol::GEN0, 'IO::Socket' ), '_retries' => 2 }, 'Net::SNMP::Transport::IP +v4::UDP' ), '_error' => undef, '_context_engine_id' => undef, '_context_name' => undef, '_delay' => 0, '_discovery_queue' => [], '_hostname' => '127.0.0.1' }, 'Net::SNMP' );

The strange part is that although that IP and port at the -hostname and -port are read normally. But later on it appears like the characters have wrong format.

I noticed that here where I post the code you can not observe the funny characters, so I will try to describe them based on the location.

'_dest_name' => '�', '_sock_name' => '',

They appear on this two locations.

Has anyone ever encounter this problem? Any suggestions would be much appreciated.

Thank you in advance for your time and effort.

UPDATE: Thank you Perl Monks for your assistance and support. I wanted to post my solution just in case that someone else has the same problem with me.

This is a simple of SNMP get_request() taken from Net::SNMP.

The code is the following:

#! /usr/local/bin/perl use strict; use warnings; use Net::SNMP; use Data::Dumper; #use Net::SNMP qw (:snmp); my $OID_sysUpTime = '1.3.6.1.2.1.1.3.0'; my $OID_sysDescr = '1.3.6.1.2.1.1.1.0'; my @request; my ($session, $error) = Net::SNMP->session( -hostname => shift || 'localhost', -community => shift || 'public', ); if (!defined $session) { printf "ERROR: %s.\n", $error; exit 1; } #@request = ('1.3.6.1.2.1.1.3.0'); #push @request, '1.3.6.1.2.1.1.3.0'; #print Dumper(@request); push (@request, ($OID_sysDescr,$OID_sysUpTime)); my $result = $session->get_request( -varbindlist => [ @request ], ); if (!defined $result) { printf "ERROR: %s.\n", $session->error(); $session->close(); exit 1; } printf "The sysUpTime and sysDescr for host '%s' is %s and %s.\n", $session->hostname(), $result->{$OID_sysUpTime}, $result->{$OID_sysDescr}; $session->close(); exit 0;

My code had small differences from CPAN but something interesting to notice is to send less as possible SNMP get_request(). On my code I use an @array to put all the OID addresses together in on request.

I hope that will help someone else beginner like me in the future.

  • Comment on ERROR: The OBJECT IDENTIFIER value "ARRAY(0x1b80628)" is expected in dotted decimal notation.
  • Select or Download Code

Replies are listed 'Best First'.
Re: SNMP get request error
by kcott (Archbishop) on Mar 22, 2014 at 05:58 UTC

    G'day thanos1983,

    [Disclaimer: I'm not a user of Net::SNMP. The following information just comes from that module's documentation.]

    That problem seems to be related to the value of the -varbindlist argument in a call to get_request() (or a related method, e.g. get_next_request()).

    Have you shown the entirety of the error message? Was there any reference to the file or line number that generated that error? Without that sort of information, it's difficult to track down the problem remotely.

    Have a look in Net::SNMP::get_request() for information about "OBJECT IDENTIFIERs" and the -varbindlist argument. There's also example code here.

    See also the EXAMPLES section which has a lot more sample code.

    -- Ken

      To: Ken,

      Thanks Ken, for your advices. You gave the idea of creating a small example and apply my code in order to find the real problem.

      I has an extra "\" at the point:

      push (@request, ($sysDescr,$sysUpTime)); $output = $session->get_request( -varbindlist => [\@request] , );

      When I removed the "\" everything worked perfectly

      Well the problem is that I do not exactly understand the reference part from CPAN where it says:

      "This list is passed to the method as an array reference using the -varbindlist argument."

      Thank you for your time and effore regarding my query. Since I am begginer I have so many questions and so many errors that I can not understand fast.

        "Since I am begginer I have so many questions and so many errors that I can not understand fast."

        I recommend you read "Perl introduction for beginners".

        You haven't shown enough of your test script but, if you're using

        push (@request, ($sysDescr,$sysUpTime));

        to create the @request array, that document will show you a better way:

        my @request = ($sysDescr, $sysUpTime);

        Perl will tell you about many of the problems in your code if you ask it to. Often these problems are the result of simple typos and have nothing to do with your proficiency with the language. Just add these two lines at the top of all your scripts (as I always do):

        use strict; use warnings;

        If you're having difficulties understanding the short messages that are produced by those, you can add this (although I'd advise against leaving that line in production code):

        use diagnostics;

        Another useful one, if your script is performing any I/O, is this (which I often use):

        use autodie;

        All of those are documented in Pragmas.

        "Well the problem is that I do not exactly understand the reference part ..."

        I recommend you read "Perl references short introduction".

        Specifically with [\@request], you're taking a reference to @request (i.e. \@request); then you create an anonymous array (with [...]) whose only element is an array reference. By removing the '\' (i.e. [@request]), you create an anonymous array whose elements are the values in @request.

        Another way of doing this would have been to remove the brackets instead of the backslash (i.e. change [\@request] to \@request). However, there's a subtle difference: [...] creates a new array reference; \@array creates a reference to an existing array. The following script may help in understanding this.

        #!/usr/bin/env perl -l use strict; use warnings; my @array = (1, 2, 3); my $array_ref_1 = \@array; my $array_ref_2 = [@array]; my $array_ref_3 = [1, 2, 3]; my $array_ref_ref = [\@array]; use Data::Dumper; print '*** $array_ref_1 = \@array ***'; print Dumper $array_ref_1; print '*** $array_ref_2 = [@array] ***'; print Dumper $array_ref_2; print '*** $array_ref_3 = [1, 2, 3] ***'; print Dumper $array_ref_3; print '*** $array_ref_ref = [\@array] ***'; print Dumper $array_ref_ref; my $array_ref_1_new = \@array; my $array_ref_2_new = [@array]; my $array_ref_3_new = [1, 2, 3]; print "\n"; print 'SAME: $array_ref_1 and $array_ref_1_new'; print "SAME: $array_ref_1 and $array_ref_1_new"; print "\n"; print 'DIFF: $array_ref_2 and $array_ref_2_new'; print "DIFF: $array_ref_2 and $array_ref_2_new"; print "\n"; print 'DIFF: $array_ref_3 and $array_ref_3_new'; print "DIFF: $array_ref_3 and $array_ref_3_new"; print "\n"; print 'SAME: $array_ref_1 and $array_ref_1_new and $array_ref_ref->[0] +'; print "SAME: $array_ref_1 and $array_ref_1_new and $array_ref_ref->[0] +";

        Output:

        *** $array_ref_1 = \@array *** $VAR1 = [ 1, 2, 3 ]; *** $array_ref_2 = [@array] *** $VAR1 = [ 1, 2, 3 ]; *** $array_ref_3 = [1, 2, 3] *** $VAR1 = [ 1, 2, 3 ]; *** $array_ref_ref = [\@array] *** $VAR1 = [ [ 1, 2, 3 ] ]; SAME: $array_ref_1 and $array_ref_1_new SAME: ARRAY(0x7fa0f202a628) and ARRAY(0x7fa0f202a628) DIFF: $array_ref_2 and $array_ref_2_new DIFF: ARRAY(0x7fa0f2029c68) and ARRAY(0x7fa0f210e2a8) DIFF: $array_ref_3 and $array_ref_3_new DIFF: ARRAY(0x7fa0f2029d40) and ARRAY(0x7fa0f20ca2f0) SAME: $array_ref_1 and $array_ref_1_new and $array_ref_ref->[0] SAME: ARRAY(0x7fa0f202a628) and ARRAY(0x7fa0f202a628) and ARRAY(0x7fa0 +f202a628)

        -- Ken

Re: SNMP get request error
by ww (Archbishop) on Mar 22, 2014 at 12:42 UTC

    IMO, it seems likely that "funny characters" means you're dealing (or more precisely, 'not dealing') with a character-set issue -- "There are Seven character encoding schemes in Unicode: UTF-8, UTF-16, UTF-16BE, UTF-16LE, UTF-32 (UCS-4), UTF-32BE (UCS-4BE) and UTF-32LE ...."

    See perldoc -f encode. The module Encode::Guess may be helpful.


    Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
    1. code
    2. verbatim error and/or warning messages
    3. a coherent explanation of what "doesn't work actually means.

      Thank you for the advices, I am new to the area of programming so maybe I did not explain my problem. When I am executing my code it prints on the terminal:

      Problem with session get request: The OBJECT IDENTIFIER value "ARRAY(0 +x942c50)" is expected in dotted decimal notation.

      While I was trying to debug my code, I put a print Dumper(\$session); so I could actually see in further analysis what is happenning. When I did that I saw on the terminal:

      $VAR1 = \bless( { '_translate' => 0, '_security' => bless( { '_error' => undef, '_community' => 'public', '_version' => 0 }, 'Net::SNMP::Security::Comm +unity' ), '_transport_argv' => [ '-retries', '2', '-hostname', '127.0.0.1', '-port', '161', '-maxmsgsize', '1472', '-domain', 'udp/ipv4', '-timeout', '3' ], '_pdu' => undef, '_callback' => undef, '_nonblocking' => 0, '_version' => 0, '_transport' => bless( { '_dest_name' => '� +', '_max_msg_size' => 1472, '_sock_name' => '', '_timeout' => 3, '_error' => undef, '_sock_hostname' => '', '_dest_hostname' => '127.0 +.0.1', '_socket' => bless( \*Symb +ol::GEN0, 'IO::Socket' ), '_retries' => 2 }, 'Net::SNMP::Transport::IP +v4::UDP' ), '_error' => undef, '_context_engine_id' => undef, '_context_name' => undef, '_delay' => 0, '_discovery_queue' => [], '_hostname' => '127.0.0.1' }, 'Net::SNMP' );

      At this point I saw the funny characters. Based on experimentation I found the error. I did not know include the request:

      push (@request, ($sysDescr,$sysUpTime)); $output = $session->get_request( -varbindlist => [\@request] , );

      When I removed the "\" it works just fine. I can not exaclty understand the error or the reason but based on what I have read is the reference on the hash.

      Based on the documentation from CPAN

      "This list is passed to the method as an array reference using the -varbindlist argument."

      But I can not completely understand why if I remove the "\" it works.

      Thanks in advance for your time,advices and assistance to my query

        "When I removed the "\" it works just fine. I can not exaclty (sic) understand the error or the reason...."

        The backslash "\" you removed was escaping the "@" sigil, identifying your variable. That prevented Perl from understanding what you wanted.

        Without getting into referencing and dereferencing, observe what happens with a simple array:

        #!/usr/bin/perl use 5.016; use strict; use warnings; my @foo = ("bar", "baz", "bat"); say "\@foo with the backslash is: \@foo"; say "\@foo without the slash is @foo"; =head C:\>thanos.pl @foo with the backslash is: @foo # i.e., the escape makes it print as + a literal "@" here @foo without the slash is bar baz bat # but here, Perl gives you the +values in @foo! =cut

        In other words, be alert to the different uses of the "\" and the "/".

        For your precise case (and you seem to have done most of your homework here), see:

        1. perldoc perlref read down to referencing and dereferencing.
        2. References quick reference and look for the slash

        Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
        1. code
        2. verbatim error and/or warning messages
        3. a coherent explanation of what "doesn't work actually means.