serge123 has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm having an issue with Net:SNMP and retreiving values listed as Hex-STRING. Here's a unix snmpwalk which looks OK:

snmpwalk -v 2c -c COMM 10.1.1.1 1.3.6.1.4.1.9.9.273.1.2.1.1.16
SNMPv2-SMI::enterprises.9.9.273.1.2.1.1.16.1.11.97.108.105.97.110.116.95.119.105.102.105.0.19.206.233.215.61 = Hex-STRING: 0A 40 12 81
SNMPv2-SMI::enterprises.9.9.273.1.2.1.1.16.1.11.97.108.105.97.110.116.95.119.105.102.105.0.144.75.10.176.166 = Hex-STRING: 0A 40 12 45
SNMPv2-SMI::enterprises.9.9.273.1.2.1.1.16.1.11.97.108.105.97.110.116.95.119.105.102.105.0.144.150.180.214.183 = Hex-STRING: 0A 40 12 96
SNMPv2-SMI::enterprises.9.9.273.1.2.1.1.16.1.11.97.108.105.97.110.116.95.119.105.102.105.0.144.150.182.172.193 = Hex-STRING: 0A 40 12 87

Here's the same walk with perl:

perl walktest.pl (walking 1.3.6.1.4.1.9.9.273.1.2.1.1.16)
Trying 'snmpwalk' on 10.1.1.1
1.11.97.108.105.97.110.116.95.119.105.102.105.0.19.206.233.215.61:
@
1.11.97.108.105.97.110.116.95.119.105.102.105.0.144.75.10.176.166:
@E
1.11.97.108.105.97.110.116.95.119.105.102.105.0.144.150.180.214.183:
@
1.11.97.108.105.97.110.116.95.119.105.102.105.0.144.150.182.172.193:
@

I get similar weird results if I do an snmpget with perl on 1 OID:

perl test.pl
1.3.6.1.4.1.9.9.273.1.2.1.1.2.1.11.97.108.105.97.110.116.95.119.105.102.105.0.19.206.233.215.61 = bÚZ`

Either way, the “Hex-STRING” data is never returned correctly. This happens with any OID holding a “Hex-STRING”. I don't have a problem with other OID types. At first I thought it was just a formatting issue so I played with printing the output using “hex” but it didn’t help. There also aren't enough chars sent back to be a formatting issue. I wonder if Net::SNMP can’t handle an OID value with a space in it?

The perl code I'm using looks like this:

use strict; use Net::SNMP; use BER; use SNMP_Session; use SNMP_util; #variable declaration and assigment omitted... print "Trying 'snmpwalk' on $host\n"; @ret = &snmpwalk("$community\@$host\:\:\:\:\:$version", $oid ); foreach (@ret) { print "$_\n"; }

As you can see I've been trying various SNMP modules. I've always get the same problem regardless of which way I query to OID.

Any help you can provide would be appreciated.

Thanks,
Serge

Replies are listed 'Best First'.
Re: Net::SNMP not retreiving Hex-STRING correctly
by Argel (Prior) on Mar 09, 2006 at 23:38 UTC
    Instead of doing an snmpwalk have you tried a get_request?
    $response_href = $session->get_request( $sysContact, $sysDescr, $sysLo +cation, $sysObjectID, $localDomain, $localHostname );
    You might also want to use Data::Dumper to output the results:
    use Data::Dumper; print Data::Dumper->Dump([$response_href],['response hash']);
Re: Net::SNMP not retreiving Hex-STRING correctly
by atcroft (Abbot) on Mar 09, 2006 at 23:58 UTC

    There was a bug report for Net::SNMP that seems to describe your issue. A former coworker of mine was referred to it when he experienced a similar issue a year or two ago.

    Hope that helps.

Re: Net::SNMP not retreiving Hex-STRING correctly
by serge123 (Initiate) on Mar 10, 2006 at 17:30 UTC
    Hello,

    Thanks for the info. This following walk did the trick:

    use strict; use Net::SNMP; use Data::Dumper; #Variable declaration & assigment ommited ($session, $error) = Net::SNMP->session( -hostname => $host, -version => $version, -community => $community, ); # do the SNMP walk, returns a hash ($bindings) = $session->get_table ($oid); # close the SNMP Session $session->close(); # print "Errors: $error\n"; print Data::Dumper->Dump([$bindings],['response hash']);
    The output looks as follows:

    $response hash = { '1.3.6.1.4.1.9.9.273.1.2.1.1.16.1.11.97.108.105.97.110.116.95.119.105.102.105.0.18.121.63.143.69' => '0x0a4012bb',
    '1.3.6.1.4.1.9.9.273.1.2.1.1.16.1.11.97.108.105.97.110.116.95.119.105.102.105.0.9.45.133.249.209' => '0x0a4012cc'
    };

    The OIDs shown above actually have 3 values as indexes. It's easier to walk to base OID than gather the 3 index values and use a get. That's why I'm not using snmpget ;)

    Thank you very much!
    Serge

Re: Net::SNMP not retreiving Hex-STRING correctly
by ikegami (Patriarch) on Jun 29, 2007 at 15:10 UTC

    @ is ASCII char 0x40.
    E is ASCII char 0x45.
    Your data is simply "packed".

    unpack('H*', $_) will convert the gobbledygook to "0A401281".