I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-06-22 09:34:38-07 by frank85
How is it possible to change the outputformat with the translate function
Hello, I have a question: How is it possible for a get request or something else, to change the outputformat in hexadecimal and after the request I want to change back the format (to standard). Everybody know how I can use the translate function. I tried this:
$session->translate( -octetstring => 0x1 );
But it doesn't work. There is no error but no change, too.
Frank
Direct Responses: 11023 | Write a response
Posted on 2009-06-22 12:35:04-07 by dtown in response to 11022
Re: How is it possible to change the outputformat with the translate function
Translation is on by default, so your call to translate(-octetstring => 0x1) is really a no-op. The translation of OCTET STRINGs is done by a pattern match. See the "translate() - enable or disable the translation mode for the object" section of the documentation which discusses what triggers translation for an OCTET STRING. The string you are receiving back might be all printable according to the module and no translation is taking place. If that is the case, you would need to turn translation off, and then use unpack() to format your string. See a related "bug" report at http://rt.cpan.org/Public/Bug/Display.html?id=27819.
Direct Responses: 11025 | Write a response
Posted on 2009-06-22 12:52:39-07 by frank85 in response to 11023
Re: How is it possible to change the outputformat with the translate function
Ok, translation is enable by default by a pattern match. I think that I understand this, but my problem is:
That I get a string in hexadecimal but the snmpget doesn't detect the string as hexadecimal output.
That is the reason, why I get a confused output. On the console under unix I can use snmpget -Ox and that works fine. But now I want use this option for my get-request only in perl.
Direct Responses: 11026 | Write a response
Posted on 2009-06-22 12:59:36-07 by dtown in response to 11025
Re: How is it possible to change the outputformat with the translate function
You would need to do something like:
$oid = "<your OID>"; $session->translate(-octetstring => 0x0); $response = $session->get_request(-varbindlist => [$oid]); printf "%s: %s\n", $oid, hex_format($response->{$oid}); $session->translate(-octetstring => 0x1); ... sub hex_format { sprintf '0x%s', unpack 'H*', $_[0]; }
Direct Responses: 11027 | Write a response
Posted on 2009-06-22 13:47:00-07 by frank85 in response to 11026
Re: How is it possible to change the outputformat with the translate function
Thanks for the answer. But unfortunatly this function translate somehow.
It shouldn't be translate the values, which are in Hex-String. I want only translate strings or numbers and the hexadecimal numbers should be in their hexadecimal format.
Hex-STRING: 0A 00 3F FE <- this values shouldn't be reformated - This in output from snmpget STRING: <NL>6-- <- This line with some special characters should be format.
The hex-string show me for my first line in your example as output: 0x30783061303033666665
And for the second line the correct Hex-STRING.

Do you know the reason for it?
Thank you in advance for your efforts.
Direct Responses: 11028 | Write a response
Posted on 2009-06-22 14:59:42-07 by dtown in response to 11027
Re: How is it possible to change the outputformat with the translate function
With translation disabled, you have to selectively translate the values yourself. If you "know" that the response to a particular OID is printable, you do not call hex_format(), and if it requires conversion, then you call it. It does not look like you have disabled translation because the hexadecimal value 30783061303033666665 in ASCII is "0x0a003ffe". So the response was translated, first by the module to ASCII "0x0a003ffe" and then by the hex_format() function to "0x30783061303033666665".
Direct Responses: 11033 | Write a response
Posted on 2009-06-23 05:48:02-07 by frank85 in response to 11028
Re: How is it possible to change the outputformat with the translate function
Thank you for this response.
I extend your example function - with checking the first two characters on "0x". I don't know, if this will work anyway but currently it works.
But what I thought, that when I set the octetstring to 0x0 - the string will automatically a hexadecimal value. And I get as result the hexadecimal value - without using a special function - for reformatting. I'm a little confused but it is apperently the solution for my problem.
Direct Responses: 11043 | Write a response
Posted on 2009-06-24 12:04:55-07 by dtown in response to 11033
Re: How is it possible to change the outputformat with the translate function
All of the OCTET STRING data is binary data. You are talking about presentation format. If you tell Perl to display it as hexadecimal it will be displayed as hexadecimal, if you want ASCII text it will be displayed as ASCII text. The translation functionality of Net::SNMP attempts examine the binary data and based on the content of try to provide the most appropriate presentation format. Without MIB information to guide the presentation format, this is what can be accomplished.
Direct Responses: Write a response