| 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)/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 |
); |
| 1023 |
$DevInfo{Vendor} = 'Unknown Vendor - '.$DevInfo{sysObjectID}; |
| 1024 |
foreach (keys %vendorIDs) { |
| 1025 |
$DevInfo{Vendor} = $vendorIDs{$_} if ($DevInfo{sysObjectID} =~ /\Q$_\E/); |
| 1026 |
} |
| 1027 |
debug('base',"Vendor Id: $DevInfo{Vendor}"); |
| 1028 |
return \%DevInfo; |
| 1029 |
} else { |
| 1030 |
# we just die because the snmp module has already complained |
| 1031 |
return undef; |
| 1032 |
} |
| 1033 |
} # end DeviceInfo |
| 1034 |
|
| 1035 |
|
| 1036 |
sub fmi ($$) { |
| 1037 |
my $number = shift; |
| 1038 |
my $flags = shift; |
| 1039 |
my(@short); |
| 1040 |
if ($$flags{bits}){ |
| 1041 |
$number*=8; |
| 1042 |
@short = ("bits/s","kbits/s","Mbits/s","Gbits/s"); |
| 1043 |
} else { |
| 1044 |
@short = ("Bytes/s","kBytes/s","MBytes/s","GBytes/s"); |
| 1045 |
} |
| 1046 |
my $digits=length("".$number); |
| 1047 |
my $divm=0; |
| 1048 |
while ($digits-$divm*3 > 4) { $divm++; } |
| 1049 |
my $divnum = $number/10**($divm*3); |
| 1050 |
return sprintf("%1.1f %s",$divnum,$short[$divm]); |
| 1051 |
} # end fmi |
| 1052 |
|
| 1053 |
|
| 1054 |
sub IfType ($) { |
| 1055 |
my $id = shift; |
| 1056 |
my $ift = { |
| 1057 |
'1'=>'Other', |
| 1058 |
'2'=>'regular1822', |
| 1059 |
'3'=>'hdh1822', |
| 1060 |
'4'=>'ddnX25', |
| 1061 |
'5'=>'rfc877x25', |
| 1062 |
'6'=>'ethernetCsmacd', |
| 1063 |
'7'=>'iso88023Csmacd', |
| 1064 |
'8'=>'iso88024TokenBus', |
| 1065 |
'9'=>'iso88025TokenRing', |
| 1066 |
'10'=>'iso88026Man', |
| 1067 |
'11'=>'starLan', |
| 1068 |
'12'=>'proteon10Mbit', |
| 1069 |
'13'=>'proteon80Mbit', |
| 1070 |
'14'=>'hyperchannel', |
| 1071 |
'15'=>'fddi', |
| 1072 |
'16'=>'lapb', |
| 1073 |
'17'=>'sdlc', |
| 1074 |
'18'=>'ds1', |
| 1075 |
'19'=>'e1', |
| 1076 |
'20'=>'basicISDN', |
| 1077 |
'21'=>'primaryISDN', |
| 1078 |
'22'=>'propPointToPointSerial', |
| 1079 |
'23'=>'ppp', |
| 1080 |
'24'=>'softwareLoopback', |
| 1081 |
'25'=>'eon', |
| 1082 |
'26'=>'ethernet-3Mbit', |
| 1083 |
'27'=>'nsip', |
| 1084 |
'28'=>'slip', |
| 1085 |
'29'=>'ultra', |
| 1086 |
'30'=>'ds3', |
| 1087 |
'31'=>'sip', |
| 1088 |
'32'=>'frame-relay', |
| 1089 |
'33'=>'rs232', |
| 1090 |
'34'=>'para', |
| 1091 |
'35'=>'arcnet', |
| 1092 |
'36'=>'arcnetPlus', |
| 1093 |
'37'=>'atm', |
| 1094 |
'38'=>'miox25', |
| 1095 |
'39'=>'sonet', |
| 1096 |
'40'=>'x25ple', |
| 1097 |
'41'=>'iso88022llc', |
| 1098 |
'42'=>'localTalk', |
| 1099 |
'43'=>'smdsDxi', |
| 1100 |
'44'=>'frameRelayService', |
| 1101 |
'45'=>'v35', |
| 1102 |
'46'=>'hssi', |
| 1103 |
'47'=>'hippi', |
| 1104 |
'48'=>'modem', |
| 1105 |
'49'=>'aal5', |
| 1106 |
'50'=>'sonetPath', |
| 1107 |
'51'=>'sonetVT', |
| 1108 |
'52'=>'smdsIcip', |
| 1109 |
'53'=>'propVirtual', |
| 1110 |
'54'=>'propMultiplexor', |
| 1111 |
'55'=>'100BaseVG', |
| 1112 |
'56'=>'Fibre Channel', |
| 1113 |
'57'=>'HIPPI Interface', |
| 1114 |
'58'=>'Obsolete for FrameRelay', |
| 1115 |
'59'=>'ATM Emulation of 802.3 LAN', |
| 1116 |
'60'=>'ATM Emulation of 802.5 LAN', |
| 1117 |
'61'=>'ATM Emulation of a Circuit', |
| 1118 |
'62'=>'FastEthernet (100BaseT)', |
| 1119 |
'63'=>'ISDN & X.25', |
| 1120 |
'64'=>'CCITT V.11/X.21', |
| 1121 |
'65'=>'CCITT V.36', |
| 1122 |
'66'=>'CCITT G703 at 64Kbps', |
| 1123 |
'67'=>'Obsolete G702 see DS1-MIB', |
| 1124 |
'68'=>'SNA QLLC', |
| 1125 |
'69'=>'Full Duplex Fast Ethernet (100BaseFX)', |
| 1126 |
'70'=>'Channel', |
| 1127 |
'71'=>'Radio Spread Spectrum (802.11)', |
| 1128 |
'72'=>'IBM System 360/370 OEMI Channel', |
| 1129 |
'73'=>'IBM Enterprise Systems Connection', |
| 1130 |
'74'=>'Data Link Switching', |
| 1131 |
'75'=>'ISDN S/T Interface', |
| 1132 |
'76'=>'ISDN U Interface', |
| 1133 |
'77'=>'Link Access Protocol D (LAPD)', |
| 1134 |
'78'=>'IP Switching Objects', |
| 1135 |
'79'=>'Remote Source Route Bridging', |
| 1136 |
'80'=>'ATM Logical Port', |
| 1137 |
'81'=>'AT&T DS0 Point (64 Kbps)', |
| 1138 |
'82'=>'AT&T Group of DS0 on a single DS1', |
| 1139 |
'83'=>'BiSync Protocol (BSC)', |
| 1140 |
'84'=>'Asynchronous Protocol', |
| 1141 |
'85'=>'Combat Net Radio', |
| 1142 |
'86'=>'ISO 802.5r DTR', |
| 1143 |
'87'=>'Ext Pos Loc Report Sys', |
| 1144 |
'88'=>'Apple Talk Remote Access Protocol', |
| 1145 |
'89'=>'Proprietary Connectionless Protocol', |
| 1146 |
'90'=>'CCITT-ITU X.29 PAD Protocol', |
| 1147 |
'91'=>'CCITT-ITU X.3 PAD Facility', |
| 1148 |
'92'=>'MultiProtocol Connection over Frame/Relay', |
| 1149 |
'93'=>'CCITT-ITU X213', |
| 1150 |
'94'=>'Asymmetric Digital Subscriber Loop (ADSL)', |
| 1151 |
'95'=>'Rate-Adapt Digital Subscriber Loop (RDSL)', |
| 1152 |
'96'=>'Symmetric Digital Subscriber Loop (SDSL)', |
| 1153 |
'97'=>'Very High Speed Digital Subscriber Loop (HDSL)', |
| 1154 |
'98'=>'ISO 802.5 CRFP', |
| 1155 |
'99'=>'Myricom Myrinet', |
| 1156 |
'100'=>'Voice recEive and transMit (voiceEM)', |
| 1157 |
'101'=>'Voice Foreign eXchange Office (voiceFXO)', |
| 1158 |
'102'=>'Voice Foreign eXchange Station (voiceFXS)', |
| 1159 |
'103'=>'Voice Encapsulation', |
| 1160 |
'104'=>'Voice Over IP Encapsulation', |
| 1161 |
'105'=>'ATM DXI', |
| 1162 |
'106'=>'ATM FUNI', |
| 1163 |
'107'=>'ATM IMA', |
| 1164 |
'108'=>'PPP Multilink Bundle', |
| 1165 |
'109'=>'IBM IP over CDLC', |
| 1166 |
'110'=>'IBM Common Link Access to Workstation', |
| 1167 |
'111'=>'IBM Stack to Stack', |
| 1168 |
'112'=>'IBM Virtual IP Address (VIPA)', |
| 1169 |
'113'=>'IBM Multi-Protocol Channel Support', |
| 1170 |
'114'=>'IBM IP over ATM', |
| 1171 |
'115'=>'ISO 802.5j Fiber Token Ring', |
| 1172 |
'116'=>'IBM Twinaxial Data Link Control (TDLC)', |
| 1173 |
'117'=>'Gigabit Ethernet', |
| 1174 |
'118'=>'Higher Data Link Control (HDLC)', |
| 1175 |
'119'=>'Link Access Protocol F (LAPF)', |
| 1176 |
'120'=>'CCITT V.37', |
| 1177 |
'121'=>'CCITT X.25 Multi-Link Protocol', |
| 1178 |
'122'=>'CCITT X.25 Hunt Group', |
| 1179 |
'123'=>'Transp HDLC', |
| 1180 |
'124'=>'Interleave Channel', |
| 1181 |
'125'=>'Fast Channel', |
| 1182 |
'126'=>'IP (for APPN HPR in IP Networks)', |
| 1183 |
'127'=>'CATV MAC Layer', |
| 1184 |
'128'=>'CATV Downstream Interface', |
| 1185 |
'129'=>'CATV Upstream Interface', |
| 1186 |
'130'=>'Avalon Parallel Processor', |
| 1187 |
'131'=>'Encapsulation Interface', |
| 1188 |
'132'=>'Coffee Pot', |
| 1189 |
'133'=>'Circuit Emulation Service', |
| 1190 |
'134'=>'ATM Sub Interface', |
| 1191 |
'135'=>'Layer 2 Virtual LAN using 802.1Q', |
| 1192 |
'136'=>'Layer 3 Virtual LAN using IP', |
| 1193 |
'137'=>'Layer 3 Virtual LAN using IPX', |
| 1194 |
'138'=>'IP Over Power Lines', |
| 1195 |
'139'=>'Multi-Media Mail over IP', |
| 1196 |
'140'=>'Dynamic synchronous Transfer Mode (DTM)', |
| 1197 |
'141'=>'Data Communications Network', |
| 1198 |
'142'=>'IP Forwarding Interface', |
| 1199 |
'144'=>'IEEE1394 High Performance Serial Bus', |
| 1200 |
'150'=>'MPLS Tunnel Virtual Interface', |
| 1201 |
'161'=>'IEEE 802.3ad Link Aggregate', |
| 1202 |
'162'=>'Cisco Express Forwarding Interface', |
| 1203 |
'166'=>'MPLS', |
| 1204 |
'238'=>'Asymmetric Digital Subscriber Loop', |
| 1205 |
'246'=>'Pseudowire interface type', |
| 1206 |
'251'=>'Very high speed digital subscriber line', |
| 1207 |
}; |
| 1208 |
return ($ift->{$id} || "Unknown Interface Type"); |
| 1209 |
} # end IfType |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
sub options ($$) { |
| 1216 |
my $opt = shift; |
| 1217 |
my $routers = shift; |
| 1218 |
|
| 1219 |
my $noofrouter = 0; # How many routers we've seen on cmdline. |
| 1220 |
|
| 1221 |
# The $flags hash stores what we've seen in Options[_], |
| 1222 |
# Options[^] and Options[$] so far. |
| 1223 |
# A cmdline arg like --global 'Options[_]: bits' will insert |
| 1224 |
# the element $$flags{default}{bits}="set". |
| 1225 |
# Similarly --global 'Options[$]:' will delete all elements |
| 1226 |
# in $$flags{append} |
| 1227 |
# |
| 1228 |
# This was originally created to manipulate the "bits" flag |
| 1229 |
# so fmi should know when to use "bits" or "bytes". It might |
| 1230 |
# be overkill to use such a complex solution but it makes life |
| 1231 |
# easier if cfgmaker in the future has to be extended to be |
| 1232 |
# aware of other Options[] settings like gauge, growright etc. |
| 1233 |
|
| 1234 |
my %flags; |
| 1235 |
{ |
| 1236 |
my $def = {}; |
| 1237 |
my $pre = {}; |
| 1238 |
my $app = {}; |
| 1239 |
%flags = (default => $def, |
| 1240 |
prepend => $pre, |
| 1241 |
append => $app); |
| 1242 |
} |
| 1243 |
|
| 1244 |
my $addrouter_ornf = addrouter($opt, |
| 1245 |
$routers, |
| 1246 |
\$noofrouter, |
| 1247 |
\%flags); |
| 1248 |
|
| 1249 |
Getopt::Long::Configure("permute"); |
| 1250 |
GetOptions( $opt, |
| 1251 |
'help|?', |
| 1252 |
'man', |
| 1253 |
'subdirs=s', |
| 1254 |
'no-down', |
| 1255 |
'show-op-down', |
| 1256 |
'noreversedns', |
| 1257 |
'ifref=s', |
| 1258 |
'ifdesc=s', |
| 1259 |
'if-filter=s', |
| 1260 |
'if-template=s', |
| 1261 |
'interfaces!', |
| 1262 |
'host-template=s', |
| 1263 |
'community=s', |
| 1264 |
'username=s', |
| 1265 |
'authkey=s', |
| 1266 |
'authpassword=s', |
| 1267 |
'authprotocol=s', |
| 1268 |
'contextengineid=s', |
| 1269 |
'contextname=s', |
| 1270 |
'privkey=s', |
| 1271 |
'privpassword=s', |
| 1272 |
'privprotocol=s', |
| 1273 |
'snmp-options=s', |
| 1274 |
'dns-domain=s', |
| 1275 |
'version', |
| 1276 |
'output=s', |
| 1277 |
'global=s@', |
| 1278 |
'nodefaultglobal', |
| 1279 |
'enable-ipv6', |
| 1280 |
'enablesnmpv3', |
| 1281 |
'use-16bit', |
| 1282 |
'zero-speed=s', |
| 1283 |
'<>', $addrouter_ornf) or pod2usage(2); |
| 1284 |
|
| 1285 |
die("cfgmaker for mrtg-2.17.10\n") if $$opt{version}; |
| 1286 |
pod2usage(-exitval => 0, -verbose => 2) if $$opt{man}; |
| 1287 |
pod2usage(-verbose => 1) if not keys %$routers; |
| 1288 |
} # end options |
| 1289 |
|
| 1290 |
# The callback routine used by GetOptions to process "non-option |
| 1291 |
# strings" (routers) among the arguments is given only ONE argument. |
| 1292 |
# However, I want it to be able to specify both the %options hash |
| 1293 |
# (for read access) and the %routers hash (for modifying) as well |
| 1294 |
# as the router's name. This makes for three arguments. |
| 1295 |
# |
| 1296 |
# The solution is to use a closure. addrouter takes a opt hash, a |
| 1297 |
# routers hash, an index to the current number of routers and a flags |
| 1298 |
# hash and then returns a function which "remembers" these |
| 1299 |
# values (the closure) but also takes an argument (the router name). |
| 1300 |
|
| 1301 |
sub addrouter() { |
| 1302 |
my $opt = shift; |
| 1303 |
my $routers = shift; |
| 1304 |
my $noofrouter = shift; |
| 1305 |
my $flags = shift; |
| 1306 |
|
| 1307 |
return sub { |
| 1308 |
my $rawname = shift; |
| 1309 |
|
| 1310 |
$$noofrouter++; # First increase the number of routers seen. |
| 1311 |
|
| 1312 |
my ($community,$routername,$routerkey,$snmpopt,$dnsdomain,$tmpname,@tmpsnmp); |
| 1313 |
|
| 1314 |
# Now make sure that the router is defined with the |
| 1315 |
# proper community, domainname and SNMP options. |
| 1316 |
# Dissect the rawname to find out what it contains. |
| 1317 |
|
| 1318 |
# First check for community: |
| 1319 |
if ($rawname =~ /^(.+)\@([^@]+)$/) { |
| 1320 |
# Community was given explicitly! |
| 1321 |
$community = $1; |
| 1322 |
$tmpname = $2 |
| 1323 |
} else { |
| 1324 |
$community = $$opt{community}; |
| 1325 |
$tmpname = $rawname; |
| 1326 |
} |
| 1327 |
# Now separate the router name from the options. We |
| 1328 |
# can't just split on the : character because a numeric |
| 1329 |
# IPv6 address contains a variable number of :'s |
| 1330 |
if( ($tmpname =~ /^(\[.*\]):(.*)$/) || ($tmpname =~ /^(\[.*\])$/) ){ |
| 1331 |
# Numeric IPv6 address between [] |
| 1332 |
($routername, $snmpopt) = ($1, $2); |
| 1333 |
} else { |
| 1334 |
# Hostname or numeric IPv4 address |
| 1335 |
($routername, $snmpopt) = split(':', $tmpname, 2); |
| 1336 |
} |
| 1337 |
@tmpsnmp = split(':', $snmpopt || ''); |
| 1338 |
|
| 1339 |
$routername =~ s/\.$//; # if the hostname ends in a '.' remove it |
| 1340 |
# it seems to cause trouble in some other |
| 1341 |
# parts of mrtg |
| 1342 |
|
| 1343 |
# Now setup the SNMP options. |
| 1344 |
if (not defined $$opt{'snmp-options'}) { |
| 1345 |
$snmpopt = ':' . (join ':', @tmpsnmp); # No merge needed. |
| 1346 |
} else { |
| 1347 |
my ($t,$o,@s); |
| 1348 |
my @optsnmp = split ':',$$opt{'snmp-options'}; |
| 1349 |
|
| 1350 |
# Trim first element as the SNMP options start |
| 1351 |
# with a colon and thus the first element is a |
| 1352 |
# dummy "" string not corresponding to any SNMP option |
| 1353 |
# (or rather, corresponding to a router, if there had |
| 1354 |
# been one...) |
| 1355 |
shift @optsnmp; |
| 1356 |
|
| 1357 |
while ((scalar @tmpsnmp > 0) |
| 1358 |
or (scalar @optsnmp > 0)) { |
| 1359 |
$t = shift @tmpsnmp; |
| 1360 |
$o = shift @optsnmp; |
| 1361 |
|
| 1362 |
if(not defined $t) {$t = "";} |
| 1363 |
if(not defined $o) {$o = "";} |
| 1364 |
|
| 1365 |
if($t ne "") |
| 1366 |
{ |
| 1367 |
push @s, $t; |
| 1368 |
} else { |
| 1369 |
push @s, $o; |
| 1370 |
} |
| 1371 |
} |
| 1372 |
|
| 1373 |
$snmpopt = ':' . (join ':', @s); |
| 1374 |
} |
| 1375 |
|
| 1376 |
my $newopt={}; # Perhaps unnecessary initialization but... |
| 1377 |
|
| 1378 |
foreach my $o (keys %$opt) { |
| 1379 |
my $ovalue = $$opt{$o}; |
| 1380 |
|
| 1381 |
$$newopt{$o} = $ovalue |
| 1382 |
unless |
| 1383 |
($o =~ /^fullcmd$/ or |
| 1384 |
$o =~ /^community$/ or |
| 1385 |
$o =~ /^snmp-options$/ or |
| 1386 |
$o =~ /^global$/ or |
| 1387 |
$o =~ /^output$/ |
| 1388 |
); |
| 1389 |
|
| 1390 |
# Ok, copy the --globals array from $$opt so we know |
| 1391 |
# that which global(s) to print out into the config. |
| 1392 |
push @{$$newopt{$o}}, @{$$opt{$o}} if ($o =~ /^global$/); |
| 1393 |
|
| 1394 |
# Go through these --global statements one by one. |
| 1395 |
# If anyone of them contains Options[] for any of the |
| 1396 |
# targets [_], [^] or [_], process those statements |
| 1397 |
# tenderly and populate the $$flags{}{} hashes accordingly. |
| 1398 |
for my $g (@{$$opt{"global"}}) { |
| 1399 |
if ($g =~ /^options\[([_^\$])\]:\s*(.*)$/i){ |
| 1400 |
my ($t,$fs); |
| 1401 |
$t = $1; |
| 1402 |
$fs = $2; |
| 1403 |
$t =~ s/_/default/; |
| 1404 |
$t =~ s/\^/prepend/; |
| 1405 |
$t =~ s/\$/append/; |
| 1406 |
|
| 1407 |
# If a line like "options[X]:" is found clear |
| 1408 |
# all flags for that category and then go to next |
| 1409 |
# --global 'Options[..' line if any. |
| 1410 |
if ($fs =~ /^\s*$/) { |
| 1411 |
$$flags{$t} = {}; |
| 1412 |
next; |
| 1413 |
} else { |
| 1414 |
for my $f (split /\s*,\s*/,$fs) { |
| 1415 |
$$flags{$t}{$f} = "set"; |
| 1416 |
} |
| 1417 |
} |
| 1418 |
} |
| 1419 |
} |
| 1420 |
$$opt{$o} = [] if ($o =~ /^global$/); |
| 1421 |
} |
| 1422 |
|
| 1423 |
# Now let this router get it's own copy of |
| 1424 |
# the "currently effective" flags. |
| 1425 |
# Note, Options[_] should only be considered |
| 1426 |
# if Options[^] and Options[$] both are absent. |
| 1427 |
|
| 1428 |
my $newflags = {}; |
| 1429 |
|
| 1430 |
if((0 == keys %{$$flags{prepend}}) |
| 1431 |
and (0== keys %{$$flags{append}})) { |
| 1432 |
for my $f (keys %{$$flags{default}}) { |
| 1433 |
$$newflags{$f}="set"; |
| 1434 |
} |
| 1435 |
} else { |
| 1436 |
for my $f (keys %{$$flags{prepend}}, |
| 1437 |
keys %{$$flags{append}}) { |
| 1438 |
$$newflags{$f}="set"; |
| 1439 |
} |
| 1440 |
} |
| 1441 |
|
| 1442 |
if(defined $$opt{'dns-domain'}) { |
| 1443 |
$dnsdomain=$$opt{'dns-domain'}; |
| 1444 |
} else { |
| 1445 |
$dnsdomain=""; |
| 1446 |
} |
| 1447 |
|
| 1448 |
$routerkey = |
| 1449 |
"${community}\@${routername}" |
| 1450 |
. (($dnsdomain eq "")?"":".") |
| 1451 |
. "${dnsdomain}${snmpopt}"; |
| 1452 |
|
| 1453 |
$$routers{$routerkey}= { |
| 1454 |
# rawname is the unprocessed string from the |
| 1455 |
# command line. |
| 1456 |
rawname => $rawname, |
| 1457 |
|
| 1458 |
# opt is the commandline options which are |
| 1459 |
# in effect for THIS particular router. |
| 1460 |
opt => $newopt, |
| 1461 |
|
| 1462 |
# noofrouter is the unique number for the |
| 1463 |
# router. The first router on the command |
| 1464 |
# line is given number 1, the second number 2 |
| 1465 |
# and so on. |
| 1466 |
noofrouter => $$noofrouter, |
| 1467 |
|
| 1468 |
# flags contains which --global 'Options[^_$]: flags' |
| 1469 |
# are effective for THIS particular router. |
| 1470 |
flags => $newflags, |
| 1471 |
|
| 1472 |
# community is the SNMP community used for the router |
| 1473 |
community => $community, |
| 1474 |
|
| 1475 |
# snmpopt is the SNMP options on the form |
| 1476 |
# [port[:timeout[:retries[:backoff[:version]]]]] |
| 1477 |
# The empty string simply means that no |
| 1478 |
# specific SNMP options has been given. |
| 1479 |
'snmp-options' => $snmpopt, |
| 1480 |
snmpopt_current => $snmpopt, |
| 1481 |
|
| 1482 |
# dns-domain is a domain which should be added |
| 1483 |
# to the routers hostname. |
| 1484 |
# e.g if dns-domain is place.xyz and host is router |
| 1485 |
# the host "router.place.xyz" will be polled. |
| 1486 |
# If host is "router.dept" the poll will be against |
| 1487 |
# "router.dept.place.xyz". |
| 1488 |
'dns-domain' => $dnsdomain, |
| 1489 |
|
| 1490 |
# routername is the routers name as given on the |
| 1491 |
# command line but with SNMP community (if given) |
| 1492 |
# and SNMP options (if given) stripped. |
| 1493 |
# |
| 1494 |
# (Yes, routername COULD be on the form |
| 1495 |
# "host.domain" or "host.subdomain.domain") |
| 1496 |
routername => $routername, |
| 1497 |
|
| 1498 |
# routerkey is the same as the has key used for the |
| 1499 |
# router, which is the router name with everything |
| 1500 |
# taken into account: community, dns-domain and |
| 1501 |
# snmp-options. This is the value used when doing |
| 1502 |
# SNMP communication with the router. |
| 1503 |
routerkey => $routerkey, |
| 1504 |
}; |
| 1505 |
} |
| 1506 |
} # end addrouter |
| 1507 |
|
| 1508 |
sub html_escape ($) { |
| 1509 |
my $s = shift || ''; |
| 1510 |
$s =~ s/&/&/g; |
| 1511 |
$s =~ s/</</g; |
| 1512 |
$s =~ s/>/>/g; |
| 1513 |
$s =~ s/[\n\r]+([^\n\r])/<BR>\n $1/g; |
| 1514 |
return $s; |
| 1515 |
} # end html_escape |
| 1516 |
|
| 1517 |
sub oid_pick ($$$;@){ |
| 1518 |
my $router = shift; |
| 1519 |
my $v3opt = shift; |
| 1520 |
my @oids = @_; |
| 1521 |
local $SNMP_Session::suppress_warnings = 3; |
| 1522 |
foreach my $oid (@oids){ |
| 1523 |
local $SNMP_Session::errmsg = undef; |
| 1524 |
my $counter = snmpget($router,$v3opt,$oid); |
| 1525 |
if (not defined $SNMP_Session::errmsg and defined $counter and $counter ne '' ) { |
| 1526 |
debug('base',"oid_pick - found $oid to work for $router"); |
| 1527 |
return $oid; |
| 1528 |
} |
| 1529 |
} |
| 1530 |
debug('base',"oid_pick - none of ".(join ",",@oids)." seem to work for $router"); |
| 1531 |
return undef; |
| 1532 |
} |
| 1533 |
|
| 1534 |
|
| 1535 |
sub parsev3 ($) { |
| 1536 |
my $opt = shift; |
| 1537 |
my %v3opt; |
| 1538 |
if (!exists ($$opt{username})) { |
| 1539 |
die "SMNP V3 requires a --username parameter as part of the User Security Model"; |
| 1540 |
} else { |
| 1541 |
$v3opt{username} = $$opt{username}; |
| 1542 |
} |
| 1543 |
$v3opt{contextname} = $$opt{contextname} if exists($$opt{contextname}); |
| 1544 |
if (exists ($$opt{authkey})) { |
| 1545 |
die "Can't use both an --authkey and --authpassword in the User Security Model" if exists($$opt{authpassword}); |
| 1546 |
$v3opt{authkey} = $$opt{authkey}; |
| 1547 |
} |
| 1548 |
if (exists ($$opt{authpassword})) { |
| 1549 |
die "Use of --authpassword requires --contextengineid" if !exists($$opt{contextengineid}); |
| 1550 |
$v3opt{authpassword} = $$opt{authpassword}; |
| 1551 |
} |
| 1552 |
if (exists ($$opt{authprotocol})) { |
| 1553 |
die "Only sha and md5 are defined for --authprotocol" if $$opt{authprotocol} !~ /^(md5|sha)$/i; |
| 1554 |
die "--authprotocol can only be used with --authpassword or --authkey" if ! exists($$opt{authpassword}) and ! exists($$opt{authkey}); |
| 1555 |
($v3opt{authprotocol}) = (lc($$opt{authprotocol}) =~ /^(md5|sha)$/); |
| 1556 |
} |
| 1557 |
if (exists ($$opt{privkey})) { |
| 1558 |
die "Can't use both an --privkey and --privpassword in the User Security Model" if exists($$opt{privpassword}); |
| 1559 |
die "Can't have privacy parameters without authentication in the User security Model" if ! exists($$opt{authpassword}) and ! exists($$opt{authkey}); |
| 1560 |
$v3opt{privkey} = $$opt{privkey}; |
| 1561 |
} |
| 1562 |
if (exists ($$opt{privpassword})) { |
| 1563 |
die "Use of --privpassword requires --contextengineid" if !exists($$opt{contextengineid}); |
| 1564 |
die "Can't have privacy parameters without authentication in the User security Model" if ! exists($$opt{authpassword}) and ! exists($$opt{authkey}); |
| 1565 |
$v3opt{privpassword} = $$opt{privpassword}; |
| 1566 |
} |
| 1567 |
if (exists ($$opt{privprotocol})) { |
| 1568 |
die "Only des, 3des, 3desede, aes, aes128 are defined for --privprotocol" if $$opt{privprotocol} !~ /^(?:3?des(?:ede)?|aes(?:128)?)$/; |
| 1569 |
die "--privprotocol can only be used with --privpassword or --privkey" if ! exists($$opt{privpassword}) and ! exists($$opt{privkey}); |
| 1570 |
$v3opt{privprotocol} = lc($$opt{privprotocol}); |
| 1571 |
} |
| 1572 |
return %v3opt; |
| 1573 |
} |
| 1574 |
|
| 1575 |
|
| 1576 |
sub init () { |
| 1577 |
snmpmapOID('sysObjectID' => '1.3.6.1.2.1.1.2.0', |
| 1578 |
'CiscolocIfDescr' => '1.3.6.1.4.1.9.2.2.1.1.28', |
| 1579 |
'CiscoCatalystPortName' => '1.3.6.1.4.1.9.5.1.4.1.1.4', |
| 1580 |
'ppPortName' => '1.3.6.1.4.1.2272.1.4.10.1.1.35', |
| 1581 |
'vlanTrunkPortDynamicStatus'=> '1.3.6.1.4.1.9.9.46.1.6.1.1.14', |
| 1582 |
'vmVlan' => '1.3.6.1.4.1.9.9.68.1.2.2.1.2', |
| 1583 |
'ifAlias' => '1.3.6.1.2.1.31.1.1.1.18'); |
| 1584 |
} # end init |
| 1585 |
|
| 1586 |
__END__ |
| 1587 |
|
| 1588 |
=pod |
| 1589 |
|
| 1590 |
=head1 NAME |
| 1591 |
|
| 1592 |
cfgmaker - Creates mrtg.cfg files (for mrtg-2.17.10) |
| 1593 |
|
| 1594 |
=head1 SYNOPSIS |
| 1595 |
|
| 1596 |
cfgmaker [options] [community@]router [[options] [community@]router ...] |
| 1597 |
|
| 1598 |
=head1 OPTIONS |
| 1599 |
|
| 1600 |
--ifref=name interface references by Interface Name (default) |
| 1601 |
--ifref=ip ... by Ip Address |
| 1602 |
--ifref=eth ... by Ethernet Number |
| 1603 |
--ifref=descr ... by Interface Description |
| 1604 |
--ifref=nr ... by Interface Number |
| 1605 |
--ifref=type ... by Interface Type |
| 1606 |
You may also use multiple options separated by commas, |
| 1607 |
in which case the first available one is used: |
| 1608 |
e.g. --ifref=ip,name,nr |
| 1609 |
|
| 1610 |
--ifdesc=nr interface description uses Interface Number (default) |
| 1611 |
--ifdesc=ip ... uses Ip Address |
| 1612 |
--ifdesc=eth ... uses Ethernet Number |
| 1613 |
--ifdesc=descr ... uses Interface Description |
| 1614 |
--ifdesc=name ... uses Interface Name |
| 1615 |
--ifdesc=catname ... uses CatOS Interface Name |
| 1616 |
--ifdesc=ppname ... uses Passport Port Name |
| 1617 |
--ifdesc=alias ... uses Interface Alias |
| 1618 |
--ifdesc=type ... uses Interface Type |
| 1619 |
You may also use multiple options separated by commas, |
| 1620 |
in which case the first available one is used: |
| 1621 |
e.g. --ifdesc=catname,ppname,descr,alias,ip,name,nr |
| 1622 |
|
| 1623 |
--if-filter=f Test every interface against filter f to decide whether |
| 1624 |
or not to include that interface into the collection. |
| 1625 |
Currently f is being evaluated as a Perl expression |
| 1626 |
and it's truth value is used to reject or accept the |
| 1627 |
interface. |
| 1628 |
(Experimental, under development, might change) |
| 1629 |
|
| 1630 |
--if-template=templatefile |
| 1631 |
Replace the normal target entries for the interfaces |
| 1632 |
with an entry as specified by the contents in the file |
| 1633 |
templatefile. The file is supposed to contain Perl |
| 1634 |
code to be executed to generate the lines for the |
| 1635 |
target in the configuration file. |
| 1636 |
(Experimental, under development, might change) |
| 1637 |
|
| 1638 |
--host-template=templatefile |
| 1639 |
In addition to creating targets for a host's interfaces |
| 1640 |
do also create targets for the host itself as specified |
| 1641 |
by the contents in the file templatefile. The file is |
| 1642 |
supposed to contain Perl code to be executed to generate |
| 1643 |
the lines for the host related targets (such as CPU, |
| 1644 |
ping response time measurements etc.) in the config- |
| 1645 |
uration file. |
| 1646 |
(Experimental, under development, might change) |
| 1647 |
|
| 1648 |
--global "x: a" add global config entries |
| 1649 |
|
| 1650 |
--nodefaultglobal do not include default global settings |
| 1651 |
|
| 1652 |
--no-down do not look at admin or opr status of interfaces |
| 1653 |
|
| 1654 |
--show-op-down show interfaces which are operatively down |
| 1655 |
|
| 1656 |
--zero-speed=spd use this speed in bits-per-second as the interface |
| 1657 |
speed for all interfaces that return a speed of 0 |
| 1658 |
via ifSpeed/ifHighSpeed. 100Mbps = 100000000 |
| 1659 |
|
| 1660 |
--subdirs=format give each router its own subdirectory, naming each per |
| 1661 |
"format", in which HOSTNAME and SNMPNAME will be |
| 1662 |
replaced by the values of those items -- for instance, |
| 1663 |
--subdirs=HOSTNAME or --subdirs="HOSTNAME (SNMPNAME)" |
| 1664 |
|
| 1665 |
--noreversedns do not reverse lookup ip numbers |
| 1666 |
|
| 1667 |
--community=cmty Set the default community string to "cmty" instead of |
| 1668 |
"public". |
| 1669 |
|
| 1670 |
--enable-ipv6 Enable IPv6 support, if the required libraries are |
| 1671 |
present. Numeric IPv6 addresses must be enclosed |
| 1672 |
in square brackets, e.g. public@[2001:760:4::1]:161 |
| 1673 |
|
| 1674 |
--use-16bit Use 16bit SNMP request IDs to query all routers. |
| 1675 |
|
| 1676 |
--snmp-options=:[<port>][:[<tmout>][:[<retr>][:[<backoff>][:<ver>]]]] |
| 1677 |
|
| 1678 |
Specify default SNMP options to be appended to all |
| 1679 |
routers following. Individual fields can be empty. |
| 1680 |
Routers following might override some or all of the |
| 1681 |
options given to --snmp-options. |
| 1682 |
|
| 1683 |
--dns-domain=domain |
| 1684 |
Specifies a domain to append to the name of all |
| 1685 |
routers following. |
| 1686 |
|
| 1687 |
--nointerfaces Don't do generate any configuration lines for interfaces, |
| 1688 |
skip the step of gathering interface information and |
| 1689 |
don't run any interface template code. |
| 1690 |
|
| 1691 |
--interfaces Generate configuration lines for interfaces (this is the |
| 1692 |
default). The main purpose of this option is to negate |
| 1693 |
an --nointerfaces appearing earlier on the command line. |
| 1694 |
|
| 1695 |
--help brief help message |
| 1696 |
--man full documentation |
| 1697 |
--version print the version of cfgmaker |
| 1698 |
|
| 1699 |
--output=file output filename default is STDOUT |
| 1700 |
|
| 1701 |
=head1 DESCRIPTION |
| 1702 |
|
| 1703 |
B<Cfgmaker> creates MRTG configuration files based on information |
| 1704 |
pulled from a router or another SNMP manageable device. |
| 1705 |
|
| 1706 |
[I<community>B<@>]I<router> |
| 1707 |
|
| 1708 |
I<Community> is the community name of the device you want to create a |
| 1709 |
configuration for. If not specified, it defaults to 'B<public>'; you might |
| 1710 |
want to try this first if you do not know the community name of a |
| 1711 |
device. If you are using the wrong community name you will get no |
| 1712 |
response from the device. |
| 1713 |
|
| 1714 |
I<Router> is the DNS name or the IP number of an SNMP-manageable device. |
| 1715 |
Following the name you can specify 6 further options separated by |
| 1716 |
colons. The full syntax looks like this: |
| 1717 |
|
| 1718 |
B<router>[:[B<prt>][:[B<tmout>][:[B<retr>][:[B<backoff>][:B<vers>]]]]] |
| 1719 |
|
| 1720 |
Of special interest may be the last parameter, B<vers>. If you set this to |
| 1721 |
'2' then your device will be queried with SNMP version 2 requests. This |
| 1722 |
allows you to poll the 64 bit traffic counters in the device and will thus work |
| 1723 |
much better with fast interfaces (no more counter overrun). Note that the |
| 1724 |
order in which the routers are specified on the command line do matter as |
| 1725 |
the same order is used when the configuration file is generated. The first |
| 1726 |
specified router has it's configuration lines generated first, followed by |
| 1727 |
the lines belonging to the next router and so on. |
| 1728 |
|
| 1729 |
Note that the first line of the generated cfg file will contain all the |
| 1730 |
commandline options you used for generating it. This is to allow for the |
| 1731 |
easy 'regeneration' in case you want to add newhosts or make some other |
| 1732 |
global change. |
| 1733 |
|
| 1734 |
=head2 Configuration |
| 1735 |
|
| 1736 |
Except for the B<--output> and B<--global> options, all options affect |
| 1737 |
only the routers following them on the command line. If an option |
| 1738 |
specified earlier on the command line reappears later on the command |
| 1739 |
line with another value, the new value overrides the old value as far as |
| 1740 |
remaining routers are concerned. This way options might be tailored for |
| 1741 |
groups of routers or for individual routers. |
| 1742 |
|
| 1743 |
See B<--output> and B<--global> for how their behaviour is affected by |
| 1744 |
where or how many times they appear on the command line. |
| 1745 |
|
| 1746 |
See the B<Examples> below on how to set an option differently for |
| 1747 |
multiple routers. |
| 1748 |
|
| 1749 |
=over |
| 1750 |
|
| 1751 |
=item B<--help> |
| 1752 |
|
| 1753 |
Print a brief help message and exit. |
| 1754 |
|
| 1755 |
=item B<--man> |
| 1756 |
|
| 1757 |
Prints the manual page and exits. |
| 1758 |
|
| 1759 |
=item B<--version> |
| 1760 |
|
| 1761 |
Print the version of cfgmaker. This should match the version of MRTG |
| 1762 |
for which config files are being created. |
| 1763 |
|
| 1764 |
=item B<--ifref> B<nr>|B<ip>|B<eth>|B<descr>|B<name> |
| 1765 |
|
| 1766 |
Select the interface identification method. Default is B<nr> which |
| 1767 |
identifies the router interfaces by their number. Unfortunately the |
| 1768 |
interface numbering scheme in an SNMP tree can change. Some routers |
| 1769 |
change their numbering when new interfaces are added, others change |
| 1770 |
their numbering every full moon just for fun. |
| 1771 |
|
| 1772 |
To work around this sad problem MRTG can identify interfaces by 4 |
| 1773 |
other properties. None of these works for all interfaces, but you |
| 1774 |
should be able to find one which does fine for you. Note that |
| 1775 |
especially ethernet addresses can be problematic as some routers have |
| 1776 |
the same ethernet address on most of their interface cards. |
| 1777 |
|
| 1778 |
Select B<ip> to identify the interface by its IP number. Use B<eth> to |
| 1779 |
use the ethernet address for identification. Use B<descr> to use |
| 1780 |
the Interface description. Or use B<name> to use the Interface name. |
| 1781 |
|
| 1782 |
You can specify multiple properties if you wish, separated by commas. |
| 1783 |
In this case, cfgmaker will use the first item in the list which |
| 1784 |
can provide unique identification. This allows you to specify, for |
| 1785 |
example, to use IP address and to use ifName if this is not defined: |
| 1786 |
--ifref ip,name |
| 1787 |
|
| 1788 |
If your chosen method does not allow unique interface identification on |
| 1789 |
the device you are querying, B<cfgmaker> will tell you about it. |
| 1790 |
|
| 1791 |
=item B<--ifdesc> B<nr>|B<ip>|B<eth>|B<descr>|B<name>|B<type>|B<alias> |
| 1792 |
|
| 1793 |
Select what to use as the description of the interface. The description |
| 1794 |
appears in the C<Title[]> property for the target as well as the text header |
| 1795 |
in the HTML code defined in the target's C<PageTop[]>. Default is to use |
| 1796 |
B<nr> which is just the interface number which isn't always useful |
| 1797 |
to the viewer of the graphs. |
| 1798 |
|
| 1799 |
There are 6 other properties which could be used. Use B<ip> if you want |
| 1800 |
to use the interface's IP-address. Use B<eth> if you want to use the |
| 1801 |
interface's ethernet address. If you want a better description, you can |
| 1802 |
use either B<descr>, B<name> or B<alias>. Exactly what each of these do |
| 1803 |
varies between different equipment so you might need to experiment. For |
| 1804 |
instance, for a serial interface on a Cisco router running IOS using B<name> |
| 1805 |
might result in C<"S0"> being the interface description , B<descr> might result |
| 1806 |
in C<"Serial0"> and B<alias> might result in C<"Link to HQ"> (provided that is |
| 1807 |
what is used as the interface's C<description> in the router's configuration). |
| 1808 |
|
| 1809 |
Finally, if you want to describe the interface by it's Btype |
| 1810 |
(i.e C<"ethernetCSMA">, C<"propPointtoPoint"> etc) you can use B<type>. |
| 1811 |
|
| 1812 |
You can specify multiple properties if you wish, separated by commas. |
| 1813 |
In this case, cfgmaker will use the first item in the list which |
| 1814 |
is available for this interface. This allows you to specify, for |
| 1815 |
example, to use any of the different aliases in order of preference. |
| 1816 |
|
| 1817 |
=item B<--if-filter> 'B<filter-expression>' |
| 1818 |
|
| 1819 |
First of all, this is under some development and is experimental. |
| 1820 |
|
| 1821 |
Use this if you want to have better control over what interfaces gets |
| 1822 |
included into the configuration. The B<filter-expression> is evaluated |
| 1823 |
as a piece of Perl code and is expected |
| 1824 |
to return a truth value. If true, include the interface and if false, |
| 1825 |
exclude the interface. |
| 1826 |
|
| 1827 |
For a further discussion on how these filters work, see the section |
| 1828 |
L<Details on Filters> below. |
| 1829 |
|
| 1830 |
=item B<--if-template> B<template-file> |
| 1831 |
|
| 1832 |
First of all, this is under some development and is experimental. |
| 1833 |
|
| 1834 |
Use this if you want to control what the line for each target should look |
| 1835 |
like in the configuration file. The contents of the file B<template-file> |
| 1836 |
will be evaluated as a Perl program which generates the lines using certain |
| 1837 |
variables for input and output. |
| 1838 |
|
| 1839 |
For a further discussion on how these templates work, see the section |
| 1840 |
L<Details on Templates> below. |
| 1841 |
|
| 1842 |
=item B<--host-template> B<template-file> |
| 1843 |
|
| 1844 |
First of all, this is under some development and is experimental. |
| 1845 |
|
| 1846 |
Use this if you want to have some extra targets related to the host itself |
| 1847 |
such as CPU utilization, ping response time to the host, number of busy |
| 1848 |
modems etc. The contents of the file B<template-file> will be evaluated |
| 1849 |
once per host as a Perl program which generates the lines using certain |
| 1850 |
variables for input and output. |
| 1851 |
|
| 1852 |
For a further discussion on how these templates work, see the section |
| 1853 |
L<Details on Templates> below. |
| 1854 |
|
| 1855 |
=item B<--community> B<community-string> |
| 1856 |
|
| 1857 |
Use this to set the community for the routers following on the command |
| 1858 |
line to B<community-string>. Individual routers might override this |
| 1859 |
community string by using the syntax B<community>B<@>B<router>. |
| 1860 |
|
| 1861 |
=item B<--enable-ipv6> |
| 1862 |
|
| 1863 |
This option enables IPv6 support. It requires the appropriate perl |
| 1864 |
modules; if they are not found then IPv6 is disabled (see the ipv6 |
| 1865 |
documentation). |
| 1866 |
|
| 1867 |
cfgmaker will use IPv6 or IPv4 depending on the target. If the target |
| 1868 |
is a numeric address, the protocol depends on the type of address. If the |
| 1869 |
target is a hostname, cfgmaker will try to resolve the name first to an |
| 1870 |
IPv6 address then to an IPv4 address. |
| 1871 |
|
| 1872 |
IPv6 numeric addresses must be specified between square braces. |
| 1873 |
|
| 1874 |
For example: |
| 1875 |
|
| 1876 |
cfgmaker --enable-ipv6 [2001:760:4::1]:165:::2 |
| 1877 |
|
| 1878 |
If the target has both an IPv6 address and an IPv4 address with the same |
| 1879 |
hostname, cfgmaker first queries the target using IPv6 and falls back to |
| 1880 |
IPv4 if it fails. This is useful for targets which don't support SNMP |
| 1881 |
over IPv6. |
| 1882 |
|
| 1883 |
=item B<--use-16bit> |
| 1884 |
|
| 1885 |
This option forces the use of 16bit SNMP request IDs. Some broken SNMP |
| 1886 |
agents do not accept 32bit request IDs. Try to avoid this option as much |
| 1887 |
as possible, complain to your agent vendor instead. |
| 1888 |
|
| 1889 |
=item B<--snmp-options> :[B<port>][:[B<timeout>][:[B<retries>][:[B<backoff>][:B<version>]]]] |
| 1890 |
|
| 1891 |
Use this to set the default SNMP options for all routers following on the |
| 1892 |
command line. Individual values might be omitted as well as trailing |
| 1893 |
colons. Note that routers might override individual (or all) values |
| 1894 |
specified by B<--snmp-options> by using the syntax |
| 1895 |
|
| 1896 |
B<router>[:[B<port>][:[B<timeout>][:[B<retries>][:[B<backoff>][:B<version>]]]]] |
| 1897 |
|
| 1898 |
=item B<--global> B<">I<bla: abc>B<"> |
| 1899 |
|
| 1900 |
Use this to add global options to the generated config file. |
| 1901 |
You can call B<--global> several times to add multiple options. |
| 1902 |
The line will appear in the configuration just before the config for |
| 1903 |
the next router appearing on the command line. |
| 1904 |
|
| 1905 |
--global "workdir: /home/mrtg" |
| 1906 |
|
| 1907 |
If you want some default Options you might want to put |
| 1908 |
|
| 1909 |
--global "options[_]: growright,bits" |
| 1910 |
|
| 1911 |
Specifying B<--global> after the last router on the command line will |
| 1912 |
create a line in the configuration file which will appear after all the |
| 1913 |
routers. |
| 1914 |
|
| 1915 |
=item B<--noreversedns> |
| 1916 |
|
| 1917 |
Do not try to reverse lookup IP numbers ... a must for DNS free environments. |
| 1918 |
|
| 1919 |
=item B<--no-down> |
| 1920 |
|
| 1921 |
Normally cfgmaker will not include interfaces which are marked |
| 1922 |
anything but administratively and operationally UP. With this |
| 1923 |
switch you get them all. |
| 1924 |
|
| 1925 |
=item B<--show-op-down> |
| 1926 |
|
| 1927 |
Include interfaces which are operatively down. |
| 1928 |
|
| 1929 |
=item B<--zero-speed> I<speed> |
| 1930 |
|
| 1931 |
Assign this speed in bits-per-second to all interfaces which return 0 |
| 1932 |
for ifSpeed and ifHighSpeed. Some switches, notably Foundry equipment, |
| 1933 |
return a speed of zero for some interfaces. For example, to have |
| 1934 |
all interfaces reporting zero set to 100Mbps, use |
| 1935 |
--zero-speed=100000000. |
| 1936 |
|
| 1937 |
=item B<--subdirs> I<format> |
| 1938 |
|
| 1939 |
Give each router its own subdirectory for the HTML and graphics (or |
| 1940 |
.rrd) files. The directory name is the given I<format> string with a |
| 1941 |
couple of pattern replacements. The string "HOSTNAME" will be |
| 1942 |
replaced by the hostname of the router (however you specified it on |
| 1943 |
the B<cfgmaker> commandline -- it may be an actual hostname or just an |
| 1944 |
IP address), and "SNMPNAME" will be replaced with the device's idea of |
| 1945 |
its own name (the same name that appears on the right side of the |
| 1946 |
"Title" lines). For instance, a call like: |
| 1947 |
|
| 1948 |
cfgmaker --subdirs=HOSTNAME__SNMPNAME [email protected] |
| 1949 |
|
| 1950 |
would result in the generation of lines looking something like: |
| 1951 |
|
| 1952 |
Directory[10.10.0.18_1]: 10.10.0.18__fp2200-bothrip-1.3 |
| 1953 |
|
| 1954 |
=item B<--output> I<file> |
| 1955 |
|
| 1956 |
Write the output from B<cfgmaker> into the file I<file>. The default |
| 1957 |
is to use C<STDOUT>. B<--output> is expected to appear only once on the |
| 1958 |
command line. If used multiple times, the file specified by the last |
| 1959 |
B<--output> will be used. |
| 1960 |
|
| 1961 |
=item B<--nointerfaces> |
| 1962 |
|
| 1963 |
Don't generate configuration lines for interfaces. |
| 1964 |
|
| 1965 |
This makes cfgmaker skip all steps related to interfaces which means |
| 1966 |
it will not do any polling of the router to retrieve interface |
| 1967 |
information which speeds up the execution of cfgmaker and it will |
| 1968 |
neither run any interface templates. |
| 1969 |
|
| 1970 |
=item B<--interfaces> |
| 1971 |
|
| 1972 |
This makes cfgmaker generate configuration lines for interfaces (the |
| 1973 |
default behaviour). |
| 1974 |
|
| 1975 |
The main usage of this option is to negate an --nointerfaces appearing |
| 1976 |
earlier on the command line. |
| 1977 |
|
| 1978 |
|
| 1979 |
=back |
| 1980 |
|
| 1981 |
=head2 SNMP V3 Options |
| 1982 |
|
| 1983 |
B<Cfgmaker> supports SNMP V3 using the B<Net:SNMP> perl module. There are optional |
| 1984 |
parameters affecting SNMP operation. |
| 1985 |
|
| 1986 |
=over |
| 1987 |
|
| 1988 |
=item --enablesnmpv3 {yes|no} |
| 1989 |
|
| 1990 |
The B<--enablesnmpv3> option is an optional flag to check for the presence of |
| 1991 |
the B<Net::SNMP> libraries. B<Cfgmaker> will try to determine whether this flag is |
| 1992 |
required and will set the values automatically. |
| 1993 |
|
| 1994 |
=back |
| 1995 |
|
| 1996 |
=head3 SNMPv3 Arguments |
| 1997 |
|
| 1998 |
A SNMP context is a collection of management information accessible by a SNMP |
| 1999 |
entity. An item of management information may exist in more than one context |
| 2000 |
and a SNMP entity potentially has access to many contexts. The combination of |
| 2001 |
a contextEngineID and a contextName unambiguously identifies a context within |
| 2002 |
an administrative domain. In a SNMPv3 message, the contextEngineID and |
| 2003 |
contextName are included as part of the scopedPDU. All methods that generate |
| 2004 |
a SNMP message optionally take a B<--contextengineid> and B<--contextname> |
| 2005 |
argument to configure these fields. |
| 2006 |
|
| 2007 |
=over |
| 2008 |
|
| 2009 |
=item Context Engine ID |
| 2010 |
|
| 2011 |
The B<--contextengineid> argument expects a hexadecimal string representing |
| 2012 |
the desired contextEngineID. The string must be 10 to 64 characters (5 to |
| 2013 |
32 octets) long and can be prefixed with an optional "0x". Once the |
| 2014 |
B<--contextengineid> is specified it stays with the object until it is changed |
| 2015 |
again or reset to default by passing in the undefined value. By default, the |
| 2016 |
contextEngineID is set to match the authoritativeEngineID of the authoritative |
| 2017 |
SNMP engine. |
| 2018 |
|
| 2019 |
=item Context Name |
| 2020 |
|
| 2021 |
The contextName is passed as a string which must be 0 to 32 octets in length |
| 2022 |
using the B<--contextname> argument. The contextName stays with the object |
| 2023 |
until it is changed. The contextName defaults to an empty string which |
| 2024 |
represents the "default" context. |
| 2025 |
|
| 2026 |
=back |
| 2027 |
|
| 2028 |
=head3 User-based Security Model Arguments |
| 2029 |
|
| 2030 |
The User-based Security Model (USM) used by SNMPv3 requires that a securityName |
| 2031 |
be specified using the B<--username> argument. The creation of a Net::SNMP |
| 2032 |
object with the version set to SNMPv3 will fail if the B<--username> argument |
| 2033 |
is not present. The B<--username> argument expects a string 1 to 32 octets |
| 2034 |
in length. |
| 2035 |
|
| 2036 |
Different levels of security are allowed by the User-based Security Model which |
| 2037 |
address authentication and privacy concerns. A SNMPv3 target will |
| 2038 |
derive the security level (securityLevel) based on which of the following |
| 2039 |
arguments are specified. |
| 2040 |
|
| 2041 |
By default a securityLevel of 'noAuthNoPriv' is assumed. If the B<--authkey> |
| 2042 |
or B<--authpassword> arguments are specified, the securityLevel becomes |
| 2043 |
'authNoPriv'. The B<--authpassword> argument expects a string which is at |
| 2044 |
least 1 octet in length. Optionally, the B<--authkey> argument can be used so |
| 2045 |
that a plain text password does not have to be specified in a script. The |
| 2046 |
B<--authkey> argument expects a hexadecimal string produced by localizing the |
| 2047 |
password with the authoritativeEngineID for the specific destination device. |
| 2048 |
The C<snmpkey> utility included with the Net::SNMP distribution can be used to create |
| 2049 |
the hexadecimal string (see L<snmpkey>). |
| 2050 |
|
| 2051 |
Two different hash algorithms are defined by SNMPv3 which can be used by the |
| 2052 |
Security Model for authentication. These algorithms are HMAC-MD5-96 "MD5" |
| 2053 |
(RFC 1321) and HMAC-SHA-96 "SHA-1" (NIST FIPS PUB 180-1). The default |
| 2054 |
algorithm used by the module is HMAC-MD5-96. This behavior can be changed by |
| 2055 |
using the B<--authprotocol> argument. This argument expects either the string |
| 2056 |
'md5' or 'sha' to be passed to modify the hash algorithm. |
| 2057 |
|
| 2058 |
By specifying the arguments B<--privkey> or B<--privpassword> the securityLevel |
| 2059 |
associated with the object becomes 'authPriv'. According to SNMPv3, privacy |
| 2060 |
requires the use of authentication. Therefore, if either of these two |
| 2061 |
arguments are present and the B<--authkey> or B<--authpassword> arguments are |
| 2062 |
missing, the creation of the object fails. The B<--privkey> and |
| 2063 |
B<--privpassword> arguments expect the same input as the B<--authkey> and |
| 2064 |
B<--authpassword> arguments respectively. |
| 2065 |
|
| 2066 |
The User-based Security Model described in RFC 3414 defines a single encryption |
| 2067 |
protocol to be used for privacy. This protocol, CBC-DES "DES" (NIST FIPS PUB |
| 2068 |
46-1), is used by default or if the string 'des' is passed to the |
| 2069 |
B<--privprotocol> argument. By working with the Extended Security Options |
| 2070 |
Consortium http://www.snmp.com/eso/, the module also supports additional |
| 2071 |
protocols which have been defined in draft specifications. The draft |
| 2072 |
http://www.snmp.com/eso/draft-reeder-snmpv3-usm-3desede-00.txt |
| 2073 |
defines the support of CBC-3DES-EDE "Triple-DES" (NIST FIPS 46-3) in the |
| 2074 |
User-based Security Model. This protocol can be selected using the |
| 2075 |
B<--privprotocol> argument with the string '3desede'. The draft |
| 2076 |
http://www.snmp.com/eso/draft-blumenthal-aes-usm-04.txt |
| 2077 |
describes the use of CFB128-AES-128/192/256 "AES" (NIST FIPS PUB 197) in the |
| 2078 |
USM. The three AES encryption protocols, differentiated by their key sizes, |
| 2079 |
can be selected by passing 'aescfb128', 'aescfb192', or 'aescfb256' to the |
| 2080 |
B<-privprotocol> argument. |
| 2081 |
|
| 2082 |
=head2 Details on Filters |
| 2083 |
|
| 2084 |
The purpose of the filters is to decide which interfaces to accept and |
| 2085 |
which interfaces to reject. This decision is done for each interface by |
| 2086 |
evaluating the filter expression as a piece of Perl code and investigating |
| 2087 |
the result of the evaluation. If true, accept the interface otherwise |
| 2088 |
reject it. |
| 2089 |
|
| 2090 |
When working with filters, remember that Perl has it's own idea of what truth |
| 2091 |
and false is. The empty string "" and the string "0" are false, all other |
| 2092 |
strings are true. This further implies that any integer value of 0 is |
| 2093 |
false as well as any undef value. It also implies that all references |
| 2094 |
are considered true. |
| 2095 |
|
| 2096 |
As the filter is evaluated as a Perl expression, several useful constructs |
| 2097 |
in Perl are worth mentioning: |
| 2098 |
|
| 2099 |
Expressions might be grouped by using parentheses "()". Expressions might |
| 2100 |
be combined using boolean operators such as the following: |
| 2101 |
|
| 2102 |
=over |
| 2103 |
|
| 2104 |
=item "B<and>" (equivalent with "B<&&>") |
| 2105 |
|
| 2106 |
Boolean "and" of the two expressions, is only true if both expressions are |
| 2107 |
true. Example: I<expression1> B<and> I<expression2> |
| 2108 |
|
| 2109 |
=item "B<or>" (equivalent with "B<||>") |
| 2110 |
|
| 2111 |
Boolean "or" of the two expressions, is true if either or both expressions |
| 2112 |
are true. Example: I<expression1> B<or> I<expression2> |
| 2113 |
|
| 2114 |
=item "B<not>" (equivalent with "B<!>") |
| 2115 |
|
| 2116 |
Boolean negation of a single expression. Example: B<not> I<expression> . |
| 2117 |
Yet another example: B<!>I<expression> |
| 2118 |
|
| 2119 |
=back |
| 2120 |
|
| 2121 |
(For more details on this I recommend a book on Perl) |
| 2122 |
|
| 2123 |
=head3 Predefined Filter Variables |
| 2124 |
|
| 2125 |
To facilitate, there are a number of predefined values available to use |
| 2126 |
in the filter. Note that these variables are also available when templates |
| 2127 |
interfaces are evaluated (but not host templates). |
| 2128 |
|
| 2129 |
Caveat: All these variables' names begin with a dollar sign ($), which |
| 2130 |
is a syntactic requirement for scalar variables in Perl. The danger here |
| 2131 |
is that the dollar sign in many shells is an active character (often |
| 2132 |
used for shell variables exactly as in Perl variables) so it is important |
| 2133 |
to ensure that the Perl expression isn't evaluated by the command line |
| 2134 |
shell as shell code before being passed to cfgmaker as command line |
| 2135 |
arguments. In shells like Bourne shell, ksh shell or bash shell, placing |
| 2136 |
the entire expression within single quotes will avoid such accidental |
| 2137 |
evaluation: |
| 2138 |
|
| 2139 |
'--if-filter=($default_iftype && $if_admin)' |
| 2140 |
|
| 2141 |
=over |
| 2142 |
|
| 2143 |
=item B<$if_type> |
| 2144 |
|
| 2145 |
This is an integer specifying the interface type as |
| 2146 |
per the SNMP standards and as reported by the polled device. A complete list |
| 2147 |
of interface types would be impractical for this document , but there are |
| 2148 |
a number predefined variables below. Normally, cfgmaker puts in the target's |
| 2149 |
PageTop this iftype value within parenthesis after the name of the interface |
| 2150 |
type. (e.g "propPointToPointSerial (22)"). |
| 2151 |
|
| 2152 |
Here's a list of some of the most common interface types by number: |
| 2153 |
|
| 2154 |
6 ethernetCsmacd |
| 2155 |
7 iso88023Csmacd |
| 2156 |
9 iso88025TokenRing |
| 2157 |
15 fddi |
| 2158 |
19 E1 |
| 2159 |
20 basicISDN |
| 2160 |
21 primaryISDN |
| 2161 |
22 propPointToPointSerial |
| 2162 |
23 ppp |
| 2163 |
24 softwareLoopback |
| 2164 |
30 ds3 |
| 2165 |
32 frame-relay |
| 2166 |
33 rs232 |
| 2167 |
37 atm |
| 2168 |
39 sonet |
| 2169 |
44 frameRelayService |
| 2170 |
46 hssi |
| 2171 |
49 aal5 |
| 2172 |
53 propVirtual |
| 2173 |
62 Fast Ethernet (100BaseT) |
| 2174 |
63 ISDN & X.25 |
| 2175 |
69 Full Duplex Fast Ethernet (100BaseFX) |
| 2176 |
94 Asymmetric Digital Subscriber Loop (ADSL) |
| 2177 |
117 Gigabit Ethernet |
| 2178 |
134 ATM Sub Interface |
| 2179 |
|
| 2180 |
=item B<$default> |
| 2181 |
|
| 2182 |
True if and only if cfgmaker normally should |
| 2183 |
accepted the interface based on the interfaces administrative and |
| 2184 |
operational state (taking the flags B<--no-down> and B<--show-op-down> into |
| 2185 |
account) and it's type (and a few other things). |
| 2186 |
|
| 2187 |
=item B<$default_ifstate> |
| 2188 |
|
| 2189 |
True if and only if cfgmaker would have accepted the |
| 2190 |
interface based on it's operational and administrative states (also taking |
| 2191 |
into account the presence of the flags B<--no-down> and B<--show-op-down>). |
| 2192 |
|
| 2193 |
=item B<$default_iftype> |
| 2194 |
|
| 2195 |
True if and only if cfgmaker would have accepted the |
| 2196 |
interface based on it's type (and a few type specific details in addition). |
| 2197 |
|
| 2198 |
=item B<$if_admin> |
| 2199 |
|
| 2200 |
True if and only if the interface is in an administrative up |
| 2201 |
state. |
| 2202 |
|
| 2203 |
=item B<$if_oper> |
| 2204 |
|
| 2205 |
True if and only if the interface is in an operational up |
| 2206 |
state. |
| 2207 |
|
| 2208 |
=back |
| 2209 |
|
| 2210 |
A number of variables are also predefined to easily decide if an interface |
| 2211 |
belong to a certain category or not. Below is all those variables listed |
| 2212 |
together with which if_type numbers each variable will be true for. Note |
| 2213 |
that some variables refer to other variables as well. |
| 2214 |
|
| 2215 |
=over |
| 2216 |
|
| 2217 |
=item B<$if_is_ethernet> |
| 2218 |
|
| 2219 |
True for ethernet interfaces (nr 6, 7, 26, 62, 69 and 117). |
| 2220 |
|
| 2221 |
=item B<$if_is_isdn> |
| 2222 |
|
| 2223 |
True for various ISDN interface types (nr 20, 21, 63, 75, 76 and 77) |
| 2224 |
|
| 2225 |
=item B<$if_is_dialup> |
| 2226 |
|
| 2227 |
True for dial-up interfaces such as PPP as well |
| 2228 |
as ISDN. (nr 23, 81, 82 and 108 in addition to the numbers of |
| 2229 |
B<$if_is_isdn>). |
| 2230 |
|
| 2231 |
=item B<$if_is_atm> |
| 2232 |
|
| 2233 |
True for miscellaneous ATM related interface types (nr 37, 49, 107, 105, |
| 2234 |
106, 114 and 134). |
| 2235 |
|
| 2236 |
=item B<$if_is_wan> |
| 2237 |
|
| 2238 |
True for WAN interfaces point to point, Frame Relay and High Speed Serial ( 22,32,44,46) |
| 2239 |
|
| 2240 |
=item B<$if_is_lan> |
| 2241 |
|
| 2242 |
True for LAN interfaces (8, 9, 11, 15, 26, 55, 59, 60 and 115 in addition |
| 2243 |
to the numbers of B<$if_is_ethernet>). |
| 2244 |
|
| 2245 |
=item B<$if_is_dsl> |
| 2246 |
|
| 2247 |
True for ADSL, RDSL, HDSL and SDSL (nr 94, 95, 96, 97) |
| 2248 |
|
| 2249 |
=item B<$if_is_loopback> |
| 2250 |
|
| 2251 |
True for software loopback interfaces (nr 24) |
| 2252 |
|
| 2253 |
=item B<$if_is_ciscovlan> |
| 2254 |
|
| 2255 |
True for Cisco VLAN interfaces (interfaces with the |
| 2256 |
word Vlan or VLAN in their ifdescs) |
| 2257 |
|
| 2258 |
=item B<$if_vlan_id> |
| 2259 |
|
| 2260 |
Returns the vlan id associated with a specific port |
| 2261 |
on Cisco Catalyst switches under both Catalyst OS |
| 2262 |
and IOS, and 3Com switches. If it is not a vlan interface, will return undef. |
| 2263 |
|
| 2264 |
=item B<$if_cisco_trunk> |
| 2265 |
|
| 2266 |
Returns the trunking state of a specific port |
| 2267 |
on Cisco Catalyst switches under both Catalyst OS |
| 2268 |
and IOS. Returns "1" if the interface is a trunk, undef otherwise. |
| 2269 |
|
| 2270 |
=item B<$if_MTU> |
| 2271 |
|
| 2272 |
Returns the Maximum Transfer Unit associated with a specific port. |
| 2273 |
|
| 2274 |
=back |
| 2275 |
|
| 2276 |
Besides that, you can also use the variables defined for templates below. |
| 2277 |
Further, all the variables available in cfgmaker is at the scripts disposal |
| 2278 |
even if the use of such features is discouraged. More "shortcuts" in the |
| 2279 |
form of variables and functions will be made available in the future instead. |
| 2280 |
|
| 2281 |
=head3 Examples on Filters |
| 2282 |
|
| 2283 |
The following filter will not affect which interfaces gets included or |
| 2284 |
excluded, it will make cfgmaker behave as normally. |
| 2285 |
|
| 2286 |
'--if-filter=$default' |
| 2287 |
|
| 2288 |
The following filter will make cfgmaker exclude PPP (23) interfaces: |
| 2289 |
|
| 2290 |
'--if-filter=$default && $if_type!=23' |
| 2291 |
|
| 2292 |
The following filter will make cfgmaker behave as usual except that it will |
| 2293 |
consider the operational state of an interface irrelevant but still reject |
| 2294 |
all interfaces which are administratively down. |
| 2295 |
|
| 2296 |
'--if-filter=$if_admin && $default_iftype' |
| 2297 |
|
| 2298 |
=head2 Details on Templates |
| 2299 |
|
| 2300 |
The contents of the template files are evaluated as a Perl program. A |
| 2301 |
number or Perl variables are available for the program to read and others |
| 2302 |
are used to be written to. |
| 2303 |
|
| 2304 |
As quite a few of the predefined variables has values which are are supposed |
| 2305 |
to be used in HTML code some of them have an "HTML-escaped" variant, e.g |
| 2306 |
$html_syslocation is the HTML escaped variant of $syslocation. The HTML |
| 2307 |
escaping means that the chars "<", ">" and "&" are replaced by "<", |
| 2308 |
">" and "&" and that newlines embedded in the string are prepended |
| 2309 |
with "<BR>" and appended with a space character (if a newline is last in the |
| 2310 |
string it is not touched). |
| 2311 |
|
| 2312 |
=head3 Writable Template Variables |
| 2313 |
|
| 2314 |
These are the variables available to store the configuration lines in. |
| 2315 |
Some of them are initialized prior to the evaluation of the template but |
| 2316 |
such content normally is comments for inclusion in the final configuration |
| 2317 |
file so those variables might be reset to the empty string in the template |
| 2318 |
code to eliminate the comments. The other way around is also possible, the |
| 2319 |
contents of these variables might be extended with further information |
| 2320 |
for various reasons such as debugging etc. |
| 2321 |
|
| 2322 |
Once the template has been evaluated, the following happens: if the |
| 2323 |
template is a interface template and the actual interface for some reason |
| 2324 |
is rejected and thus needs to be commented out, all the lines in the |
| 2325 |
variable B<$target_lines> are turned into comments by adding a hash mark |
| 2326 |
("#") at their beginning. Then all the variables B<$head_lines>, |
| 2327 |
B<$problem_lines> , B<$target_lines> and B<$separator_lines> |
| 2328 |
are concatenated together to form the lines to add to the configuration file. |
| 2329 |
|
| 2330 |
=over |
| 2331 |
|
| 2332 |
=item B<$target_lines> |
| 2333 |
|
| 2334 |
This variable is the placeholder for the configuration lines created |
| 2335 |
by the template. B<$target_lines> is predefined to be empty when |
| 2336 |
the template code is evaluated. |
| 2337 |
|
| 2338 |
=item B<$head_lines> |
| 2339 |
|
| 2340 |
This variable is intended to be the placeholder for the comment line |
| 2341 |
appearing just before the target in the configuration file. It is |
| 2342 |
initialized with that comment line before the evaluation of the template |
| 2343 |
code and if the template doesn't modify B<$head_lines> during evaluation, |
| 2344 |
the comment will look like usual in the config file. |
| 2345 |
|
| 2346 |
=item B<$problem_lines> |
| 2347 |
|
| 2348 |
This variable is intended to be the placholder for the comment lines |
| 2349 |
describing any problems which might have been encountered when trying |
| 2350 |
to add the target into the configuration. For host templates it's |
| 2351 |
normally not used and for those it's predefined as the empty string. |
| 2352 |
For interface templates B<$problem_lines> is predefined with |
| 2353 |
the error description comments which cfgmaker normally would use for |
| 2354 |
rejected interfaces or as the empty string for accepted interfaces. |
| 2355 |
|
| 2356 |
It is possible to test against B<$problem_lines> to find out if |
| 2357 |
an interface will be included or rejected but this is not recommended. |
| 2358 |
Test against B<$if_ok> instead. |
| 2359 |
|
| 2360 |
=item B<$separator_lines> |
| 2361 |
|
| 2362 |
This variable is the placeholder for the string to use as the separator |
| 2363 |
between the code for individual targets. The contents of this variable |
| 2364 |
is put after each target (so the lines will appear after the end of the |
| 2365 |
last target in the config as well). |
| 2366 |
|
| 2367 |
=back |
| 2368 |
|
| 2369 |
=head3 Predefined Template Variables |
| 2370 |
|
| 2371 |
All the variables below are available for interface templates to use. |
| 2372 |
For host templates, only those listed under L<Host and System Variables> |
| 2373 |
are available. |
| 2374 |
|
| 2375 |
For interface templates the variables listed under |
| 2376 |
L<Predefined Filter Variables> are also available. |
| 2377 |
|
| 2378 |
=head3 Host and System Variables |
| 2379 |
|
| 2380 |
=over |
| 2381 |
|
| 2382 |
=item B<$router_name> |
| 2383 |
|
| 2384 |
This is the fully qualified name for the router. It is affected by the |
| 2385 |
following items on the command line: the router name itself and |
| 2386 |
B<--dns-domain>. |
| 2387 |
|
| 2388 |
=item B<$router_connect> |
| 2389 |
|
| 2390 |
This is the reference string for the router being polled. It is on the |
| 2391 |
form community@router possibly followed by some snmp options. It is |
| 2392 |
affected by the following items on the command line: the router name |
| 2393 |
itself, B<--community>, B<--snmp-options> and B<--dns-domain>. |
| 2394 |
(There's no HTML escaped variant available) |
| 2395 |
|
| 2396 |
=item B<$directory_name> |
| 2397 |
|
| 2398 |
This variable should contain the directory name as cfgmaker normally would |
| 2399 |
use as the value for the "Directory[]" directive. The value is determined |
| 2400 |
by the B<--subdirs> command line option. If B<--subdirs> isn't specified |
| 2401 |
B<$directory_name> will be the empty string. (There's no HTML escaped |
| 2402 |
variant available) |
| 2403 |
|
| 2404 |
=item B<$syscontact> |
| 2405 |
|
| 2406 |
This variable is the router's SNMP sysContact value. (HTML escaped |
| 2407 |
variant: B<$html_syscontact>) |
| 2408 |
|
| 2409 |
=item B<$sysname> |
| 2410 |
|
| 2411 |
This variable is the router's SNMP sysName value. (No HTML escaped |
| 2412 |
variant available) |
| 2413 |
|
| 2414 |
=item B<$syslocation> |
| 2415 |
|
| 2416 |
This variable is the router's SNMP sysLocation value. (HTML escaped |
| 2417 |
variant: B<$html_syslocation>) |
| 2418 |
|
| 2419 |
=item B<$sysdescr> |
| 2420 |
|
| 2421 |
This variable is the router's SNMP sysDescr value. It is normally not used |
| 2422 |
by cfgmaker but might be useful in a template. (HTML escaped variant: |
| 2423 |
B<$html_sysdescr>) |
| 2424 |
|
| 2425 |
=back |
| 2426 |
|
| 2427 |
=head3 Interface Target Related Variables |
| 2428 |
|
| 2429 |
=over |
| 2430 |
|
| 2431 |
=item B<$target_name> |
| 2432 |
|
| 2433 |
This is what cfgmaker normally would use as the the name of the target. |
| 2434 |
The target name is what is found within the square brackets, "[]", for target |
| 2435 |
directives. (There's no HTML escaped variant available) |
| 2436 |
|
| 2437 |
=item B<$if_ref> |
| 2438 |
|
| 2439 |
This the reference string for the interface. It is expected to be used |
| 2440 |
in the "Target[xyz]" directive to distinguish what interface to use. The |
| 2441 |
value of this variable is affected by the B<--ifref> command line option. |
| 2442 |
It is normally used together with B<$router_connect>. |
| 2443 |
(There's no HTML escaped variant available) |
| 2444 |
|
| 2445 |
=item B<$if_ok> |
| 2446 |
|
| 2447 |
This variable is true if the interface is going to be included into the |
| 2448 |
configuration file, otherwise false. Don't test against other variables |
| 2449 |
such as B<$problem_lines> to find out if an interface will be rejected |
| 2450 |
or not, use this B<$if_ok> instead. |
| 2451 |
|
| 2452 |
=item B<$default_target_lines> |
| 2453 |
|
| 2454 |
This variable contains all the target lines which cfgmaker by default outputs |
| 2455 |
for this interface. It's useful if you want to have the "standard target" |
| 2456 |
but want to add some extra lines to it by using a template. |
| 2457 |
|
| 2458 |
=back |
| 2459 |
|
| 2460 |
By default cfgmaker uses the following directives for each target it |
| 2461 |
generates: Target[], SetEnv[], MaxBytes[], Title[], PageTop[] and if |
| 2462 |
there is any directory specified also the Directory[] directive. |
| 2463 |
|
| 2464 |
To facilitate the creation of templates which generates target configs |
| 2465 |
which are similar to the default one, each of the above mentioned |
| 2466 |
directive lines have a corresponding variable containing the line as |
| 2467 |
cfgmaker would have output it by default. |
| 2468 |
|
| 2469 |
Note that none of these have a HTML escaped variant, text in them is |
| 2470 |
HTML escaped where needed. Also note that they do not have any newline |
| 2471 |
at the end. |
| 2472 |
|
| 2473 |
=over |
| 2474 |
|
| 2475 |
=item B<$default_target_directive> |
| 2476 |
|
| 2477 |
This variable contains the default string for the Target[] directive line. |
| 2478 |
|
| 2479 |
=item B<$default_setenv_directive> |
| 2480 |
|
| 2481 |
This variable contains the default string for the SetEnv[] directive line. |
| 2482 |
|
| 2483 |
=item B<$default_directory_directive> |
| 2484 |
|
| 2485 |
This variable contains the default string for the Directory[] directive line |
| 2486 |
which means it is an empty string (with no newline) if there's no directory. |
| 2487 |
|
| 2488 |
=item B<$default_maxbytes_directive> |
| 2489 |
|
| 2490 |
This variable contains the default string for the MaxBytes[] directive line. |
| 2491 |
|
| 2492 |
=item B<$default_title_directive> |
| 2493 |
|
| 2494 |
This variable contains the default string for the Title[] directive line. |
| 2495 |
|
| 2496 |
=item B<$default_pagetop_directive> |
| 2497 |
|
| 2498 |
This variable contains the default string for the PageTop[] directive lines. |
| 2499 |
|
| 2500 |
=back |
| 2501 |
|
| 2502 |
=head3 Interface Network Configuration Variables |
| 2503 |
|
| 2504 |
=over |
| 2505 |
|
| 2506 |
=item B<$if_ip> |
| 2507 |
|
| 2508 |
This variable should contain the IP-address of the interface, if any has |
| 2509 |
been assigned to it. (There's no HTML escaped variant available) |
| 2510 |
|
| 2511 |
=item B<$ifindex> |
| 2512 |
|
| 2513 |
This variable is the SNMP ifIndex for the interface which per definition |
| 2514 |
always is an integer. (There's no HTML escaped variant available) |
| 2515 |
|
| 2516 |
=item B<$if_index> |
| 2517 |
|
| 2518 |
Equivalent with B<$ifindex>. |
| 2519 |
|
| 2520 |
=item B<$if_eth> |
| 2521 |
|
| 2522 |
Contains the ethernet address of the interface, if any. (There's no HTML |
| 2523 |
escaped variant available) |
| 2524 |
|
| 2525 |
=item B<$if_speed> |
| 2526 |
|
| 2527 |
This variable is the speed in bytes/second (with prefixes). (There's no |
| 2528 |
HTML escaped variant available) |
| 2529 |
|
| 2530 |
=item B<$if_speed_str> |
| 2531 |
|
| 2532 |
This variable is a cooked speed description which is either in bits or |
| 2533 |
bytes depending on whether or not the bits option is active and also with |
| 2534 |
the proper prefix for the speed (k, M, G etc). (No HTML escaped variant |
| 2535 |
available) |
| 2536 |
|
| 2537 |
=item B<$if_type_desc> |
| 2538 |
|
| 2539 |
This variable is a textual description of the interface type. (HTML |
| 2540 |
escaped variant: B<$html_if_type_desc>) |
| 2541 |
|
| 2542 |
=item B<$if_type_num> |
| 2543 |
|
| 2544 |
This variable the integer value corresponding to the interface type (for a |
| 2545 |
listing for the value for the more common interface types, see the section |
| 2546 |
DETAILS ON FILTERS above). (No HTML escaped variant available) |
| 2547 |
|
| 2548 |
=item B<$if_dns_name> |
| 2549 |
|
| 2550 |
This is the DNS name for the interface. (No HTML escaped variant available) |
| 2551 |
|
| 2552 |
=back |
| 2553 |
|
| 2554 |
=head3 Interface Name, Description and Alias Variables |
| 2555 |
|
| 2556 |
It might seem confusing with both I<Name>, I<Description> and I<Alias> in |
| 2557 |
this context and to some extent it is. I<Name> and I<Description> are |
| 2558 |
usually supported on most equipment but how they are used varies, both |
| 2559 |
between manufacturers as well as between different categories of equipment |
| 2560 |
from the same manufacturer. The I<Alias> is at least supported by Cisco |
| 2561 |
IOS, and that variable contains whatever is used in the IOS statement |
| 2562 |
called "description" for the interface (not to be confused with the SNMP |
| 2563 |
variables for I<Description>). |
| 2564 |
|
| 2565 |
For better control from the command line consider B<$if_title_desc> which contents |
| 2566 |
are controlled by the B<--if-descr> command line option. |
| 2567 |
|
| 2568 |
=over |
| 2569 |
|
| 2570 |
=item B<$if_snmp_descr> |
| 2571 |
|
| 2572 |
This variable should contain the "raw" description of the interface as |
| 2573 |
determined by the SNMP polling of the router. (HTML escaped variant: |
| 2574 |
B<$html_if_snmp_descr>) |
| 2575 |
|
| 2576 |
=item B<$if_snmp_name> |
| 2577 |
|
| 2578 |
The "raw" name for the interface as provided by SNMP polling. (HTML escaped |
| 2579 |
variant: B<$html_if_snmp_name>) |
| 2580 |
|
| 2581 |
=item B<$if_snmp_alias> |
| 2582 |
|
| 2583 |
The "raw" ifAlias for the interface as provided by SNMP polling. (HTML |
| 2584 |
escaped variant: B<$html_if_snmp_alias>) |
| 2585 |
|
| 2586 |
=item B<$if_cisco_descr> |
| 2587 |
|
| 2588 |
The "raw" CiscolocIfDescr for the interface as provided by SNMP polling. |
| 2589 |
(HTML escaped variant: B<$html_if_cisco_descr>) |
| 2590 |
|
| 2591 |
=item B<$if_description> |
| 2592 |
|
| 2593 |
This is the "cooked" description string for the interface, taking into account |
| 2594 |
the SNMP values found for the interface's RDescr, ifAlias and |
| 2595 |
CiscolocIfDescr. (HTML escaped variant: B<$html_if_description>) |
| 2596 |
|
| 2597 |
=item B<$if_title> |
| 2598 |
|
| 2599 |
The full string cfgmaker by default would have used for the Title[] directive |
| 2600 |
in the configuration as well as the content of the topmost H1 tag in the |
| 2601 |
PageTop[]. Is composed by the contents of B<$desc_prefix>, |
| 2602 |
B<$if_title_desc> and B<$sysname>. |
| 2603 |
|
| 2604 |
As B<$if_title> depends on B<$if_title_desc>, it is possible to indirectly |
| 2605 |
control B<$if_title> by using the command line option B<--if-descr>. |
| 2606 |
|
| 2607 |
(HTML escaped variant: B<$html_if_title>) |
| 2608 |
|
| 2609 |
=item B<$if_port_name> |
| 2610 |
|
| 2611 |
If the host is a Cisco Catalyst LAN switch, this variable is the name of |
| 2612 |
that port. (No HTML escaped variant available) |
| 2613 |
|
| 2614 |
=item B<$if_pp_port_name> |
| 2615 |
|
| 2616 |
If the host is a Nortel Passport LAN switch, this variable is the name of |
| 2617 |
that port. (No HTML escaped variant available) |
| 2618 |
|
| 2619 |
=item B<$desc_prefix> |
| 2620 |
|
| 2621 |
This variable is a prefix of the description of what the target is to use in |
| 2622 |
the "Title[]" directive and in the H1 section of the "PageTop[]". Default is |
| 2623 |
"Traffic analysis for ". (HTML escaped variant: B<$html_desc_prefix>) |
| 2624 |
|
| 2625 |
=item B<$if_title_desc> |
| 2626 |
|
| 2627 |
This is the description of the interface normally used by cfgmaker as part |
| 2628 |
of the variable B<$if_title>. The latter is used as the full string in the |
| 2629 |
"Title[]" directive and the H1 section in the PageTop[]. |
| 2630 |
|
| 2631 |
B<$if_title_desc> is controlled by the command line option B<--if-descr> |
| 2632 |
which indirectly controls the contents of B<$if_title> |
| 2633 |
|
| 2634 |
(HTML escaped variant: B<$html_if_title_desc>) |
| 2635 |
|
| 2636 |
=back |
| 2637 |
|
| 2638 |
=head3 Help Functions for Templates |
| 2639 |
|
| 2640 |
The following functions exists to facilitate the writing of host and |
| 2641 |
interface templates. |
| 2642 |
|
| 2643 |
=over |
| 2644 |
|
| 2645 |
=item B<html_escape(I<string>)> |
| 2646 |
|
| 2647 |
B<html_escape()> takes a string as an argument and returns a new string |
| 2648 |
where the following substitutions has been done: the chars "<", ">" and |
| 2649 |
"&" are replaced by "<", ">" and "&" and that newlines embedded |
| 2650 |
in the string are prepended with "<BR>" and appended with a space character |
| 2651 |
(newlines at the end of the string are not touched). |
| 2652 |
|
| 2653 |
=item B<oid_pick($router_connect,$v3opt,"oid1","oid2"...)> |
| 2654 |
|
| 2655 |
This function will try to poll each of the oids specified until |
| 2656 |
it is successful or has run out of oids. It will return the name of the |
| 2657 |
first oid that worked or undef if it is not successful |
| 2658 |
|
| 2659 |
=back |
| 2660 |
|
| 2661 |
=head3 Example Template Files |
| 2662 |
|
| 2663 |
=head4 Template Example 1: Eliminating Rejected Targets From Appearing |
| 2664 |
|
| 2665 |
This template file generates exactly the same configuration code per |
| 2666 |
interface as cfgmaker does by default, with the exception that it eliminates |
| 2667 |
all lines (comments as well as config code) for an interface if the |
| 2668 |
interface happens to be rejected. |
| 2669 |
|
| 2670 |
if(not $problem_lines) |
| 2671 |
{ |
| 2672 |
$target_lines .= <<ECHO; |
| 2673 |
|
| 2674 |
Target[$target_name]: $if_ref:$router_connect |
| 2675 |
SetEnv[$target_name]: MRTG_INT_IP="$if_ip" MRTG_INT_DESCR="$if_snmp_descr" |
| 2676 |
ECHO |
| 2677 |
|
| 2678 |
if ($directory_name) { |
| 2679 |
$target_lines .= "Directory[$target_name]: $directory_name\n"; |
| 2680 |
} |
| 2681 |
|
| 2682 |
$target_lines .= <<ECHO; |
| 2683 |
MaxBytes[$target_name]: $if_speed |
| 2684 |
Title[$target_name]: $html_desc_prefix$html_if_title_desc -- $sysname |
| 2685 |
PageTop[$target_name]: <h1>$html_desc_prefix$html_if_title_desc -- $sysname</h1> |
| 2686 |
<div id="sysdetails"> |
| 2687 |
<table> |
| 2688 |
<tr> |
| 2689 |
<td>System:</td> |
| 2690 |
<td>$sysname in $html_syslocation</td> |
| 2691 |
</tr> |
| 2692 |
<tr> |
| 2693 |
<td>Maintainer:</td> |
| 2694 |
<td>$html_syscontact</td> |
| 2695 |
</tr> |
| 2696 |
<tr> |
| 2697 |
<td>Description:</td> |
| 2698 |
<td>$html_if_description</td> |
| 2699 |
</tr> |
| 2700 |
<tr> |
| 2701 |
<td>ifType:</td> |
| 2702 |
<td>$html_if_type_desc ($if_type_num)</td> |
| 2703 |
</tr> |
| 2704 |
<tr> |
| 2705 |
<td>ifName:</td> |
| 2706 |
<td>$html_if_snmp_name</td> |
| 2707 |
</tr> |
| 2708 |
ECHO |
| 2709 |
|
| 2710 |
$target_lines .= <<ECHO if defined $if_port_name; |
| 2711 |
<tr> |
| 2712 |
<td>Port Name:</td> |
| 2713 |
<td>$if_port_name</td> |
| 2714 |
</tr> |
| 2715 |
ECHO |
| 2716 |
|
| 2717 |
$target_lines .= <<ECHO if defined $if_pp_port_name; |
| 2718 |
<tr> |
| 2719 |
<td>Port Name:</td> |
| 2720 |
<td>$if_pp_port_name</td> |
| 2721 |
</tr> |
| 2722 |
ECHO |
| 2723 |
|
| 2724 |
$target_lines .= <<ECHO; |
| 2725 |
<tr> |
| 2726 |
<td>Max Speed:</td> |
| 2727 |
<td>$if_speed_str</td> |
| 2728 |
</tr> |
| 2729 |
ECHO |
| 2730 |
|
| 2731 |
$target_lines .= <<ECHO if $if_ip; |
| 2732 |
<tr> |
| 2733 |
<td>Ip:</td> |
| 2734 |
<td>$if_ip ($if_dns_name)</td> |
| 2735 |
</tr> |
| 2736 |
ECHO |
| 2737 |
|
| 2738 |
$target_lines .= <<ECHO; |
| 2739 |
</table> |
| 2740 |
</div> |
| 2741 |
ECHO |
| 2742 |
} else { |
| 2743 |
$head_lines=""; |
| 2744 |
$problem_lines=""; |
| 2745 |
$target_lines=""; |
| 2746 |
$separator_lines=""; |
| 2747 |
} |
| 2748 |
|
| 2749 |
=head3 Template Example 2: Simpler Version of Example 1 |
| 2750 |
|
| 2751 |
Example 1 was partly intended to demonstrate how to customize the generation |
| 2752 |
of interface targets but also to provide a hint of how the variables are |
| 2753 |
used in the "default" template which one could consider that cfgmaker |
| 2754 |
normally uses. |
| 2755 |
|
| 2756 |
If you're only interested in the easiest way of entirely eliminating those |
| 2757 |
reject interfaces, the template below would do the job as well by using |
| 2758 |
B<$default_target_lines>. |
| 2759 |
|
| 2760 |
if($if_ok) { |
| 2761 |
$target_lines = $default_target_lines; |
| 2762 |
} else { |
| 2763 |
$head_lines=""; |
| 2764 |
$problem_lines=""; |
| 2765 |
$target_lines=""; |
| 2766 |
$separator_lines=""; |
| 2767 |
} |
| 2768 |
|
| 2769 |
=head3 Template Example 3: Creating CPU Targets for Hosts |
| 2770 |
|
| 2771 |
Below is an example of a host template. |
| 2772 |
|
| 2773 |
$head_lines .= <<ECHO; |
| 2774 |
#--------------------------------------------------------------------- |
| 2775 |
ECHO |
| 2776 |
|
| 2777 |
my $target_name = $router_name . ".cpu"; |
| 2778 |
|
| 2779 |
$target_lines .= <<ECHO; |
| 2780 |
|
| 2781 |
YLegend[$target_name]: Percentage CPU load |
| 2782 |
ShortLegend[$target_name]: % |
| 2783 |
Legend1[$target_name]: CPU load in % |
| 2784 |
Legend2[$target_name]: |
| 2785 |
Legend3[$target_name]: Max Observed CPU load |
| 2786 |
Legend4[$target_name]: |
| 2787 |
LegendI[$target_name]: CPU Load: |
| 2788 |
LegendO[$target_name]: |
| 2789 |
WithPeak[$target_name]: ywm |
| 2790 |
MaxBytes[$target_name]: 100 |
| 2791 |
Options[$target_name]: growright, gauge, nopercent |
| 2792 |
Title[$target_name]: $router_name CPU load |
| 2793 |
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 |
| 2794 |
PageTop[$target_name]: <h1>$router_name CPU load</h1> |
| 2795 |
<div> |
| 2796 |
<table> |
| 2797 |
<tr> |
| 2798 |
<td>System:</td> |
| 2799 |
<td>$router_name in $html_syslocation</td> |
| 2800 |
</tr> |
| 2801 |
<tr> |
| 2802 |
<td>Maintainer:</td> |
| 2803 |
<td>$html_syscontact</td> |
| 2804 |
</tr> |
| 2805 |
<tr> |
| 2806 |
<td>Description:</td> |
| 2807 |
<td>$html_sysdescr</td> |
| 2808 |
</tr> |
| 2809 |
<tr> |
| 2810 |
<td>Resource:</td> |
| 2811 |
<td>CPU.</td> |
| 2812 |
</tr> |
| 2813 |
</table> |
| 2814 |
</div> |
| 2815 |
ECHO |
| 2816 |
|
| 2817 |
|
| 2818 |
=head1 EXAMPLES |
| 2819 |
|
| 2820 |
The first example creates a config file for I<router.place.xyz>: the router |
| 2821 |
has the community name I<public>. Interfaces get identified by their |
| 2822 |
IP number. Two global options get added to the config file. The |
| 2823 |
config file gets redirected to I<mrtg.conf>. The '\' signs at the end |
| 2824 |
of the line mean that this command should be written on a single line. |
| 2825 |
|
| 2826 |
cfgmaker --global "WorkDir: /home/tobi" \ |
| 2827 |
--global "Options[_]: growright,bits" \ |
| 2828 |
--ifref=ip \ |
| 2829 |
[email protected] > mrtg.cfg |
| 2830 |
|
| 2831 |
Note: if cfgmaker is not in your path, but you are in the directory where |
| 2832 |
cfgmaker is stored, you can start it with ./cfgmaker |
| 2833 |
|
| 2834 |
The next example creates a config file for four devices: |
| 2835 |
I<router1.place.xyz>, I<router2.place.xyz>, I<switch1.place.xyz> and |
| 2836 |
I<switch2.place.xyz> all with the community I<public>. |
| 2837 |
|
| 2838 |
The two routers will have B<--ifref> set to B<descr> whilst the two |
| 2839 |
switches will use B<--ifref> set to B<name>. Further the routers will |
| 2840 |
use B<--ifdesc> set to B<alias> and I<switch1.place.xyz> will use |
| 2841 |
B<--ifdesc> set to B<descr> whilst I<switch2.place.xyz> use B<name> instead. |
| 2842 |
|
| 2843 |
Finally, there will be two Options lines inserted in the configuration: |
| 2844 |
One will be in the beginning, whilst the other will be inserted after |
| 2845 |
the lines related to the two routers but before those lines related |
| 2846 |
to the switches. |
| 2847 |
|
| 2848 |
cfgmaker --global "WorkDir: /home/tobi" \ |
| 2849 |
--global "Options[_]: growright,bits" \ |
| 2850 |
--ifref=descr \ |
| 2851 |
--ifdesc=alias \ |
| 2852 |
[email protected] \ |
| 2853 |
[email protected] \ |
| 2854 |
--global "Options[_]: growright" \ |
| 2855 |
--ifref=name \ |
| 2856 |
--ifdesc=descr \ |
| 2857 |
[email protected] \ |
| 2858 |
--ifdesc=name \ |
| 2859 |
[email protected] > mrtg.cfg |
| 2860 |
|
| 2861 |
|
| 2862 |
The next example demonstrates how to use the B<--community>, |
| 2863 |
B<--snmp-options> and B<--dns-domain> to make the command line |
| 2864 |
simpler. All the equipment will use the community I<hidden>, except for |
| 2865 |
the ppp-server which use community I<access>. All equipment uses these |
| 2866 |
SNMP options: B<1s timeout>, B<1 retry> and B<SNMP version 2> (B<backoff> and |
| 2867 |
B<port> is unspecified which means they use the default values). |
| 2868 |
The exception again is the ppp-server which uses B<SNMP version 1>. |
| 2869 |
Finally, all the equipment is part of the domain I<place.xyz>, except |
| 2870 |
for the ppp-server which is part of the domain I<remote.place.xyz>. |
| 2871 |
Note that the latter is achieved simply by specifying the name |
| 2872 |
of the ppp-server to be I<ppp-server.B<remote>> . |
| 2873 |
|
| 2874 |
cfgmaker --global "WorkDir: /home/tobi" \ |
| 2875 |
--global "Options[_]: growright,bits" \ |
| 2876 |
--dns-domain=place.xyz \ |
| 2877 |
--community=hidden \ |
| 2878 |
--snmp-options=::1:1::2 \ |
| 2879 |
router1 \ |
| 2880 |
router2 \ |
| 2881 |
router3 \ |
| 2882 |
router4 \ |
| 2883 |
router5 \ |
| 2884 |
switch1 \ |
| 2885 |
switch2 \ |
| 2886 |
switch3 \ |
| 2887 |
switch4 \ |
| 2888 |
switch5 \ |
| 2889 |
switch6 \ |
| 2890 |
switch7 \ |
| 2891 |
[email protected]:::::1 > mrtg.cfg |
| 2892 |
|
| 2893 |
|
| 2894 |
=head1 SEE ALSO |
| 2895 |
|
| 2896 |
L<mrtg-reference> |
| 2897 |
|
| 2898 |
=head1 AUTHOR |
| 2899 |
|
| 2900 |
Tobias Oetiker E<lt>[email protected]<gt> and |
| 2901 |
Jakob Ilves E<lt>[email protected]<gt> |
| 2902 |
|
| 2903 |
|
| 2904 |
=head1 LICENSE |
| 2905 |
|
| 2906 |
GNU General Public License |
| 2907 |
|
| 2908 |
=head1 COPYRIGHT |
| 2909 |
|
| 2910 |
Cfgmaker is Copyright 2000 by Tobias Oetiker E<lt>[email protected]<gt> |
| 2911 |
|
| 2912 |
=cut |