[mrtg] Conversion code for hex to integer

Dan Lynch dan.lynch at placer.ca.gov
Tue Oct 19 21:08:09 MEST 2004

Greetings list,

My device returns an octet string for a query. To convert this hex value to an integer I'm trying a ConversionCode subroutine which I've gleaned from this list's archives. But every time the error is returned: "Illegal hexadecimal digit". 

Could it be that I need to strip off unnecessary characters passed by SNMP? When I GET any of several similar OIDs, the returned result is always prefixed by the bytes "04 05", followed by five more octets of hex data. Here's the value returned from the OID representing an HTTP proxy cache's "Total amount of object data transfered to browsers in Kbytes":


And the value for proxyStatsObjCacheDirectFetchedData ("Amount of object data fetched from direct source in Kbytes").


Do these bytes (04 05) simply indicate that what follows is hex? Does MRTG strip this before passing it to the subroutine?

Here is a snip of the config file:

    ConversionCode: hextoint.pl
    Target[IPnumber_tput]: at IPnumber|hextoint

Here is my perl code:

     sub hextoint {
       my $value = shift;
       return hex ($value);

In troubleshooting, I've had the subroutine write $VALUE to a file both before and (comma-separated) after processing. I get output like:

F»+ ,15

I've never dealt with PERL before. I'm relying on PERL reference web sites and mail list archives for everything. I love a challenge  : >  Next I'll want to do math on the returned integer values. Seriously.

Anything you can offer to educate me would be greatly appreciated.


Dan Lynch, CISSP
Information Technology Analyst
County of Placer
Auburn, CA

Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi

More information about the mrtg mailing list