模板文件的例子

Template Example 1: Eliminating Rejected Targets From Appearing
This template file generates exactly the same configuration code per interface as cfgmaker does by default, with the exception that it eliminates all lines (comments as well as config code) for an interface if the interface happens to be rejected.

if(not $problem_lines)

{

  $target_lines .= <<ECHO;



Target[$target_name]: $if_ref:$router_connect

SetEnv[$target_name]: MRTG_INT_IP="$if_ip" MRTG_INT_DESCR="$if_snmp_descr"

ECHO



  if ($directory_name) {

      $target_lines .= "Directory[$target_name]: $directory_name\n";

  }



  $target_lines .= <<ECHO;

MaxBytes[$target_name]: $if_speed

Title[$target_name]: $html_desc_prefix$html_if_title_desc -- $sysname

PageTop[$target_name]: <h1>$html_desc_prefix$html_if_title_desc -- $sysname</h1>

               <div id="sysdetails">

                       <table>

                               <tr>

                                       <td>System:</td>

                                       <td>$sysname in $html_syslocation</td>

                               </tr>

                               <tr>

                                       <td>Maintainer:</td>

                                       <td>$html_syscontact</td>

                               </tr>

                               <tr>

                                       <td>Description:</td>

                                       <td>$html_if_description</td>

                               </tr>

                               <tr>

                                       <td>ifType:</td>

                                       <td>$html_if_type_desc ($if_type_num)</td>

                               </tr>

                               <tr>

                                       <td>ifName:</td>

                                       <td>$html_if_snmp_name</td>

                               </tr>

ECHO



  $target_lines .= <<ECHO if defined $if_port_name;

                               <tr>

                                       <td>Port Name:</td>

                                       <td>$if_port_name</td>

                               </tr>

ECHO



  $target_lines .= <<ECHO;

                               <tr>

                                       <td>Max Speed:</td>

                                       <td>$if_speed_str</td>

                               </tr>

ECHO



  $target_lines .= <<ECHO if $if_ip;

                               <tr>

                                       <td>Ip:</td>

                                       <td>$if_ip ($if_dns_name)</td>

                               </tr>

ECHO



  $target_lines .= <<ECHO;

                       </table>

               </div>

ECHO

} else {

  $head_lines="";

  $problem_lines="";

  $target_lines="";

  $separator_lines="";

}


Template Example 2: Simplier Version of Example 1
Example 1 was partly intended to demonstrate how to customize the generation of interface targets but also to provide a hint of how the variables are used in the default template which one could consider that cfgmaker normally uses.

If you're only intrested in the easiest way of entirely eliminating those reject interfaces, the template below would do the job as well by using $default_target_lines.

if($if_ok) {

$target_lines = $default_target_lines;

} else {

  $head_lines="";

  $problem_lines="";

  $target_lines="";

  $separator_lines="";

}


Template Example 3: Creating CPU Targets for Hosts
Below is an example of a host template.:

$head_lines .= <<ECHO;

#---------------------------------------------------------------------

ECHO



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



$target_lines .= <<ECHO;



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]:  CPU Load:

LegendO[$target_name]:

WithPeak[$target_name]: ywm

MaxBytes[$target_name]: 100

Options[$target_name]: growright, gauge, nopercent

Title[$target_name]: $router_name CPU load

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

PageTop[$target_name]: <h1>$router_name CPU load</h1>

               <div>

                       <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>$html_sysdescr</td>

                               </tr>

                               <tr>

                                       <td>Resource:</td>

                                       <td>CPU.</td>

                               </tr>

                       </table>

               </div>

ECHO


实例
The first example creates a config file for router.place.xyz: the router has the community name public. Interfaces get identified by their IP number. Two global options get added to the config file. The config file gets redirected to mrtg.conf. The '' signs at the end of the line mean that this command should be written on a single line.

cfgmaker --global "WorkDir: /home/tobi"           \

         --global "Options[_]: growright,bits"    \

         --ifref=ip                               \

         public@router.place.xyz > mrtg.cfg


Note:
if cfgmaker is not in your path, but you are in the directory where cfgmaker is stored, you can start it with ./cfgmaker
The next example creates a config file for four devices: router1.place.xyz, router2.place.xyz, switch1.place.xyz and switch2.place.xyz all with the community public.

The two routers will have --ifref set to descr whilst the two switches will use --ifref set to name. Further the routers will use --ifdesc set to alias and switch1.place.xyz will use --ifdesc set to descr whilst switch2.place.xyz use name instead.

Finally, there will be two Options lines inserted in the configuration: One will be in the beginning, whilst the other will be inserted after the lines related to the two routers but before those lines related to the switches.

cfgmaker --global "WorkDir: /home/tobi"           \

         --global "Options[_]: growright,bits"    \

         --ifref=descr                            \

         --ifdesc=alias                           \

         public@router1.place.xyz                 \

         public@router2.place.xyz                 \

         --global "Options[_]: growright"         \

         --ifref=name                             \

         --ifdesc=descr                           \

         public@switch1.place.xyz                 \

         --ifdesc=name                            \

         public@switch2.place.xyz > mrtg.cfg


The next example demonstrates how to use the --community, --snmp-options and --dns-domain to make the command line simpler. All the equipment will use the community hidden, except for the ppp-server which use community access. All equipment uses these SNMP options: 1s timeout, 1 retry and SNMP version 2 (backoff and port is unspecified which means they use the default values). The exception again is the ppp-server which uses SNMP version 1. Finally, all the equipment is part of the domain place.xyz, except for the ppp-server which is part of the domain remote.place.xyz. Note that the latter is achieved simply by specifying the name of the ppp-server to be ppp-server.remote .

cfgmaker --global "WorkDir: /home/tobi"           \

         --global "Options[_]: growright,bits"    \

         --dns-domain=place.xyz                   \

         --community=hidden                       \

         --snmp-options=::1:1::2                  \

         router1                                  \

         router2                                  \

         router3                                  \

         router4                                  \

         router5                                  \

         switch1                                  \

         switch2                                  \

         switch3                                  \

         switch4                                  \

         switch5                                  \

         switch6                                  \

         switch7                                  \

         access@ppp-server.remote:::::1 > mrtg.cfg