Hello, Monks! My question about using SNMP via perl. I trynig to get some values from snmp (I use net-snmp-5.2.1), and write simple script for this:
#!/usr/bin/perl -w # vi:ts=4:sw=4 use strict; use Getopt::Long; use SNMP::Simple; our %opt = ( DestHost => 'localhost', Community => 'public', Version => 1, Timeout => 1_000_000, ); our $oid; GetOptions( 'h|host=s' => \$opt{DestHost}, 'c|community=s' => \$opt{Community}, 'v|version=i' => \$opt{Version}, 't|timeout=i' => \$opt{Timeout}, 'o|oid=s' => \$oid, ); our $snmp = SNMP::Simple->new(%opt); print $snmp->get($oid), "\n";
When I run this - results is same as from snmpwalk for some queries:
% snmpwalk -v 1 -c public localhost dskDevice.1 UCD-SNMP-MIB::dskDevice.1 = STRING: /dev/sda3 % ./snmp_get -o dskDevice.1 /dev/sda3
But for system date it's different:
% snmpwalk -v 1 -c public localhost hrSystemDate.0 HOST-RESOURCES-MIB::hrSystemDate.0 = STRING: 2006-3-6,16:18:27.0,+2:0 % ./snmp_get -o hrSystemDate.0|od -t x1 0000000 07 d6 03 06 10 12 1d 00 2b 02 00 0a 0000014
After searching man/inet/etc I found this (in man snmpcmd):
-Ih By default, the library will use DISPLAY-HINT information when assigning values. This flag disables this behaviour. The result is that instead of snmpset localhost HOST-RESOURCES-MIB::hrSystemDate.0 = 2002-1 +2-10,2:4:6.8 you will have to write snmpset localhost HOST-RESOURCES-MIB::hrSystemData.0 x "07 D2 + 0C 0A 02 04 06 08"
Also I tried to use Net::SNMP but resuls was same.

So, my question is: how I can change this behaviour in my perl scripts? how I can get date in string form using SNMP::Simple?

2006-03-06 Retitled by g0n, as per Monastery guidelines
Original title: 'SNMP::Simple'


In reply to how I can get date in string form using SNMP::Simple by cub.uanic

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.