#!/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 quieries:
% snmpwalk -v 1 -c public localhost dskDevice.1 UCD-SNMP-MIB::dskDevice.1 = STRING: /dev/sda3 % ./snmp_get -o dskDevice.1 /dev/sda3But 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 0000014After 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-12-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.
my %opt = (
DestHost => 'localhost',
Community => 'public',
Version => 1,
Timeout => 1_000_000,
UseSprintValue =>1, ## Added to print DATES
);
From the doc for SNMP::Session,
UseSprintValue
defaults to the value of SNMP::use_sprint_value at time of session creation. set to non-zero to have return values for 'get' and 'getnext' methods formatted with the libraries sprint_value function. This will result in certain data types being returned in non-canonical format Note: values returned with this option set may not be appropriate for 'set' operations (see discussion of value formats in
"For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken
perlmonks.org content © perlmonks.org and cub.uanic, NetWallah
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03