[mrtg] Re: Template files

Jason Poley jpoley at co.santa-barbara.ca.us
Fri Jan 18 16:50:35 MET 2002


David,

A template file is some Perl script you write that will run inside cfgmaker to augment the creation of your mrtg.cfg file.  So, you first must understand Perl, at least a little.  Even more important, you must understand what you want your finished mrtg.cfg file to look like.  The most important thing that I found was that I needed to REALLY understand what cfgmaker was doing.  Take a look at it's code and discover what $problem_lines represent, what $target_lines are, what $default_target_lines are, and take a good look at the way the mrtg.cfg file is constructed.

If this is all beyond you and you don't have time to figure out how to write Perl scripts, I would suggest just manually editing the mrtg.cfg file.  The reason I have had to spend so much time figuring this out, is that I am automating the process of updating MRTG for less sophisticated users ;-)  

Host templates will be processed once for each host you define as an MRTG target.  Interface templates will be processed for each interface on each host.

Take a look at the examples in the MRTG documentation (cfgmaker.html).  They may help you understand how this all works together.  The host template example is a good one since many of us want to watch router cpu utilization.  Try it.

Here are samples of what I do which also may help...

¯---------- < cfgmaker.script>  ¯---
#!/bin/sh
cfgmaker --global "WorkDir: /home/apache/htdocs/mrtg"                           \
         --global "Options[_]: growright,bits" --ifref=descr                    \
         --ifdesc=alias --host-template=host.template --subdirs=HOSTNAME        \
         --if-template=if.template --output=/etc/mrtg/mrtg.cfg.new              \
                'public at rsb1.co.sbcgov.net'             \
                'public at rsb1.co.sbcgov.net'             \
                'public at rsb2.co.sbcgov.net'             \
                'public at rsbt1.co.sbcgov.net'            \
                'public at rsbt2.co.sbcgov.net'            \
                'public at rsb3.co.sbcgov.net'             \
                'public at rgo1.co.sbcgov.net'             \
                'public at rgo2.co.sbcgov.net' 


¯-----------------------------------------------------------

Here is my host template to add a CPU utilization graph to every router
¯----------<host.template>--------------

#
#  This template is designed for MRTG-2.9.17
#  12/20/01 Jason Poley
#
 

# This section will include CPU utilization for all Cisco routers

my $target_name = $router_name . ".cpu";

$head_lines .= <<ECHO;
 # CPU Utilization for $target_name
 #---------------------------------------------------------------------
ECHO

$target_lines .= <<ECHO;


Target[$target_name]: 1.3.6.1.4.1.9.2.1.58.0&1.3.6.1.4.1.9.2.1.58.0:$router_connect
RouterUptime[$target_name]: $router_connect
Directory[$target_name]: $directory_name 
YLegend[$target_name]: Percentage CPU load
ShortLegend[$target_name]: %
Legend1[$target_name]: CPU load in %
Legend2[$target_name]: 
Legend3[$target_name]: Max Observed CPU load
Legend4[$target_name]: 
LegendI[$target_name]: &nbsp;CPU Load:
LegendO[$target_name]: 
Unscaled[$target_name]: ywmd
MaxBytes[$target_name]: 100
Options[$target_name]: growright, gauge, nopercent
Title[$target_name]: $router_name CPU load
PageTop[$target_name]: <H1>$router_name CPU load</H1>
   <TABLE>
     <TR><TD>System:</TD><TD>$router_name in $html_syslocation</TD></TR>
     <TR><TD>Maintainer:</TD><TD>$html_syscontact</TD></TR>
     <TR><TD>Description:</TD><TD>CPU Utilzation </TD></TR>
     <TR><TD>Resource:</TD><TD>CPU</TD></TR>
   </TABLE>
ECHO

print $target_lines;

¯--------------------------------------------


Here is if.template which will ADD collision stats to Ethernet interfaces and input and output errors to Serial interfaces.  Keep in mind that any interface template defined will REPLACE the regular output of cfgmaker for ALL interfaces.  Thus you will most likely want to have a line similar to the first non-comment line below.  "$target_lines = $default_target_lines;"  Thus preserving the work already done by cfgmaker.

¯---------------<if.template>---------------
#
# This template is designed for MRTG-2.9.17
#  01/11/02 Jason Poley
#
 
# default target lines have already been defined.  We want to keep them.  
$target_lines = $default_target_lines;

# This section will create a collitions graph for each Ethernet interface 

if ($target_name =~ "_Ethernet") {


        my $target_name = $target_name . ".coll";

        $head_lines .= <<ECHO;
#  Collision counters for $target_name
#---------------------------------------------------------------------
ECHO


        $target_lines .= <<ECHO;


Target[$target_name]: 1.3.6.1.2.1.10.7.2.1.4.$if_index&1.3.6.1.2.1.10.7.2.1.5.$if_index:$router_connect
RouterUptime[$target_name]: $router_connect
Directory[$target_name]: $directory_name 
YLegend[$target_name]: Single Collisions
ShortLegend[$target_name]: /s
Legend1[$target_name]: Collisions
Legend2[$target_name]: 
Legend3[$target_name]: Collisions
Legend4[$target_name]: 
LegendI[$target_name]: &nbsp;Single Collisions:&nbsp;
LegendO[$target_name]: &nbsp;Multiple Collisions:&nbsp; 
Unscaled[$target_name]: ywmd
MaxBytes[$target_name]: 1000
#AbsMax[$target_name]: 10000
Options[$target_name]: growright, nopercent
Title[$target_name]: $router_name $if_ref Collisions 
PageTop[$target_name]: <H1>$router_name $if_ref</H1>
   <TABLE>
     <TR><TD>System:</TD><TD>$router_name in $html_syslocation</TD></TR>
     <TR><TD>Maintainer:</TD><TD>$html_syscontact</TD></TR>
     <TR><TD>Description:</TD><TD> Collision counters </TD></TR>
     <TR><TD>Resource:</TD><TD>$if_ref</TD></TR>
   </TABLE>

ECHO

}

# This section will produce a input/output errors graph for each interface

if ($target_name =~ "_Serial") {

        my $target_name = $target_name . ".err";

        $head_lines .= <<ECHO;
#  Input/output errors  for $target_name
#---------------------------------------------------------------------
ECHO


        $target_lines .= <<ECHO;


Target[$target_name]: ifInErrors.$if_index&ifOutErrors.$if_index:$router_connect
RouterUptime[$target_name]: $router_connect
Directory[$target_name]: $directory_name
YLegend[$target_name]: Error Packets 
ShortLegend[$target_name]: /s
Legend1[$target_name]: Error Packets
Legend2[$target_name]:
Legend3[$target_name]: Error Packets
Legend4[$target_name]:
LegendI[$target_name]: &nbsp;Inbound Error Packets:&nbsp;
LegendO[$target_name]: &nbsp;Outbound Error Packets:&nbsp;
Unscaled[$target_name]: ywmd
MaxBytes[$target_name]: 1000
Options[$target_name]: growright, nopercent
Title[$target_name]: $router_name $if_ref Errors
PageTop[$target_name]: <H1>$router_name $if_ref</H1>
   <TABLE>
     <TR><TD>System:</TD><TD>$router_name in $html_syslocation</TD></TR>
     <TR><TD>Maintainer:</TD><TD>$html_syscontact</TD></TR>
     <TR><TD>Description:</TD><TD> In/Out Error counters </TD></TR>
     <TR><TD>Resource:</TD><TD>$if_ref</TD></TR>
   </TABLE>

ECHO

}


print $target_lines;

¯--------------------------------


I hope this helps.

Cheer,

JDP


-------------------------------------------------------
Jason D. Poley 
jpoley at co.santa-barbara.ca.us
Network Tech, County of Santa Barbara
(805) 568-2680

>>> "Spicer, David" <David_Spicer at fmi.com> 01/18/02 07:01AM >>> 
I have MRTG up and running on a BSD box. Graphing traffic. I want to start 
making config files for graphing errors. This will take a long time. I 
have looked around for instructions for using template files. I see alot of 
documentation on variables, cfgmaker switches, etc. But I don't see a very 
simple how-to for making a cfg file with a template file. So I tell 
cfgmaker to make a config file, with the if-template switch? There are 
variables in the template file. (i.e., $CFGNAME, $DEVICE, $INSTANCE). Do I 
replace these variables in the template file myself? Will cfgmaker see the 
variables and ask me to key in the values? Very simply, how do I use a 
template file? 






-- 
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 

--
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