MRTG_lib is part of MRTG, the Multi Router Traffic Grapher. It was separated
from MRTG to allow other programs to easily use the same config files. The
main part of MRTG_lib is the config file parser but some other funcions are
there too.
Reads a config file, parses it and fills some arrays and hashes. The
mandatory arguments are: the name of the config file, a ref to an array which
will be filled with a list of the target names, a hashref for the global
configuration, a hashref for the target configuration.
The configuration file syntax is:
globaloption: value
targetoption[targetname]: value
aprefix*extglobal: value
aprefix*exttarget[target2]: value
readcfg can take two additional arguments to extend the config file
syntax. This allows programs to put their configuration into the mrtg config
file. The fifth argument is the prefix of the extension, the sixth argument
is a hash with the checkrules for these extension settings. E.g. if the
prefix is ``14all'' readcfg will check config lines that begin with
``14all*'', i.e. all lines like
against the rules in %extrules. The format of this hash is:
$extrules{option} = [sub{$_[0] =~ m/^\d+$/}, sub{"Error message for $_[0]"}]
i.e.
$extrules{option}[0] -> a test expression
$extrules{option}[1] -> error message if test fails
The first part of the array is a perl expression to test the value of the
option. The test can access this value in the variable ``$arg''. The second
part of the array is an error message to display when the test fails. The
failed value can be integrated by using the variable ``$arg''.
Config settings with an different prefix than the one given in the readcfg
call are not checked but inserted into %globalcfg and %targetcfg.
Prefixed settings keep their prefix in the config hashes:
Checks the configuration read by readcfg. Checks the values in the config
for syntactical and/or semantical errors. Sets defaults for some options.
Parses the ``target[...]'' options and filles the array @parsed_targets ready
for mrtg functions.
The first three arguments are the same as for readcfg. The fourth argument
is an arrayref which will be filled with the parsed target defs.
cfgcheck converts the values of target settings options, e.g.
This is not done by readcfg so if you don't use cfgcheck you have to
check the scalar variable $targetcfg{'option'}{'router1'} (MRTG allows
options to be separated by space or ',').
Checks that the pathname does not contain double path separators and ends
with a path separator. It uses $MRTG_lib::SL as path separator which will be /
or \ depending on the OS.
Install signalhandlers for __DIE__ and __WARN__ making the errors
go the the specified destination. If filename is 'eventlog'
mrtg will log to the windows event logger.
Reads the SNMP variables ifDescr, ipAdEntIfIndex, ifPhysAddress, ifName from
the host and stores the values in %confcache as follows:
$confcache{$host}{'Descr'}{ifDescr}{oid} = (ifDescr or 'Dup')
$confcache{$host}{'IP'}{ipAdEntIfIndex}{oid} = (ipAdEntIfIndex or 'Dup')
$confcache{$host}{'Eth'}{ifPhysAddress}{oid} = (ifPhysAddress or 'Dup')
$confcache{$host}{'Name'}{ifName}{oid} = (ifName or 'Dup')
$confcache{$host}{'Type'}{ifType}{oid} = (ifType or 'Dup')
The value (at the right side of =) is 'Dup' if a value was retrieved
muliple times, the retrieved value else.