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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SNMP get request error
by kcott (Archbishop) on Mar 22, 2014 at 05:58 UTC | |
by thanos1983 (Parson) on Mar 22, 2014 at 18:27 UTC | |
by kcott (Archbishop) on Mar 23, 2014 at 04:57 UTC | |
by thanos1983 (Parson) on Mar 25, 2014 at 12:15 UTC | |
|
Re: SNMP get request error
by ww (Archbishop) on Mar 22, 2014 at 12:42 UTC | |
by thanos1983 (Parson) on Mar 22, 2014 at 18:05 UTC | |
by ww (Archbishop) on Mar 22, 2014 at 18:32 UTC | |
by thanos1983 (Parson) on Mar 23, 2014 at 02:14 UTC |