Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SNMP hrSystemDate convert to time format

Status
Not open for further replies.

Hemulll

Technical User
Nov 10, 2008
25
RU
Hello All.
In Host Resources MIB file has hrSystemDate attribute, that show localtime of server. It possible to get this attribute via SNMP (1.3.6.1.2.1.25.1.2 OID). My problem is: values are in HEX, so, it possible to convert it to string ? or some understandable format ?

Examples of HEX format:
1) 07 D9 0C 02 0D 25 25 00 2B 03 00
2) 07 D9 0C 02 0D 24 2B 00 2D B9 38

It should be like "2009-12-2,9:13:1.0,+3:0".

My Script:
<code>
@Instrumentations = $session->getInstances("HR_SystemDate_Fault");
foreach $Iinstance (@Instrumentations) {
$sysDateObj = $session->object($Iinstance);
$srvTime = $sysDateObj->{HR_SystemDateStr};

if (!$srvTime) { next; }

$octets = $srvTime;

$octets =~ s/ //g;
print " DEBUG :: $octets\n";

## convert each two digit into char code
$octets =~ s/([a-fA-F0-9][a-fA-F0-9])/chr(hex($1))/eg;
</code>


But have no luck :-(
Please help.
 
Found solution

<code>
$octets = $srvTime;
$octets =~ s/ //g;

$octets = pack "H*", $octets;

@date = unpack 'n C6 a C2', $octets;
#print Dumper "DEBUG :: @date\n";
print Dumper $datetime = sprintf "%04d-%02d-%02d %02d:%02d:%02d", @date;
</code>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top