[mrtg] newbie question: how to convert string -> value?

McDonald, Dan Dan.McDonald at austinenergy.com
Fri Feb 27 14:57:07 CET 2009

On Fri, 2009-02-27 at 12:58 +0000, Niall O'Reilly wrote:
> On Fri, 2009-02-27 at 04:29 -0800, Evert wrote:
> > 
> > I was hoping to do it all from within mrtg.conf, but I guess that's
> > not possible...?
> 	Possible:

Or, use the conversion code feature:
Some devices may produce non-numeric values that would nevertheless be
useful to graph with MRTG if those values could be converted to numbers.
The ConversionCode keyword specifies the path to a file containing Perl
code to perform such conversions. The code in this file must consist of
one or more Perl subroutines. Each subroutine must accept a single
string argument and return a single numeric value. When RRDtool is in
use, a decimal value may be returned. When the name of one of these
subroutines is specified in a target definition (see below), MRTG calls
it twice for that target, once to convert the the input value being
monitored and a second time to convert the output value. The subroutine
must return an undefined value if the conversion fails. In case of
failure, a warning may be posted to the MRTG log file using Perl's warn
function. MRTG imports the subroutines into a separate name space
(package MRTGConversion), so the user need not worry about pollution of
MRTG's global name space. MRTG automatically prepends this package
declaration to the user-supplied code.

Example: Suppose a particular OID returns a character string whose
length is proportional to the value to be monitored. To convert this
string to a number that can be graphed by MRTG, create a file
arbitrarily named "MyConversions.pl" containing the following code:

# Return the length of the string argument
 sub Length2Int {
   my $value = shift;
   return length( $value );

Then include the following global keyword in the MRTG configuration file
(assuming that the conversion code file is saved in the mrtg/bin
directory along with mrtg itself):

ConversionCode: MyConversions.pl

This will cause MRTG to include the definition of the subroutine
Length2Int in its execution environment. Length2Int can then be invoked
on any target by appending "|Length2Int" to the target definition as

Target[myrouter]: at mydevice|Length2Int

See "Extended Host Name Syntax" below for complete target definition
syntax information.

Daniel J McDonald, CCIE #2495, CISSP #78281, CNX
Austin Energy

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.oetiker.ch/pipermail/mrtg/attachments/20090227/c9fae591/attachment.bin 

More information about the mrtg mailing list