Hello Monks,

I am writing a script that will check date/time on a network device. I am using Net::SNMP module to walk the OID for the current time on the device and then will compare it against current time on a server..However, whenever i walk the switch for the time, the return value comes back as 1 instead of the actual value. I can manually walk the switch, or use system call to invoke snmpwalk, but since i need to do this on a couple of thousand of devices i am really trying to stick with SNMP module. Any ideas of what i am doing wrong?

# /usr/bin/perl use warnings; use strict; use Net::SNMP; use Data::Dumper; my $oid= '1.3.6.1.4.1.1588.2.1.1.1.1.1'; my $host="host1.testdoman.com"; my $community='test'; my ($session, $error) = Net::SNMP->session( -hostname => $host, -community =>$community, -nonblocking => 1, ); my $result = $session->get_request(-varbindlist => [ $oid ],); if (!defined $result) { $error = $session->error(); print "GET_REQUEST ERROR: $error\n"; $session->close(); exit(1); } print Dumper $result; $session->close; exit(0);

Just to illustrate what output i am expecting. The following code invokes snmpwalk utility and produces the desired output:

# /usr/bin/perl use warnings; use strict; my $community='test'; my $host= "host1.testdoman.com"; my $Time = `snmpwalk -v1 -c $community $host 1.3.6.1.4.1.1588.2.1.1.1 +.1.1`; print $Time;

SNMPv2-SMI::enterprises.1588.2.1.1.1.1.1.0 = STRING: "Fri Oct 25 07:23:33 2013 "

However, when i try to use the Net:SNMP module it produces output $VAR1 = 1;

Any help would be appreciated!!

Thanks in advance


In reply to Perl Net::SNMP returns 1 instead of the desired outcome by vlad3848

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.