1CFGMAKER(1)                          mrtg                          CFGMAKER(1)
2
3
4

NAME

6       cfgmaker - Creates mrtg.cfg files (for mrtg-2.15.1)
7

SYNOPSIS

9       cfgmaker [options] [community@]router [[options] [community@]router
10       ...]
11

OPTIONS

13        --ifref=nr    interface references by Interface Number (default)
14        --ifref=ip                     ... by Ip Address
15        --ifref=eth                        ... by Ethernet Number
16        --ifref=descr                      ... by Interface Description
17        --ifref=name                       ... by Interface Name
18        --ifref=type                       ... by Interface Type
19
20        --ifdesc=nr       interface description uses Interface Number (default)
21        --ifdesc=ip                        ... uses Ip Address
22        --ifdesc=eth                       ... uses Ethernet Number
23        --ifdesc=descr                     ... uses Interface Description
24        --ifdesc=name                      ... uses Interface Name
25        --ifdesc=catname                   ... uses CatOS Interface Name
26        --ifdesc=alias                     ... uses Interface Alias
27        --ifdesc=type                      ... uses Interface Type
28
29        --if-filter=f     Test every interface against filter f to decide wether
30                          or not to include that interface into the collection.
31                          Currently f is being evaluated as a Perl expression
32                          and it's truth value is used to reject or accept the
33                          interface.
34                          (Experimental, under development, might change)
35
36        --if-template=templatefile
37                          Replace the normal target entries for the interfaces
38                          with an entry as specified by the contents in the file
39                          templatefile.  The file is supposed to contain Perl
40                          code to be executed to generate the lines for the
41                          target in the configuration file.
42                          (Experimental, under development, might change)
43
44        --host-template=templatefile
45                          In addition to creating targets for a host's interfaces
46                          do also create targets for the host itself as specified
47                          by the contents in the file templatefile.  The file is
48                          supposed to contain Perl code to be executed to generate
49                          the lines for the host related targets (such as CPU,
50                          ping response time measurements etc.) in the config-
51                          uration file.
52                          (Experimental, under development, might change)
53
54        --global "x: a"   add global config entries
55
56        --no-down         do not look at admin or opr status of interfaces
57
58        --show-op-down    show interfaces which are operatively down
59
60        --zero-speed=spd  use this speed in bits-per-second as the interface
61                          speed for all interfaces that return a speed of 0
62                          via ifSpeed/ifHighSpeed.  100Mbps = 100000000
63
64        --subdirs=format  give each router its own subdirectory, naming each per
65                          "format", in which HOSTNAME and SNMPNAME will be
66                          replaced by the values of those items -- for instance,
67                          --subdirs=HOSTNAME or --subdirs="HOSTNAME (SNMPNAME)"
68
69        --noreversedns    do not reverse lookup ip numbers
70
71        --community=cmty  Set the default community string to "cmty" instead of
72                          "public".
73
74        --enable-ipv6     Enable IPv6 support, if the required libraries are
75                          present. Numeric IPv6 addresses must be enclosed
76                          in square brackets, e.g. public@[2001:760:4::1]:161
77
78        --use-16bit       Use 16bit SNMP request IDs to query all routers.
79
80        --snmp-options=:[<port>][:[<tmout>][:[<retr>][:[<backoff>][:<ver>]]]]
81
82                          Specify default SNMP options to be appended to all
83                          routers following.  Individual fields can be empty.
84                          Routers following might override some or all of the
85                  options given to --snmp-options.
86
87        --dns-domain=domain
88                  Specifies a domain to append to the name of all
89                  routers following.
90
91        --nointerfaces    Don't do generate any configuration lines for interfaces,
92                          skip the step of gathering interface information and
93                          don't run any interface template code.
94
95        --interfaces      Generate configuration lines for interfaces (this is the
96                          default).  The main purpose of this option is to negate
97                          an --nointerfaces appearing earlier on the command line.
98
99        --help            brief help message
100        --man             full documentation
101        --version         print the version of cfgmaker
102
103        --output=file     output filename default is STDOUT
104

DESCRIPTION

106       Cfgmaker creates MRTG configuration files based on information pulled
107       from a router or another SNMP manageable device.
108
109       [community@]router
110
111       Community is the community name of the device you want to create a con‐
112       figuration for. If not specified, it defaults to 'public'; you might
113       want to try this first if you do not know the community name of a
114       device. If you are using the wrong community name you will get no
115       response from the device.
116
117       Router is the DNS name or the IP number of an SNMP-managable device.
118       Following the name you can specify 6 further options separated by
119       colons.  The full syntax looks like this:
120
121       router[:[prt][:[tmout][:[retr][:[backoff][:vers]]]]]
122
123       Of special interest may be the last parameter, vers.  If you set this
124       to '2' then your device will be queried with SNMP version 2 requests.
125       This allows to poll the 64 bit traffic counters in the device and will
126       thus work much better with fast interfaces (no more counter overrun).
127       Note that the order in which the routers are specified on the command
128       line do matter as the same order is used when the configuration file is
129       generated.  The first specified router has it's configuration lines
130       genrated first, followed by the lines belonging to the next router and
131       so on.
132
133       Note that the first line of the generated cfg file will contain all the
134       commandline options you used for generating it. This is to allow for
135       the easy 'regeneration' in case you want to add newhosts or make some
136       other global change.
137
138       Configuration
139
140       Except for the --output and --global options, all options affect only
141       the routers following them on the command line.  If an option specified
142       earlier on the command line reappears later on the command line with
143       another value, the new value overrides the old value as far as remain‐
144       ing routers are concerned.  This way options might be tailored for
145       groups of routers or for individual routers.
146
147       See --output and --global for how their behaviour is affected by where
148       or how many times they appear on the command line.
149
150       See the Examples below on how to set an option differently for multiple
151       routers.
152
153       --help
154           Print a brief help message and exit.
155
156       --man
157           Prints the manual page and exits.
158
159       --version
160           Print the version of cfgmaker.  This should match the version of
161           MRTG for which config files are being created.
162
163       --ifref nripethdescrname
164           Select the interface identification method.  Default is nr which
165           identifies the router interfaces by their number.  Unfortunately
166           the interface numbering scheme in an SNMP tree can change. Some
167           routers change their numbering when new interfaces are added, oth‐
168           ers change thier numbering every full moon just for fun.
169
170           To work around this sad problem MRTG can identify interfaces by 4
171           other properties. None of these works for all interfaces, but you
172           should be able to find one which does fine for you. Note that espe‐
173           cially ethernet addrsses can be problematic as some routers have
174           the same ethernet address on most of their interface cards.
175
176           Select ip to identify the interface by its IP number. Use eth to
177           use the ethernet address for identification. Use descr to use the
178           Interface description. Or use name to use the Interface name.
179
180           If your chosen method does not allow unique interface identifica‐
181           tion on the device you are querying, cfgmaker will tell you about
182           it.
183
184       --ifdesc nripethdescrnametypealias
185           Select what to use as the description of the interface.  The
186           description appears in the "Title[]" property for the target as
187           well as the text header in the HTML code defined in the target's
188           "PageTop[]".  Default is to use nr which is just the interface num‐
189           ber which isn't always useful to the viewer of the graphs.
190
191           There are 6 other properties which could be used.  Use ip if you
192           want to use the interface's IP-address.  Use eth if you want to use
193           the interface's ethernet address.  If you want a better descrip‐
194           tion, you can use either descr, name or alias.  Exactly what each
195           of these do varies between different equipment so you might need to
196           experiment.  For instance, for a serial interface on a Cisco router
197           running IOS using name might result in "S0" being the interface
198           description , descr might result in "Serial0" and alias might
199           result in "Link to HQ" (provided that is what is used as the inter‐
200           face's "description" in the router's configuration).
201
202           Finally, if you want to describe the interface by it's Btype (i.e
203           "ethernetCSMA", "propPointtoPoint" etc) you can use type.
204
205       --if-filter 'filter-expression'
206           First of all, this is under some developement and is experimental.
207
208           Use this if you want to have better control over what interfaces
209           gets included into the configuration.  The filter-expression is
210           evaluated as a piece of Perl code and is expected to return a truth
211           value.  If true, include the interface and if false, exclude the
212           interface.
213
214           For a further discussion on how these filters work, see the section
215           "Details on Filters" below.
216
217       --if-template template-file
218           First of all, this is under some development and is experimental.
219
220           Use this if you want to control what the line for each target
221           should look like in the configuration file.  The contents of the
222           file template-file will be evaluated as a Perl program which gener‐
223           ates the lines using certain variables for input and output.
224
225           For a further discussion on how these templates work, see the sec‐
226           tion "Details on Temaplates" below.
227
228       --host-template template-file
229           First of all, this is under some development and is experimental.
230
231           Use this if you want to have some extra targets related to the host
232           itself such as CPU utilization, ping response time to the host,
233           number of busy modems etc.  The contents of the file template-file
234           will be evaluated once per host as a Perl program which generates
235           the lines using certain variables for input and output.
236
237           For a further discussion on how these templates work, see the sec‐
238           tion "Details on Templates" below.
239
240       --community community-string
241           Use this to set the community for the routers following on the com‐
242           mand line to community-string.  Individual routers might overrride
243           this community string by using the syntax community@router.
244
245       --enable-ipv6
246           This option enables IPv6 support. It requires the appropriate perl
247           modules; if they are not found then IPv6 is disabled (see the ipv6
248           documentation).
249
250           cfgmaker will use IPv6 or IPv4 depending on the target. If the tar‐
251           get is a numeric address, the protocol depends on the type of
252           address. If the target is a hostname, cfgmaker will try to resolve
253           the name first to an IPv6 address then to an IPv4 address.
254
255           IPv6 numeric addresses must be specified between square braces.
256
257           For example:
258
259            cfgmaker --enable-ipv6 [2001:760:4::1]:165:::2
260
261           If the target has both an IPv6 address and an IPv4 address with the
262           same hostname, cfgmaker first queries the target using IPv6 and
263           falls back to IPv4 if it fails. This is useful for targets which
264           don't support SNMP over IPv6.
265
266       --use-16bit
267           This option forces the use of 16bit SNMP request IDs.  Some broken
268           SNMP agents do not accept 32bit request IDs.  Try to avoid this
269           option as much as possible, complain to your agent vendor instead.
270
271       --snmp-options  :[port][:[timeout][:[retries][:[backoff][:version]]]]
272           Use this to set the default SNMP options for all routers following
273           on the command line.  Individual values might be omitted as well as
274           trailing colons.  Note that routers might override individual (or
275           all) values specified by --snmp-options by using the syntax
276
277           router[:[port][:[timeout][:[retries][:[backoff][:version]]]]]
278
279       --global "bla: abc"
280           Use this to add global options to the generated config file.  You
281           can call --global several times to add multiple options.  The line
282           will appear in the configuration just before the config for the
283           next router appearing on the command line.
284
285            --global "workdir: /home/mrtg"
286
287           If you want some default Options you might want to put
288
289            --global "options[_]: growright,bits"
290
291           Specifying --global after the last router on the command line will
292           create a line in the configuration file which will appear after all
293           the routers.
294
295       --noreversedns
296           Do not try to reverse lookup IP numbers ... a must for DNS free
297           environments.
298
299       --no-down
300           Normally cfgmaker will not include interfaces which are marked any‐
301           thing but administratively and operationally UP. With this switch
302           you get them all.
303
304       --show-op-down
305           Include interfaces which are operatively down.
306
307       --zero-speed speed
308           Assign this speed in bits-per-second to all interfaces which return
309           0 for ifSpeed and ifHighSpeed.  Some switches, notably Foundry
310           equipment, return a speed of zero for some interfaces.  For exam‐
311           ple, to have all interfaces reporting zero set to 100Mbps, use
312           --zero-speed=100000000.
313
314       --subdirs format
315           Give each router its own subdirectory for the HTML and graphics (or
316           .rrd) files.  The directory name is the given format string with a
317           couple of pattern replacements.  The string "HOSTNAME" will be
318           replaced by the hostname of the router (however you specified it on
319           the cfgmaker commandline -- it may be an actual hostname or just an
320           IP address), and "SNMPNAME" will be replaced with the device's idea
321           of its own name (the same name that appears on the right side of
322           the "Title" lines).  For instance, a call like:
323
324            cfgmaker --subdirs=HOSTNAME__SNMPNAME public@10.10.0.18
325
326           would result in the generation of lines looking something like:
327
328            Directory[10.10.0.18_1]: 10.10.0.18__fp2200-bothrip-1.3
329
330       --output file
331           Write the output from cfgmaker into the file file. The default is
332           to use "STDOUT". --output is expected to appear only once on the
333           command line. If used multiple times, the file specified by the
334           last --output will be used.
335
336       --nointerfaces
337           Don't generate configuration lines for interfaces.
338
339           This makes cfgmaker skip all steps related to interfaces which
340           means it will not do any polling of the router to retrieve inter‐
341           face information which speeds up the execution of cfgmaker and it
342           will neither run any interface templates.
343
344       --interfaces
345           This makes cfgmaker generate configuration lines for interfaces
346           (the default behaviour).
347
348           The main usage of this option is to negate an --nointerfaces
349           appearing earlier on the command line.
350
351       SNMP V3 Options
352
353       Cfgmaker supports SNMP V3 using the Net:SNMP perl module.  There are
354       optional parameters affecting SNMP operation.
355
356--enablesnmpv3 {yes⎪no}
357The --enablesnmpv3 option is an optional flag to check for the presence of the

Net::SNMP libraries. Cfgmaker will try to determine whether this flag is

359required and will set the values automatically.
360

SNMPv3 Arguments

362
363A SNMP context is a collection of management information accessible by a SNMP
364entity.  An item of management information may exist in more than one context
365and a SNMP entity potentially has access to many contexts.  The combination of
366a contextEngineID and a contextName unambiguously identifies a context within
367an administrative domain.  In a SNMPv3 message, the contextEngineID and con‐
368textName are included as part of the scopedPDU.  All methods that generate a
369SNMP message optionally take a --contextengineid and --contextname argument to
370configure these fields.
371
372Context Engine ID
373    The --contextengineid argument expects a hexadecimal string representing
374    the desired contextEngineID.  The string must be 10 to 64 characters (5 to
375    32 octets) long and can be prefixed with an optional "0x".  Once the
376    --contextengineid is specified it stays with the object until it is
377    changed again or reset to default by passing in the undefined value.  By
378    default, the contextEngineID is set to match the authoritativeEngineID of
379    the authoritative SNMP engine.
380
381Context Name
382    The contextName is passed as a string which must be 0 to 32 octets in
383    length using the --contextname argument.  The contextName stays with the
384    object until it is changed.  The contextName defaults to an empty string
385    which represents the "default" context.
386

User-based Security Model Arguments

388
389The User-based Security Model (USM) used by SNMPv3 requires that a security‐
390Name be specified using the --username argument.  The creation of a Net::SNMP
391object with the version set to SNMPv3 will fail if the --username argument is
392not present.  The --username argument expects a string 1 to 32 octets in
393length.
394
395Different levels of security are allowed by the User-based Security Model
396which address authentication and privacy concerns.  A SNMPv3 target will
397derive the security level (securityLevel) based on which of the following
398arguments are specified.
399
400By default a securityLevel of 'noAuthNoPriv' is assumed.  If the --authkey or

--authpassword arguments are specified, the securityLevel becomes 'authNo‐

402Priv'.  The --authpassword argument expects a string which is at least 1 octet
403in length.  Optionally, the --authkey argument can be used so that a plain
404text password does not have to be specified in a script.  The --authkey argu‐
405ment expects a hexadecimal string produced by localizing the password with the
406authoritativeEngineID for the specific destination device.  The "snmpkey"
407utility included with the Net::SNMP  distribution can be used to create the
408hexadecimal string (see snmpkey).
409
410Two different hash algorithms are defined by SNMPv3 which can be used by the
411Security Model for authentication.  These algorithms are HMAC-MD5-96 "MD5"
412(RFC 1321) and HMAC-SHA-96 "SHA-1" (NIST FIPS PUB 180-1).   The default algo‐
413rithm used by the module is HMAC-MD5-96.  This behavior can be changed by
414using the --authprotocol argument.  This argument expects either the string
415'md5' or 'sha' to be passed to modify the hash algorithm.
416
417By specifying the arguments --privkey or --privpassword the securityLevel
418associated with the object becomes 'authPriv'.  According to SNMPv3, privacy
419requires the use of authentication.  Therefore, if either of these two argu‐
420ments are present and the --authkey or --authpassword arguments are missing,
421the creation of the object fails.  The --privkey and --privpassword arguments
422expect the same input as the --authkey and --authpassword arguments respec‐
423tively.
424
425The User-based Security Model described in RFC 3414 defines a single encryp‐
426tion protocol to be used for privacy.  This protocol, CBC-DES "DES" (NIST FIPS
427PUB 46-1), is used by default or if the string 'des' is passed to the

--privprotocol argument. By working with the Extended Security Options Con‐

429sortium http://www.snmp.com/eso/, the module also supports additional proto‐
430cols which have been defined in draft specifications.  The draft
431http://www.snmp.com/eso/draft-reeder-snmpv3-usm-3desede-00.txt defines the
432support of CBC-3DES-EDE "Triple-DES" (NIST FIPS 46-3) in the User-based Secu‐
433rity Model.  This protocol can be selected using the --privprotocol argument
434with the string '3desede'.  The draft http://www.snmp.com/eso/draft-blumen
435thal-aes-usm-04.txt describes the use of CFB128-AES-128/192/256 "AES" (NIST
436FIPS PUB 197) in the USM. The three AES encryption protocols, differentiated
437by their key sizes, can be selected by passing 'aescfb128', 'aescfb192', or
438'aescfb256' to the -privprotocol argument.
439

Details on Filters

441
442The purpose of the filters is to decide which interfaces to accept and which
443interfaces to reject.  This decision is done for each interface by evaluating
444the filter expression as a piece of Perl code and investigating the result of
445the evaluation.  If true, accept the interface otherwise reject it.
446
447When working with filters, remember that Perl has it's own idea of what truth
448and false is.  The empty string "" and the string "0" are false, all other
449strings are true.  This further imples that any integer value of 0 is false as
450well as any undef value.  It also implies that all references are considered
451true.
452
453As the filter is evaluated as a Perl expression, several useful constructs in
454Perl are worth mentioning:
455
456Expressions might be grouped by using parentheses "()".  Expressions might be
457combined using boolean operators such as the following:
458
459"and" (equivalent with "&&")
460    Boolean "and" of the two expressions, is only true if both expressions are
461    true.  Example: expression1 and expression2
462
463"or" (equivalent with "⎪⎪")
464    Boolean "or" of the two expressions, is true if either or both expressions
465    are true.  Example: expression1 or expression2
466
467"not" (equivalent with "!")
468    Boolean negation of a single expression.  Example:  not expression .  Yet
469    another example: !expression
470
471(For more details on this I recommend a book on Perl)
472

Predefined Filter Variables

474
475To facilitate, there are a number of predefined values available to use in the
476filter.  Note that these variables are also available when templates inter‐
477faces are evaluated (but not host templates).
478
479Caveat:  All these variables' names begin with a dollar sign  ($), which is a
480syntactic requirement for scalar variables in Perl.  The danger here is that
481the dollar sign in many shells is an active character (often used for shell
482variables exactly as in Perl variables) so it is important to ensure that the
483Perl expression isn't evaluated by the command line shell as shell code before
484being passed to cfgmaker as command line arguments.  In shells like Bourne
485shell, ksh shell or bash shell, placing the entire expression within single
486qoutes will avoid such accidental evaluation:
487
488 '--if-filter=($default_iftype && $if_admin)'
489

$if_type

491    This is an integer specifying the interface type as per the SNMP standards
492    and as reported by the polled device.  A complete list of interface types
493    would be impractical for this document , but there are a number predefined
494    varables below.  Normally, cfgmaker puts in the target's PageTop this
495    iftype value within paranthesis after the name of the interface type. (e.g
496    "propPointToPointSerial (22)").
497
498    Here's a list of some of the most common interface types by number:
499
500       6 ethernetCsmacd
501       7 iso88023Csmacd
502       9 iso88025TokenRing
503      15 fddi
504      19 E1
505      20 basicISDN
506      21 primaryISDN
507      22 propPointToPointSerial
508      23 ppp
509      24 softwareLoopback
510      30 ds3
511      32 frame-relay
512      33 rs232
513      37 atm
514      39 sonet
515      44 frameRelayService
516      46 hssi
517      49 aal5
518      53 propVirtual
519      62 Fast Ethernet (100BaseT)
520      63 ISDN & X.25
521      69 Full Duplex Fast Ethernet (100BaseFX)
522      94 Asymetric Digital Subscriber Loop (ADSL)
523     117 Gigabit Ethernet
524     134 ATM Sub Interface
525

$default

527    True if and only if cfgmaker normally should accepted the interface based
528    on the interfaces administrative and operational state (taking the flags
529    --no-down and --show-op-down into account) and it's type (and a few other
530    things).
531

$default_ifstate

533    True if and only if cfgmaker would have accepted the interface based on
534    it's operational and administrative states (also taking into account the
535    presence of the flags --no-down and --show-op-down).
536

$default_iftype

538    True if and only if cfgmaker would have accepted the interface based on
539    it's type (and a few type specific details in addition).
540

$if_admin

542    True if and only if the interface is in an adminstrative up state.
543

$if_oper

545    True if and only if the interface is in an operational up state.
546
547A number of variables are also predefined to easily decide if an interface
548belong to a certain cathegory or not.  Below is all those variables listed
549together with which if_type numbers each variable will be true for.  Note that
550some variables refer to other variables as well.
551

$if_is_ethernet

553    True for ethernet interfaces (nr 6, 7, 26, 62, 69 and 117).
554

$if_is_isdn

556    True for various ISDN interface types (nr 20, 21, 63, 75, 76 and 77)
557

$if_is_dialup

559    True for dial-up interfaces such as PPP as well as ISDN.  (nr 23, 81, 82
560    and 108 in addition to the numbers of $if_is_isdn).
561

$if_is_atm

563    True for miscellaneous ATM related interface types (nr 37, 49, 107, 105,
564    106, 114 and 134).
565

$if_is_wan

567    True for WAN interfaces point to point, Frame Relay and High Speed Serial
568    ( 22,32,44,46)
569

$if_is_lan

571    True for LAN interfaces (8, 9, 11, 15, 26, 55, 59, 60 and 115 in addition
572    to the numbers of $if_is_ethernet).
573

$if_is_dsl

575    True for ADSL, RDSL, HDSL and SDSL (nr 94, 95, 96, 97)
576

$if_is_loopback

578    True for software loopback interfaces (nr 24)
579

$if_is_ciscovlan

581    True for Cisco VLAN interfaces (interfaces with the word Vlan or VLAN in
582    their ifdescs)
583

$if_vlan_id

585    Returns the vlan id associated with a specific port on Cisco Catalyst
586    switches under both Catalyst OS and IOS, and 3Com switches.  If it is not
587    a vlan interface, will return undef.
588

$if_cisco_trunk

590    Returns the trunking state of a specific port on Cisco Catalyst switches
591    under both Catalyst OS and IOS.  Returns "1" if the interface is a trunk,
592    undef otherwise.
593

$if_MTU

595    Returns the Maximum Transfer Unit associated with a specific port.
596
597Besides that, you can also use the variables defined for templates below.
598Further, all the variables available in cfgmaker is at the scripts disposal
599even if the use of such features is discouraged.  More "shortcuts" in the form
600of variables and functions will be made avaiable in the future instead.
601

Examples on Filters

603
604The following filter will not affect which interfaces get's included or
605excluded, it will make cfgmaker behave as normally.
606
607 '--if-filter=$default'
608
609The following filter will make cfgmaker exclude PPP (23) interfaces:
610
611 '--if-filter=$default && $if_type!=23'
612
613The following filter will make cfgmaker behave as usual except that it will
614consider the operational state of an interface irrelevant but still reject all
615interfaces which are administratively down.
616
617 '--if-filter=$if_admin && $default_iftype'
618

Details on Templates

620
621The contents of the template files are evaluated as a Perl program.  A number
622or Perl variables are available for the program to read and others are used to
623be written to.
624
625As quite a few of the predefined variables has values which are are supposed
626to be used in HTML code some of them have an "HTML-escaped" variant, e.g
627$html_syslocation is the HTML escaped variant of $syslocation.  The HTML
628escaping means that the chars "<", ">" and "&" are replaced by "&lt;", "&gt;"
629and "&amp;" and that newlines embedded in the string are prepended with "<BR>"
630and appended with a space character (if a newline is last in the string it is
631not touched).
632

Writable Template Variables

634
635These are the variables available to store the configuration lines in.  Some
636of them are initialized prior to the evaluation of the template but such con‐
637tent normally is comments for inclusion in the final configuration file so
638those variables might be reset to the empty string in the template code to
639eliminate the comments.  The other way around is also possible, the contents
640of these variables might be extended with further information for various rea‐
641sons such as debugging etc.
642
643Once the template has been evaluated, the following happens:  if the template
644is a interface template and the actual interface for some reason is rejected
645and thus needs to be commented out, all the lines in the variable $tar‐

get_lines are turned into comments by adding a hash mark ("#") at their begin‐

647ning.  Then all the variables $head_lines, $problem_lines , $target_lines and

$separator_lines are concatenated together to form the lines to add to the

649configuration file.
650

$target_lines

652    This variable is the placeholder for the configuration lines created by
653    the template.  $target_lines is predefined to be empty when the template
654    code is evaluated.
655

$head_lines

657    This variable is intended to be the placeholder for the comment line
658    appearing just before the target in the configuration file.  It is ini‐
659    tialized with that comment line before the evaluation of the template code
660    and if the template doesn't modify $head_lines during evaluation, the com‐
661    ment will look like usual in the config file.
662

$problem_lines

664    This variable is intended to be the placholder for the comment lines
665    describing any problems which might have been encountered when trying to
666    add the target into the configuration.  For host templates it's normally
667    not used and for those it's predefined as the empty string.  For interface
668    templates $problem_lines is predefined with the error description comments
669    which cfgmaker normally would use for rejected interfaces or as the empty
670    string for accepted interfaces.
671
672    It is possible to test against $problem_lines to find out if an interface
673    will be included or rejected but this is not recommended.  Test against
674    $if_ok instead.
675

$separator_lines

677    This variable is the placeholder for the string to use as the separator
678    between the code for individual targets.  The contents of this variable is
679    put after each target (so the lines will appear after the end of the last
680    target in the config as well).
681

Predefined Template Variables

683
684All the variables below are available for interface templates to use.  For
685host templates, only those listed under "Host and System Variables" are avail‐
686able.
687
688For interface templates the variables listed under "Predefined Filter Vari‐
689ables" are also available.
690

Host and System Variables

692

$router_name

694    This is the fully qualified name for the router.  It is affected by the
695    following items on the command line:  the router name itself and
696    --dns-domain.
697

$router_connect

699    This is the reference string for the router being polled.  It is on the
700    form community@router possibly followed by some snmp options.  It is
701    affected by the following items on the command line:  the router name
702    itself, --community, --snmp-options and --dns-domain.  (There's no HTML
703    escaped variant available)
704

$directory_name

706    This variable should contain the directory name as cfgmaker normally would
707    use as the value for the "Directory[]" directive.  The value is determined
708    by the --subdirs command line option.  If --subdirs isn't specified
709    $directory_name will be the empty string.  (There's no HTML escaped vari‐
710    ant available)
711

$syscontact

713    This variable is the router's SNMP sysContact value.  (HTML escaped vari‐
714    ant: $html_syscontact)
715

$sysname

717    This variable is the router's SNMP sysName value.  (No HTML escaped vari‐
718    ant available)
719

$syslocation

721    This variable is the router's SNMP sysLocation value.  (HTML escaped vari‐
722    ant: $html_syslocation)
723

$sysdescr

725    This variable is the router's SNMP sysDescr value.  It is normally not
726    used by cfgmaker but might be useful in a template.  (HTML escaped vari‐
727    ant: $html_sysdescr)
728
730

$target_name

732    This is what cfgmaker normally would use as the the name of the target.
733    The target name is what is found within the square brackets, "[]", for
734    target directives.  (There's no HTML escaped variant available)
735

$if_ref

737    This the reference string for the interface.  It is expected to be used in
738    the "Target[xyz]" directive to distinguish what interface to use.  The
739    value of this variable is affected by the --ifref command line option.  It
740    is normally used together with $router_connect.  (There's no HTML escaped
741    variant available)
742

$if_ok

744    This variable is true if the interface is going to be included into the
745    configuration file, otherwise false.  Don't test against other variables
746    such as $problem_lines to find out if an interface will be rejected or
747    not, use this $if_ok instead.
748

$default_target_lines

750    This variable contains all the target lines which cfgmaker by default out‐
751    puts for this interface.  It's useful if you want to have the "standard
752    target" but want to add some extra lines to it by using a template.
753
754By default cfgmaker uses the following directives for each target it gener‐
755ates: Target[], SetEnv[], MaxBytes[], Title[], PageTop[] and if there is any
756directory specified also the Directory[] directive.
757
758To facilitate the creation of templates which generates target configs which
759are similar to the default one, each of the above mentioned directive lines
760have a corresponding variable containing the line as cfgmaker would have out‐
761put it by default.
762
763Note that none of these have a HTML escaped variant, text in them is HTML
764escaped where needed.  Also note that they do not have any newline at the end.
765

$default_target_directive

767    This variable contains the default string for the Target[] directive line.
768

$default_setenv_directive

770    This variable contains the default string for the SetEnv[] directive line.
771

$default_directory_directive

773    This variable contains the default string for the Directory[] directive
774    line which means it is an empty string (with no newline) if there's no
775    directory.
776

$default_maxbytes_directive

778    This variable contains the default string for the MaxBytes[] directive
779    line.
780

$default_title_directive

782    This variable contains the default string for the Title[] directive line.
783

$default_pagetop_directive

785    This variable contains the default string for the PageTop[] directive
786    lines.
787

Interface Network Configuration Variables

789

$if_ip

791    This variable should contain the IP-address of the interface, if any has
792    been assigned to it.  (There's no HTML escaped variant available)
793

$ifindex

795    This variable is the SNMP ifIndex for the interface which per definition
796    always is an integer.  (There's no HTML escaped variant available)
797

$if_index

799    Equivalent with $ifindex.
800

$if_eth

802    Contains the ethernet address of the interface, if any.  (There's no HTML
803    escaped variant available)
804

$if_speed

806    This variable is the speed in bytes/second (with prefixes).  (There's no
807    HTML escaped variant available)
808

$if_speed_str

810    This variable is a cooked speed description which is either in bits or
811    bytes depending on wether or not the bits option is active and also with
812    the proper prefix for the speed (k, M, G etc).  (No HTML escaped variant
813    available)
814

$if_type_desc

816    This variable is a textual description of the interface type.  (HTML
817    escaped variant: $html_if_type_desc)
818

$if_type_num

820    This variable the integer value corresponding to the interface type (for a
821    listing for the value for the more common interface types, see the section
822    DETAILS ON FILTERS above).  (No HTML escaped variant available)
823

$if_dns_name

825    This is the DNS name for the interface.  (No HTML escaped variant avail‐
826    able)
827

Interface Name, Description and Alias Variables

829
830It might seem confusing with both Name, Description and Alias in this context
831and to some extent it is.  Name and Description are usually supported on most
832equipment but how they are used varies, both between manufacturers as well as
833between different cathegories of equipment from the same manufacturer.  The

Alias is at least supported by Cisco IOS, and that variable contains whatever

835is used in the IOS statement called "description" for the interface (not to be
836confused with the SNMP variables for Description).
837
838For better control from the command line consider $if_title_desc which con‐
839tents are controlled by the --if-descr command line option.
840

$if_snmp_descr

842    This variable should contain the "raw" description of the interface as
843    determined by the SNMP polling of the router.  (HTML escaped variant:
844    $html_if_snmp_descr)
845

$if_snmp_name

847    The "raw" name for the interface as provided by SNMP polling.  (HTML
848    escaped variant: $html_if_snmp_name)
849

$if_snmp_alias

851    The "raw" ifAlias for the interface as provided by SNMP polling. (HTML
852    escaped variant: $html_if_snmp_alias)
853

$if_cisco_descr

855    The "raw" CiscolocIfDescr for the interface as provided by SNMP polling.
856    (HTML escaped variant: $html_if_cisco_descr)
857

$if_description

859    This is the "cooked" description string for the interface, taking into
860    account the SNMP values found for the interface's RDescr, ifAlias and Cis‐
861    colocIfDescr.  (HTML escaped variant: $html_if_description)
862

$if_title

864    The full string cfgmaker by default would have used for the Title[] direc‐
865    tive in the configuration as well as the content of the topmost H1 tag in
866    the PageTop[].  Is composed by the contents of $desc_prefix,
867    $if_title_desc and $sysname.
868
869    As $if_title depends on $if_title_desc, it is possible to indirectly con‐
870    trol $if_title by using the command line option --if-descr.
871
872    (HTML escaped variant: $html_if_title)
873

$if_port_name

875    If the host is a Cisco Catalyst LAN switch, this variable is the name of
876    that port.  (No HTML escaped variant available)
877

$desc_prefix

879    This variable is a prefix of the description of what the target is to use
880    in the "Title[]" directive and in the H1 section of the "PageTop[]".
881    Default is "Traffic analysis for ".  (HTML escaped variant:
882    $html_desc_prefix)
883

$if_title_desc

885    This is the description of the interface normally used by cfgmaker as part
886    of the variable $if_title.  The latter is used as the full string in the
887    "Title[]" directove and the H1 section in the PageTop[].
888
889    $if_title_desc is controlled by the command line option --if-descr which
890    indirectly controls the contents of $if_title
891
892    (HTML escaped variant: $html_if_title_desc)
893

Help Functions for Templates

895
896The following functions exists to facilitate the writing of host and interface
897templates.
898

html_escape(string)

900    html_escape() takes a string as an argument and returns a new string where
901    the following substitutions has been done:  the chars "<", ">" and "&" are
902    replaced by "&lt;", "&gt;" and "&amp;" and that newlines embedded in the
903    string are prepended with "<BR>" and appended with a space character (new‐
904    lines at the end of the string are not touched).
905

oid_pick($router_connect,$v3opt,"oid1","oid2"...)

907    This function will try to poll each of the oids specified until it is suc‐
908    cessful or has run out of oids. It will return the name of the first oid
909    that worked or undef if it is not successful
910

Example Template Files

912
913Template Example 1: Eliminating Rejected Targets From Appearing
914
915This template file generates exactly the same configuration code per interface
916as cfgmaker does by default, with the exception that it eliminates all lines
917(comments as well as config code) for an interface if the interface happens to
918be rejected.
919
920 if(not $problem_lines)
921 {
922   $target_lines .= <<ECHO;
923
924 Target[$target_name]: $if_ref:$router_connect
925 SetEnv[$target_name]: MRTG_INT_IP="$if_ip" MRTG_INT_DESCR="$if_snmp_descr"
926 ECHO
927
928   if ($directory_name) {
929       $target_lines .= "Directory[$target_name]: $directory_name\n";
930   }
931
932   $target_lines .= <<ECHO;
933 MaxBytes[$target_name]: $if_speed
934 Title[$target_name]: $html_desc_prefix$html_if_title_desc -- $sysname
935 PageTop[$target_name]: <h1>$html_desc_prefix$html_if_title_desc -- $sysname</h1>
936                <div id="sysdetails">
937                        <table>
938                                <tr>
939                                        <td>System:</td>
940                                        <td>$sysname in $html_syslocation</td>
941                                </tr>
942                                <tr>
943                                        <td>Maintainer:</td>
944                                        <td>$html_syscontact</td>
945                                </tr>
946                                <tr>
947                                        <td>Description:</td>
948                                        <td>$html_if_description</td>
949                                </tr>
950                                <tr>
951                                        <td>ifType:</td>
952                                        <td>$html_if_type_desc ($if_type_num)</td>
953                                </tr>
954                                <tr>
955                                        <td>ifName:</td>
956                                        <td>$html_if_snmp_name</td>
957                                </tr>
958 ECHO
959
960   $target_lines .= <<ECHO if defined $if_port_name;
961                                <tr>
962                                        <td>Port Name:</td>
963                                        <td>$if_port_name</td>
964                                </tr>
965 ECHO
966
967   $target_lines .= <<ECHO;
968                                <tr>
969                                        <td>Max Speed:</td>
970                                        <td>$if_speed_str</td>
971                                </tr>
972 ECHO
973
974   $target_lines .= <<ECHO if $if_ip;
975                                <tr>
976                                        <td>Ip:</td>
977                                        <td>$if_ip ($if_dns_name)</td>
978                                </tr>
979 ECHO
980
981   $target_lines .= <<ECHO;
982                        </table>
983                </div>
984 ECHO
985 } else {
986   $head_lines="";
987   $problem_lines="";
988   $target_lines="";
989   $separator_lines="";
990 }
991

Template Example 2: Simplier Version of Example 1

993
994Example 1 was partly intended to demonstrate how to customize the generation
995of interface targets but also to provide a hint of how the variables are used
996in the "default" template which one could consider that cfgmaker normally
997uses.
998
999If you're only intrested in the easiest way of entirely eliminating those
1000reject interfaces, the template below would do the job as well by using

$default_target_lines.

1002
1003 if($if_ok) {
1004  $target_lines = $default_target_lines;
1005 } else {
1006   $head_lines="";
1007   $problem_lines="";
1008   $target_lines="";
1009   $separator_lines="";
1010 }
1011

Template Example 3: Creating CPU Targets for Hosts

1013
1014Below is an example of a host template.
1015
1016 $head_lines .= <<ECHO;
1017 #---------------------------------------------------------------------
1018 ECHO
1019
1020 my $target_name = $router_name . ".cpu";
1021
1022 $target_lines .= <<ECHO;
1023
1024 YLegend[$target_name]: Percentage CPU load
1025 ShortLegend[$target_name]: %
1026 Legend1[$target_name]: CPU load in %
1027 Legend2[$target_name]:
1028 Legend3[$target_name]: Max Observed CPU load
1029 Legend4[$target_name]:
1030 LegendI[$target_name]: &nbsp;CPU Load:
1031 LegendO[$target_name]:
1032 WithPeak[$target_name]: ywm
1033 MaxBytes[$target_name]: 100
1034 Options[$target_name]: growright, gauge, nopercent
1035 Title[$target_name]: $router_name CPU load
1036 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
1037 PageTop[$target_name]: <h1>$router_name CPU load</h1>
1038                <div>
1039                        <table>
1040                                <tr>
1041                                        <td>System:</td>
1042                                        <td>$router_name in $html_syslocation</td>
1043                                </tr>
1044                                <tr>
1045                                        <td>Maintainer:</td>
1046                                        <td>$html_syscontact</td>
1047                                </tr>
1048                                <tr>
1049                                        <td>Description:</td>
1050                                        <td>$html_sysdescr</td>
1051                                </tr>
1052                                <tr>
1053                                        <td>Resource:</td>
1054                                        <td>CPU.</td>
1055                                </tr>
1056                        </table>
1057                </div>
1058 ECHO
1059

EXAMPLES

1061       The first example creates a config file for router.place.xyz:  the
1062       router has the community name public.  Interfaces get identified by
1063       their IP number.  Two global options get added to the config file.  The
1064       config file gets redirected to mrtg.conf.  The '\' signs at the end of
1065       the line mean that this command should be written on a single line.
1066
1067        cfgmaker --global "WorkDir: /home/tobi"           \
1068                 --global "Options[_]: growright,bits"    \
1069                 --ifref=ip                               \
1070                 public@router.place.xyz > mrtg.cfg
1071
1072       Note: if cfgmaker is not in your path, but you are in the directory
1073       where cfgmaker is stored, you can start it with ./cfgmaker
1074
1075       The next example creates a config file for four devices:
1076       router1.place.xyz, router2.place.xyz, switch1.place.xyz and
1077       switch2.place.xyz all with the community public.
1078
1079       The two routers will have --ifref set to descr whilst the two switches
1080       will use --ifref set to name.  Further the routers will use --ifdesc
1081       set to alias and switch1.place.xyz will use --ifdesc set to descr
1082       whilst switch2.place.xyz use name instead.
1083
1084       Finally, there will be two Options lines inserted in the configuration:
1085       One will be in the beginning, whilst the other will be inserted after
1086       the lines related to the two routers but before those lines related to
1087       the switches.
1088
1089        cfgmaker --global "WorkDir: /home/tobi"           \
1090                 --global "Options[_]: growright,bits"    \
1091                 --ifref=descr                            \
1092                 --ifdesc=alias                           \
1093                 public@router1.place.xyz                 \
1094                 public@router2.place.xyz                 \
1095                 --global "Options[_]: growright"         \
1096                 --ifref=name                             \
1097                 --ifdesc=descr                           \
1098                 public@switch1.place.xyz                 \
1099                 --ifdesc=name                            \
1100                 public@switch2.place.xyz > mrtg.cfg
1101
1102       The next example demonstrates how to use the --community,
1103       --snmp-options and --dns-domain to make the command line simpler.  All
1104       the equipment will use the community hidden, except for the ppp-server
1105       which use community access.  All equipment uses these SNMP options: 1s
1106       timeout, 1 retry and SNMP version 2 (backoff and port is unspecified
1107       which means they use the default values).  The exception again is the
1108       ppp-server which uses SNMP version 1.  Finally, all the equipment is
1109       part of the domain place.xyz, except for the ppp-server which is part
1110       of the domain remote.place.xyz.  Note that the latter is achieved sim‐
1111       ply by specifying the name of the ppp-server to be ppp-server.remote .
1112
1113        cfgmaker --global "WorkDir: /home/tobi"           \
1114                 --global "Options[_]: growright,bits"    \
1115                 --dns-domain=place.xyz                   \
1116                 --community=hidden                       \
1117                 --snmp-options=::1:1::2                  \
1118                 router1                                  \
1119                 router2                                  \
1120                 router3                                  \
1121                 router4                                  \
1122                 router5                                  \
1123                 switch1                                  \
1124                 switch2                                  \
1125                 switch3                                  \
1126                 switch4                                  \
1127                 switch5                                  \
1128                 switch6                                  \
1129                 switch7                                  \
1130                 access@ppp-server.remote:::::1 > mrtg.cfg
1131

SEE ALSO

1133       mrtg-reference
1134

AUTHOR

1136       Tobias Oetiker <tobi@oetiker.ch> and Jakob Ilves <jakob.ilves@ora‐
1137       cle.com>
1138

LICENSE

1140       GNU General Public License
1141
1143       Cfgmaker is Copyright 2000 by Tobias Oetiker <tobi@oetiker.ch>
1144
1145
1146
11472.15.1                            2007-02-01                       CFGMAKER(1)
Impressum