[mrtg] Re: cfgmaker question

kelsey hudson khudson at tsss.org
Wed Feb 15 17:45:55 MET 2006

Shane Presley wrote:
> cfgmaker --output=/etc/mrtg/cisco.inc --community=mystring  --global
> "options[_]: bits" --global "WorkDir: /var/www/html/mrtg-data/"
> --ifdesc=alias --host-template=cisco.template
> myserver.domain.dom:::::2 myserver2.domain.dom:::::2

> However, I need to use lots of different cfgmaker scripts, since I
> need to define different options for certain switches.  For example on
> some I want to use a certain template, and some I might use a
> different ifdesc.

That's fine. You can do things like this:

cfgmaker --community=mystring --global "blah" --ifdesc=alias \
          --host-template=some-template.tpl switch1.some.com:::::2 \
          --ifdesc=descr --host-template=new-template.tpl \
          switch2.some.com [...] >>/etc/mrtg/cisco.inc

Or, of course, you can put these on different lines in a script file, 
then have the output append to a single config file. If this is 
something you generate, say, every night, you could do something like 
this and put it in a cron job:

GLOBALS=("--global" "options[_]: bits" "--global" "WorkDir: /path")

typeset -A TEMPLATES
typeset -A IFREFS

TARGETS=("switch1.dom.com" \
          "switch2.dom.com" \

TEMPLATES=(${TARGETS[1]} "switch1-template.tpl" \
            ${TARGETS[3]} "switch3-template.tpl")

IFREFS=(${TARGETS[2]} "alias" \
         ${TARGETS[3]} "name")

rm -f /etc/mrtg/cisco.inc

for target in "${TARGETS[@]}" ; do

    cfgmaker ${GLOBALS[@]} ${ifdesc}${IFDESCS[$target]:-descr} \
       ${community}@${target} >>/etc/mrtg/cisco.inc


TARGETS   is a list of routers, switches, etc.
TEMPLATES is an associative array of the name of a certain router/switch 
  (must match the name in TARGETS above or be specified with the list 
subscript of TARGETS itself) specifying which template to run for which 
IFREFS is much like TEMPLATES except it deals with the --ifref= statement.
Entries in both TEMPLATES and IFREFS are optional -- it will be replaced 
by a default value (default-template.tpl or descr, respectively) if none 
exists in the hash map. All of the targets are output to the same file 

Note that I just blindly hacked this out and haven't tested it, so YMMV.

> So using multiple cfgmaker scripts is great, but each one needs to
> output to a different file.  So that makes things a pain for me.  Is
> it possible to have these append to a single output file?  Or
> specificy different options (like ifdesc and host-template) per
> target?

good luck,

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

More information about the mrtg mailing list