Debian Codegraph @

bin/cfgmaker

raw ◀ ▶
2 Debian patches touch this file
1 #! /home/oetiker/.plenv/shims/perl -w
2 # -*- mode: Perl -*-
3 ##################################################################
4 # MRTG 2.17.10 -- Config file creator
5 ##################################################################
6 # Created by Tobias Oetiker <[email protected]>
7 # this produces an mrtg config file for one router or more routers
8 # by pulling info off the router via snmp
9 ##################################################################
10 # Distributed under the GNU copyleft
11 # Copyright 2000 by Tobias Oetiker
12 ##################################################################
13
14 # DEBUG TARGETS
15 # base - basic program flow
16 # snpo - SNMP Polling
17 # snpd - SNMP Detail
18 #@main::DEBUG=qw(base);
19 @main::DEBUG=qw(base snpo snpd);
20
21 require 5.005;
22 use strict;
23
24 BEGIN {
25 # Automatic OS detection ... do NOT touch
26 if ( $^O =~ /^(?:(ms)?(dos|win(32|nt)?))/i ) {
27 $main::OS = 'NT';
28 $main::SL = '\\';
29 $main::PS = ';';
30 } elsif ( $^O =~ /^NetWare$/i ) {
31 $main::OS = 'NW';
32 $main::SL = '/';
33 $main::PS = ';';
34 } elsif ( $^O =~ /^VMS$/i ) {
35 $main::OS = 'VMS';
36 $main::SL = '.';
37 $main::PS = ':';
38 } else {
39 $main::OS = 'UNIX';
40 $main::SL = '/';
41 $main::PS = ':';
42 }
43 }
44
45 use FindBin;
46 use lib "${FindBin::Bin}";
47 use lib "${FindBin::Bin}${main::SL}..${main::SL}lib${main::SL}mrtg2";
48
49 use MRTG_lib "2.100015";
50 use Getopt::Long;
51 use Pod::Usage;
52 use Socket;
53
54
55 sub main {
56
57 # assign defaults
58 my %opt = (
59 'enable-ipv6' => 0,
60 'use-16bit' => 0,
61 'community' => 'public',
62 'interfaces' => 1,
63 'enablesnmpv3' => 0,
64 # 'snmp-options' => ':::::2'
65 );
66 my %routers;
67 my %confcache;
68 my $ipv4only;
69 my %v3opt;
70 $opt{fullcmd} =
71 "$0 ".(join " ",
72 map {$_ =~ /[ \[\]\*\{\}\;\>\<\&]/ ? qq{"$_"} : $_ } @ARGV);
73 options(\%opt,\%routers);
74
75 # Check for IPv6 libraries if IPv6 is enabled.
76 # If the check fails, IPv6 is disabled.
77 $ipv4only = 1;
78 if ($opt{'enable-ipv6'} == 1) {
79 if ((eval {local $SIG{__DIE__};require Socket6;}) && (eval {local $SIG{__DIE__};require IO::Socket::INET6;})) {
80 debug ('base',"IPv6 libraries found, IPv6 enabled.");
81 $ipv4only = 0;
82 } else {
83 warn "WARNING: IPv6 libraries not found, IPv6 disabled.\n";
84 $opt{'enable-ipv6'} = 0;
85 }
86 }
87
88 if ($opt{'use-16bit'} == 1) {
89 warn "WARNING: Using 16bit RequestIDs\n";
90 no warnings;
91 $SNMP_Session::default_use_16bit_request_ids=1;
92 }
93 # Check for SNMP V3
94 #
95 if (exists($opt{username}) or lc($opt{enablesnmpv3}) eq "yes" ) {
96 if (eval {local $SIG{__DIE__};require Net_SNMP_util;}) {
97 import Net_SNMP_util;
98 debug('base', "SNMP V3 libraries found, SNMP V3 enabled.");
99 $opt{enablesnmpv3} = "yes";
100 push @{$opt{global}}, "enablesnmpv3: yes";
101 } else {
102 warn "WARNING: SNMP V3 libraries not found, SNMP V3 disabled. Falling back to V2c.\n";
103 require SNMP_util;
104 import SNMP_util;
105 $opt{enablesnmpv3} = "revert";
106 }
107 }
108 else {
109 require SNMP_util;
110 import SNMP_util;
111 $opt{enablesnmpv3} = "no";
112 }
113
114 init();
115
116 foreach my $router
117 (sort
118 {($routers{$a}{noofrouter}) <=> ($routers{$b}{noofrouter})}
119 keys %routers)
120 {
121 my @snmpopt = split(/:/,$routers{$router}{'snmp-options'});
122 if ($snmpopt[5] and $snmpopt[5] == 3) {
123 if ($opt{enablesnmpv3} eq "revert") {
124 $snmpopt[5] = 2;
125 warn "reverting to snmpV2c for router $router\n";
126 $routers{$router}{'snmp-options'} = join(":",@snmpopt);
127 $routers{$router}{snmpopt_current} = $routers{$router}{'snmp-options'};
128 } else {
129 die "SNMP V3 requires a --username parameter as part of the User Security Model for router $routers{$router}{routerkey}" if $opt{enablesnmpv3} eq "no";
130 $routers{$router}{enablesnmpv3} = $opt{enablesnmpv3};
131 %v3opt = parsev3(\%opt);
132 }
133 } else {
134 debug('base',"snmpv3 available, but using v1/v2c for $routers{$router}{routerkey}") if $opt{enablesnmpv3} eq "yes";
135 }
136
137
138 # pod2usage(-verbose=>1,-message=>"ERROR: Could not Parse $router\n")
139 # unless $router =~ /.*\@.*/;
140 debug('base',"Get Device Info on $router");
141 $routers{$router}{ipv4only} = $ipv4only;
142 if ( my $devinfo = DeviceInfo($router,\%routers,\%v3opt) ) {
143 $routers{$router}{deviceinfo} = $devinfo;
144 } else {
145 warn "WARNING: Skipping $router as no info could be retrieved\n\n";
146 sleep 5;
147 next;
148 }
149
150 if ($opt{interfaces}) {
151 debug('base',"Populating confcache");
152 populateconfcache(\%confcache,$router,$routers{$router}{ipv4only},1,\%v3opt);
153 debug('base',"Get Interface Info");
154 InterfaceInfo(\%confcache,\%routers,$router,\%opt,\%v3opt);
155 }
156 }
157 GenConf(\%opt,\%routers,\%confcache,\%v3opt);
158 } # end main
159
160 main;
161 exit 0;
162
163 sub InterfaceInfo($$$$$) {
164 my $confcache = shift;
165 my $routers = shift;
166 my $router = shift;
167 my $opt = shift;
168 my $v3opt = shift;
169 my @Variables = qw (ifIndex ifType ifAdminStatus ifOperStatus ifMtu);
170
171 my $snmphost = v4onlyifnecessary($router, $routers->{$router}{ipv4only});
172
173 if ($routers->{$router}{deviceinfo}{Vendor} eq 'cisco' &&
174 $routers->{$router}{deviceinfo}{sysDescr} =~ m/Version\s+(\d+\.\d+)/) {
175 push @Variables, ($1 > 11.0 or $1 < 10.0 ) ? "ifAlias" : "CiscolocIfDescr";
176 if ($1 > 11.2) {push @Variables, "vmVlan";};
177 if ($1 > 11.3) {push @Variables, "vlanTrunkPortDynamicStatus";};
•178 } elsif ( $routers->{$router}{deviceinfo}{Vendor} =~ /(?:hp|juniper|dlink|wwp|foundry|dellLan|force10|3com|extremenetworks|openBSD|arista|enterasys|zyxel|vyatta|dcn|brocade|datacom|alcatel|mikrotik|huawei|eltex|ubiquiti)/i) {
179 push @Variables, "ifAlias";
180 }
181
182 my $descr = $routers->{$router}{deviceinfo}{sysDescr};
183 if ($routers->{$router}{deviceinfo}{Vendor} eq 'cisco' &&
184 $descr =~ m/Catalyst\sOperating\sSystem|Cisco\sSystems\sWS-C2900/ ) {
185 push @Variables, "CiscoCatalystPortName";
186 push @Variables, "vmVlan";
187 }
188 if ($routers->{$router}{deviceinfo}{Vendor} eq 'cisco' &&
189 $descr =~ m/Catalyst/ ) {
190 push @Variables, "vlanTrunkPortDynamicStatus";
191 }
192 if ($descr =~ m/Passport-8610/ || $descr =~ m/MERS-8610/ ) {
193 push @Variables, "ppPortName";
194 }
195
196 foreach my $var (@Variables) {
197 debug('base',"Walking $var");
198 foreach my $tuple (snmpwalk($snmphost,$v3opt, $var)){
199 my($if,$value) = split /:/, $tuple, 2;
200 $value =~ s/[\0- ]+$//; # no trailing space
201 $routers->{$router}{$if}{$var} = $value;
202 debug('snpd'," $router -> $if -> $var = $value");
203 }
204 }
205
206 # interface speed var depends on snmp version
207
208 my $snmp_version = (split(':', $router, 6))[5] || 1;
209 if ( $snmp_version =~ /[23]/ ) {
210 debug('base',"Walking ifSpeed");
211 my @ifSpeed = snmpwalk($snmphost, $v3opt,'ifSpeed');
212 debug('snpd',"\@ifSpeed = @ifSpeed\n");
213 debug('base',"Walking ifHighSpeed");
214 my @ifHighSpeed = snmpwalk($snmphost,$v3opt, 'ifHighSpeed');
215 for ( my $i=0; $i<=$#ifSpeed; $i++ ) {
216 my ($if,$value) = split /:/, $ifSpeed[$i], 2;
217 # the mib entry on ifSpeed says
218 # "An estimate of the interface's current bandwidth in bits
219 # per second. For interfaces which do not vary in bandwidth
220 # or for those where no accurate estimation can be made, this
221 # object should contain the nominal bandwidth. If the
222 # bandwidth of the interface is greater than the maximum value
223 # reportable by this object then this object should report its
224 # maximum value (4,294,967,295) and ifHighSpeed must be used
225 # to report the interface's speed. For a sub-layer which has
226 # no concept of bandwidth, this object should be zero."
227 if ( (not defined $value) || ($value == 2**32-1) ) {
228 ($if, $value) = split /:/, $ifHighSpeed[$i], 2;
229 $value = $value * 1000000; # highSpeed = contador * 10^6
230 debug('base',"Speed: $if - $value");
231 }
232 if ( ($descr =~ m/MERS-8610/ ) && (defined $ifHighSpeed[$i]) ) {
233 ($if, $value) = split /:/, $ifHighSpeed[$i], 2;
234 $value = $value * 1000000; # highSpeed = contador * 10^6
235 debug('base',"Speed: $if - $value");
236
237 }
238 $routers->{$router}{$if}{'ifSpeed'} = $value;
239 }
240 } else {
241 debug('base',"Walking ifSpeed");
242 foreach my $tuple (snmpwalk($snmphost,$v3opt, 'ifSpeed')){
243 my($if,$value) = split /:/, $tuple, 2;
244 $routers->{$router}{$if}{'ifSpeed'} = $value;
245 debug('snpd'," $router -> $if -> ifSpeed = $value");
246 }
247 }
248
249 # magic speed determination for portmaster IFs
250
251 if ($routers->{$router}{deviceinfo}{Vendor} eq 'portmaster') {
252 # We can only approximate speeds
253 #
254 # so we think that ppp can do 76800 bit/s, and slip 38400.
255 # (actually, slip is a bit faster, but usually users with newer modems
256 # use ppp). Alternatively, you can set async speed to 115200 or
257 # 230400 (the maximum speed supported by portmaster).
258 #
259 # But if the interface is ptpW (sync), max speed is 128000
260 # change it to your needs. On various Portmasters there are
261 # various numbers of sync interfaces, so modify it.
262 #
263 # The most commonly used PM-2ER has only one sync.
264 #
265 # Paul Makeev ([email protected])
266 #
267 foreach my $if (keys %{$routers->{$router}}) {
268 next unless $if =~ /^\d+$/;
269 my $ift = $routers->{$router}{$if}{ifType};
270 my $ifd = $routers->{$router}{$if}{Descr};
271 if ($ift == 23) {
272 if ($ifd eq 'ptpW1') {
273 $routers->{$router}{$if}{ifSpeed} = 128000;
274 } else {
275 $routers->{$router}{$if}{ifSpeed} = 76800;
276 }
277 } elsif ($ift == 28) {
278 $routers->{$router}{$if}{ifSpeed} = 38400;
279 } elsif ($ift == 6) {
280 $routers->{$router}{$if}{ifSpeed} = 10000000;
281 }
282 }
283 }
284
285 # match confcache info into tree
286 my $cachekey = cleanhostkey $router;
287
288 foreach my $method (keys %{$$confcache{$cachekey}}) {
289 foreach my $key (keys %{$$confcache{$cachekey}{$method}}) {
290 my $if = readfromcache($confcache,$router,$method,$key);
291 next unless $if =~ /^\d+$/;
292 $routers->{$router}{$if}{$method} = $key;
293 for ($method) {
294 #fix special chars in ifdescr
295 # no need for this we fix if references later on
296 # /^Descr|Name$/ && do {
297 # $routers->{$router}{$if}{"R$method"} = $routers->{$router}{$if}{$method};
298 # $routers->{$router}{$if}{$method} =~ s/(:)/\\$1/g;
299 # next;
300 # };
301
302 #find hostname of IF
303 !$$opt{noreversedns} && /^Ip$/ and do {
304 my $name =
305 gethostbyaddr(
306 pack('C4',
307 split(/\./,
308 $routers->{$router}{$if}{$method})),
309 AF_INET);
310 $routers->{$router}{$if}{DNSName} = ($name or "");
311 next;
312 };
313 }
314 }
315 }
316 } # end InterfaceInfo
317
318 sub GenConf ($$$$) {
319 my $opt = shift;
320 my $routers = shift;
321 my $confcache = shift;
322 my $v3opt = shift;
323 my $conf = "# Created by \n# $$opt{fullcmd}\n\n";
324
325 # print global options
326 unless (defined $$opt{'nodefaultglobal'}) {
327 $conf .= <<ECHO;
328
329 ### Global Config Options
330
331 # for UNIX
332 # WorkDir: /home/http/mrtg
333
334 # for NT
335 # WorkDir: c:\\mrtgdata
336
337 # for several Linux, like Debian, RHEL and it's derivatives
338 # WorkDir: /var/www/html/mrtg
339
340 # for others Linux
341 # WorkDir: /srv/http/mrtg
342
343 ### Global Defaults
344
345 # to get bits instead of bytes and graphs growing to the right
346 # Options[_]: growright, bits
347
348 ECHO
349 }
350
351 # Add EnableIPv6 option to configuration file
352 if ($$opt{'enable-ipv6'} == 1) {
353 $conf .= "EnableIPv6: yes\n";
354 } else {
355 $conf .= "EnableIPv6: no\n";
356 }
357
358 foreach my $router
359 (sort {($$routers{$a}{noofrouter}) <=> ($$routers{$b}{noofrouter})}
360 keys %$routers ) {
361 my $router_ref = $$routers{$router};
362 my $router_opt = $$router_ref{opt};
363 my $router_dev = $$router_ref{deviceinfo};
364
365 # Did any global options appear on the command line
366 # before this router? If so, include them into the
367 # configuration file.
368 if (defined $$router_opt{global}) {
369 foreach my $key (@{$$router_opt{global}}) {
370 $conf .= "$key\n";
371 }
372 }
373
374 # If IPv6 is enabled, add IPv4Only target directive for targets
375 # that do not support SNMP over IPv6.
376 my $ipv4only_directive;
377 my $router_ipv4only = ($$opt{'enable-ipv6'} == 1) && $$router_ref{ipv4only};
378
379 my $syscontact = $$router_dev{sysContact};
380 my $html_syscontact = html_escape($syscontact);
381 my $syslocation = $$router_dev{sysLocation};
382 my $html_syslocation = html_escape($syslocation);
383 my $sysname = $$router_dev{sysName};
384 my $sysdescr = $$router_dev{sysDescr};
385 my $comment_sysdescr = $sysdescr;
386 # make sure embedded newlines do not harm us here
387 $comment_sysdescr =~ s/[\n\r]+/\n\# /g;
388 my $community = $$router_ref{community};
389 $community =~ s/([@ ])/\\$1/g;
390 my $router_connect = "$community\@$$router_ref{routername}$$router_ref{snmpopt_current}";
391 my @v3options;
392 foreach my $v3op (keys %$v3opt) {
393 push @v3options, $v3op."=>'".$$v3opt{$v3op}."'";
394 }
395 my $v3options = join(",",@v3options) if $$router_ref{'snmp-options'} =~ /(?::[^:]*){4}:3/ ;
396 my $html_sysdescr = html_escape($sysdescr);
397 my $router_name =
398 ($$router_ref{routername}
399 . (($$router_ref{'dns-domain'})?'.':'')
400 . $$router_ref{'dns-domain'});
401
402 # James Overbeck 2001/09/20
403 # Moved $directory_name definition from within the interface
404 # foreach loop to here. In its previous location, $directory_name
405 # was not accessible to host templates. $directory_name is not
406 # changed per-interface so it might as well be here instead of
407 # where it was.
408
409 my $directory_name = "";
410
411 if (defined $$router_opt{subdirs}) {
412 $directory_name = $$router_opt{subdirs};
413 $directory_name =~ s/HOSTNAME/$router_name/g;
414 $directory_name =~ s/SNMPNAME/$$router_dev{sysName}/g;
415 }
416
417
418 my $target_lines = "";
419 my $problem_lines = "";
420 my $head_lines = "
421 ######################################################################
422 # System: $sysname
423 # Description: $comment_sysdescr
424 # Contact: $syscontact
425 # Location: $syslocation
426 ######################################################################
427 ";
428
429 my $separator_lines = "\n\n";
430
431 # Host specific config lines generation code starts HERE
432
433 if(defined $$router_opt{'host-template'}) {
434 # First test if the file exists and is readable, die if not.
435 die "File $$router_opt{'host-template'} didn't exist.\n"
436 unless (-e $$router_opt{'host-template'}
437 and -r $$router_opt{'host-template'});
438 # Open the file (or die).
439 open IF_TEMPLATE, $$router_opt{'host-template'}
440 or die "File $$router_opt{'host-template'} couldn't be opened.\n";
441
442 my @template_lines = readline *IF_TEMPLATE;
443 close IF_TEMPLATE;
444 $@ = undef;
445 eval ('local $SIG{__DIE__};'.join("", @template_lines));
446
447 die "ERROR Evaluation of the contents in the file \n\n".
448 "$$router_opt{'host-template'}\ngave the error \n\n\"$@\"\n\nExiting cfgmaker\n" if $@;
449 }
450
451 $conf .= ($head_lines
452 . $problem_lines
453 . $target_lines
454 . $separator_lines);
455
456 # Host specific config lines generation code ends HERE
457
458
459 if ($$router_opt{'interfaces'}) {
460 foreach my $ifindex (sort {int($a) <=> int($b)} grep /^\d+$/, keys %$router_ref) {
461 my $i = $$router_ref{$ifindex};
462
463 # Now define a number of variables used for this interface.
464 # Some variables are just used internally by cfgmaker to
465 # process the interface, others are provided for usage in
466 # host and interface templates and for interface filters.
467
468 my $if_index = $ifindex;
469 my $if_eth = $$i{Eth} || 'No Ethernet Id';
470
471 # does it make sense to look at the interface ?
472 my @prob;
473 my $default_ifstate = 1; # State assumed up.
474 my $default_iftype = 1; # iftype assumed ok.
475 my $if_ok = 1; #
476
477 my $if_admin = (($$i{ifAdminStatus} || 0) == 1);
478 my $if_oper = (($$i{ifOperStatus} || 0) == 1);
479
480 my $if_type = $$i{ifType} || -1;
481 my $if_is_ethernet = 0 < scalar(grep {$_ == $if_type;}
482 (6,7,26,62,69,117));
483 my $if_is_isdn = (0 < scalar (grep {$_ == $if_type;}
484 (20,21,63,75,76,77)));
485 my $if_is_dialup = $if_is_isdn ||
486 (0 < scalar (grep {$_ == $if_type;}
487 (23,81,82,108)));
488 my $if_is_atm = (0 < scalar(grep {$_ == $if_type;}
489 (37,49,107,105,106,114,134)));
490
491 my $if_is_wan = 0 < scalar(grep {$_ == $if_type;}
492 (22,30,32,39,44,46));
493
494 my $if_is_lan = $if_is_ethernet ||
495 (0 < scalar (grep {$_ == $if_type;}
496 (8,9,11,15,26,55,59,60,115)));
497 my $if_is_dsl = (0 < scalar(grep {$_ == $if_type;}
498 (94,95,96,97)));
499 my $if_is_loopback = $if_type == 24;
500 my $if_is_ciscovlan =
501 ($$router_dev{Vendor} eq 'cisco'
502 and $$i{Descr} =~ /^(unrouted )?[- ]?VLAN[- ]?\d*$/i);
503
504 my $if_ip = $$i{Ip} || 'No Ip';
505 my $if_snmp_descr = $$i{Descr} || 'No Description';
506 $if_snmp_descr =~ s/\n$//; # no you don't want to know who does this
507 # ok ... dell 3524
508 $if_snmp_descr =~ s/ /-/g;
509 my $if_type_num = $$i{ifType} || 'Unknown Type';
510 $$i{ifType} ||= -1;
511 my $if_snmp_name = $$i{Name} || 'No Name';
512 my $if_snmp_alias = $$i{ifAlias} || '';
513 my $if_cisco_descr = $$i{CiscolocIfDescr} || '';
514 my $if_dns_name = $$i{DNSName} || 'No DNS name';
515 my $if_vlan_id = $$i{vmVlan} || 'No Vlan';
516 my $if_cisco_trunk = ($$i{vlanTrunkPortDynamicStatus} || 0 == 1);
517 my $if_MTU = $$i{ifMtu} || 'No MTU';
518
519 # For Nokia IPSO, find non-ethernet interfaces with IP addresses
520 # and add missing MAC address and Port Speed information to
521 # to the LOGICAL and LOGICAL+VLAN interfaces.
522 if ( $$router_dev{Vendor} eq 'nokiaipsofw' ) {
523 if ($$i{ifType} ne "6" and
524 $$router_dev{sysDescr} =~ / IPSO / &&
525 $$i{Ip} =~ /^\d+/ and
526 (not $$i{Eth} or
527 not $$i{ifSpeed} or
528 $$i{ifSpeed} < 10 )
529 ) {
530 my $logical_if_name = $$i{Name};
531
532 # Split the LOGICAL interface name in attempt
533 # to match with base PHYSICAL interface detail.
534 my ($logical_if_HEAD, $logical_if_TAIL) =
535 $logical_if_name =~ /^(.*)(c\d+)$/;
536
537 foreach my $ifindexTMP (sort {int($a) <=> int($b)}
538 grep /^\d+$/, keys %$router_ref) {
539 next unless $ifindexTMP =~ /^\d+$/;
540
541 my $physical_if_name = $$router_ref{$ifindexTMP};
542
543 if ($$physical_if_name{ifType} == 6 &&
544 $logical_if_HEAD eq $$physical_if_name{Name} ) {
545 $$i{Eth} ||= $$physical_if_name{Eth};
546 $$i{ifSpeed} = $$physical_if_name{ifSpeed}
547 if ( not $$i{ifSpeed} or $$i{ifSpeed} < 10 );
548 }
549 }
550 }
551 }
552
553 # First investigate the state of the interface.
554 if (not defined $$router_opt{'no-down'}) {
555 if (($$i{ifAdminStatus} || 0 )== 2) {
556 push @prob, "it is administratively DOWN";
557 $default_ifstate = 0;
558 } elsif (($$i{ifAdminStatus} || 0 ) == 3) {
559 push @prob, "it is in administrative TEST mode";
560 $default_ifstate = 0;
561 }
562
563 if (not defined $$router_opt{'show-op-down'}) {
564 if (($$i{ifOperStatus} || 0 ) == 2) {
565 push @prob, "it is operationally DOWN";
566 $default_ifstate = 0;
567 } elsif (($$i{ifOperStatus} || 0 ) == 3) {
568 push @prob, "it is in operational TEST mode";
569 $default_ifstate = 0;
570 }
571 }
572 }
573
574
575 # Investigate the type of the interface.
576 if ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 18) { # by [email protected]
577 push @prob, "it is a DS1 controllers";
578 $default_iftype = 0;
579 } elsif ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 19) { # by [email protected]
580 push @prob, "it is a E1 controllers";
581 $default_iftype = 0;
582 } elsif ($$i{ifType} == 24) {
583 push @prob, "it is a Software Loopback interface" ;
584 $default_iftype = 0;
585 } elsif ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 30) { # by [email protected]
586 push @prob, "it is a DS3 controller";
587 $default_iftype = 0;
588 } elsif ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 102) { # by [email protected]
589 push @prob, "it is a Voice controller";
590 $default_iftype = 0;
591 } elsif ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 103) { # by [email protected]
592 push @prob, "it is a Voice dial peer";
593 $default_iftype = 0;
594 } elsif ($$i{ifType} == 162) {
595 push @prob, "it is a CEF Sub-interface"; # John Begley <[email protected]>
596 } elsif ($$router_dev{Vendor} eq 'cisco'
597 and $$i{Descr} eq 'Null0') {
598 push @prob, "it is a cisco Null0 interface";
599 $default_iftype = 0;
600 }
601 my $default = $default_iftype && $default_ifstate;
602
603 # Do some futher investigation if the interface makes
604 # sense to collect on
605
606 # I debated whether to insert the zero-speed check before
607 # or after the "will always be zero" sections below.
608 # I settled on before since I'll assume the user knows
609 # what speed the zero-speed interfaces should be better
610 # than the simple logic below.
611 if (not $$i{ifSpeed} and $$router_opt{'zero-speed'}) {
612 # Set all interfaces with zero speed to the value specified
613 # by the --zero-speed= command line option.
614
615 # Be sure the value specified is a valid integer.
616 # It seems like this could be done once when
617 # $$router_opt is set, but I didn't see any example
618 # of input validation in that part of cfgmaker,
619 # so it gets done here, more times than are
620 # really necessary. ;-)
621 unless ($$router_opt{'zero-speed'} =~ /^\d+$/) {
622 die "ERROR: zero-speed specified with non-integer speed: $$router_opt{'zero-speed'}";
623 }
624 $$i{ifSpeed} = $$router_opt{'zero-speed'};
625 }
626
627 if (not $$i{ifSpeed} and $$router_dev{Vendor} eq 'foundry' and $$i{ifType} and $$i{ifType} == 194) {
628 # foundry ATM subinterfaces always report 0 speed, make it 155Mbps instead.
629 $$i{ifSpeed} = 155000000;
630 } elsif (not $$i{ifSpeed} and $$router_dev{Vendor} eq 'foundry' and $$i{ifType} and $$i{ifType} == 135) {
631 # Foundry virtual Ethernet interfaces always report 0 speed, make it 1GB instead.
632 $$i{ifSpeed} = 1000000000;
633 } elsif (not $$i{ifSpeed} and $$router_dev{Vendor} eq 'cisco' and $$i{sysDescr} and $$i{sysDescr} =~ /FWSM-Firewall / ) {
634 # Cisco PIX Firewall Switch Modules have effective backplane speed of 600 Megs
635 $$i{ifSpeed} = 600000000;
636 } elsif (not $$i{ifSpeed} and $$router_dev{Vendor} eq '3com' and $$i{Descr} and $$i{Descr} =~ /RMON VLAN (\d+)/ ) {
637 $$i{ifSpeed} = 100000000;
638 $if_vlan_id = $1;
639 } elsif (not $$i{ifSpeed}) {
640 push @prob, "has no ifSpeed property";
641 $$i{ifSpeed} = 0;
642 $if_ok = 0;
643 }
644
645 my $message;
646 my $nohc =0;
647 if ($message = IsCounterBroken($ifindex, $router_ref,$v3opt)) {
648 # set snmpopt_current to working snmp options
649 if ($message eq '1') {
650 $nohc = 1;
651 } else {
652 push @prob, "got '$message' from interface when trying to query";
653 $if_ok = 0;
654 }
655 }
656
657 my $community = $$router_ref{community};
658 $community =~ s/([@ ])/\\$1/g;
659 my $router_connect = "$community\@$$router_ref{routername}$$router_ref{snmpopt_current}";
660
661 my $v3options = join(",",@v3options) if $$router_ref{snmpopt_current} =~ /(?::[^:]*){4}:3/ ;
662
663 # determine interface reference
664 my $if_ref;
665 if (defined $$router_opt{ifref}) {
666 foreach (split /,/,$$router_opt{ifref}) {
667 /^ip$/ && do { if($$i{Ip} ){ $if_ref = "/".$$i{Ip}; last;} next};
668 /^eth$/ && do { if($$i{Eth} ){ $if_ref = "!".$$i{Eth}; last;} next};
669 /^descr?$/&& do { if($$i{Descr}){ $if_ref = "\\".$$i{Descr};last;} next};
670 /^name$/ && do { if($$i{Name} ){ $if_ref = "#".$$i{Name}; last;} next};
671 /^type$/ && do { if($$i{Type} ){ $if_ref = "%".$$i{Type}; last;} next};
672 /^nr$/ && do { $if_ref = $ifindex; last };
673 die "ERROR: Invalid value for --ifref: $$router_opt{ifref} ($_)\n";
674 }
675 if (not defined $if_ref) {
676 push @prob, "--ifref=$$router_opt{ifref} is not unique for this interface";
677 $if_ref = $ifindex;
678 $if_ok = 0;
679 }
680 } else {
681 if ($$i{Name}) {
682 $if_ref = "#".$$i{Name};
683 } else {
684 $if_ref = $ifindex;
685 }
686 }
687
688 # generate Target name
689 my $trim_if_ref = $if_ref;
690 $trim_if_ref =~ s/[\#!\/\\:\s\@%]+/_/g;
691 $trim_if_ref =~ s/^_*(.+?)_*$/$1/;
692 my $target_name = "${router_name}_$trim_if_ref";
693 my $if_title_desc = $if_ref;
694 $if_title_desc =~ s/^[^\d]//;
695 my $if_speed = int($$i{ifSpeed} / 8);
696 my $if_speed_str = fmi($if_speed,$$router_ref{flags});
697 my $if_type_desc = IfType($$i{ifType});
698 my $html_if_type_desc = html_escape($if_type_desc);
699 my $desc_prefix = 'Traffic Analysis for ';
700
701 my $port_dot = $$i{Name} || 'Unknown';
702 $port_dot =~ s/\//./g;
703 my $if_port_name = $$router_ref{$port_dot}{CiscoCatalystPortName};
704 my $if_pp_port_name = $$router_ref{$ifindex}{ppPortName};
705
706 if (defined $$router_opt{ifdesc}) {
707 $desc_prefix = '';
708 foreach (split /,/,$$router_opt{ifdesc}) {
709 /^ip$/ && do { if($$i{Ip}) { $if_title_desc = $$i{Ip}; last } next };
710 /^eth$/ && do { if($$i{Eth}) { $if_title_desc = $$i{Eth}; last } next };
711 /^descr?$/ && do { if($$i{Descr}){ $if_title_desc = $if_snmp_descr; last } next };
712 /^alias$/ && do { if($$i{ifAlias}){ $if_title_desc = "$if_snmp_descr $if_snmp_alias $if_cisco_descr"; last } next };
713 /^name$/ && do { if($$i{Name}) {$if_title_desc = "#".$$i{Name}; last } next };
714 /^catname$/ && do {$if_title_desc = $if_port_name; last };
715 /^ppname$/ && do {$if_title_desc = $if_pp_port_name; last};
716 /^type$/ && do { if($$i{Type}) { $if_title_desc = "%".$$i{Type}; last } next };
717 /^nr$/ && do {$if_title_desc = "Interface $ifindex"; last};
718 /^$/ && do {$if_title_desc = $if_type_desc || $if_snmp_descr; last };
719 die "ERROR: Invalid value for --ifdesc: '$$router_opt{ifdesc} ($_)'\n";
720 }
721 }
722
723 # Now setup a large number of variables needed for the
724 # generation of the configuration lines.
725
726 $if_title_desc =~ s/\\([:@\\\/\# ])/$1/g; # unescape
727 $if_title_desc = $if_snmp_name if not $if_title_desc;
728 my $html_if_title_desc = html_escape($if_title_desc);
729 my $html_desc_prefix = html_escape($desc_prefix);
730
731 my $html_if_snmp_descr = html_escape($if_snmp_descr);
732 my $html_if_snmp_name = html_escape($if_snmp_name);
733 my $html_if_snmp_alias = html_escape($if_snmp_alias);
734 my $html_if_cisco_descr = html_escape($if_cisco_descr);
735 my $if_description = "$if_snmp_descr $if_snmp_alias $if_cisco_descr";
736 my $html_if_description = html_escape($if_description);
737 my $if_title = "$desc_prefix$if_title_desc -- $sysname";
738 my $html_if_title = html_escape($if_title);
739
740 my $head_lines = "### Interface $ifindex >> Descr: '$if_snmp_descr' |".
741 " Name: '$if_snmp_name' | Ip: '$if_ip' | Eth: '$if_eth' ###\n";
742
743 my $target_lines = "";
744 my $separator_lines = "\n\n";
745
746 # escape the if reference
747 $if_ref =~ s/([& :])/\\$1/g;
748 my $default_target_directive = "Target[$target_name]: $if_ref:$router_connect";
749 $default_target_directive .= "\nSnmpOptions[$target_name]: $v3options" if $$router_ref{snmpopt_current} =~ /(?::[^:]*){4}:3/ ;
750 $default_target_directive .= "\nnoHC[$target_name]: yes" if $nohc == 1;
751 my $if_snmp_descr_save = $if_snmp_descr;
752 $if_snmp_descr_save =~ s/"/'/g;
753 my $default_setenv_directive = "SetEnv[$target_name]: MRTG_INT_IP=\"$if_ip\" MRTG_INT_DESCR=\"$if_snmp_descr_save\"";
754 my $default_directory_directive = ($directory_name ? "Directory[$target_name]: $directory_name" : "");
755 my $default_maxbytes_directive = "MaxBytes[$target_name]: $if_speed";
756
757 $ipv4only_directive = $router_ipv4only ? "IPv4Only[$target_name]: yes" : "";
758
759 my $default_title_directive = "Title[$target_name]: $html_desc_prefix$html_if_title_desc -- $sysname";
760 my $default_pagetop_directive =
761 "PageTop[$target_name]: <h1>$html_desc_prefix$html_if_title_desc -- $sysname</h1>
762 <div id=\"sysdetails\">
763 <table>
764 <tr>
765 <td>System:</td>
766 <td>$sysname in $html_syslocation</td>
767 </tr>
768 <tr>
769 <td>Maintainer:</td>
770 <td>$html_syscontact</td>
771 </tr>
772 <tr>
773 <td>Description:</td>
774 <td>$html_if_description</td>
775 </tr>
776 <tr>
777 <td>ifType:</td>
778 <td>$html_if_type_desc ($if_type_num)</td>
779 </tr>
780 <tr>
781 <td>ifName:</td>
782 <td>$html_if_snmp_name</td>
783 </tr>";
784 $default_pagetop_directive .= "
785 <tr>
786 <td>Port Name:</td>
787 <td>$if_port_name</td>
788 </tr>" if defined $if_port_name;
789 $default_pagetop_directive .= "
790 <tr>
791 <td>Port Name:</td>
792 <td>$if_pp_port_name</td>
793 </tr>" if defined $if_pp_port_name;
794 $default_pagetop_directive .= "
795 <tr>
796 <td>Max Speed:</td>
797 <td>$if_speed_str</td>
798 </tr>";
799 $default_pagetop_directive .= "
800 <tr>
801 <td>Ip:</td>
802 <td>$if_ip ($if_dns_name)</td>
803 </tr>" if $if_ip;
804 $default_pagetop_directive .= "
805 </table>
806 </div>";
807
808 my $default_target_lines =
809 ("\n"
810 . $default_target_directive . "\n"
811 . $default_setenv_directive . "\n"
812 . ($default_directory_directive
813 ? ($default_directory_directive . "\n")
814 : "")
815 . $default_maxbytes_directive . "\n"
816 . ($ipv4only_directive
817 ? ($ipv4only_directive . "\n")
818 : "")
819 . $default_title_directive . "\n"
820 . $default_pagetop_directive . "\n");
821
822
823 # If --if-filter is provided, evaluate that. If it
824 # returns true, clear @prob. If it returns false,
825 # instead add a complaint to @prob.
826
827 if (defined $$router_opt{'if-filter'}) {
828 $@ = undef;
829 if (eval('local $SIG{__DIE__};'.$$router_opt{'if-filter'})) {
830 @prob = ();
831 } else {
832 push @prob, "filter specified by --if-filter rejected the interface";
833 $if_ok = 0;
834 }
835 die "ERROR: with if-filter $$router_opt{'if-filter'}: $@" if $@;
836 }
837
838
839 # issue problem report
840
841 my $problem_lines = "";
842
843 if (@prob) {
844 $problem_lines .= "### The following interface is commented out because:\n";
845 map {$problem_lines .= "### * $_\n"} @prob;
846 $if_ok = 0;
847 }
848
849 # The target config generation code starts HERE.
850
851
852 if (defined $$router_opt{'if-template'}) {
853 # First test if the file exists and is readable,
854 # die if not.
855 die "File $$router_opt{'if-template'} didn't exist.\n" unless (-e $$router_opt{'if-template'}
856 and -r $$router_opt{'if-template'});
857 # Open the file (or die).
858 open IF_TEMPLATE, $$router_opt{'if-template'}
859 or die "File $$router_opt{'if-template'} couldn't be opened.\n";
860 my @template_lines = readline *IF_TEMPLATE;
861
862 $@ = undef;
863 eval ('local $SIG{__DIE__};'.join( "", @template_lines));
864 die "Evaluation of the contents in the file \n\n$$router_opt{'if-template'}\n".
865 "gave the error \n\n\"$@\"\n\nExiting cfgmaker\n" if $@;
866 } else {
867 $target_lines = $default_target_lines;
868 }
869
870
871 if ($target_lines && not $if_ok) { # comment out the target lines if needed
872 $target_lines =~ s/^/\# /gm;
873 }
874
875 $conf .= ($head_lines
876 . $problem_lines
877 . $target_lines
878 . $separator_lines);
879
880 }
881 # Target generation code ends HERE.
882 }
883 }
884
885 # print any global options which might have
886 # appeared on the command line after the last
887 # router.
888 if (defined $$opt{global}) {
889 foreach my $key (@{$$opt{global}}) {
890 $conf .= "$key\n";
891 }
892 }
893
894 if ($$opt{output}) {
895 debug ('base', "Writing $$opt{output}");
896 open X, ">$$opt{output}" or die "ERROR: creating $$opt{output}: $!\n";
897 print X $conf;
898 close X;
899 } else {
900 print $conf;
901 }
902 } # end GenConf
903
904 sub IsCounterBroken ($$$) {
905 my $if = shift;
906 my $router_ref = shift;
907 my $v3opt = shift;
908 my $router = $$router_ref{routerkey};
909 my $fallback = 0;
910 local $SNMP_Session::suppress_warnings = 3;
911 local $Net_SNMP_util::suppress_warnings = 3;
912
913 my $ipv4only = $$router_ref{ipv4only};
914 my $snmphost = v4onlyifnecessary($router, $ipv4only);
915
916 if ($router =~ /:[\d.]*:[\d.]*:[\d.]*:[23]/) {
•917 my $speed = (snmpget($snmphost, $v3opt, 'ifHighSpeed.'.$if))[0] // 'unknown';
918 debug('base',"snmpget $snmphost for ifHighSpeed.$if -> $speed Mb/s");
919 $SNMP_Session::errmsg = undef;
920 $Net_SNMP_util::ErrorMessage = undef;
•921 my $counter = (snmpget($snmphost,$v3opt, 'ifHCInOctets.'.$if))[0] // 'unknown';
922 debug('base',"snmpget $snmphost for ifHCInOctets.$if -> $counter");
923 if( $speed eq 'unknown' or $counter !~ /^\d+$/ or $SNMP_Session::errmsg or $Net_SNMP_util::ErrorMessage){
924 $SNMP_Session::errmsg = undef;
925 $Net_SNMP_util::ErrorMessage = undef;
926 $fallback = 1;
927 debug('base',"check for HighspeedCounters failed ... Dropping back to V1");
928 } else {
929 return 0;
930 }
931 }
932 if ( $fallback == 1 or $$router_ref{snmpopt_current} !~ /:[\d.]*:[\d.]*:[\d.]*:[23]/) {
933 my $counter = (snmpget($snmphost, 'ifInOctets.'.$if))[0];
934 if (defined $SNMP_Session::errmsg) {
935 my $error = $SNMP_Session::errmsg;
936 $SNMP_Session::errmsg = undef;
937 $error =~ s/\n/\n### /g;
938 return $error;
939 } elsif (defined $Net_SNMP_util::ErrorMessage and $Net_SNMP_util::ErrorMessage =~ /\w/) {
940 my $error = $Net_SNMP_util::ErrorMessage;
941 $Net_SNMP_util::ErrorMessage = undef;
942 $error =~ s/\n/\n### /g;
943 return $error;
944 } elsif (not defined $counter or $counter eq '' or $counter =~ /\D/) {
945 return "No counter exists for $if";
946 }
947 }
948 return $fallback;
949 } # end IsCounterBroken
950
951 # DeviceInfo does fallback between IPv6 and IPv4: if an IPv6 snmpwalk returns
952 # undef values (= an error) and the target is a hostname, then it repeats the
953 # query using IPv4 in case the target does not support SNMP over IPv6.
954 # If DeviceInfo falls back to IPv4, it sets the ipv4only field for the target
955 # in the routers hash.
956 sub DeviceInfo ($$$) {
957 my $router=shift;
958 my $routers=shift;
959 my $v3opt=shift;
960 my %DevInfo;
961 my $ipv4only = $$routers{$router}{ipv4only};
962
963 my @variables = snmpwalk(v4onlyifnecessary($router, $ipv4only),$v3opt,'1.3.6.1.2.1.1'); # walk system
964 if (!(defined $variables[0])) {
965 # Do we need to fall back to IPv4?
966 my ($community, $host) = ($1, $2) if ($router =~ /^(.*)@([^@]+)$/);
967 if ( ( ! $ipv4only ) && ( $host !~ /^\[(.*)\]/) ) {
968 # Not using IPv4, not an IPv6 address, so a hostname
969 debug ('base',"No response using IPv6 for $router, trying again using IPv4");
970 $$routers{$router}{ipv4only} = 1;
971 @variables = snmpwalk(v4onlyifnecessary($router, 1),$v3opt, '1.3.6.1.2.1.1');
972 }
973 }
974 if ( defined $variables[0] ) {
975 my (%DevInfo, %revOIDS);
976
977 if ($$routers{$router}{enablesnmpv3} || '' eq "yes") {
978 no warnings;
979 %revOIDS = reverse %Net_SNMP_util::OIDS;
980 }
981 else {
982 no warnings;
983 %revOIDS = reverse %SNMP_util::OIDS;
984 }
985 foreach my $variable ( @variables ) {
986 my ($oid, $value) = split ( ':', $variable, 2);
987 if ($revOIDS{'1.3.6.1.2.1.1.'.$oid}){
988 $DevInfo{ $revOIDS{'1.3.6.1.2.1.1.'.$oid} } = $value;
989 }
990 }
991 # vendor identification
992 my %vendorIDs = (
993 # Add your vendor here
994 # sysObjectID Vendora
995 '1.3.6.1.4.1.11863.' => 'tplink',
996 '1.3.6.1.4.1.43.' => '3com',
997 '1.3.6.1.4.1.11.' => 'hp',
998 '1.3.6.1.4.1.9.' => 'cisco',
999 '1.3.6.1.4.1.171.' => 'dlink',
1000 '1.3.6.1.4.1.6141.' => 'wwp',
1001 '1.3.6.1.4.1.674.10895.' => 'dellLan',
1002 '1.3.6.1.4.1.1916.' => 'extremenetworks',
1003 '1.3.6.1.4.1.1991.' => 'foundry',
1004 '1.3.6.1.4.1.6027.' => 'force10',
1005 '1.3.6.1.4.1.2636.' => 'juniper',
1006 '1.3.6.1.4.1.94.' => 'nokiaipsofw',
1007 '1.3.6.1.4.1.307.' => 'portmaster',
1008 '1.3.6.1.4.1.890.' => 'zyxel',
1009 '1.3.6.1.4.1.2272.30' => 'nortel',
1010 '1.3.6.1.4.1.6339' => 'DCN',
1011 '1.3.6.1.4.1.30155.' => 'openBSD',
1012 '1.3.6.1.4.1.30065.' => 'arista',
1013 '1.3.6.1.4.1.5624.' => 'enterasys',
1014 '1.3.6.1.4.1.30803.' => 'Vyatta',
1015 '1.3.6.1.4.1.3955.' => 'LinkSys',
1016 '1.3.6.1.4.1.1588.' => 'brocade',
1017 '1.3.6.1.4.1.3709.' => 'datacom',
1018 '1.3.6.1.4.1.14988.' => 'mikrotik',
1019 '1.3.6.1.4.1.6486.' => 'alcatel',
1020 '1.3.6.1.4.1.2011.' => 'huawei',
•1021 '1.3.6.1.4.1.35265.' => 'eltex',
1022 '1.3.6.1.4.1.4413' => 'ubiquiti',
1023 '1.3.6.1.4.1.41112' => 'ubiquiti'
1024
1025
1026 );
1027 $DevInfo{Vendor} = 'Unknown Vendor - '.$DevInfo{sysObjectID};
1028 foreach (keys %vendorIDs) {
1029 $DevInfo{Vendor} = $vendorIDs{$_} if ($DevInfo{sysObjectID} =~ /\Q$_\E/);
1030 }
1031 debug('base',"Vendor Id: $DevInfo{Vendor}");
1032 return \%DevInfo;
1033 } else {
1034 # we just die because the snmp module has already complained
1035 return undef;
1036 }
1037 } # end DeviceInfo
1038
1039
1040 sub fmi ($$) {
1041 my $number = shift;
1042 my $flags = shift;
1043 my(@short);
1044 if ($$flags{bits}){
1045 $number*=8;
1046 @short = ("bits/s","kbits/s","Mbits/s","Gbits/s");
1047 } else {
1048 @short = ("Bytes/s","kBytes/s","MBytes/s","GBytes/s");
1049 }
1050 my $digits=length("".$number);
1051 my $divm=0;
1052 while ($digits-$divm*3 > 4) { $divm++; }
1053 my $divnum = $number/10**($divm*3);
1054 return sprintf("%1.1f %s",$divnum,$short[$divm]);
1055 } # end fmi
1056
1057
1058 sub IfType ($) {
1059 my $id = shift;
1060 my $ift = {
1061 '1'=>'Other',
1062 '2'=>'regular1822',
1063 '3'=>'hdh1822',
1064 '4'=>'ddnX25',
1065 '5'=>'rfc877x25',
1066 '6'=>'ethernetCsmacd',
1067 '7'=>'iso88023Csmacd',
1068 '8'=>'iso88024TokenBus',
1069 '9'=>'iso88025TokenRing',
1070 '10'=>'iso88026Man',
1071 '11'=>'starLan',
1072 '12'=>'proteon10Mbit',
1073 '13'=>'proteon80Mbit',
1074 '14'=>'hyperchannel',
1075 '15'=>'fddi',
1076 '16'=>'lapb',
1077 '17'=>'sdlc',
1078 '18'=>'ds1',
1079 '19'=>'e1',
1080 '20'=>'basicISDN',
1081 '21'=>'primaryISDN',
1082 '22'=>'propPointToPointSerial',
1083 '23'=>'ppp',
1084 '24'=>'softwareLoopback',
1085 '25'=>'eon',
1086 '26'=>'ethernet-3Mbit',
1087 '27'=>'nsip',
1088 '28'=>'slip',
1089 '29'=>'ultra',
1090 '30'=>'ds3',
1091 '31'=>'sip',
1092 '32'=>'frame-relay',
1093 '33'=>'rs232',
1094 '34'=>'para',
1095 '35'=>'arcnet',
1096 '36'=>'arcnetPlus',
1097 '37'=>'atm',
1098 '38'=>'miox25',
1099 '39'=>'sonet',
1100 '40'=>'x25ple',
1101 '41'=>'iso88022llc',
1102 '42'=>'localTalk',
1103 '43'=>'smdsDxi',
1104 '44'=>'frameRelayService',
1105 '45'=>'v35',
1106 '46'=>'hssi',
1107 '47'=>'hippi',
1108 '48'=>'modem',
1109 '49'=>'aal5',
1110 '50'=>'sonetPath',
1111 '51'=>'sonetVT',
1112 '52'=>'smdsIcip',
1113 '53'=>'propVirtual',
1114 '54'=>'propMultiplexor',
1115 '55'=>'100BaseVG',
1116 '56'=>'Fibre Channel',
1117 '57'=>'HIPPI Interface',
1118 '58'=>'Obsolete for FrameRelay',
1119 '59'=>'ATM Emulation of 802.3 LAN',
1120 '60'=>'ATM Emulation of 802.5 LAN',
1121 '61'=>'ATM Emulation of a Circuit',
1122 '62'=>'FastEthernet (100BaseT)',
1123 '63'=>'ISDN & X.25',
1124 '64'=>'CCITT V.11/X.21',
1125 '65'=>'CCITT V.36',
1126 '66'=>'CCITT G703 at 64Kbps',
1127 '67'=>'Obsolete G702 see DS1-MIB',
1128 '68'=>'SNA QLLC',
1129 '69'=>'Full Duplex Fast Ethernet (100BaseFX)',
1130 '70'=>'Channel',
1131 '71'=>'Radio Spread Spectrum (802.11)',
1132 '72'=>'IBM System 360/370 OEMI Channel',
1133 '73'=>'IBM Enterprise Systems Connection',
1134 '74'=>'Data Link Switching',
1135 '75'=>'ISDN S/T Interface',
1136 '76'=>'ISDN U Interface',
1137 '77'=>'Link Access Protocol D (LAPD)',
1138 '78'=>'IP Switching Objects',
1139 '79'=>'Remote Source Route Bridging',
1140 '80'=>'ATM Logical Port',
1141 '81'=>'AT&T DS0 Point (64 Kbps)',
1142 '82'=>'AT&T Group of DS0 on a single DS1',
1143 '83'=>'BiSync Protocol (BSC)',
1144 '84'=>'Asynchronous Protocol',
1145 '85'=>'Combat Net Radio',
1146 '86'=>'ISO 802.5r DTR',
1147 '87'=>'Ext Pos Loc Report Sys',
1148 '88'=>'Apple Talk Remote Access Protocol',
1149 '89'=>'Proprietary Connectionless Protocol',
1150 '90'=>'CCITT-ITU X.29 PAD Protocol',
1151 '91'=>'CCITT-ITU X.3 PAD Facility',
1152 '92'=>'MultiProtocol Connection over Frame/Relay',
1153 '93'=>'CCITT-ITU X213',
1154 '94'=>'Asymmetric Digital Subscriber Loop (ADSL)',
1155 '95'=>'Rate-Adapt Digital Subscriber Loop (RDSL)',
1156 '96'=>'Symmetric Digital Subscriber Loop (SDSL)',
1157 '97'=>'Very High Speed Digital Subscriber Loop (HDSL)',
1158 '98'=>'ISO 802.5 CRFP',
1159 '99'=>'Myricom Myrinet',
1160 '100'=>'Voice recEive and transMit (voiceEM)',
1161 '101'=>'Voice Foreign eXchange Office (voiceFXO)',
1162 '102'=>'Voice Foreign eXchange Station (voiceFXS)',
1163 '103'=>'Voice Encapsulation',
1164 '104'=>'Voice Over IP Encapsulation',
1165 '105'=>'ATM DXI',
1166 '106'=>'ATM FUNI',
1167 '107'=>'ATM IMA',
1168 '108'=>'PPP Multilink Bundle',
1169 '109'=>'IBM IP over CDLC',
1170 '110'=>'IBM Common Link Access to Workstation',
1171 '111'=>'IBM Stack to Stack',
1172 '112'=>'IBM Virtual IP Address (VIPA)',
1173 '113'=>'IBM Multi-Protocol Channel Support',
1174 '114'=>'IBM IP over ATM',
1175 '115'=>'ISO 802.5j Fiber Token Ring',
1176 '116'=>'IBM Twinaxial Data Link Control (TDLC)',
1177 '117'=>'Gigabit Ethernet',
1178 '118'=>'Higher Data Link Control (HDLC)',
1179 '119'=>'Link Access Protocol F (LAPF)',
1180 '120'=>'CCITT V.37',
1181 '121'=>'CCITT X.25 Multi-Link Protocol',
1182 '122'=>'CCITT X.25 Hunt Group',
1183 '123'=>'Transp HDLC',
1184 '124'=>'Interleave Channel',
1185 '125'=>'Fast Channel',
1186 '126'=>'IP (for APPN HPR in IP Networks)',
1187 '127'=>'CATV MAC Layer',
1188 '128'=>'CATV Downstream Interface',
1189 '129'=>'CATV Upstream Interface',
1190 '130'=>'Avalon Parallel Processor',
1191 '131'=>'Encapsulation Interface',
1192 '132'=>'Coffee Pot',
1193 '133'=>'Circuit Emulation Service',
1194 '134'=>'ATM Sub Interface',
1195 '135'=>'Layer 2 Virtual LAN using 802.1Q',
1196 '136'=>'Layer 3 Virtual LAN using IP',
1197 '137'=>'Layer 3 Virtual LAN using IPX',
1198 '138'=>'IP Over Power Lines',
1199 '139'=>'Multi-Media Mail over IP',
1200 '140'=>'Dynamic synchronous Transfer Mode (DTM)',
1201 '141'=>'Data Communications Network',
1202 '142'=>'IP Forwarding Interface',
1203 '144'=>'IEEE1394 High Performance Serial Bus',
1204 '150'=>'MPLS Tunnel Virtual Interface',
1205 '161'=>'IEEE 802.3ad Link Aggregate',
1206 '162'=>'Cisco Express Forwarding Interface',
1207 '166'=>'MPLS',
1208 '238'=>'Asymmetric Digital Subscriber Loop',
1209 '246'=>'Pseudowire interface type',
1210 '251'=>'Very high speed digital subscriber line',
1211 };
1212 return ($ift->{$id} || "Unknown Interface Type");
1213 } # end IfType
1214
1215
1216
1217
1218
1219 sub options ($$) {
1220 my $opt = shift;
1221 my $routers = shift;
1222
1223 my $noofrouter = 0; # How many routers we've seen on cmdline.
1224
1225 # The $flags hash stores what we've seen in Options[_],
1226 # Options[^] and Options[$] so far.
1227 # A cmdline arg like --global 'Options[_]: bits' will insert
1228 # the element $$flags{default}{bits}="set".
1229 # Similarly --global 'Options[$]:' will delete all elements
1230 # in $$flags{append}
1231 #
1232 # This was originally created to manipulate the "bits" flag
1233 # so fmi should know when to use "bits" or "bytes". It might
1234 # be overkill to use such a complex solution but it makes life
1235 # easier if cfgmaker in the future has to be extended to be
1236 # aware of other Options[] settings like gauge, growright etc.
1237
1238 my %flags;
1239 {
1240 my $def = {};
1241 my $pre = {};
1242 my $app = {};
1243 %flags = (default => $def,
1244 prepend => $pre,
1245 append => $app);
1246 }
1247
1248 my $addrouter_ornf = addrouter($opt,
1249 $routers,
1250 \$noofrouter,
1251 \%flags);
1252
1253 Getopt::Long::Configure("permute");
1254 GetOptions( $opt,
1255 'help|?',
1256 'man',
1257 'subdirs=s',
1258 'no-down',
1259 'show-op-down',
1260 'noreversedns',
1261 'ifref=s',
1262 'ifdesc=s',
1263 'if-filter=s',
1264 'if-template=s',
1265 'interfaces!',
1266 'host-template=s',
1267 'community=s',
1268 'username=s',
1269 'authkey=s',
1270 'authpassword=s',
1271 'authprotocol=s',
1272 'contextengineid=s',
1273 'contextname=s',
1274 'privkey=s',
1275 'privpassword=s',
1276 'privprotocol=s',
1277 'snmp-options=s',
1278 'dns-domain=s',
1279 'version',
1280 'output=s',
1281 'global=s@',
1282 'nodefaultglobal',
1283 'enable-ipv6',
1284 'enablesnmpv3',
1285 'use-16bit',
1286 'zero-speed=s',
1287 '<>', $addrouter_ornf) or pod2usage(2);
1288
1289 die("cfgmaker for mrtg-2.17.10\n") if $$opt{version};
1290 pod2usage(-exitval => 0, -verbose => 2) if $$opt{man};
1291 pod2usage(-verbose => 1) if not keys %$routers;
1292 } # end options
1293
1294 # The callback routine used by GetOptions to process "non-option
1295 # strings" (routers) among the arguments is given only ONE argument.
1296 # However, I want it to be able to specify both the %options hash
1297 # (for read access) and the %routers hash (for modifying) as well
1298 # as the router's name. This makes for three arguments.
1299 #
1300 # The solution is to use a closure. addrouter takes a opt hash, a
1301 # routers hash, an index to the current number of routers and a flags
1302 # hash and then returns a function which "remembers" these
1303 # values (the closure) but also takes an argument (the router name).
1304
1305 sub addrouter() {
1306 my $opt = shift;
1307 my $routers = shift;
1308 my $noofrouter = shift;
1309 my $flags = shift;
1310
1311 return sub {
1312 my $rawname = shift;
1313
1314 $$noofrouter++; # First increase the number of routers seen.
1315
1316 my ($community,$routername,$routerkey,$snmpopt,$dnsdomain,$tmpname,@tmpsnmp);
1317
1318 # Now make sure that the router is defined with the
1319 # proper community, domainname and SNMP options.
1320 # Dissect the rawname to find out what it contains.
1321
1322 # First check for community:
1323 if ($rawname =~ /^(.+)\@([^@]+)$/) {
1324 # Community was given explicitly!
1325 $community = $1;
1326 $tmpname = $2
1327 } else {
1328 $community = $$opt{community};
1329 $tmpname = $rawname;
1330 }
1331 # Now separate the router name from the options. We
1332 # can't just split on the : character because a numeric
1333 # IPv6 address contains a variable number of :'s
1334 if( ($tmpname =~ /^(\[.*\]):(.*)$/) || ($tmpname =~ /^(\[.*\])$/) ){
1335 # Numeric IPv6 address between []
1336 ($routername, $snmpopt) = ($1, $2);
1337 } else {
1338 # Hostname or numeric IPv4 address
1339 ($routername, $snmpopt) = split(':', $tmpname, 2);
1340 }
1341 @tmpsnmp = split(':', $snmpopt || '');
1342
1343 $routername =~ s/\.$//; # if the hostname ends in a '.' remove it
1344 # it seems to cause trouble in some other
1345 # parts of mrtg
1346
1347 # Now setup the SNMP options.
1348 if (not defined $$opt{'snmp-options'}) {
1349 $snmpopt = ':' . (join ':', @tmpsnmp); # No merge needed.
1350 } else {
1351 my ($t,$o,@s);
1352 my @optsnmp = split ':',$$opt{'snmp-options'};
1353
1354 # Trim first element as the SNMP options start
1355 # with a colon and thus the first element is a
1356 # dummy "" string not corresponding to any SNMP option
1357 # (or rather, corresponding to a router, if there had
1358 # been one...)
1359 shift @optsnmp;
1360
1361 while ((scalar @tmpsnmp > 0)
1362 or (scalar @optsnmp > 0)) {
1363 $t = shift @tmpsnmp;
1364 $o = shift @optsnmp;
1365
1366 if(not defined $t) {$t = "";}
1367 if(not defined $o) {$o = "";}
1368
1369 if($t ne "")
1370 {
1371 push @s, $t;
1372 } else {
1373 push @s, $o;
1374 }
1375 }
1376
1377 $snmpopt = ':' . (join ':', @s);
1378 }
1379
1380 my $newopt={}; # Perhaps unnecessary initialization but...
1381
1382 foreach my $o (keys %$opt) {
1383 my $ovalue = $$opt{$o};
1384
1385 $$newopt{$o} = $ovalue
1386 unless
1387 ($o =~ /^fullcmd$/ or
1388 $o =~ /^community$/ or
1389 $o =~ /^snmp-options$/ or
1390 $o =~ /^global$/ or
1391 $o =~ /^output$/
1392 );
1393
1394 # Ok, copy the --globals array from $$opt so we know
1395 # that which global(s) to print out into the config.
1396 push @{$$newopt{$o}}, @{$$opt{$o}} if ($o =~ /^global$/);
1397
1398 # Go through these --global statements one by one.
1399 # If anyone of them contains Options[] for any of the
1400 # targets [_], [^] or [_], process those statements
1401 # tenderly and populate the $$flags{}{} hashes accordingly.
1402 for my $g (@{$$opt{"global"}}) {
1403 if ($g =~ /^options\[([_^\$])\]:\s*(.*)$/i){
1404 my ($t,$fs);
1405 $t = $1;
1406 $fs = $2;
1407 $t =~ s/_/default/;
1408 $t =~ s/\^/prepend/;
1409 $t =~ s/\$/append/;
1410
1411 # If a line like "options[X]:" is found clear
1412 # all flags for that category and then go to next
1413 # --global 'Options[..' line if any.
1414 if ($fs =~ /^\s*$/) {
1415 $$flags{$t} = {};
1416 next;
1417 } else {
1418 for my $f (split /\s*,\s*/,$fs) {
1419 $$flags{$t}{$f} = "set";
1420 }
1421 }
1422 }
1423 }
1424 $$opt{$o} = [] if ($o =~ /^global$/);
1425 }
1426
1427 # Now let this router get it's own copy of
1428 # the "currently effective" flags.
1429 # Note, Options[_] should only be considered
1430 # if Options[^] and Options[$] both are absent.
1431
1432 my $newflags = {};
1433
1434 if((0 == keys %{$$flags{prepend}})
1435 and (0== keys %{$$flags{append}})) {
1436 for my $f (keys %{$$flags{default}}) {
1437 $$newflags{$f}="set";
1438 }
1439 } else {
1440 for my $f (keys %{$$flags{prepend}},
1441 keys %{$$flags{append}}) {
1442 $$newflags{$f}="set";
1443 }
1444 }
1445
1446 if(defined $$opt{'dns-domain'}) {
1447 $dnsdomain=$$opt{'dns-domain'};
1448 } else {
1449 $dnsdomain="";
1450 }
1451
1452 $routerkey =
1453 "${community}\@${routername}"
1454 . (($dnsdomain eq "")?"":".")
1455 . "${dnsdomain}${snmpopt}";
1456
1457 $$routers{$routerkey}= {
1458 # rawname is the unprocessed string from the
1459 # command line.
1460 rawname => $rawname,
1461
1462 # opt is the commandline options which are
1463 # in effect for THIS particular router.
1464 opt => $newopt,
1465
1466 # noofrouter is the unique number for the
1467 # router. The first router on the command
1468 # line is given number 1, the second number 2
1469 # and so on.
1470 noofrouter => $$noofrouter,
1471
1472 # flags contains which --global 'Options[^_$]: flags'
1473 # are effective for THIS particular router.
1474 flags => $newflags,
1475
1476 # community is the SNMP community used for the router
1477 community => $community,
1478
1479 # snmpopt is the SNMP options on the form
1480 # [port[:timeout[:retries[:backoff[:version]]]]]
1481 # The empty string simply means that no
1482 # specific SNMP options has been given.
1483 'snmp-options' => $snmpopt,
1484 snmpopt_current => $snmpopt,
1485
1486 # dns-domain is a domain which should be added
1487 # to the routers hostname.
1488 # e.g if dns-domain is place.xyz and host is router
1489 # the host "router.place.xyz" will be polled.
1490 # If host is "router.dept" the poll will be against
1491 # "router.dept.place.xyz".
1492 'dns-domain' => $dnsdomain,
1493
1494 # routername is the routers name as given on the
1495 # command line but with SNMP community (if given)
1496 # and SNMP options (if given) stripped.
1497 #
1498 # (Yes, routername COULD be on the form
1499 # "host.domain" or "host.subdomain.domain")
1500 routername => $routername,
1501
1502 # routerkey is the same as the has key used for the
1503 # router, which is the router name with everything
1504 # taken into account: community, dns-domain and
1505 # snmp-options. This is the value used when doing
1506 # SNMP communication with the router.
1507 routerkey => $routerkey,
1508 };
1509 }
1510 } # end addrouter
1511
1512 sub html_escape ($) {
1513 my $s = shift || '';
1514 $s =~ s/&/&amp;/g;
1515 $s =~ s/</&lt;/g;
1516 $s =~ s/>/&gt;/g;
1517 $s =~ s/[\n\r]+([^\n\r])/<BR>\n $1/g;
1518 return $s;
1519 } # end html_escape
1520
1521 sub oid_pick ($$$;@){
1522 my $router = shift;
1523 my $v3opt = shift;
1524 my @oids = @_;
1525 local $SNMP_Session::suppress_warnings = 3;
1526 foreach my $oid (@oids){
1527 local $SNMP_Session::errmsg = undef;
1528 my $counter = snmpget($router,$v3opt,$oid);
1529 if (not defined $SNMP_Session::errmsg and defined $counter and $counter ne '' ) {
1530 debug('base',"oid_pick - found $oid to work for $router");
1531 return $oid;
1532 }
1533 }
1534 debug('base',"oid_pick - none of ".(join ",",@oids)." seem to work for $router");
1535 return undef;
1536 }
1537
1538
1539 sub parsev3 ($) {
1540 my $opt = shift;
1541 my %v3opt;
1542 if (!exists ($$opt{username})) {
1543 die "SMNP V3 requires a --username parameter as part of the User Security Model";
1544 } else {
1545 $v3opt{username} = $$opt{username};
1546 }
1547 $v3opt{contextname} = $$opt{contextname} if exists($$opt{contextname});
1548 if (exists ($$opt{authkey})) {
1549 die "Can't use both an --authkey and --authpassword in the User Security Model" if exists($$opt{authpassword});
1550 $v3opt{authkey} = $$opt{authkey};
1551 }
1552 if (exists ($$opt{authpassword})) {
1553 die "Use of --authpassword requires --contextengineid" if !exists($$opt{contextengineid});
1554 $v3opt{authpassword} = $$opt{authpassword};
1555 }
1556 if (exists ($$opt{authprotocol})) {
1557 die "Only sha and md5 are defined for --authprotocol" if $$opt{authprotocol} !~ /^(md5|sha)$/i;
1558 die "--authprotocol can only be used with --authpassword or --authkey" if ! exists($$opt{authpassword}) and ! exists($$opt{authkey});
1559 ($v3opt{authprotocol}) = (lc($$opt{authprotocol}) =~ /^(md5|sha)$/);
1560 }
1561 if (exists ($$opt{privkey})) {
1562 die "Can't use both an --privkey and --privpassword in the User Security Model" if exists($$opt{privpassword});
1563 die "Can't have privacy parameters without authentication in the User security Model" if ! exists($$opt{authpassword}) and ! exists($$opt{authkey});
1564 $v3opt{privkey} = $$opt{privkey};
1565 }
1566 if (exists ($$opt{privpassword})) {
1567 die "Use of --privpassword requires --contextengineid" if !exists($$opt{contextengineid});
1568 die "Can't have privacy parameters without authentication in the User security Model" if ! exists($$opt{authpassword}) and ! exists($$opt{authkey});
1569 $v3opt{privpassword} = $$opt{privpassword};
1570 }
1571 if (exists ($$opt{privprotocol})) {
1572 die "Only des, 3des, 3desede, aes, aes128 are defined for --privprotocol" if $$opt{privprotocol} !~ /^(?:3?des(?:ede)?|aes(?:128)?)$/;
1573 die "--privprotocol can only be used with --privpassword or --privkey" if ! exists($$opt{privpassword}) and ! exists($$opt{privkey});
1574 $v3opt{privprotocol} = lc($$opt{privprotocol});
1575 }
1576 return %v3opt;
1577 }
1578
1579
1580 sub init () {
1581 snmpmapOID('sysObjectID' => '1.3.6.1.2.1.1.2.0',
1582 'CiscolocIfDescr' => '1.3.6.1.4.1.9.2.2.1.1.28',
1583 'CiscoCatalystPortName' => '1.3.6.1.4.1.9.5.1.4.1.1.4',
1584 'ppPortName' => '1.3.6.1.4.1.2272.1.4.10.1.1.35',
1585 'vlanTrunkPortDynamicStatus'=> '1.3.6.1.4.1.9.9.46.1.6.1.1.14',
1586 'vmVlan' => '1.3.6.1.4.1.9.9.68.1.2.2.1.2',
1587 'ifAlias' => '1.3.6.1.2.1.31.1.1.1.18');
1588 } # end init
1589
1590 __END__
1591
1592 =pod
1593
1594 =head1 NAME
1595
1596 cfgmaker - Creates mrtg.cfg files (for mrtg-2.17.10)
1597
1598 =head1 SYNOPSIS
1599
1600 cfgmaker [options] [community@]router [[options] [community@]router ...]
1601
1602 =head1 OPTIONS
1603
1604 --ifref=name interface references by Interface Name (default)
1605 --ifref=ip ... by Ip Address
1606 --ifref=eth ... by Ethernet Number
1607 --ifref=descr ... by Interface Description
1608 --ifref=nr ... by Interface Number
1609 --ifref=type ... by Interface Type
1610 You may also use multiple options separated by commas,
1611 in which case the first available one is used:
1612 e.g. --ifref=ip,name,nr
1613
1614 --ifdesc=nr interface description uses Interface Number (default)
1615 --ifdesc=ip ... uses Ip Address
1616 --ifdesc=eth ... uses Ethernet Number
1617 --ifdesc=descr ... uses Interface Description
1618 --ifdesc=name ... uses Interface Name
1619 --ifdesc=catname ... uses CatOS Interface Name
1620 --ifdesc=ppname ... uses Passport Port Name
1621 --ifdesc=alias ... uses Interface Alias
1622 --ifdesc=type ... uses Interface Type
1623 You may also use multiple options separated by commas,
1624 in which case the first available one is used:
1625 e.g. --ifdesc=catname,ppname,descr,alias,ip,name,nr
1626
1627 --if-filter=f Test every interface against filter f to decide whether
1628 or not to include that interface into the collection.
1629 Currently f is being evaluated as a Perl expression
1630 and it's truth value is used to reject or accept the
1631 interface.
1632 (Experimental, under development, might change)
1633
1634 --if-template=templatefile
1635 Replace the normal target entries for the interfaces
1636 with an entry as specified by the contents in the file
1637 templatefile. The file is supposed to contain Perl
1638 code to be executed to generate the lines for the
1639 target in the configuration file.
1640 (Experimental, under development, might change)
1641
1642 --host-template=templatefile
1643 In addition to creating targets for a host's interfaces
1644 do also create targets for the host itself as specified
1645 by the contents in the file templatefile. The file is
1646 supposed to contain Perl code to be executed to generate
1647 the lines for the host related targets (such as CPU,
1648 ping response time measurements etc.) in the config-
1649 uration file.
1650 (Experimental, under development, might change)
1651
1652 --global "x: a" add global config entries
1653
1654 --nodefaultglobal do not include default global settings
1655
1656 --no-down do not look at admin or opr status of interfaces
1657
1658 --show-op-down show interfaces which are operatively down
1659
1660 --zero-speed=spd use this speed in bits-per-second as the interface
1661 speed for all interfaces that return a speed of 0
1662 via ifSpeed/ifHighSpeed. 100Mbps = 100000000
1663
1664 --subdirs=format give each router its own subdirectory, naming each per
1665 "format", in which HOSTNAME and SNMPNAME will be
1666 replaced by the values of those items -- for instance,
1667 --subdirs=HOSTNAME or --subdirs="HOSTNAME (SNMPNAME)"
1668
1669 --noreversedns do not reverse lookup ip numbers
1670
1671 --community=cmty Set the default community string to "cmty" instead of
1672 "public".
1673
1674 --enable-ipv6 Enable IPv6 support, if the required libraries are
1675 present. Numeric IPv6 addresses must be enclosed
1676 in square brackets, e.g. public@[2001:760:4::1]:161
1677
1678 --use-16bit Use 16bit SNMP request IDs to query all routers.
1679
1680 --snmp-options=:[<port>][:[<tmout>][:[<retr>][:[<backoff>][:<ver>]]]]
1681
1682 Specify default SNMP options to be appended to all
1683 routers following. Individual fields can be empty.
1684 Routers following might override some or all of the
1685 options given to --snmp-options.
1686
1687 --dns-domain=domain
1688 Specifies a domain to append to the name of all
1689 routers following.
1690
1691 --nointerfaces Don't do generate any configuration lines for interfaces,
1692 skip the step of gathering interface information and
1693 don't run any interface template code.
1694
1695 --interfaces Generate configuration lines for interfaces (this is the
1696 default). The main purpose of this option is to negate
1697 an --nointerfaces appearing earlier on the command line.
1698
1699 --help brief help message
1700 --man full documentation
1701 --version print the version of cfgmaker
1702
1703 --output=file output filename default is STDOUT
1704
1705 =head1 DESCRIPTION
1706
1707 B<Cfgmaker> creates MRTG configuration files based on information
1708 pulled from a router or another SNMP manageable device.
1709
1710 [I<community>B<@>]I<router>
1711
1712 I<Community> is the community name of the device you want to create a
1713 configuration for. If not specified, it defaults to 'B<public>'; you might
1714 want to try this first if you do not know the community name of a
1715 device. If you are using the wrong community name you will get no
1716 response from the device.
1717
1718 I<Router> is the DNS name or the IP number of an SNMP-manageable device.
1719 Following the name you can specify 6 further options separated by
1720 colons. The full syntax looks like this:
1721
1722 B<router>[:[B<prt>][:[B<tmout>][:[B<retr>][:[B<backoff>][:B<vers>]]]]]
1723
1724 Of special interest may be the last parameter, B<vers>. If you set this to
1725 '2' then your device will be queried with SNMP version 2 requests. This
1726 allows you to poll the 64 bit traffic counters in the device and will thus work
1727 much better with fast interfaces (no more counter overrun). Note that the
1728 order in which the routers are specified on the command line do matter as
1729 the same order is used when the configuration file is generated. The first
1730 specified router has it's configuration lines generated first, followed by
1731 the lines belonging to the next router and so on.
1732
1733 Note that the first line of the generated cfg file will contain all the
1734 commandline options you used for generating it. This is to allow for the
1735 easy 'regeneration' in case you want to add newhosts or make some other
1736 global change.
1737
1738 =head2 Configuration
1739
1740 Except for the B<--output> and B<--global> options, all options affect
1741 only the routers following them on the command line. If an option
1742 specified earlier on the command line reappears later on the command
1743 line with another value, the new value overrides the old value as far as
1744 remaining routers are concerned. This way options might be tailored for
1745 groups of routers or for individual routers.
1746
1747 See B<--output> and B<--global> for how their behaviour is affected by
1748 where or how many times they appear on the command line.
1749
1750 See the B<Examples> below on how to set an option differently for
1751 multiple routers.
1752
1753 =over
1754
1755 =item B<--help>
1756
1757 Print a brief help message and exit.
1758
1759 =item B<--man>
1760
1761 Prints the manual page and exits.
1762
1763 =item B<--version>
1764
1765 Print the version of cfgmaker. This should match the version of MRTG
1766 for which config files are being created.
1767
1768 =item B<--ifref> B<nr>|B<ip>|B<eth>|B<descr>|B<name>
1769
1770 Select the interface identification method. Default is B<nr> which
1771 identifies the router interfaces by their number. Unfortunately the
1772 interface numbering scheme in an SNMP tree can change. Some routers
1773 change their numbering when new interfaces are added, others change
1774 their numbering every full moon just for fun.
1775
1776 To work around this sad problem MRTG can identify interfaces by 4
1777 other properties. None of these works for all interfaces, but you
1778 should be able to find one which does fine for you. Note that
1779 especially ethernet addresses can be problematic as some routers have
1780 the same ethernet address on most of their interface cards.
1781
1782 Select B<ip> to identify the interface by its IP number. Use B<eth> to
1783 use the ethernet address for identification. Use B<descr> to use
1784 the Interface description. Or use B<name> to use the Interface name.
1785
1786 You can specify multiple properties if you wish, separated by commas.
1787 In this case, cfgmaker will use the first item in the list which
1788 can provide unique identification. This allows you to specify, for
1789 example, to use IP address and to use ifName if this is not defined:
1790 --ifref ip,name
1791
1792 If your chosen method does not allow unique interface identification on
1793 the device you are querying, B<cfgmaker> will tell you about it.
1794
1795 =item B<--ifdesc> B<nr>|B<ip>|B<eth>|B<descr>|B<name>|B<type>|B<alias>
1796
1797 Select what to use as the description of the interface. The description
1798 appears in the C<Title[]> property for the target as well as the text header
1799 in the HTML code defined in the target's C<PageTop[]>. Default is to use
1800 B<nr> which is just the interface number which isn't always useful
1801 to the viewer of the graphs.
1802
1803 There are 6 other properties which could be used. Use B<ip> if you want
1804 to use the interface's IP-address. Use B<eth> if you want to use the
1805 interface's ethernet address. If you want a better description, you can
1806 use either B<descr>, B<name> or B<alias>. Exactly what each of these do
1807 varies between different equipment so you might need to experiment. For
1808 instance, for a serial interface on a Cisco router running IOS using B<name>
1809 might result in C<"S0"> being the interface description , B<descr> might result
1810 in C<"Serial0"> and B<alias> might result in C<"Link to HQ"> (provided that is
1811 what is used as the interface's C<description> in the router's configuration).
1812
1813 Finally, if you want to describe the interface by it's Btype
1814 (i.e C<"ethernetCSMA">, C<"propPointtoPoint"> etc) you can use B<type>.
1815
1816 You can specify multiple properties if you wish, separated by commas.
1817 In this case, cfgmaker will use the first item in the list which
1818 is available for this interface. This allows you to specify, for
1819 example, to use any of the different aliases in order of preference.
1820
1821 =item B<--if-filter> 'B<filter-expression>'
1822
1823 First of all, this is under some development and is experimental.
1824
1825 Use this if you want to have better control over what interfaces gets
1826 included into the configuration. The B<filter-expression> is evaluated
1827 as a piece of Perl code and is expected
1828 to return a truth value. If true, include the interface and if false,
1829 exclude the interface.
1830
1831 For a further discussion on how these filters work, see the section
1832 L<Details on Filters> below.
1833
1834 =item B<--if-template> B<template-file>
1835
1836 First of all, this is under some development and is experimental.
1837
1838 Use this if you want to control what the line for each target should look
1839 like in the configuration file. The contents of the file B<template-file>
1840 will be evaluated as a Perl program which generates the lines using certain
1841 variables for input and output.
1842
1843 For a further discussion on how these templates work, see the section
1844 L<Details on Templates> below.
1845
1846 =item B<--host-template> B<template-file>
1847
1848 First of all, this is under some development and is experimental.
1849
1850 Use this if you want to have some extra targets related to the host itself
1851 such as CPU utilization, ping response time to the host, number of busy
1852 modems etc. The contents of the file B<template-file> will be evaluated
1853 once per host as a Perl program which generates the lines using certain
1854 variables for input and output.
1855
1856 For a further discussion on how these templates work, see the section
1857 L<Details on Templates> below.
1858
1859 =item B<--community> B<community-string>
1860
1861 Use this to set the community for the routers following on the command
1862 line to B<community-string>. Individual routers might override this
1863 community string by using the syntax B<community>B<@>B<router>.
1864
1865 =item B<--enable-ipv6>
1866
1867 This option enables IPv6 support. It requires the appropriate perl
1868 modules; if they are not found then IPv6 is disabled (see the ipv6
1869 documentation).
1870
1871 cfgmaker will use IPv6 or IPv4 depending on the target. If the target
1872 is a numeric address, the protocol depends on the type of address. If the
1873 target is a hostname, cfgmaker will try to resolve the name first to an
1874 IPv6 address then to an IPv4 address.
1875
1876 IPv6 numeric addresses must be specified between square braces.
1877
1878 For example:
1879
1880 cfgmaker --enable-ipv6 [2001:760:4::1]:165:::2
1881
1882 If the target has both an IPv6 address and an IPv4 address with the same
1883 hostname, cfgmaker first queries the target using IPv6 and falls back to
1884 IPv4 if it fails. This is useful for targets which don't support SNMP
1885 over IPv6.
1886
1887 =item B<--use-16bit>
1888
1889 This option forces the use of 16bit SNMP request IDs. Some broken SNMP
1890 agents do not accept 32bit request IDs. Try to avoid this option as much
1891 as possible, complain to your agent vendor instead.
1892
1893 =item B<--snmp-options> :[B<port>][:[B<timeout>][:[B<retries>][:[B<backoff>][:B<version>]]]]
1894
1895 Use this to set the default SNMP options for all routers following on the
1896 command line. Individual values might be omitted as well as trailing
1897 colons. Note that routers might override individual (or all) values
1898 specified by B<--snmp-options> by using the syntax
1899
1900 B<router>[:[B<port>][:[B<timeout>][:[B<retries>][:[B<backoff>][:B<version>]]]]]
1901
1902 =item B<--global> B<">I<bla: abc>B<">
1903
1904 Use this to add global options to the generated config file.
1905 You can call B<--global> several times to add multiple options.
1906 The line will appear in the configuration just before the config for
1907 the next router appearing on the command line.
1908
1909 --global "workdir: /home/mrtg"
1910
1911 If you want some default Options you might want to put
1912
1913 --global "options[_]: growright,bits"
1914
1915 Specifying B<--global> after the last router on the command line will
1916 create a line in the configuration file which will appear after all the
1917 routers.
1918
1919 =item B<--noreversedns>
1920
1921 Do not try to reverse lookup IP numbers ... a must for DNS free environments.
1922
1923 =item B<--no-down>
1924
1925 Normally cfgmaker will not include interfaces which are marked
1926 anything but administratively and operationally UP. With this
1927 switch you get them all.
1928
1929 =item B<--show-op-down>
1930
1931 Include interfaces which are operatively down.
1932
1933 =item B<--zero-speed> I<speed>
1934
1935 Assign this speed in bits-per-second to all interfaces which return 0
1936 for ifSpeed and ifHighSpeed. Some switches, notably Foundry equipment,
1937 return a speed of zero for some interfaces. For example, to have
1938 all interfaces reporting zero set to 100Mbps, use
1939 --zero-speed=100000000.
1940
1941 =item B<--subdirs> I<format>
1942
1943 Give each router its own subdirectory for the HTML and graphics (or
1944 .rrd) files. The directory name is the given I<format> string with a
1945 couple of pattern replacements. The string "HOSTNAME" will be
1946 replaced by the hostname of the router (however you specified it on
1947 the B<cfgmaker> commandline -- it may be an actual hostname or just an
1948 IP address), and "SNMPNAME" will be replaced with the device's idea of
1949 its own name (the same name that appears on the right side of the
1950 "Title" lines). For instance, a call like:
1951
1952 cfgmaker --subdirs=HOSTNAME__SNMPNAME [email protected]
1953
1954 would result in the generation of lines looking something like:
1955
1956 Directory[10.10.0.18_1]: 10.10.0.18__fp2200-bothrip-1.3
1957
1958 =item B<--output> I<file>
1959
1960 Write the output from B<cfgmaker> into the file I<file>. The default
1961 is to use C<STDOUT>. B<--output> is expected to appear only once on the
1962 command line. If used multiple times, the file specified by the last
1963 B<--output> will be used.
1964
1965 =item B<--nointerfaces>
1966
1967 Don't generate configuration lines for interfaces.
1968
1969 This makes cfgmaker skip all steps related to interfaces which means
1970 it will not do any polling of the router to retrieve interface
1971 information which speeds up the execution of cfgmaker and it will
1972 neither run any interface templates.
1973
1974 =item B<--interfaces>
1975
1976 This makes cfgmaker generate configuration lines for interfaces (the
1977 default behaviour).
1978
1979 The main usage of this option is to negate an --nointerfaces appearing
1980 earlier on the command line.
1981
1982
1983 =back
1984
1985 =head2 SNMP V3 Options
1986
1987 B<Cfgmaker> supports SNMP V3 using the B<Net:SNMP> perl module. There are optional
1988 parameters affecting SNMP operation.
1989
1990 =over
1991
1992 =item --enablesnmpv3 {yes|no}
1993
1994 The B<--enablesnmpv3> option is an optional flag to check for the presence of
1995 the B<Net::SNMP> libraries. B<Cfgmaker> will try to determine whether this flag is
1996 required and will set the values automatically.
1997
1998 =back
1999
2000 =head3 SNMPv3 Arguments
2001
2002 A SNMP context is a collection of management information accessible by a SNMP
2003 entity. An item of management information may exist in more than one context
2004 and a SNMP entity potentially has access to many contexts. The combination of
2005 a contextEngineID and a contextName unambiguously identifies a context within
2006 an administrative domain. In a SNMPv3 message, the contextEngineID and
2007 contextName are included as part of the scopedPDU. All methods that generate
2008 a SNMP message optionally take a B<--contextengineid> and B<--contextname>
2009 argument to configure these fields.
2010
2011 =over
2012
2013 =item Context Engine ID
2014
2015 The B<--contextengineid> argument expects a hexadecimal string representing
2016 the desired contextEngineID. The string must be 10 to 64 characters (5 to
2017 32 octets) long and can be prefixed with an optional "0x". Once the
2018 B<--contextengineid> is specified it stays with the object until it is changed
2019 again or reset to default by passing in the undefined value. By default, the
2020 contextEngineID is set to match the authoritativeEngineID of the authoritative
2021 SNMP engine.
2022
2023 =item Context Name
2024
2025 The contextName is passed as a string which must be 0 to 32 octets in length
2026 using the B<--contextname> argument. The contextName stays with the object
2027 until it is changed. The contextName defaults to an empty string which
2028 represents the "default" context.
2029
2030 =back
2031
2032 =head3 User-based Security Model Arguments
2033
2034 The User-based Security Model (USM) used by SNMPv3 requires that a securityName
2035 be specified using the B<--username> argument. The creation of a Net::SNMP
2036 object with the version set to SNMPv3 will fail if the B<--username> argument
2037 is not present. The B<--username> argument expects a string 1 to 32 octets
2038 in length.
2039
2040 Different levels of security are allowed by the User-based Security Model which
2041 address authentication and privacy concerns. A SNMPv3 target will
2042 derive the security level (securityLevel) based on which of the following
2043 arguments are specified.
2044
2045 By default a securityLevel of 'noAuthNoPriv' is assumed. If the B<--authkey>
2046 or B<--authpassword> arguments are specified, the securityLevel becomes
2047 'authNoPriv'. The B<--authpassword> argument expects a string which is at
2048 least 1 octet in length. Optionally, the B<--authkey> argument can be used so
2049 that a plain text password does not have to be specified in a script. The
2050 B<--authkey> argument expects a hexadecimal string produced by localizing the
2051 password with the authoritativeEngineID for the specific destination device.
2052 The C<snmpkey> utility included with the Net::SNMP distribution can be used to create
2053 the hexadecimal string (see L<snmpkey>).
2054
2055 Two different hash algorithms are defined by SNMPv3 which can be used by the
2056 Security Model for authentication. These algorithms are HMAC-MD5-96 "MD5"
2057 (RFC 1321) and HMAC-SHA-96 "SHA-1" (NIST FIPS PUB 180-1). The default
2058 algorithm used by the module is HMAC-MD5-96. This behavior can be changed by
2059 using the B<--authprotocol> argument. This argument expects either the string
2060 'md5' or 'sha' to be passed to modify the hash algorithm.
2061
2062 By specifying the arguments B<--privkey> or B<--privpassword> the securityLevel
2063 associated with the object becomes 'authPriv'. According to SNMPv3, privacy
2064 requires the use of authentication. Therefore, if either of these two
2065 arguments are present and the B<--authkey> or B<--authpassword> arguments are
2066 missing, the creation of the object fails. The B<--privkey> and
2067 B<--privpassword> arguments expect the same input as the B<--authkey> and
2068 B<--authpassword> arguments respectively.
2069
2070 The User-based Security Model described in RFC 3414 defines a single encryption
2071 protocol to be used for privacy. This protocol, CBC-DES "DES" (NIST FIPS PUB
2072 46-1), is used by default or if the string 'des' is passed to the
2073 B<--privprotocol> argument. By working with the Extended Security Options
2074 Consortium http://www.snmp.com/eso/, the module also supports additional
2075 protocols which have been defined in draft specifications. The draft
2076 http://www.snmp.com/eso/draft-reeder-snmpv3-usm-3desede-00.txt
2077 defines the support of CBC-3DES-EDE "Triple-DES" (NIST FIPS 46-3) in the
2078 User-based Security Model. This protocol can be selected using the
2079 B<--privprotocol> argument with the string '3desede'. The draft
2080 http://www.snmp.com/eso/draft-blumenthal-aes-usm-04.txt
2081 describes the use of CFB128-AES-128/192/256 "AES" (NIST FIPS PUB 197) in the
2082 USM. The three AES encryption protocols, differentiated by their key sizes,
2083 can be selected by passing 'aescfb128', 'aescfb192', or 'aescfb256' to the
2084 B<-privprotocol> argument.
2085
2086 =head2 Details on Filters
2087
2088 The purpose of the filters is to decide which interfaces to accept and
2089 which interfaces to reject. This decision is done for each interface by
2090 evaluating the filter expression as a piece of Perl code and investigating
2091 the result of the evaluation. If true, accept the interface otherwise
2092 reject it.
2093
2094 When working with filters, remember that Perl has it's own idea of what truth
2095 and false is. The empty string "" and the string "0" are false, all other
2096 strings are true. This further implies that any integer value of 0 is
2097 false as well as any undef value. It also implies that all references
2098 are considered true.
2099
2100 As the filter is evaluated as a Perl expression, several useful constructs
2101 in Perl are worth mentioning:
2102
2103 Expressions might be grouped by using parentheses "()". Expressions might
2104 be combined using boolean operators such as the following:
2105
2106 =over
2107
2108 =item "B<and>" (equivalent with "B<&&>")
2109
2110 Boolean "and" of the two expressions, is only true if both expressions are
2111 true. Example: I<expression1> B<and> I<expression2>
2112
2113 =item "B<or>" (equivalent with "B<||>")
2114
2115 Boolean "or" of the two expressions, is true if either or both expressions
2116 are true. Example: I<expression1> B<or> I<expression2>
2117
2118 =item "B<not>" (equivalent with "B<!>")
2119
2120 Boolean negation of a single expression. Example: B<not> I<expression> .
2121 Yet another example: B<!>I<expression>
2122
2123 =back
2124
2125 (For more details on this I recommend a book on Perl)
2126
2127 =head3 Predefined Filter Variables
2128
2129 To facilitate, there are a number of predefined values available to use
2130 in the filter. Note that these variables are also available when templates
2131 interfaces are evaluated (but not host templates).
2132
2133 Caveat: All these variables' names begin with a dollar sign ($), which
2134 is a syntactic requirement for scalar variables in Perl. The danger here
2135 is that the dollar sign in many shells is an active character (often
2136 used for shell variables exactly as in Perl variables) so it is important
2137 to ensure that the Perl expression isn't evaluated by the command line
2138 shell as shell code before being passed to cfgmaker as command line
2139 arguments. In shells like Bourne shell, ksh shell or bash shell, placing
2140 the entire expression within single quotes will avoid such accidental
2141 evaluation:
2142
2143 '--if-filter=($default_iftype && $if_admin)'
2144
2145 =over
2146
2147 =item B<$if_type>
2148
2149 This is an integer specifying the interface type as
2150 per the SNMP standards and as reported by the polled device. A complete list
2151 of interface types would be impractical for this document , but there are
2152 a number predefined variables below. Normally, cfgmaker puts in the target's
2153 PageTop this iftype value within parenthesis after the name of the interface
2154 type. (e.g "propPointToPointSerial (22)").
2155
2156 Here's a list of some of the most common interface types by number:
2157
2158 6 ethernetCsmacd
2159 7 iso88023Csmacd
2160 9 iso88025TokenRing
2161 15 fddi
2162 19 E1
2163 20 basicISDN
2164 21 primaryISDN
2165 22 propPointToPointSerial
2166 23 ppp
2167 24 softwareLoopback
2168 30 ds3
2169 32 frame-relay
2170 33 rs232
2171 37 atm
2172 39 sonet
2173 44 frameRelayService
2174 46 hssi
2175 49 aal5
2176 53 propVirtual
2177 62 Fast Ethernet (100BaseT)
2178 63 ISDN & X.25
2179 69 Full Duplex Fast Ethernet (100BaseFX)
2180 94 Asymmetric Digital Subscriber Loop (ADSL)
2181 117 Gigabit Ethernet
2182 134 ATM Sub Interface
2183
2184 =item B<$default>
2185
2186 True if and only if cfgmaker normally should
2187 accepted the interface based on the interfaces administrative and
2188 operational state (taking the flags B<--no-down> and B<--show-op-down> into
2189 account) and it's type (and a few other things).
2190
2191 =item B<$default_ifstate>
2192
2193 True if and only if cfgmaker would have accepted the
2194 interface based on it's operational and administrative states (also taking
2195 into account the presence of the flags B<--no-down> and B<--show-op-down>).
2196
2197 =item B<$default_iftype>
2198
2199 True if and only if cfgmaker would have accepted the
2200 interface based on it's type (and a few type specific details in addition).
2201
2202 =item B<$if_admin>
2203
2204 True if and only if the interface is in an administrative up
2205 state.
2206
2207 =item B<$if_oper>
2208
2209 True if and only if the interface is in an operational up
2210 state.
2211
2212 =back
2213
2214 A number of variables are also predefined to easily decide if an interface
2215 belong to a certain category or not. Below is all those variables listed
2216 together with which if_type numbers each variable will be true for. Note
2217 that some variables refer to other variables as well.
2218
2219 =over
2220
2221 =item B<$if_is_ethernet>
2222
2223 True for ethernet interfaces (nr 6, 7, 26, 62, 69 and 117).
2224
2225 =item B<$if_is_isdn>
2226
2227 True for various ISDN interface types (nr 20, 21, 63, 75, 76 and 77)
2228
2229 =item B<$if_is_dialup>
2230
2231 True for dial-up interfaces such as PPP as well
2232 as ISDN. (nr 23, 81, 82 and 108 in addition to the numbers of
2233 B<$if_is_isdn>).
2234
2235 =item B<$if_is_atm>
2236
2237 True for miscellaneous ATM related interface types (nr 37, 49, 107, 105,
2238 106, 114 and 134).
2239
2240 =item B<$if_is_wan>
2241
2242 True for WAN interfaces point to point, Frame Relay and High Speed Serial ( 22,32,44,46)
2243
2244 =item B<$if_is_lan>
2245
2246 True for LAN interfaces (8, 9, 11, 15, 26, 55, 59, 60 and 115 in addition
2247 to the numbers of B<$if_is_ethernet>).
2248
2249 =item B<$if_is_dsl>
2250
2251 True for ADSL, RDSL, HDSL and SDSL (nr 94, 95, 96, 97)
2252
2253 =item B<$if_is_loopback>
2254
2255 True for software loopback interfaces (nr 24)
2256
2257 =item B<$if_is_ciscovlan>
2258
2259 True for Cisco VLAN interfaces (interfaces with the
2260 word Vlan or VLAN in their ifdescs)
2261
2262 =item B<$if_vlan_id>
2263
2264 Returns the vlan id associated with a specific port
2265 on Cisco Catalyst switches under both Catalyst OS
2266 and IOS, and 3Com switches. If it is not a vlan interface, will return undef.
2267
2268 =item B<$if_cisco_trunk>
2269
2270 Returns the trunking state of a specific port
2271 on Cisco Catalyst switches under both Catalyst OS
2272 and IOS. Returns "1" if the interface is a trunk, undef otherwise.
2273
2274 =item B<$if_MTU>
2275
2276 Returns the Maximum Transfer Unit associated with a specific port.
2277
2278 =back
2279
2280 Besides that, you can also use the variables defined for templates below.
2281 Further, all the variables available in cfgmaker is at the scripts disposal
2282 even if the use of such features is discouraged. More "shortcuts" in the
2283 form of variables and functions will be made available in the future instead.
2284
2285 =head3 Examples on Filters
2286
2287 The following filter will not affect which interfaces gets included or
2288 excluded, it will make cfgmaker behave as normally.
2289
2290 '--if-filter=$default'
2291
2292 The following filter will make cfgmaker exclude PPP (23) interfaces:
2293
2294 '--if-filter=$default && $if_type!=23'
2295
2296 The following filter will make cfgmaker behave as usual except that it will
2297 consider the operational state of an interface irrelevant but still reject
2298 all interfaces which are administratively down.
2299
2300 '--if-filter=$if_admin && $default_iftype'
2301
2302 =head2 Details on Templates
2303
2304 The contents of the template files are evaluated as a Perl program. A
2305 number or Perl variables are available for the program to read and others
2306 are used to be written to.
2307
2308 As quite a few of the predefined variables has values which are are supposed
2309 to be used in HTML code some of them have an "HTML-escaped" variant, e.g
2310 $html_syslocation is the HTML escaped variant of $syslocation. The HTML
2311 escaping means that the chars "<", ">" and "&" are replaced by "&lt;",
2312 "&gt;" and "&amp;" and that newlines embedded in the string are prepended
2313 with "<BR>" and appended with a space character (if a newline is last in the
2314 string it is not touched).
2315
2316 =head3 Writable Template Variables
2317
2318 These are the variables available to store the configuration lines in.
2319 Some of them are initialized prior to the evaluation of the template but
2320 such content normally is comments for inclusion in the final configuration
2321 file so those variables might be reset to the empty string in the template
2322 code to eliminate the comments. The other way around is also possible, the
2323 contents of these variables might be extended with further information
2324 for various reasons such as debugging etc.
2325
2326 Once the template has been evaluated, the following happens: if the
2327 template is a interface template and the actual interface for some reason
2328 is rejected and thus needs to be commented out, all the lines in the
2329 variable B<$target_lines> are turned into comments by adding a hash mark
2330 ("#") at their beginning. Then all the variables B<$head_lines>,
2331 B<$problem_lines> , B<$target_lines> and B<$separator_lines>
2332 are concatenated together to form the lines to add to the configuration file.
2333
2334 =over
2335
2336 =item B<$target_lines>
2337
2338 This variable is the placeholder for the configuration lines created
2339 by the template. B<$target_lines> is predefined to be empty when
2340 the template code is evaluated.
2341
2342 =item B<$head_lines>
2343
2344 This variable is intended to be the placeholder for the comment line
2345 appearing just before the target in the configuration file. It is
2346 initialized with that comment line before the evaluation of the template
2347 code and if the template doesn't modify B<$head_lines> during evaluation,
2348 the comment will look like usual in the config file.
2349
2350 =item B<$problem_lines>
2351
2352 This variable is intended to be the placholder for the comment lines
2353 describing any problems which might have been encountered when trying
2354 to add the target into the configuration. For host templates it's
2355 normally not used and for those it's predefined as the empty string.
2356 For interface templates B<$problem_lines> is predefined with
2357 the error description comments which cfgmaker normally would use for
2358 rejected interfaces or as the empty string for accepted interfaces.
2359
2360 It is possible to test against B<$problem_lines> to find out if
2361 an interface will be included or rejected but this is not recommended.
2362 Test against B<$if_ok> instead.
2363
2364 =item B<$separator_lines>
2365
2366 This variable is the placeholder for the string to use as the separator
2367 between the code for individual targets. The contents of this variable
2368 is put after each target (so the lines will appear after the end of the
2369 last target in the config as well).
2370
2371 =back
2372
2373 =head3 Predefined Template Variables
2374
2375 All the variables below are available for interface templates to use.
2376 For host templates, only those listed under L<Host and System Variables>
2377 are available.
2378
2379 For interface templates the variables listed under
2380 L<Predefined Filter Variables> are also available.
2381
2382 =head3 Host and System Variables
2383
2384 =over
2385
2386 =item B<$router_name>
2387
2388 This is the fully qualified name for the router. It is affected by the
2389 following items on the command line: the router name itself and
2390 B<--dns-domain>.
2391
2392 =item B<$router_connect>
2393
2394 This is the reference string for the router being polled. It is on the
2395 form community@router possibly followed by some snmp options. It is
2396 affected by the following items on the command line: the router name
2397 itself, B<--community>, B<--snmp-options> and B<--dns-domain>.
2398 (There's no HTML escaped variant available)
2399
2400 =item B<$directory_name>
2401
2402 This variable should contain the directory name as cfgmaker normally would
2403 use as the value for the "Directory[]" directive. The value is determined
2404 by the B<--subdirs> command line option. If B<--subdirs> isn't specified
2405 B<$directory_name> will be the empty string. (There's no HTML escaped
2406 variant available)
2407
2408 =item B<$syscontact>
2409
2410 This variable is the router's SNMP sysContact value. (HTML escaped
2411 variant: B<$html_syscontact>)
2412
2413 =item B<$sysname>
2414
2415 This variable is the router's SNMP sysName value. (No HTML escaped
2416 variant available)
2417
2418 =item B<$syslocation>
2419
2420 This variable is the router's SNMP sysLocation value. (HTML escaped
2421 variant: B<$html_syslocation>)
2422
2423 =item B<$sysdescr>
2424
2425 This variable is the router's SNMP sysDescr value. It is normally not used
2426 by cfgmaker but might be useful in a template. (HTML escaped variant:
2427 B<$html_sysdescr>)
2428
2429 =back
2430
2431 =head3 Interface Target Related Variables
2432
2433 =over
2434
2435 =item B<$target_name>
2436
2437 This is what cfgmaker normally would use as the the name of the target.
2438 The target name is what is found within the square brackets, "[]", for target
2439 directives. (There's no HTML escaped variant available)
2440
2441 =item B<$if_ref>
2442
2443 This the reference string for the interface. It is expected to be used
2444 in the "Target[xyz]" directive to distinguish what interface to use. The
2445 value of this variable is affected by the B<--ifref> command line option.
2446 It is normally used together with B<$router_connect>.
2447 (There's no HTML escaped variant available)
2448
2449 =item B<$if_ok>
2450
2451 This variable is true if the interface is going to be included into the
2452 configuration file, otherwise false. Don't test against other variables
2453 such as B<$problem_lines> to find out if an interface will be rejected
2454 or not, use this B<$if_ok> instead.
2455
2456 =item B<$default_target_lines>
2457
2458 This variable contains all the target lines which cfgmaker by default outputs
2459 for this interface. It's useful if you want to have the "standard target"
2460 but want to add some extra lines to it by using a template.
2461
2462 =back
2463
2464 By default cfgmaker uses the following directives for each target it
2465 generates: Target[], SetEnv[], MaxBytes[], Title[], PageTop[] and if
2466 there is any directory specified also the Directory[] directive.
2467
2468 To facilitate the creation of templates which generates target configs
2469 which are similar to the default one, each of the above mentioned
2470 directive lines have a corresponding variable containing the line as
2471 cfgmaker would have output it by default.
2472
2473 Note that none of these have a HTML escaped variant, text in them is
2474 HTML escaped where needed. Also note that they do not have any newline
2475 at the end.
2476
2477 =over
2478
2479 =item B<$default_target_directive>
2480
2481 This variable contains the default string for the Target[] directive line.
2482
2483 =item B<$default_setenv_directive>
2484
2485 This variable contains the default string for the SetEnv[] directive line.
2486
2487 =item B<$default_directory_directive>
2488
2489 This variable contains the default string for the Directory[] directive line
2490 which means it is an empty string (with no newline) if there's no directory.
2491
2492 =item B<$default_maxbytes_directive>
2493
2494 This variable contains the default string for the MaxBytes[] directive line.
2495
2496 =item B<$default_title_directive>
2497
2498 This variable contains the default string for the Title[] directive line.
2499
2500 =item B<$default_pagetop_directive>
2501
2502 This variable contains the default string for the PageTop[] directive lines.
2503
2504 =back
2505
2506 =head3 Interface Network Configuration Variables
2507
2508 =over
2509
2510 =item B<$if_ip>
2511
2512 This variable should contain the IP-address of the interface, if any has
2513 been assigned to it. (There's no HTML escaped variant available)
2514
2515 =item B<$ifindex>
2516
2517 This variable is the SNMP ifIndex for the interface which per definition
2518 always is an integer. (There's no HTML escaped variant available)
2519
2520 =item B<$if_index>
2521
2522 Equivalent with B<$ifindex>.
2523
2524 =item B<$if_eth>
2525
2526 Contains the ethernet address of the interface, if any. (There's no HTML
2527 escaped variant available)
2528
2529 =item B<$if_speed>
2530
2531 This variable is the speed in bytes/second (with prefixes). (There's no
2532 HTML escaped variant available)
2533
2534 =item B<$if_speed_str>
2535
2536 This variable is a cooked speed description which is either in bits or
2537 bytes depending on whether or not the bits option is active and also with
2538 the proper prefix for the speed (k, M, G etc). (No HTML escaped variant
2539 available)
2540
2541 =item B<$if_type_desc>
2542
2543 This variable is a textual description of the interface type. (HTML
2544 escaped variant: B<$html_if_type_desc>)
2545
2546 =item B<$if_type_num>
2547
2548 This variable the integer value corresponding to the interface type (for a
2549 listing for the value for the more common interface types, see the section
2550 DETAILS ON FILTERS above). (No HTML escaped variant available)
2551
2552 =item B<$if_dns_name>
2553
2554 This is the DNS name for the interface. (No HTML escaped variant available)
2555
2556 =back
2557
2558 =head3 Interface Name, Description and Alias Variables
2559
2560 It might seem confusing with both I<Name>, I<Description> and I<Alias> in
2561 this context and to some extent it is. I<Name> and I<Description> are
2562 usually supported on most equipment but how they are used varies, both
2563 between manufacturers as well as between different categories of equipment
2564 from the same manufacturer. The I<Alias> is at least supported by Cisco
2565 IOS, and that variable contains whatever is used in the IOS statement
2566 called "description" for the interface (not to be confused with the SNMP
2567 variables for I<Description>).
2568
2569 For better control from the command line consider B<$if_title_desc> which contents
2570 are controlled by the B<--if-descr> command line option.
2571
2572 =over
2573
2574 =item B<$if_snmp_descr>
2575
2576 This variable should contain the "raw" description of the interface as
2577 determined by the SNMP polling of the router. (HTML escaped variant:
2578 B<$html_if_snmp_descr>)
2579
2580 =item B<$if_snmp_name>
2581
2582 The "raw" name for the interface as provided by SNMP polling. (HTML escaped
2583 variant: B<$html_if_snmp_name>)
2584
2585 =item B<$if_snmp_alias>
2586
2587 The "raw" ifAlias for the interface as provided by SNMP polling. (HTML
2588 escaped variant: B<$html_if_snmp_alias>)
2589
2590 =item B<$if_cisco_descr>
2591
2592 The "raw" CiscolocIfDescr for the interface as provided by SNMP polling.
2593 (HTML escaped variant: B<$html_if_cisco_descr>)
2594
2595 =item B<$if_description>
2596
2597 This is the "cooked" description string for the interface, taking into account
2598 the SNMP values found for the interface's RDescr, ifAlias and
2599 CiscolocIfDescr. (HTML escaped variant: B<$html_if_description>)
2600
2601 =item B<$if_title>
2602
2603 The full string cfgmaker by default would have used for the Title[] directive
2604 in the configuration as well as the content of the topmost H1 tag in the
2605 PageTop[]. Is composed by the contents of B<$desc_prefix>,
2606 B<$if_title_desc> and B<$sysname>.
2607
2608 As B<$if_title> depends on B<$if_title_desc>, it is possible to indirectly
2609 control B<$if_title> by using the command line option B<--if-descr>.
2610
2611 (HTML escaped variant: B<$html_if_title>)
2612
2613 =item B<$if_port_name>
2614
2615 If the host is a Cisco Catalyst LAN switch, this variable is the name of
2616 that port. (No HTML escaped variant available)
2617
2618 =item B<$if_pp_port_name>
2619
2620 If the host is a Nortel Passport LAN switch, this variable is the name of
2621 that port. (No HTML escaped variant available)
2622
2623 =item B<$desc_prefix>
2624
2625 This variable is a prefix of the description of what the target is to use in
2626 the "Title[]" directive and in the H1 section of the "PageTop[]". Default is
2627 "Traffic analysis for ". (HTML escaped variant: B<$html_desc_prefix>)
2628
2629 =item B<$if_title_desc>
2630
2631 This is the description of the interface normally used by cfgmaker as part
2632 of the variable B<$if_title>. The latter is used as the full string in the
2633 "Title[]" directive and the H1 section in the PageTop[].
2634
2635 B<$if_title_desc> is controlled by the command line option B<--if-descr>
2636 which indirectly controls the contents of B<$if_title>
2637
2638 (HTML escaped variant: B<$html_if_title_desc>)
2639
2640 =back
2641
2642 =head3 Help Functions for Templates
2643
2644 The following functions exists to facilitate the writing of host and
2645 interface templates.
2646
2647 =over
2648
2649 =item B<html_escape(I<string>)>
2650
2651 B<html_escape()> takes a string as an argument and returns a new string
2652 where the following substitutions has been done: the chars "<", ">" and
2653 "&" are replaced by "&lt;", "&gt;" and "&amp;" and that newlines embedded
2654 in the string are prepended with "<BR>" and appended with a space character
2655 (newlines at the end of the string are not touched).
2656
2657 =item B<oid_pick($router_connect,$v3opt,"oid1","oid2"...)>
2658
2659 This function will try to poll each of the oids specified until
2660 it is successful or has run out of oids. It will return the name of the
2661 first oid that worked or undef if it is not successful
2662
2663 =back
2664
2665 =head3 Example Template Files
2666
2667 =head4 Template Example 1: Eliminating Rejected Targets From Appearing
2668
2669 This template file generates exactly the same configuration code per
2670 interface as cfgmaker does by default, with the exception that it eliminates
2671 all lines (comments as well as config code) for an interface if the
2672 interface happens to be rejected.
2673
2674 if(not $problem_lines)
2675 {
2676 $target_lines .= <<ECHO;
2677
2678 Target[$target_name]: $if_ref:$router_connect
2679 SetEnv[$target_name]: MRTG_INT_IP="$if_ip" MRTG_INT_DESCR="$if_snmp_descr"
2680 ECHO
2681
2682 if ($directory_name) {
2683 $target_lines .= "Directory[$target_name]: $directory_name\n";
2684 }
2685
2686 $target_lines .= <<ECHO;
2687 MaxBytes[$target_name]: $if_speed
2688 Title[$target_name]: $html_desc_prefix$html_if_title_desc -- $sysname
2689 PageTop[$target_name]: <h1>$html_desc_prefix$html_if_title_desc -- $sysname</h1>
2690 <div id="sysdetails">
2691 <table>
2692 <tr>
2693 <td>System:</td>
2694 <td>$sysname in $html_syslocation</td>
2695 </tr>
2696 <tr>
2697 <td>Maintainer:</td>
2698 <td>$html_syscontact</td>
2699 </tr>
2700 <tr>
2701 <td>Description:</td>
2702 <td>$html_if_description</td>
2703 </tr>
2704 <tr>
2705 <td>ifType:</td>
2706 <td>$html_if_type_desc ($if_type_num)</td>
2707 </tr>
2708 <tr>
2709 <td>ifName:</td>
2710 <td>$html_if_snmp_name</td>
2711 </tr>
2712 ECHO
2713
2714 $target_lines .= <<ECHO if defined $if_port_name;
2715 <tr>
2716 <td>Port Name:</td>
2717 <td>$if_port_name</td>
2718 </tr>
2719 ECHO
2720
2721 $target_lines .= <<ECHO if defined $if_pp_port_name;
2722 <tr>
2723 <td>Port Name:</td>
2724 <td>$if_pp_port_name</td>
2725 </tr>
2726 ECHO
2727
2728 $target_lines .= <<ECHO;
2729 <tr>
2730 <td>Max Speed:</td>
2731 <td>$if_speed_str</td>
2732 </tr>
2733 ECHO
2734
2735 $target_lines .= <<ECHO if $if_ip;
2736 <tr>
2737 <td>Ip:</td>
2738 <td>$if_ip ($if_dns_name)</td>
2739 </tr>
2740 ECHO
2741
2742 $target_lines .= <<ECHO;
2743 </table>
2744 </div>
2745 ECHO
2746 } else {
2747 $head_lines="";
2748 $problem_lines="";
2749 $target_lines="";
2750 $separator_lines="";
2751 }
2752
2753 =head3 Template Example 2: Simpler Version of Example 1
2754
2755 Example 1 was partly intended to demonstrate how to customize the generation
2756 of interface targets but also to provide a hint of how the variables are
2757 used in the "default" template which one could consider that cfgmaker
2758 normally uses.
2759
2760 If you're only interested in the easiest way of entirely eliminating those
2761 reject interfaces, the template below would do the job as well by using
2762 B<$default_target_lines>.
2763
2764 if($if_ok) {
2765 $target_lines = $default_target_lines;
2766 } else {
2767 $head_lines="";
2768 $problem_lines="";
2769 $target_lines="";
2770 $separator_lines="";
2771 }
2772
2773 =head3 Template Example 3: Creating CPU Targets for Hosts
2774
2775 Below is an example of a host template.
2776
2777 $head_lines .= <<ECHO;
2778 #---------------------------------------------------------------------
2779 ECHO
2780
2781 my $target_name = $router_name . ".cpu";
2782
2783 $target_lines .= <<ECHO;
2784
2785 YLegend[$target_name]: Percentage CPU load
2786 ShortLegend[$target_name]: %
2787 Legend1[$target_name]: CPU load in %
2788 Legend2[$target_name]:
2789 Legend3[$target_name]: Max Observed CPU load
2790 Legend4[$target_name]:
2791 LegendI[$target_name]: &nbsp;CPU Load:
2792 LegendO[$target_name]:
2793 WithPeak[$target_name]: ywm
2794 MaxBytes[$target_name]: 100
2795 Options[$target_name]: growright, gauge, nopercent
2796 Title[$target_name]: $router_name CPU load
2797 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
2798 PageTop[$target_name]: <h1>$router_name CPU load</h1>
2799 <div>
2800 <table>
2801 <tr>
2802 <td>System:</td>
2803 <td>$router_name in $html_syslocation</td>
2804 </tr>
2805 <tr>
2806 <td>Maintainer:</td>
2807 <td>$html_syscontact</td>
2808 </tr>
2809 <tr>
2810 <td>Description:</td>
2811 <td>$html_sysdescr</td>
2812 </tr>
2813 <tr>
2814 <td>Resource:</td>
2815 <td>CPU.</td>
2816 </tr>
2817 </table>
2818 </div>
2819 ECHO
2820
2821
2822 =head1 EXAMPLES
2823
2824 The first example creates a config file for I<router.place.xyz>: the router
2825 has the community name I<public>. Interfaces get identified by their
2826 IP number. Two global options get added to the config file. The
2827 config file gets redirected to I<mrtg.conf>. The '\' signs at the end
2828 of the line mean that this command should be written on a single line.
2829
2830 cfgmaker --global "WorkDir: /home/tobi" \
2831 --global "Options[_]: growright,bits" \
2832 --ifref=ip \
2833 [email protected] > mrtg.cfg
2834
2835 Note: if cfgmaker is not in your path, but you are in the directory where
2836 cfgmaker is stored, you can start it with ./cfgmaker
2837
2838 The next example creates a config file for four devices:
2839 I<router1.place.xyz>, I<router2.place.xyz>, I<switch1.place.xyz> and
2840 I<switch2.place.xyz> all with the community I<public>.
2841
2842 The two routers will have B<--ifref> set to B<descr> whilst the two
2843 switches will use B<--ifref> set to B<name>. Further the routers will
2844 use B<--ifdesc> set to B<alias> and I<switch1.place.xyz> will use
2845 B<--ifdesc> set to B<descr> whilst I<switch2.place.xyz> use B<name> instead.
2846
2847 Finally, there will be two Options lines inserted in the configuration:
2848 One will be in the beginning, whilst the other will be inserted after
2849 the lines related to the two routers but before those lines related
2850 to the switches.
2851
2852 cfgmaker --global "WorkDir: /home/tobi" \
2853 --global "Options[_]: growright,bits" \
2854 --ifref=descr \
2855 --ifdesc=alias \
2856 [email protected] \
2857 [email protected] \
2858 --global "Options[_]: growright" \
2859 --ifref=name \
2860 --ifdesc=descr \
2861 [email protected] \
2862 --ifdesc=name \
2863 [email protected] > mrtg.cfg
2864
2865
2866 The next example demonstrates how to use the B<--community>,
2867 B<--snmp-options> and B<--dns-domain> to make the command line
2868 simpler. All the equipment will use the community I<hidden>, except for
2869 the ppp-server which use community I<access>. All equipment uses these
2870 SNMP options: B<1s timeout>, B<1 retry> and B<SNMP version 2> (B<backoff> and
2871 B<port> is unspecified which means they use the default values).
2872 The exception again is the ppp-server which uses B<SNMP version 1>.
2873 Finally, all the equipment is part of the domain I<place.xyz>, except
2874 for the ppp-server which is part of the domain I<remote.place.xyz>.
2875 Note that the latter is achieved simply by specifying the name
2876 of the ppp-server to be I<ppp-server.B<remote>> .
2877
2878 cfgmaker --global "WorkDir: /home/tobi" \
2879 --global "Options[_]: growright,bits" \
2880 --dns-domain=place.xyz \
2881 --community=hidden \
2882 --snmp-options=::1:1::2 \
2883 router1 \
2884 router2 \
2885 router3 \
2886 router4 \
2887 router5 \
2888 switch1 \
2889 switch2 \
2890 switch3 \
2891 switch4 \
2892 switch5 \
2893 switch6 \
2894 switch7 \
2895 [email protected]:::::1 > mrtg.cfg
2896
2897
2898 =head1 SEE ALSO
2899
2900 L<mrtg-reference>
2901
2902 =head1 AUTHOR
2903
2904 Tobias Oetiker E<lt>[email protected]<gt> and
2905 Jakob Ilves E<lt>[email protected]<gt>
2906
2907
2908 =head1 LICENSE
2909
2910 GNU General Public License
2911
2912 =head1 COPYRIGHT
2913
2914 Cfgmaker is Copyright 2000 by Tobias Oetiker E<lt>[email protected]<gt>
2915
2916 =cut