Author image Karl Gaissmaier
and 1 contributors


Net::SNMP::Mixin::Util - helper class for Net::SNMP mixins


Version 0.14


A helper class for Net::SNMP mixins.

  use Net::SNMP::Mixin::Util qw/idx2val hex2octet normalize_mac/;


The following routines are exported by request:

idx2val($var_bind_list, $base_oid, [$pre], [$tail])

convert a var_bind_list into a index => value form, removing the base_oid from oid.

e.g. if base_oid is '', convert from:

  '' => 'foo'
  '' => 'bar'


  '1' => 'foo'
  '2' => 'bar'

or if base_oid is '1.0.8802.' and pre == 1 and tail == 2, convert from:

  '1.0.8802.' => 'foo',
  '1.0.8802.' => 'bar',
  '1.0.8802.' => 'baz',
  ^                 ^ ^        ^      ^    ^     ^
  |.....base_oid....|.|.index..|.tail.|    |value|
  pre ---------------|


  '' => 'foo',
  '' => 'bar',
  '' => 'baz',

Returns the hash reference with index => value. Dies on error.


Sometimes it's importend that the returned SNMP values were untranslated by Net::SNMP. If already translated, we must reconvert it to pure OCTET_STRINGs for some calculations. Returns the input parameter untranslated if it's no string in the form /^0x[0-9a-f]+$/i .


normalize MAC addresses to the IEEE form XX:XX:XX:XX:XX:XX

    normalize the different formats like,

              x:xx:x:xx:Xx:xx     to XX:XX:XX:XX:XX:XX
    or        xxxxxx-xxxxxx       to XX:XX:XX:XX:XX:XX
    or        xx-xx-xx-xx-xx-xx   to XX:XX:XX:XX:XX:XX
    or        xxxx.xxxx.xxxx      to XX:XX:XX:XX:XX:XX
    or     0x xxxxxxxxxxxx        to XX:XX:XX:XX:XX:XX
    or     plain packed '6C'      to XX:XX:XX:XX:XX:XX

or returns undef for format errors.

push_error($session, $error_msg)

Net::SNMP has only one slot for errors. During nonblocking calls it's possible that an error followed by a successful transaction is cleared before the user gets the chance to see the error. At least for the mixin modules we use an array buffer for all seen errors until they are explicit cleared.

This utility routine helps the mixin authors to push an error into the buffer without the knowledge of the buffer internas.

Dies if session isn't a Net::SNMP object or error_msg is missing.


Helper method, defines and returns the init hash slot for all mixin modules.


Net::SNMP, Sub::Exporter


There are no known bugs at the time of this release. However, if you spot a bug or are experiencing difficulties that are not explained within the POD documentation, please submit a bug to the RT system (see link below). However, it would help greatly if you are able to pinpoint problems or even supply a patch.

Fixes are dependant upon their severity and my availablity. Should a fix not be forthcoming, please feel free to (politely) remind me by sending an email to .



Karl Gaissmaier <karl.gaissmaier at>


Copyright 2008-2015 Karl Gaissmaier, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.