Blame bin/cfgmaker

Packit 667938
#! /usr/bin/perl -w
Packit 667938
# -*- mode: Perl -*-
Packit 667938
##################################################################
Packit 667938
# MRTG 2.17.7  -- Config file creator
Packit 667938
##################################################################
Packit 667938
# Created by Tobias Oetiker <tobi@oetiker.ch>
Packit 667938
# this produces an mrtg config file for one router or more routers
Packit 667938
# by pulling info off the router via snmp
Packit 667938
##################################################################
Packit 667938
# Distributed under the GNU copyleft
Packit 667938
# Copyright 2000 by Tobias Oetiker
Packit 667938
##################################################################
Packit 667938
Packit 667938
# DEBUG TARGETS
Packit 667938
# base - basic program flow
Packit 667938
# snpo - SNMP Polling
Packit 667938
# snpd - SNMP Detail
Packit 667938
#@main::DEBUG=qw(base);
Packit 667938
@main::DEBUG=qw(base snpo snpd);
Packit 667938
Packit 667938
require 5.005; 
Packit 667938
use strict;
Packit 667938
Packit 667938
BEGIN {
Packit 667938
    # Automatic OS detection ... do NOT touch
Packit 667938
    if ( $^O =~ /^(?:(ms)?(dos|win(32|nt)?))/i ) {
Packit 667938
        $main::OS = 'NT';
Packit 667938
        $main::SL = '\\';
Packit 667938
        $main::PS = ';';
Packit 667938
    } elsif ( $^O =~ /^NetWare$/i ) {
Packit 667938
        $main::OS = 'NW';
Packit 667938
        $main::SL = '/';
Packit 667938
        $main::PS = ';';
Packit 667938
    } elsif ( $^O =~ /^VMS$/i ) {
Packit 667938
        $main::OS = 'VMS';
Packit 667938
        $main::SL = '.';
Packit 667938
        $main::PS = ':';
Packit 667938
    } else {
Packit 667938
        $main::OS = 'UNIX';
Packit 667938
        $main::SL = '/';
Packit 667938
        $main::PS = ':';
Packit 667938
    }
Packit 667938
}
Packit 667938
Packit 667938
use FindBin;
Packit 667938
use lib "${FindBin::Bin}";
Packit Service e83ce7
use lib "${FindBin::Bin}${main::SL}..${main::SL}@@lib@@${main::SL}mrtg2";
Packit 667938
Packit 667938
use MRTG_lib "2.100015";
Packit 667938
use Getopt::Long;
Packit 667938
use Pod::Usage;
Packit 667938
use Socket;
Packit 667938
Packit 667938
Packit 667938
sub main {
Packit 667938
Packit 667938
    # assign defaults
Packit 667938
    my %opt = ( 
Packit 667938
        'enable-ipv6' => 0,
Packit 667938
        'use-16bit' => 0,
Packit 667938
        'community' => 'public',
Packit 667938
        'interfaces' => 1,
Packit 667938
        'enablesnmpv3' => 0,
Packit 667938
#        'snmp-options' => ':::::2'
Packit 667938
    );
Packit 667938
    my %routers;
Packit 667938
    my %confcache;
Packit 667938
    my $ipv4only;
Packit 667938
    my %v3opt;
Packit 667938
    $opt{fullcmd} =
Packit 667938
            "$0 ".(join " ",
Packit 667938
            map {$_ =~ /[ \[\]\*\{\}\;\>\<\&]/ ? qq{"$_"} : $_ } @ARGV);
Packit 667938
    options(\%opt,\%routers);
Packit 667938
Packit 667938
    # Check for IPv6 libraries if IPv6 is enabled.
Packit 667938
    # If the check fails, IPv6 is disabled.
Packit 667938
    $ipv4only = 1;
Packit 667938
    if ($opt{'enable-ipv6'} == 1) {
Packit 667938
        if ((eval {local $SIG{__DIE__};require Socket6;}) && (eval {local $SIG{__DIE__};require IO::Socket::INET6;})) {
Packit 667938
            debug ('base',"IPv6 libraries found, IPv6 enabled.");
Packit 667938
            $ipv4only = 0;
Packit 667938
        } else {
Packit 667938
            warn "WARNING: IPv6 libraries not found, IPv6 disabled.\n";
Packit 667938
            $opt{'enable-ipv6'} = 0;
Packit 667938
        }
Packit 667938
    }
Packit 667938
Packit 667938
    if ($opt{'use-16bit'} == 1) {
Packit 667938
        warn "WARNING: Using 16bit RequestIDs\n";
Packit 667938
        no warnings;
Packit 667938
        $SNMP_Session::default_use_16bit_request_ids=1;
Packit 667938
    }
Packit 667938
    # Check for SNMP V3
Packit 667938
    #
Packit 667938
    	if (exists($opt{username}) or lc($opt{enablesnmpv3}) eq "yes" ) {
Packit 667938
	       if  (eval {local $SIG{__DIE__};require Net_SNMP_util;})   {
Packit 667938
	            import Net_SNMP_util;
Packit 667938
	            debug('base', "SNMP V3 libraries found, SNMP V3 enabled.");
Packit 667938
		    $opt{enablesnmpv3} = "yes";
Packit 667938
	  	    push @{$opt{global}}, "enablesnmpv3: yes";
Packit 667938
	        } else {
Packit 667938
	            warn "WARNING: SNMP V3 libraries not found, SNMP V3 disabled. Falling back to V2c.\n";
Packit 667938
	            require SNMP_util;
Packit 667938
	            import SNMP_util;
Packit 667938
		    $opt{enablesnmpv3} = "revert";
Packit 667938
	        }															
Packit 667938
	}
Packit 667938
	else	{
Packit 667938
	        require SNMP_util;
Packit 667938
	        import SNMP_util;
Packit 667938
		$opt{enablesnmpv3} = "no";
Packit 667938
	}
Packit 667938
Packit 667938
    init();
Packit 667938
Packit 667938
    foreach my $router
Packit 667938
    (sort
Packit 667938
     {($routers{$a}{noofrouter}) <=> ($routers{$b}{noofrouter})}
Packit 667938
     keys %routers)
Packit 667938
    {
Packit 667938
	my @snmpopt = split(/:/,$routers{$router}{'snmp-options'});
Packit 667938
	if ($snmpopt[5] and $snmpopt[5] == 3) {
Packit 667938
		if ($opt{enablesnmpv3} eq "revert") {
Packit 667938
			$snmpopt[5] = 2;
Packit 667938
			warn "reverting to snmpV2c for router $router\n";
Packit 667938
			$routers{$router}{'snmp-options'} = join(":",@snmpopt);
Packit 667938
                        $routers{$router}{snmpopt_current} = $routers{$router}{'snmp-options'};
Packit 667938
		} else {
Packit 667938
			die "SNMP V3 requires a --username parameter as part of the User Security Model for router $routers{$router}{routerkey}" if $opt{enablesnmpv3} eq "no";
Packit 667938
			$routers{$router}{enablesnmpv3} = $opt{enablesnmpv3};
Packit 667938
			%v3opt = parsev3(\%opt);
Packit 667938
		}
Packit 667938
	} else {
Packit 667938
		debug('base',"snmpv3 available, but using v1/v2c for $routers{$router}{routerkey}") if $opt{enablesnmpv3} eq "yes";
Packit 667938
	}
Packit 667938
Packit 667938
			
Packit 667938
        # pod2usage(-verbose=>1,-message=>"ERROR: Could not Parse $router\n")
Packit 667938
        #     unless  $router =~ /.*\@.*/;
Packit 667938
        debug('base',"Get Device Info on $router");
Packit 667938
        $routers{$router}{ipv4only} = $ipv4only;
Packit 667938
        if ( my $devinfo = DeviceInfo($router,\%routers,\%v3opt) ) {
Packit 667938
            $routers{$router}{deviceinfo} = $devinfo;
Packit 667938
        } else {
Packit 667938
            warn "WARNING: Skipping $router as no info could be retrieved\n\n";
Packit 667938
            sleep 5;
Packit 667938
            next;
Packit 667938
        }
Packit 667938
Packit 667938
        if ($opt{interfaces}) {
Packit 667938
            debug('base',"Populating confcache");
Packit 667938
            populateconfcache(\%confcache,$router,$routers{$router}{ipv4only},1,\%v3opt);
Packit 667938
            debug('base',"Get Interface Info");
Packit 667938
            InterfaceInfo(\%confcache,\%routers,$router,\%opt,\%v3opt);
Packit 667938
        }
Packit 667938
    }
Packit 667938
    GenConf(\%opt,\%routers,\%confcache,\%v3opt);
Packit 667938
} # end main
Packit 667938
Packit 667938
main;
Packit 667938
exit 0;
Packit 667938
Packit 667938
sub InterfaceInfo($$$$$) {
Packit 667938
    my $confcache = shift;
Packit 667938
    my $routers = shift;
Packit 667938
    my $router = shift;
Packit 667938
    my $opt = shift;
Packit 667938
    my $v3opt = shift;
Packit 667938
    my @Variables = qw (ifIndex ifType ifAdminStatus ifOperStatus ifMtu);
Packit 667938
Packit 667938
    my $snmphost = v4onlyifnecessary($router, $routers->{$router}{ipv4only});
Packit 667938
Packit 667938
    if ($routers->{$router}{deviceinfo}{Vendor} eq 'cisco' &&
Packit 667938
        $routers->{$router}{deviceinfo}{sysDescr} =~ m/Version\s+(\d+\.\d+)/) {
Packit 667938
        push @Variables,  ($1 > 11.0 or $1 < 10.0 ) ? "ifAlias" : "CiscolocIfDescr";
Packit 667938
        if ($1 > 11.2) {push @Variables, "vmVlan";};
Packit 667938
       if ($1 > 11.3) {push @Variables, "vlanTrunkPortDynamicStatus";};
Packit 667938
    } elsif ( $routers->{$router}{deviceinfo}{Vendor} =~ /(?:hp|juniper|dlink|wwp|foundry|dellLan|force10|3com|extremenetworks|openBSD|arista|enterasys|zyxel|vyatta|dcn|brocade)/i) {
Packit 667938
        push @Variables, "ifAlias";
Packit 667938
    }
Packit 667938
Packit 667938
    my $descr = $routers->{$router}{deviceinfo}{sysDescr};
Packit 667938
    if ($routers->{$router}{deviceinfo}{Vendor} eq 'cisco' &&
Packit 667938
        $descr =~ m/Catalyst\sOperating\sSystem|Cisco\sSystems\sWS-C2900/ ) {
Packit 667938
        push @Variables,  "CiscoCatalystPortName";
Packit 667938
        push @Variables, "vmVlan";
Packit 667938
    }
Packit 667938
    if ($routers->{$router}{deviceinfo}{Vendor} eq 'cisco' &&
Packit 667938
        $descr =~ m/Catalyst/ ) {
Packit 667938
        push @Variables,  "vlanTrunkPortDynamicStatus";
Packit 667938
    }
Packit 667938
    if ($descr =~ m/Passport-8610/ || $descr =~ m/MERS-8610/ ) {
Packit 667938
        push @Variables,  "ppPortName";
Packit 667938
    }
Packit 667938
Packit 667938
    foreach my $var (@Variables) {
Packit 667938
        debug('base',"Walking $var");
Packit 667938
        foreach my $tuple (snmpwalk($snmphost,$v3opt, $var)){
Packit 667938
            my($if,$value) = split /:/, $tuple, 2;
Packit 667938
            $value =~ s/[\0- ]+$//; # no trailing space
Packit 667938
            $routers->{$router}{$if}{$var} = $value;
Packit 667938
	    debug('snpd',"  $router -> $if -> $var = $value");
Packit 667938
        }
Packit 667938
    }
Packit 667938
Packit 667938
    # interface speed var depends on snmp version
Packit 667938
Packit 667938
    my $snmp_version = (split(':', $router, 6))[5] || 1;
Packit 667938
    if ( $snmp_version =~ /[23]/ ) {
Packit 667938
        debug('base',"Walking ifSpeed");
Packit 667938
        my @ifSpeed = snmpwalk($snmphost, $v3opt,'ifSpeed');
Packit 667938
	debug('snpd',"\@ifSpeed = @ifSpeed\n");
Packit 667938
        debug('base',"Walking ifHighSpeed");
Packit 667938
        my @ifHighSpeed = snmpwalk($snmphost,$v3opt, 'ifHighSpeed');
Packit 667938
        for ( my $i=0; $i<=$#ifSpeed; $i++ ) {
Packit 667938
            my ($if,$value) = split /:/, $ifSpeed[$i], 2;
Packit 667938
# the mib entry on ifSpeed says
Packit 667938
#            "An estimate of the interface's current bandwidth in bits
Packit 667938
#            per second.  For interfaces which do not vary in bandwidth
Packit 667938
#            or for those where no accurate estimation can be made, this
Packit 667938
#            object should contain the nominal bandwidth.  If the
Packit 667938
#            bandwidth of the interface is greater than the maximum value
Packit 667938
#            reportable by this object then this object should report its
Packit 667938
#            maximum value (4,294,967,295) and ifHighSpeed must be used
Packit 667938
#            to report the interace's speed.  For a sub-layer which has
Packit 667938
#            no concept of bandwidth, this object should be zero."
Packit Service afd787
            if ( (not defined $value) || ($value == 2**32-1) || ($value == 2**32-2)) {
Packit 667938
                ($if, $value) = split /:/, $ifHighSpeed[$i], 2;
Packit 667938
	        $value = $value * 1000000;  # highSpeed = contador * 10^6
Packit 667938
                debug('base',"Speed: $if - $value");
Packit 667938
            }
Packit 667938
	    if ( ($descr =~ m/MERS-8610/ ) && (defined $ifHighSpeed[$i]) ) {
Packit 667938
		($if, $value) = split /:/, $ifHighSpeed[$i], 2;
Packit 667938
                $value = $value * 1000000;  # highSpeed = contador * 10^6
Packit 667938
                debug('base',"Speed: $if - $value");
Packit 667938
Packit 667938
            }
Packit 667938
            $routers->{$router}{$if}{'ifSpeed'} = $value;
Packit 667938
        }
Packit 667938
    } else {
Packit 667938
        debug('base',"Walking ifSpeed");
Packit 667938
        foreach my $tuple (snmpwalk($snmphost,$v3opt, 'ifSpeed')){
Packit 667938
            my($if,$value) = split /:/, $tuple, 2;
Packit 667938
            $routers->{$router}{$if}{'ifSpeed'} = $value;
Packit 667938
	    debug('snpd',"  $router -> $if -> ifSpeed = $value");
Packit 667938
        }
Packit 667938
    }
Packit 667938
Packit 667938
    # magic speed determination for portmaster IFs
Packit 667938
Packit 667938
    if ($routers->{$router}{deviceinfo}{Vendor} eq 'portmaster') {
Packit 667938
        # We can only approximate speeds
Packit 667938
        #
Packit 667938
        # so we think that ppp can do 76800 bit/s, and slip 38400.
Packit 667938
        # (actualy, slip is a bit faster, but usualy users with newer modems
Packit 667938
        # use ppp). Alternatively, you can set async speed to 115200 or
Packit 667938
        # 230400 (the maximum speed supported by portmaster).
Packit 667938
        #
Packit 667938
        # But if the interface is ptpW (sync), max speed is 128000
Packit 667938
        # change it to your needs. On various Portmasters there are
Packit 667938
        # various numbers of sync interfaces, so modify it.
Packit 667938
        #
Packit 667938
        #  The most commonly used PM-2ER has only one sync.
Packit 667938
        #
Packit 667938
        #  Paul Makeev (mac@redline.ru)
Packit 667938
        #
Packit 667938
        foreach my $if (keys %{$routers->{$router}}) {
Packit 667938
            next unless $if =~ /^\d+$/;
Packit 667938
            my $ift = $routers->{$router}{$if}{ifType};
Packit 667938
            my $ifd = $routers->{$router}{$if}{Descr};
Packit 667938
            if ($ift ==  23) {
Packit 667938
                if ($ifd eq 'ptpW1') {
Packit 667938
                    $routers->{$router}{$if}{ifSpeed} = 128000;
Packit 667938
                } else {
Packit 667938
                    $routers->{$router}{$if}{ifSpeed} = 76800;
Packit 667938
                }
Packit 667938
            } elsif ($ift == 28) {
Packit 667938
                $routers->{$router}{$if}{ifSpeed} = 38400;
Packit 667938
            } elsif ($ift == 6) {
Packit 667938
                $routers->{$router}{$if}{ifSpeed} = 10000000;
Packit 667938
            }
Packit 667938
        }
Packit 667938
    }
Packit 667938
Packit 667938
    # match confcache info into tree
Packit 667938
    my $cachekey = cleanhostkey $router;
Packit 667938
Packit 667938
    foreach my $method (keys %{$$confcache{$cachekey}}) {
Packit 667938
        foreach my $key (keys %{$$confcache{$cachekey}{$method}}) {
Packit 667938
            my $if = readfromcache($confcache,$router,$method,$key);
Packit 667938
            next unless $if =~ /^\d+$/;
Packit 667938
            $routers->{$router}{$if}{$method} = $key;
Packit 667938
            for ($method) {
Packit 667938
                #fix special chars in ifdescr
Packit 667938
                # no need for this we fix if references later on
Packit 667938
                # /^Descr|Name$/ && do {
Packit 667938
                #     $routers->{$router}{$if}{"R$method"} = $routers->{$router}{$if}{$method};
Packit 667938
                #     $routers->{$router}{$if}{$method} =~ s/(:)/\\$1/g;
Packit 667938
                #     next;
Packit 667938
                # };
Packit 667938
Packit 667938
                #find hostname of IF
Packit 667938
                !$$opt{noreversedns} && /^Ip$/ and do {
Packit 667938
                    my $name =
Packit 667938
                    gethostbyaddr(
Packit 667938
                    pack('C4',
Packit 667938
                         split(/\./,
Packit 667938
                         $routers->{$router}{$if}{$method})),
Packit 667938
                         AF_INET);
Packit 667938
                    $routers->{$router}{$if}{DNSName} = ($name or "");
Packit 667938
                    next;
Packit 667938
                };
Packit 667938
            }
Packit 667938
        }
Packit 667938
    }
Packit 667938
} # end InterfaceInfo
Packit 667938
Packit 667938
sub GenConf ($$$$) {
Packit 667938
    my $opt = shift;
Packit 667938
    my $routers = shift;
Packit 667938
    my $confcache = shift;
Packit 667938
    my $v3opt = shift;
Packit 667938
    my $conf = "# Created by \n# $$opt{fullcmd}\n\n";
Packit 667938
Packit 667938
    # print global options
Packit 667938
    $conf .= <
Packit 667938
Packit 667938
### Global Config Options
Packit 667938
Packit 667938
#  for UNIX
Packit 667938
# WorkDir: /home/http/mrtg
Packit 667938
Packit 667938
#  or for NT
Packit 667938
# WorkDir: c:\\mrtgdata
Packit 667938
Packit 667938
### Global Defaults
Packit 667938
Packit 667938
#  to get bits instead of bytes and graphs growing to the right
Packit 667938
# Options[_]: growright, bits
Packit 667938
Packit 667938
ECHO
Packit 667938
Packit 667938
    # Add EnableIPv6 option to configuration file
Packit 667938
    if ($$opt{'enable-ipv6'} == 1) {
Packit 667938
        $conf .= "EnableIPv6: yes\n";
Packit 667938
    } else {
Packit 667938
        $conf .= "EnableIPv6: no\n";
Packit 667938
    }
Packit 667938
Packit 667938
    foreach my $router
Packit 667938
      (sort {($$routers{$a}{noofrouter}) <=> ($$routers{$b}{noofrouter})}
Packit 667938
       keys %$routers ) {
Packit 667938
        my $router_ref = $$routers{$router};
Packit 667938
        my $router_opt = $$router_ref{opt};
Packit 667938
        my $router_dev = $$router_ref{deviceinfo};
Packit 667938
Packit 667938
        # Did any global options appear on the command line
Packit 667938
        # before this router?  If so, include them into the
Packit 667938
        # configuration file.
Packit 667938
        if (defined $$router_opt{global}) {
Packit 667938
            foreach my $key (@{$$router_opt{global}}) {
Packit 667938
                $conf .= "$key\n";
Packit 667938
            }
Packit 667938
        }
Packit 667938
Packit 667938
        # If IPv6 is enabled, add IPv4Only target directive for targets
Packit 667938
        # that do not support SNMP over IPv6.
Packit 667938
        my $ipv4only_directive;
Packit 667938
        my $router_ipv4only = ($$opt{'enable-ipv6'} == 1) && $$router_ref{ipv4only};
Packit 667938
Packit 667938
        my $syscontact = $$router_dev{sysContact};
Packit 667938
        my $html_syscontact = html_escape($syscontact);
Packit 667938
        my $syslocation = $$router_dev{sysLocation};
Packit 667938
        my $html_syslocation = html_escape($syslocation);
Packit 667938
        my $sysname = $$router_dev{sysName};
Packit 667938
        my $sysdescr = $$router_dev{sysDescr};
Packit 667938
        my $comment_sysdescr = $sysdescr;
Packit 667938
        # make sure embeded newlines do not harm us here
Packit 667938
        $comment_sysdescr =~ s/[\n\r]+/\n\#          /g;
Packit 667938
        my $community = $$router_ref{community};
Packit 667938
        $community  =~ s/([@ ])/\\$1/g;
Packit 667938
        my $router_connect = "$community\@$$router_ref{routername}$$router_ref{snmpopt_current}";
Packit 667938
	my @v3options;
Packit 667938
		foreach my $v3op (keys %$v3opt) {
Packit 667938
			push @v3options, $v3op."=>'".$$v3opt{$v3op}."'";
Packit 667938
		}
Packit 667938
	my $v3options = join(",",@v3options) if $$router_ref{'snmp-options'} =~ /(?::[^:]*){4}:3/ ;
Packit 667938
        my $html_sysdescr = html_escape($sysdescr);
Packit 667938
        my $router_name =
Packit 667938
            ($$router_ref{routername}
Packit 667938
             . (($$router_ref{'dns-domain'})?'.':'')
Packit 667938
             . $$router_ref{'dns-domain'});
Packit 667938
Packit 667938
        # James Overbeck 2001/09/20
Packit 667938
        # Moved $directory_name definition from within the interface
Packit 667938
        # foreach loop to here. In its previous location, $directory_name
Packit 667938
        # was not accessible to host templates. $directory_name is not
Packit 667938
        # changed per-interface so it might as well be here instead of
Packit 667938
        # where it was.
Packit 667938
Packit 667938
        my $directory_name = "";
Packit 667938
Packit 667938
        if (defined $$router_opt{subdirs}) {
Packit 667938
            $directory_name = $$router_opt{subdirs};
Packit 667938
            $directory_name =~ s/HOSTNAME/$router_name/g;
Packit 667938
            $directory_name =~ s/SNMPNAME/$$router_dev{sysName}/g;
Packit 667938
        }
Packit 667938
Packit 667938
Packit 667938
        my $target_lines = "";
Packit 667938
        my $problem_lines = "";
Packit 667938
        my $head_lines = "
Packit 667938
######################################################################
Packit 667938
# System: $sysname
Packit 667938
# Description: $comment_sysdescr
Packit 667938
# Contact: $syscontact
Packit 667938
# Location: $syslocation
Packit 667938
######################################################################
Packit 667938
";
Packit 667938
Packit 667938
        my $separator_lines = "\n\n";
Packit 667938
Packit 667938
        # Host specific config lines generation code starts HERE
Packit 667938
Packit 667938
        if(defined $$router_opt{'host-template'}) {
Packit 667938
            # First test if the file exists and is readable, die if not.
Packit 667938
            die "File $$router_opt{'host-template'} didn't exist.\n"
Packit 667938
            unless (-e $$router_opt{'host-template'}
Packit 667938
                and -r $$router_opt{'host-template'});
Packit 667938
            # Open the file (or die).
Packit 667938
            open IF_TEMPLATE, $$router_opt{'host-template'}
Packit 667938
                or die "File $$router_opt{'host-template'} couldn't be opened.\n";
Packit 667938
Packit 667938
            my @template_lines = readline *IF_TEMPLATE;
Packit 667938
	    close IF_TEMPLATE;
Packit 667938
            $@ = undef;
Packit 667938
            eval ('local $SIG{__DIE__};'.join("", @template_lines));
Packit 667938
Packit 667938
            die  "ERROR Evaluation of the contents in the file \n\n".
Packit 667938
                 "$$router_opt{'host-template'}\ngave the error \n\n\"$@\"\n\nExiting cfgmaker\n" if $@;
Packit 667938
        }
Packit 667938
Packit 667938
        $conf .= ($head_lines
Packit 667938
              . $problem_lines
Packit 667938
              . $target_lines
Packit 667938
              . $separator_lines);
Packit 667938
Packit 667938
        # Host specific config lines generation code ends HERE
Packit 667938
Packit 667938
Packit 667938
        if ($$router_opt{'interfaces'}) {
Packit 667938
            foreach my $ifindex (sort {int($a) <=> int($b)} grep /^\d+$/, keys %$router_ref) {
Packit 667938
                my $i = $$router_ref{$ifindex};
Packit 667938
Packit 667938
                # Now define a number of variables used for this interface.
Packit 667938
                # Some variables are just used internally by cfgmaker to
Packit 667938
                # process the interface, others are provided for usage in
Packit 667938
                # host and interface templates and for interface filters.
Packit 667938
Packit 667938
                my $if_index = $ifindex;
Packit 667938
                my $if_eth = $$i{Eth} || 'No Ethernet Id';
Packit 667938
Packit 667938
                # does it make sense to look at the interface ?
Packit 667938
                my @prob;
Packit 667938
                my $default_ifstate = 1; # State assumed up.
Packit 667938
                my $default_iftype = 1;  # iftype assumed ok.
Packit 667938
                my $if_ok = 1;           #
Packit 667938
Packit 667938
                my $if_admin = (($$i{ifAdminStatus} || 0) == 1);
Packit 667938
                my $if_oper = (($$i{ifOperStatus} || 0) == 1);
Packit 667938
Packit 667938
                my $if_type = $$i{ifType} || -1;
Packit 667938
                my $if_is_ethernet = 0 < scalar(grep {$_ == $if_type;}
Packit 667938
                                    (6,7,26,62,69,117));
Packit 667938
                my $if_is_isdn = (0 < scalar (grep {$_ == $if_type;}
Packit 667938
                                    (20,21,63,75,76,77)));
Packit 667938
                my $if_is_dialup = $if_is_isdn ||
Packit 667938
                                (0 < scalar (grep {$_ == $if_type;}
Packit 667938
                                    (23,81,82,108)));
Packit 667938
                my $if_is_atm = (0 < scalar(grep {$_ == $if_type;}
Packit 667938
                                    (37,49,107,105,106,114,134)));
Packit 667938
Packit 667938
                my $if_is_wan = 0 < scalar(grep {$_ == $if_type;}
Packit 667938
                                    (22,30,32,39,44,46));
Packit 667938
Packit 667938
                my $if_is_lan = $if_is_ethernet ||
Packit 667938
                                (0 < scalar (grep {$_ == $if_type;}
Packit 667938
                                    (8,9,11,15,26,55,59,60,115)));
Packit 667938
                my $if_is_dsl = (0 < scalar(grep {$_ == $if_type;}
Packit 667938
                                    (94,95,96,97)));
Packit 667938
                my $if_is_loopback = $if_type == 24;
Packit 667938
                my $if_is_ciscovlan =
Packit 667938
                    ($$router_dev{Vendor} eq 'cisco'
Packit 667938
                    and $$i{Descr} =~ /^(unrouted )?[- ]?VLAN[- ]?\d*$/i);
Packit 667938
Packit 667938
                my $if_ip = $$i{Ip} || 'No Ip';
Packit 667938
                my $if_snmp_descr = $$i{Descr} || 'No Description';
Packit 667938
                $if_snmp_descr =~ s/\n$//; # no you don't want to know who does this
Packit 667938
                                           # ok ... dell 3524
Packit 667938
                $if_snmp_descr =~ s/ /-/g;
Packit 667938
                my $if_type_num = $$i{ifType} || 'Unknown Type';
Packit 667938
                $$i{ifType} ||= -1;
Packit 667938
                my $if_snmp_name = $$i{Name} || 'No Name';
Packit 667938
                my $if_snmp_alias = $$i{ifAlias} || '';
Packit 667938
                my $if_cisco_descr = $$i{CiscolocIfDescr} || '';
Packit 667938
                my $if_dns_name = $$i{DNSName} || 'No DNS name';
Packit 667938
                my $if_vlan_id = $$i{vmVlan} || 'No Vlan';
Packit 667938
                my $if_cisco_trunk = ($$i{vlanTrunkPortDynamicStatus} || 0 == 1);
Packit 667938
		my $if_MTU = $$i{ifMtu} || 'No MTU';
Packit 667938
Packit 667938
                # For Nokia IPSO, find non-ethernet interfaces with IP addresses
Packit 667938
                # and add missing MAC address and Port Speed information to
Packit 667938
                # to the LOGICAL and LOGICAL+VLAN interfaces.
Packit 667938
                if ( $$router_dev{Vendor} eq 'nokiaipsofw' ) {
Packit 667938
                    if ($$i{ifType} ne "6" and
Packit 667938
                        $$router_dev{sysDescr} =~ / IPSO / &&
Packit 667938
                        $$i{Ip} =~ /^\d+/ and
Packit 667938
                       (not $$i{Eth} or
Packit 667938
                        not $$i{ifSpeed} or
Packit 667938
                        $$i{ifSpeed} < 10 )
Packit 667938
                       ) {
Packit 667938
                        my $logical_if_name = $$i{Name};
Packit 667938
Packit 667938
                        # Split the LOGICAL interface name in attempt
Packit 667938
                        # to match with base PHYSICAL interface detail.
Packit 667938
                        my ($logical_if_HEAD, $logical_if_TAIL) =
Packit 667938
                            $logical_if_name =~ /^(.*)(c\d+)$/;
Packit 667938
Packit 667938
                        foreach my $ifindexTMP (sort {int($a) <=> int($b)}
Packit 667938
                            grep /^\d+$/, keys %$router_ref) {
Packit 667938
                            next unless $ifindexTMP =~ /^\d+$/;
Packit 667938
Packit 667938
                            my $physical_if_name = $$router_ref{$ifindexTMP};
Packit 667938
Packit 667938
                            if ($$physical_if_name{ifType} == 6 &&
Packit 667938
                                $logical_if_HEAD eq $$physical_if_name{Name} ) {
Packit 667938
                                $$i{Eth} ||= $$physical_if_name{Eth};
Packit 667938
                                $$i{ifSpeed} = $$physical_if_name{ifSpeed}
Packit 667938
                                        if ( not $$i{ifSpeed} or $$i{ifSpeed} < 10 );
Packit 667938
                            }
Packit 667938
                        }
Packit 667938
                    }
Packit 667938
                }
Packit 667938
Packit 667938
                # First investigate the state of the interface.
Packit 667938
                if (not defined $$router_opt{'no-down'}) {
Packit 667938
                    if (($$i{ifAdminStatus} || 0 )== 2) {
Packit 667938
                        push @prob, "it is administratively DOWN";
Packit 667938
                        $default_ifstate = 0;
Packit 667938
                    } elsif (($$i{ifAdminStatus} || 0 ) == 3) {
Packit 667938
                        push @prob, "it is in administrative TEST mode";
Packit 667938
                        $default_ifstate = 0;
Packit 667938
                    }
Packit 667938
Packit 667938
                    if (not defined $$router_opt{'show-op-down'}) {
Packit 667938
                       if (($$i{ifOperStatus} || 0 ) == 2) {
Packit 667938
                          push @prob, "it is operationally DOWN";
Packit 667938
                          $default_ifstate = 0;
Packit 667938
                       } elsif (($$i{ifOperStatus} || 0 ) == 3) {
Packit 667938
                           push @prob, "it is in operational TEST mode";
Packit 667938
                          $default_ifstate = 0;
Packit 667938
                      }
Packit 667938
                    }
Packit 667938
                 }
Packit 667938
Packit 667938
Packit 667938
                # Investigate the type of the interface.
Packit 667938
                if ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 18) { # by fwo@obsidian.co.za
Packit 667938
                    push @prob, "it is a DS1 controllers";
Packit 667938
                    $default_iftype = 0;
Packit 667938
                } elsif ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 19) { # by fwo@obsidian.co.za
Packit 667938
                    push @prob, "it is a E1 controllers";
Packit 667938
                    $default_iftype = 0;
Packit 667938
                } elsif ($$i{ifType}  == 24) {
Packit 667938
                    push @prob, "it is a Software Loopback interface" ;
Packit 667938
                    $default_iftype = 0;
Packit 667938
                } elsif ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 30) { # by blube@floridadigital.net
Packit 667938
                    push @prob, "it is a DS3 controller";
Packit 667938
                    $default_iftype = 0;
Packit 667938
                } elsif ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 102) { # by dan.mcdonald@austinenergy.com
Packit 667938
                    push @prob, "it is a Voice controller";
Packit 667938
                    $default_iftype = 0;
Packit 667938
                } elsif ($$router_dev{Vendor} eq 'cisco' && $$i{ifType} == 103) { # by dan.mcdonald@austinenergy.com
Packit 667938
                    push @prob, "it is a Voice dial peer";
Packit 667938
                    $default_iftype = 0;
Packit 667938
                } elsif ($$i{ifType} == 162) {
Packit 667938
                    push @prob, "it is a CEF Sub-interface"; # John Begley <maslow@mediaone.net>
Packit 667938
                } elsif ($$router_dev{Vendor} eq 'cisco'
Packit 667938
                  and $$i{Descr} eq 'Null0') {
Packit 667938
                    push @prob, "it is a cisco Null0 interface";
Packit 667938
                    $default_iftype = 0;
Packit 667938
                }
Packit 667938
                my $default = $default_iftype && $default_ifstate;
Packit 667938
Packit 667938
                # Do some futher investigation if the interface makes
Packit 667938
                # sense to collect on
Packit 667938
Packit 667938
		# I debated whether to insert the zero-speed check before
Packit 667938
		# or after the "will always be zero" sections below.
Packit 667938
		# I settled on before since I'll assume the user knows
Packit 667938
		# what speed the zero-speed interfaces should be better
Packit 667938
		# than the simple logic below.
Packit 667938
		if (not $$i{ifSpeed} and $$router_opt{'zero-speed'}) {
Packit 667938
		    # Set all interfaces with zero speed to the value specified
Packit 667938
		    # by the --zero-speed= command line option.
Packit 667938
Packit 667938
		    # Be sure the value specified is a valid integer.
Packit 667938
		    # It seems like this could be done once when
Packit 667938
		    # $$router_opt is set, but I didn't see any example
Packit 667938
		    # of input validation in that part of cfgmaker,
Packit 667938
		    # so it gets done here, more times than are
Packit 667938
		    # really necessary.  ;-)
Packit 667938
		    unless ($$router_opt{'zero-speed'} =~ /^\d+$/) {
Packit 667938
		         die "ERROR: zero-speed specified with non-integer speed: $$router_opt{'zero-speed'}";
Packit 667938
		    }
Packit 667938
		    $$i{ifSpeed} = $$router_opt{'zero-speed'};
Packit 667938
		}
Packit 667938
Packit 667938
                if (not $$i{ifSpeed} and $$router_dev{Vendor} eq 'foundry' and $$i{ifType} and $$i{ifType} == 194) {
Packit 667938
                    # foundry ATM subinterfaces always report 0 speed, make it 155Mbps instead.
Packit 667938
                    $$i{ifSpeed} =  155000000;
Packit 667938
                } elsif (not $$i{ifSpeed} and $$router_dev{Vendor} eq 'foundry' and $$i{ifType} and $$i{ifType} == 135) {
Packit 667938
                    # Foundry virtual Ethernet interfaces always report 0 speed, make it 1GB instead.
Packit 667938
                    $$i{ifSpeed} = 1000000000;
Packit 667938
                } elsif (not $$i{ifSpeed} and $$router_dev{Vendor} eq 'cisco' and $$i{sysDescr} and $$i{sysDescr} =~ /FWSM-Firewall / )  {
Packit 667938
                    # Cisco PIX Firewall Switch Modules have effective backplane speed of 600 Megs
Packit 667938
		    $$i{ifSpeed} = 600000000;
Packit 667938
                } elsif (not $$i{ifSpeed} and $$router_dev{Vendor} eq '3com' and $$i{Descr} and $$i{Descr} =~ /RMON VLAN (\d+)/ ) {
Packit 667938
                    $$i{ifSpeed} = 100000000;
Packit 667938
                    $if_vlan_id = $1;
Packit 667938
                } elsif (not $$i{ifSpeed}) {
Packit 667938
                    push @prob, "has no ifSpeed property";
Packit 667938
                    $$i{ifSpeed} = 0;
Packit 667938
                    $if_ok = 0;
Packit 667938
                }
Packit 667938
Packit 667938
                my $message;
Packit 667938
		my $nohc =0;
Packit 667938
                if ($message = IsCounterBroken($ifindex, $router_ref,$v3opt)) {
Packit 667938
                    # set snmpopt_current to working snmp options
Packit 667938
		    if ($message eq '1') {
Packit 667938
			    $nohc = 1;
Packit 667938
		    } else {
Packit 667938
                            push @prob, "got '$message' from interface when trying to query";
Packit 667938
                    $if_ok = 0;
Packit 667938
	    	    }
Packit 667938
                }
Packit 667938
Packit 667938
                my $community = $$router_ref{community};
Packit 667938
                $community  =~ s/([@ ])/\\$1/g;
Packit 667938
                my $router_connect = "$community\@$$router_ref{routername}$$router_ref{snmpopt_current}";
Packit 667938
   		
Packit 667938
		my $v3options = join(",",@v3options) if $$router_ref{snmpopt_current} =~ /(?::[^:]*){4}:3/ ;
Packit 667938
		
Packit 667938
                # determine interface reference
Packit 667938
                my $if_ref;
Packit 667938
                if (defined $$router_opt{ifref}) {
Packit 667938
                    foreach  (split /,/,$$router_opt{ifref}) {
Packit 667938
                        /^ip$/   && do { if($$i{Ip}   ){ $if_ref = "/".$$i{Ip};    last;} next};
Packit 667938
                        /^eth$/  && do { if($$i{Eth}  ){ $if_ref = "!".$$i{Eth};   last;} next};
Packit 667938
                        /^descr?$/&& do { if($$i{Descr}){ $if_ref = "\\".$$i{Descr};last;} next};
Packit 667938
                        /^name$/ && do { if($$i{Name} ){ $if_ref = "#".$$i{Name};  last;} next};
Packit 667938
                        /^type$/ && do { if($$i{Type} ){ $if_ref = "%".$$i{Type};  last;} next};
Packit 667938
                        /^nr$/   && do { $if_ref = $ifindex; last };
Packit 667938
                        die "ERROR: Invalid value for --ifref: $$router_opt{ifref} ($_)\n";
Packit 667938
                    }
Packit 667938
                    if (not defined $if_ref) {
Packit 667938
                        push @prob, "--ifref=$$router_opt{ifref} is not unique for this interface";
Packit 667938
                        $if_ref = $ifindex;
Packit 667938
                        $if_ok = 0;
Packit 667938
                    }
Packit 667938
                } else {
Packit 667938
                    $if_ref = $ifindex;
Packit 667938
                }
Packit 667938
Packit 667938
                # generate Target name
Packit 667938
                my $trim_if_ref = $if_ref;
Packit 667938
                $trim_if_ref =~ s/[\#!\/\\:\s\@%]+/_/g;
Packit 667938
                $trim_if_ref =~ s/^_*(.+?)_*$/$1/;
Packit 667938
                my $target_name = "${router_name}_$trim_if_ref";
Packit 667938
                my $if_title_desc = $if_ref;
Packit 667938
                $if_title_desc =~ s/^[^\d]//;
Packit 667938
                my $if_speed = int($$i{ifSpeed} / 8);
Packit 667938
                my $if_speed_str = fmi($if_speed,$$router_ref{flags});
Packit 667938
                my $if_type_desc = IfType($$i{ifType});
Packit 667938
                my $html_if_type_desc = html_escape($if_type_desc);
Packit 667938
                my $desc_prefix = 'Traffic Analysis for ';
Packit 667938
Packit 667938
                my $port_dot = $$i{Name} || 'Unknown';
Packit 667938
                $port_dot =~ s/\//./g;
Packit 667938
                my $if_port_name = $$router_ref{$port_dot}{CiscoCatalystPortName};
Packit 667938
                my $if_pp_port_name = $$router_ref{$ifindex}{ppPortName};
Packit 667938
Packit 667938
                if (defined $$router_opt{ifdesc}) {
Packit 667938
                    $desc_prefix = '';
Packit 667938
                    foreach (split /,/,$$router_opt{ifdesc}) {
Packit 667938
                        /^ip$/    && do { if($$i{Ip})   { $if_title_desc = $$i{Ip};    last } next };
Packit 667938
                        /^eth$/   && do { if($$i{Eth})  { $if_title_desc = $$i{Eth};   last } next };
Packit 667938
                        /^descr?$/ && do { if($$i{Descr}){ $if_title_desc = $if_snmp_descr; last } next };
Packit 667938
                        /^alias$/ && do { if($$i{ifAlias}){ $if_title_desc = "$if_snmp_descr $if_snmp_alias $if_cisco_descr"; last } next };
Packit 667938
                        /^name$/ && do { if($$i{Name}) {$if_title_desc = "#".$$i{Name}; last } next };
Packit 667938
                        /^catname$/ && do {$if_title_desc = $if_port_name; last };
Packit 667938
                        /^ppname$/ && do {$if_title_desc = $if_pp_port_name; last};
Packit 667938
                        /^type$/ && do { if($$i{Type}) { $if_title_desc = "%".$$i{Type}; last } next };
Packit 667938
                        /^nr$/ && do {$if_title_desc = "Interface $ifindex"; last};
Packit 667938
                        /^$/ && do {$if_title_desc = $if_type_desc || $if_snmp_descr; last };
Packit 667938
                        die "ERROR: Invalid value for --ifdesc: '$$router_opt{ifdesc} ($_)'\n";
Packit 667938
                    }
Packit 667938
                }
Packit 667938
Packit 667938
                # Now setup a large number of variables needed for the
Packit 667938
                # generation of the configuration lines.
Packit 667938
Packit 667938
                $if_title_desc =~ s/\\([:@\\\/\# ])/$1/g; # unescape
Packit 667938
                $if_title_desc = $if_snmp_name if not $if_title_desc;
Packit 667938
                my $html_if_title_desc = html_escape($if_title_desc);
Packit 667938
                my $html_desc_prefix = html_escape($desc_prefix);
Packit 667938
Packit 667938
                my $html_if_snmp_descr = html_escape($if_snmp_descr);
Packit 667938
                my $html_if_snmp_name = html_escape($if_snmp_name);
Packit 667938
                my $html_if_snmp_alias = html_escape($if_snmp_alias);
Packit 667938
                my $html_if_cisco_descr = html_escape($if_cisco_descr);
Packit 667938
                my $if_description = "$if_snmp_descr $if_snmp_alias $if_cisco_descr";
Packit 667938
                my $html_if_description = html_escape($if_description);
Packit 667938
                my $if_title = "$desc_prefix$if_title_desc -- $sysname";
Packit 667938
                my $html_if_title = html_escape($if_title);
Packit 667938
Packit 667938
                my $head_lines = "### Interface $ifindex >> Descr: '$if_snmp_descr' |".
Packit 667938
                                 " Name: '$if_snmp_name' | Ip: '$if_ip' | Eth: '$if_eth' ###\n";
Packit 667938
Packit 667938
                my $target_lines = "";
Packit 667938
                my $separator_lines = "\n\n";
Packit 667938
Packit 667938
                # escape the if reference
Packit 667938
                $if_ref =~ s/([& :])/\\$1/g;
Packit 667938
                my $default_target_directive = "Target[$target_name]: $if_ref:$router_connect";
Packit 667938
		$default_target_directive .= "\nSnmpOptions[$target_name]: $v3options"  if $$router_ref{snmpopt_current} =~ /(?::[^:]*){4}:3/ ;
Packit 667938
		$default_target_directive .= "\nnoHC[$target_name]: yes" if $nohc == 1;
Packit 667938
	        my $if_snmp_descr_save = $if_snmp_descr;
Packit 667938
		$if_snmp_descr_save =~ s/"/'/g;
Packit 667938
                my $default_setenv_directive = "SetEnv[$target_name]: MRTG_INT_IP=\"$if_ip\" MRTG_INT_DESCR=\"$if_snmp_descr_save\"";
Packit 667938
                my $default_directory_directive = ($directory_name ? "Directory[$target_name]: $directory_name" : "");
Packit 667938
                my $default_maxbytes_directive = "MaxBytes[$target_name]: $if_speed";
Packit 667938
Packit 667938
                $ipv4only_directive = $router_ipv4only ? "IPv4Only[$target_name]: yes" : "";
Packit 667938
Packit 667938
                my $default_title_directive = "Title[$target_name]: $html_desc_prefix$html_if_title_desc -- $sysname";
Packit 667938
                my $default_pagetop_directive =
Packit 667938
                "PageTop[$target_name]: 

$html_desc_prefix$html_if_title_desc -- $sysname

Packit 667938
		
Packit 667938
			
Packit 667938
				
Packit 667938
					System:
Packit 667938
					$sysname in $html_syslocation
Packit 667938
				
Packit 667938
				
Packit 667938
					Maintainer:
Packit 667938
					$html_syscontact
Packit 667938
				
Packit 667938
				
Packit 667938
					Description:
Packit 667938
					$html_if_description
Packit 667938
				
Packit 667938
				
Packit 667938
					ifType:
Packit 667938
					$html_if_type_desc ($if_type_num)
Packit 667938
				
Packit 667938
				
Packit 667938
					ifName:
Packit 667938
					$html_if_snmp_name
Packit 667938
				";
Packit 667938
                $default_pagetop_directive .= "
Packit 667938
				
Packit 667938
					Port Name:
Packit 667938
					$if_port_name
Packit 667938
				" if defined $if_port_name;
Packit 667938
                $default_pagetop_directive .= "
Packit 667938
				
Packit 667938
					Port Name:
Packit 667938
					$if_pp_port_name
Packit 667938
				" if defined $if_pp_port_name;
Packit 667938
                $default_pagetop_directive .= "
Packit 667938
				
Packit 667938
					Max Speed:
Packit 667938
					$if_speed_str
Packit 667938
				";
Packit 667938
                $default_pagetop_directive .= "
Packit 667938
				
Packit 667938
					Ip:
Packit 667938
					$if_ip ($if_dns_name)
Packit 667938
				" if $if_ip;
Packit 667938
                $default_pagetop_directive .= "
Packit 667938
			
Packit 667938
		";
Packit 667938
Packit 667938
                my $default_target_lines =
Packit 667938
                    ("\n"
Packit 667938
                    . $default_target_directive . "\n"
Packit 667938
                    . $default_setenv_directive . "\n"
Packit 667938
                    . ($default_directory_directive
Packit 667938
                    ? ($default_directory_directive . "\n")
Packit 667938
                    : "")
Packit 667938
                    . $default_maxbytes_directive . "\n"
Packit 667938
                    . ($ipv4only_directive
Packit 667938
                    ? ($ipv4only_directive . "\n")
Packit 667938
                    : "")
Packit 667938
                    . $default_title_directive . "\n"
Packit 667938
                    . $default_pagetop_directive . "\n");
Packit 667938
Packit 667938
Packit 667938
                # If --if-filter is provided, evalutat that.  If it
Packit 667938
                # returns true, clear @prob.  If it returns false,
Packit 667938
                # instead add a complaint to @prob.
Packit 667938
Packit 667938
                if (defined $$router_opt{'if-filter'}) {
Packit 667938
                    $@ = undef;
Packit 667938
                    if (eval('local $SIG{__DIE__};'.$$router_opt{'if-filter'})) {
Packit 667938
                        @prob = ();
Packit 667938
                    } else {
Packit 667938
                        push @prob, "filter specified by --if-filter rejected the interface";
Packit 667938
                        $if_ok = 0;
Packit 667938
                    }
Packit 667938
                    die "ERROR: with if-filter $$router_opt{'if-filter'}: $@" if $@;
Packit 667938
                }
Packit 667938
Packit 667938
Packit 667938
                # issue problem report
Packit 667938
Packit 667938
                my $problem_lines = "";
Packit 667938
Packit 667938
                if (@prob) {
Packit 667938
                    $problem_lines .= "### The following interface is commented out because:\n";
Packit 667938
                    map {$problem_lines .= "### * $_\n"} @prob;
Packit 667938
                    $if_ok = 0;
Packit 667938
                }
Packit 667938
Packit 667938
                # The target config generation code starts HERE.
Packit 667938
Packit 667938
Packit 667938
                if (defined $$router_opt{'if-template'}) {
Packit 667938
                    # First test if the file exists and is readable,
Packit 667938
                    # die if not.
Packit 667938
                    die "File $$router_opt{'if-template'} didn't exist.\n" unless (-e $$router_opt{'if-template'}
Packit 667938
                        and -r $$router_opt{'if-template'});
Packit 667938
                    # Open the file (or die).
Packit 667938
                    open IF_TEMPLATE, $$router_opt{'if-template'}
Packit 667938
                        or die "File $$router_opt{'if-template'} couldn't be opened.\n";
Packit 667938
                    my @template_lines = readline *IF_TEMPLATE;
Packit 667938
Packit 667938
                    $@ = undef;
Packit 667938
                    eval ('local $SIG{__DIE__};'.join( "", @template_lines));
Packit 667938
                    die "Evaluation of the contents in the file \n\n$$router_opt{'if-template'}\n".
Packit 667938
                        "gave the error \n\n\"$@\"\n\nExiting cfgmaker\n" if $@;
Packit 667938
                } else {
Packit 667938
                    $target_lines = $default_target_lines;
Packit 667938
                }
Packit 667938
Packit 667938
Packit 667938
                if ($target_lines && not $if_ok) { # comment out the target lines if needed
Packit 667938
                    $target_lines =~ s/^/\# /gm;
Packit 667938
                }
Packit 667938
Packit 667938
                $conf .= ($head_lines
Packit 667938
                    . $problem_lines
Packit 667938
                    . $target_lines
Packit 667938
                    . $separator_lines);
Packit 667938
Packit 667938
            }
Packit 667938
            # Target generation code ends HERE.
Packit 667938
        }
Packit 667938
    }
Packit 667938
Packit 667938
    # print any global options which might have
Packit 667938
    # appeared on the command line after the last
Packit 667938
    # router.
Packit 667938
    if (defined $$opt{global}) {
Packit 667938
        foreach my $key (@{$$opt{global}}) {
Packit 667938
            $conf .= "$key\n";
Packit 667938
        }
Packit 667938
    }
Packit 667938
Packit 667938
    if ($$opt{output}) {
Packit 667938
        debug ('base', "Writing $$opt{output}");
Packit 667938
        open X, ">$$opt{output}" or die "ERROR: creating $$opt{output}: $!\n";
Packit 667938
        print X $conf;
Packit 667938
        close X;
Packit 667938
    } else {
Packit 667938
        print $conf;
Packit 667938
    }
Packit 667938
} # end GenConf
Packit 667938
Packit 667938
sub IsCounterBroken ($$$) {
Packit 667938
    my $if = shift;
Packit 667938
    my $router_ref = shift;
Packit 667938
    my $v3opt = shift;
Packit 667938
    my $router = $$router_ref{routerkey};
Packit 667938
    my $fallback = 0;
Packit 667938
    local $SNMP_Session::suppress_warnings = 3;
Packit 667938
    local $Net_SNMP_util::suppress_warnings = 3;
Packit 667938
Packit 667938
    my $ipv4only = $$router_ref{ipv4only};
Packit 667938
    my $snmphost = v4onlyifnecessary($router, $ipv4only);
Packit 667938
Packit 667938
    if ($router =~ /:[\d.]*:[\d.]*:[\d.]*:[23]/) {
Packit 667938
        my $speed = (snmpget($snmphost, $v3opt, 'ifHighSpeed.'.$if))[0] || 'unknown';
Packit 667938
        debug('base',"snmpget $snmphost for ifHighSpeed.$if -> $speed Mb/s");
Packit 667938
        $SNMP_Session::errmsg = undef;
Packit 667938
	$Net_SNMP_util::ErrorMessage = undef;
Packit 667938
        my $counter = (snmpget($snmphost,$v3opt, 'ifHCInOctets.'.$if))[0] || 'unknown';
Packit 667938
        debug('base',"snmpget $snmphost for ifHCInOctets.$if -> $counter");
Packit 667938
        if( $speed eq 'unknown' or $counter !~ /^\d+$/ or $SNMP_Session::errmsg or $Net_SNMP_util::ErrorMessage){
Packit 667938
            $SNMP_Session::errmsg = undef;
Packit 667938
            $Net_SNMP_util::ErrorMessage = undef;
Packit 667938
	    $fallback = 1;
Packit 667938
            debug('base',"check for HighspeedCounters failed ... Dropping back to V1");
Packit 667938
        } else {
Packit 667938
           return 0;
Packit 667938
        }
Packit 667938
    }
Packit 667938
    if ( $fallback == 1 or $$router_ref{snmpopt_current} !~ /:[\d.]*:[\d.]*:[\d.]*:[23]/) {
Packit 667938
         my $counter = (snmpget($snmphost, 'ifInOctets.'.$if))[0];
Packit 667938
         if (defined $SNMP_Session::errmsg) {
Packit 667938
             my $error = $SNMP_Session::errmsg;
Packit 667938
             $SNMP_Session::errmsg = undef;
Packit 667938
             $error =~ s/\n/\n###     /g;
Packit 667938
             return $error;
Packit 667938
     	} elsif (defined $Net_SNMP_util::ErrorMessage and $Net_SNMP_util::ErrorMessage =~ /\w/) {
Packit 667938
             my $error = $Net_SNMP_util::ErrorMessage;
Packit 667938
             $Net_SNMP_util::ErrorMessage = undef;
Packit 667938
             $error =~ s/\n/\n###     /g;
Packit 667938
             return $error;
Packit 667938
         } elsif (not defined $counter or $counter eq '' or $counter =~ /\D/) {
Packit 667938
              return "No counter exists for $if";
Packit 667938
         }
Packit 667938
    }
Packit 667938
    return $fallback;
Packit 667938
} # end IsCounterBroken
Packit 667938
Packit 667938
# DeviceInfo does fallback between IPv6 and IPv4: if an IPv6 snmpwalk returns
Packit 667938
# undef values (= an error) and the target is a hostname, then it repeats the
Packit 667938
# query using IPv4 in case the target does not support SNMP over IPv6.
Packit 667938
# If DeviceInfo falls back to IPv4, it sets the ipv4only field for the target
Packit 667938
# in the routers hash.
Packit 667938
sub DeviceInfo ($$$) {
Packit 667938
    my $router=shift;
Packit 667938
    my $routers=shift;
Packit 667938
    my $v3opt=shift;
Packit 667938
    my %DevInfo;
Packit 667938
    my $ipv4only = $$routers{$router}{ipv4only};
Packit 667938
Packit 667938
    my @variables = snmpwalk(v4onlyifnecessary($router, $ipv4only),$v3opt,'1.3.6.1.2.1.1'); # walk system
Packit 667938
    if (!(defined $variables[0])) {
Packit 667938
        # Do we need to fall back to IPv4?
Packit 667938
        my ($commmunity, $host) = ($1, $2) if ($router =~ /^(.*)@([^@]+)$/);
Packit 667938
        if ( ( ! $ipv4only ) && ( $host !~ /^\[(.*)\]/) ) {
Packit 667938
            # Not using IPv4, not an IPv6 address, so a hostname
Packit 667938
            debug ('base',"No response using IPv6 for $router, trying again using IPv4");
Packit 667938
            $$routers{$router}{ipv4only} = 1;
Packit 667938
            @variables = snmpwalk(v4onlyifnecessary($router, 1),$v3opt, '1.3.6.1.2.1.1');
Packit 667938
        }
Packit 667938
    }
Packit 667938
    if ( defined $variables[0] ) {
Packit 667938
        my (%DevInfo, %revOIDS);
Packit 667938
	
Packit 667938
	if ($$routers{$router}{enablesnmpv3} || '' eq "yes") {
Packit 667938
                no warnings;
Packit 667938
        	%revOIDS = reverse %Net_SNMP_util::OIDS;
Packit 667938
	 }
Packit 667938
	 else {
Packit 667938
                no warnings;
Packit 667938
		%revOIDS = reverse %SNMP_util::OIDS;
Packit 667938
	}	
Packit 667938
        foreach my $variable ( @variables ) {
Packit 667938
            my ($oid, $value) = split ( ':', $variable, 2);
Packit 667938
            if ($revOIDS{'1.3.6.1.2.1.1.'.$oid}){
Packit 667938
                $DevInfo{ $revOIDS{'1.3.6.1.2.1.1.'.$oid} } = $value; 
Packit 667938
            }
Packit 667938
       }
Packit 667938
        # vendor identification
Packit 667938
        my %vendorIDs = (
Packit 667938
            # Add your vendor here
Packit 667938
            # sysObjectID                Vendora
Packit 667938
            '1.3.6.1.4.1.11863.'    =>      'tplink',
Packit 667938
            '1.3.6.1.4.1.43.' =>        '3com',
Packit 667938
            '1.3.6.1.4.1.11.' =>        'hp',
Packit 667938
            '1.3.6.1.4.1.9.' =>         'cisco',
Packit 667938
            '1.3.6.1.4.1.171.' =>       'dlink',
Packit 667938
            '1.3.6.1.4.1.6141.' =>       'wwp',
Packit 667938
            '1.3.6.1.4.1.674.10895.' => 'dellLan',
Packit 667938
            '1.3.6.1.4.1.1916.' =>      'extremenetworks',
Packit 667938
            '1.3.6.1.4.1.1991.' =>      'foundry',
Packit 667938
            '1.3.6.1.4.1.6027.' =>      'force10',
Packit 667938
            '1.3.6.1.4.1.2636.' =>      'juniper',
Packit 667938
            '1.3.6.1.4.1.94.' =>        'nokiaipsofw',
Packit 667938
            '1.3.6.1.4.1.307.' =>       'portmaster',
Packit 667938
            '1.3.6.1.4.1.890.' =>       'zyxel',
Packit 667938
	    '1.3.6.1.4.1.2272.30' =>    'nortel',
Packit 667938
	    '1.3.6.1.4.1.6339' =>       'DCN',
Packit 667938
            '1.3.6.1.4.1.30155.' =>      'openBSD',
Packit 667938
            '1.3.6.1.4.1.30065.' =>      'arista',    
Packit 667938
            '1.3.6.1.4.1.5624.' =>      'enterasys',    
Packit 667938
            '1.3.6.1.4.1.30803.' =>      'Vyatta',    
Packit 667938
            '1.3.6.1.4.1.3955.' =>       'LinkSys',
Packit 667938
	    '1.3.6.1.4.1.1588.' =>       'brocade'
Packit 667938
        );
Packit 667938
        $DevInfo{Vendor} = 'Unknown Vendor - '.$DevInfo{sysObjectID};
Packit 667938
        foreach (keys %vendorIDs) {
Packit 667938
            $DevInfo{Vendor} = $vendorIDs{$_} if ($DevInfo{sysObjectID} =~ /\Q$_\E/);
Packit 667938
        }
Packit 667938
        debug('base',"Vendor Id: $DevInfo{Vendor}");
Packit 667938
        return \%DevInfo;
Packit 667938
    } else {
Packit 667938
        # we just die because the snmp module has already complained
Packit 667938
        return undef;
Packit 667938
    }
Packit 667938
} # end DeviceInfo
Packit 667938
Packit 667938
Packit 667938
sub fmi ($$) {
Packit 667938
    my $number = shift;
Packit 667938
    my $flags = shift;
Packit 667938
    my(@short);
Packit 667938
    if ($$flags{bits}){
Packit 667938
        $number*=8;
Packit 667938
        @short = ("bits/s","kbits/s","Mbits/s","Gbits/s");
Packit 667938
    } else {
Packit 667938
        @short = ("Bytes/s","kBytes/s","MBytes/s","GBytes/s");
Packit 667938
    }
Packit 667938
    my $digits=length("".$number);
Packit 667938
    my $divm=0;
Packit 667938
    while ($digits-$divm*3 > 4) { $divm++; }
Packit 667938
    my $divnum = $number/10**($divm*3);
Packit 667938
    return sprintf("%1.1f %s",$divnum,$short[$divm]);
Packit 667938
} # end fmi
Packit 667938
Packit 667938
Packit 667938
sub IfType ($) {
Packit 667938
  my $id = shift;
Packit 667938
  my $ift = {
Packit 667938
      '1'=>'Other',
Packit 667938
      '2'=>'regular1822',
Packit 667938
      '3'=>'hdh1822',
Packit 667938
      '4'=>'ddnX25',
Packit 667938
      '5'=>'rfc877x25',
Packit 667938
      '6'=>'ethernetCsmacd',
Packit 667938
      '7'=>'iso88023Csmacd',
Packit 667938
      '8'=>'iso88024TokenBus',
Packit 667938
      '9'=>'iso88025TokenRing',
Packit 667938
      '10'=>'iso88026Man',
Packit 667938
      '11'=>'starLan',
Packit 667938
      '12'=>'proteon10Mbit',
Packit 667938
      '13'=>'proteon80Mbit',
Packit 667938
      '14'=>'hyperchannel',
Packit 667938
      '15'=>'fddi',
Packit 667938
      '16'=>'lapb',
Packit 667938
      '17'=>'sdlc',
Packit 667938
      '18'=>'ds1',
Packit 667938
      '19'=>'e1',
Packit 667938
      '20'=>'basicISDN',
Packit 667938
      '21'=>'primaryISDN',
Packit 667938
      '22'=>'propPointToPointSerial',
Packit 667938
      '23'=>'ppp',
Packit 667938
      '24'=>'softwareLoopback',
Packit 667938
      '25'=>'eon',
Packit 667938
      '26'=>'ethernet-3Mbit',
Packit 667938
      '27'=>'nsip',
Packit 667938
      '28'=>'slip',
Packit 667938
      '29'=>'ultra',
Packit 667938
      '30'=>'ds3',
Packit 667938
      '31'=>'sip',
Packit 667938
      '32'=>'frame-relay',
Packit 667938
      '33'=>'rs232',
Packit 667938
      '34'=>'para',
Packit 667938
      '35'=>'arcnet',
Packit 667938
      '36'=>'arcnetPlus',
Packit 667938
      '37'=>'atm',
Packit 667938
      '38'=>'miox25',
Packit 667938
      '39'=>'sonet',
Packit 667938
      '40'=>'x25ple',
Packit 667938
      '41'=>'iso88022llc',
Packit 667938
      '42'=>'localTalk',
Packit 667938
      '43'=>'smdsDxi',
Packit 667938
      '44'=>'frameRelayService',
Packit 667938
      '45'=>'v35',
Packit 667938
      '46'=>'hssi',
Packit 667938
      '47'=>'hippi',
Packit 667938
      '48'=>'modem',
Packit 667938
      '49'=>'aal5',
Packit 667938
      '50'=>'sonetPath',
Packit 667938
      '51'=>'sonetVT',
Packit 667938
      '52'=>'smdsIcip',
Packit 667938
      '53'=>'propVirtual',
Packit 667938
      '54'=>'propMultiplexor',
Packit 667938
      '55'=>'100BaseVG',
Packit 667938
      '56'=>'Fibre Channel',
Packit 667938
      '57'=>'HIPPI Interface',
Packit 667938
      '58'=>'Obsolete for FrameRelay',
Packit 667938
      '59'=>'ATM Emulation of 802.3 LAN',
Packit 667938
      '60'=>'ATM Emulation of 802.5 LAN',
Packit 667938
      '61'=>'ATM Emulation of a Circuit',
Packit 667938
      '62'=>'FastEthernet (100BaseT)',
Packit 667938
      '63'=>'ISDN & X.25',
Packit 667938
      '64'=>'CCITT V.11/X.21',
Packit 667938
      '65'=>'CCITT V.36',
Packit 667938
      '66'=>'CCITT G703 at 64Kbps',
Packit 667938
      '67'=>'Obsolete G702 see DS1-MIB',
Packit 667938
      '68'=>'SNA QLLC',
Packit 667938
      '69'=>'Full Duplex Fast Ethernet (100BaseFX)',
Packit 667938
      '70'=>'Channel',
Packit 667938
      '71'=>'Radio Spread Spectrum (802.11)',
Packit 667938
      '72'=>'IBM System 360/370 OEMI Channel',
Packit 667938
      '73'=>'IBM Enterprise Systems Connection',
Packit 667938
      '74'=>'Data Link Switching',
Packit 667938
      '75'=>'ISDN S/T Interface',
Packit 667938
      '76'=>'ISDN U Interface',
Packit 667938
      '77'=>'Link Access Protocol D (LAPD)',
Packit 667938
      '78'=>'IP Switching Opjects',
Packit 667938
      '79'=>'Remote Source Route Bridging',
Packit 667938
      '80'=>'ATM Logical Port',
Packit 667938
      '81'=>'AT&T DS0 Point (64 Kbps)',
Packit 667938
      '82'=>'AT&T Group of DS0 on a single DS1',
Packit 667938
      '83'=>'BiSync Protocol (BSC)',
Packit 667938
      '84'=>'Asynchronous Protocol',
Packit 667938
      '85'=>'Combat Net Radio',
Packit 667938
      '86'=>'ISO 802.5r DTR',
Packit 667938
      '87'=>'Ext Pos Loc Report Sys',
Packit 667938
      '88'=>'Apple Talk Remote Access Protocol',
Packit 667938
      '89'=>'Proprietary Connectionless Protocol',
Packit 667938
      '90'=>'CCITT-ITU X.29 PAD Protocol',
Packit 667938
      '91'=>'CCITT-ITU X.3 PAD Facility',
Packit 667938
      '92'=>'MultiProtocol Connection over Frame/Relay',
Packit 667938
      '93'=>'CCITT-ITU X213',
Packit 667938
      '94'=>'Asymetric Digitial Subscriber Loop (ADSL)',
Packit 667938
      '95'=>'Rate-Adapt Digital Subscriber Loop (RDSL)',
Packit 667938
      '96'=>'Symetric Digitial Subscriber Loop (SDSL)',
Packit 667938
      '97'=>'Very High Speed Digitial Subscriber Loop (HDSL)',
Packit 667938
      '98'=>'ISO 802.5 CRFP',
Packit 667938
      '99'=>'Myricom Myrinet',
Packit 667938
      '100'=>'Voice recEive and transMit (voiceEM)',
Packit 667938
      '101'=>'Voice Foreign eXchange Office (voiceFXO)',
Packit 667938
      '102'=>'Voice Foreign eXchange Station (voiceFXS)',
Packit 667938
      '103'=>'Voice Encapulation',
Packit 667938
      '104'=>'Voice Over IP Encapulation',
Packit 667938
      '105'=>'ATM DXI',
Packit 667938
      '106'=>'ATM FUNI',
Packit 667938
      '107'=>'ATM IMA',
Packit 667938
      '108'=>'PPP Multilink Bundle',
Packit 667938
      '109'=>'IBM IP over CDLC',
Packit 667938
      '110'=>'IBM Common Link Access to Workstation',
Packit 667938
      '111'=>'IBM Stack to Stack',
Packit 667938
      '112'=>'IBM Virtual IP Address (VIPA)',
Packit 667938
      '113'=>'IBM Multi-Protocol Channel Support',
Packit 667938
      '114'=>'IBM IP over ATM',
Packit 667938
      '115'=>'ISO 802.5j Fiber Token Ring',
Packit 667938
      '116'=>'IBM Twinaxial Data Link Control (TDLC)',
Packit 667938
      '117'=>'Gigabit Ethernet',
Packit 667938
      '118'=>'Higher Data Link Control (HDLC)',
Packit 667938
      '119'=>'Link Access Protocol F (LAPF)',
Packit 667938
      '120'=>'CCITT V.37',
Packit 667938
      '121'=>'CCITT X.25 Multi-Link Protocol',
Packit 667938
      '122'=>'CCITT X.25 Hunt Group',
Packit 667938
      '123'=>'Transp HDLC',
Packit 667938
      '124'=>'Interleave Channel',
Packit 667938
      '125'=>'Fast Channel',
Packit 667938
      '126'=>'IP (for APPN HPR in IP Networks)',
Packit 667938
      '127'=>'CATV MAC Layer',
Packit 667938
      '128'=>'CATV Downstream Interface',
Packit 667938
      '129'=>'CATV Upstream Interface',
Packit 667938
      '130'=>'Avalon Parallel Processor',
Packit 667938
      '131'=>'Encapsulation Interface',
Packit 667938
      '132'=>'Coffee Pot',
Packit 667938
      '133'=>'Circuit Emulation Service',
Packit 667938
      '134'=>'ATM Sub Interface',
Packit 667938
      '135'=>'Layer 2 Virtual LAN using 802.1Q',
Packit 667938
      '136'=>'Layer 3 Virtual LAN using IP',
Packit 667938
      '137'=>'Layer 3 Virtual LAN using IPX',
Packit 667938
      '138'=>'IP Over Power Lines',
Packit 667938
      '139'=>'Multi-Media Mail over IP',
Packit 667938
      '140'=>'Dynamic synchronous Transfer Mode (DTM)',
Packit 667938
      '141'=>'Data Communications Network',
Packit 667938
      '142'=>'IP Forwarding Interface',
Packit 667938
      '144'=>'IEEE1394 High Performance Serial Bus',
Packit 667938
      '150'=>'MPLS Tunnel Virtual Interface',
Packit 667938
      '161'=>'IEEE 802.3ad Link Aggregate',
Packit 667938
      '162'=>'Cisco Express Forwarding Interface',
Packit 667938
      '166'=>'MPLS',
Packit 667938
      '238'=>'Asymmetric Digital Subscriber Loop',
Packit 667938
      '246'=>'Pseudowire interface type',
Packit 667938
      '251'=>'Very high speed digital subscriber line',
Packit 667938
   };
Packit 667938
   return ($ift->{$id} || "Uknown Interface Type");
Packit 667938
} # end IfType
Packit 667938
Packit 667938
Packit 667938
Packit 667938
Packit 667938
Packit 667938
sub options ($$) {
Packit 667938
    my $opt = shift;
Packit 667938
    my $routers = shift;
Packit 667938
Packit 667938
    my $noofrouter = 0; # How many routers we've seen on cmdline.
Packit 667938
Packit 667938
    # The $flags hash stores what we've seen in Options[_],
Packit 667938
    # Options[^] and Options[$] so far.
Packit 667938
    # A cmdline arg like --global 'Options[_]: bits' will insert
Packit 667938
    # the element $$flags{default}{bits}="set".
Packit 667938
    # Similarly --global 'Options[$]:' will delete all elements
Packit 667938
    # in $$flags{append}
Packit 667938
    #
Packit 667938
    # This was originally created to manipulate the "bits" flag
Packit 667938
    # so fmi should know when to use "bits" or "bytes".  It might
Packit 667938
    # be overkill to use such a comples solution but it makes life
Packit 667938
    # easier if cfgmaker in the future has to be extended to be
Packit 667938
    # aware of other Options[] settings like gauge, growright etc.
Packit 667938
Packit 667938
    my %flags;
Packit 667938
    {
Packit 667938
        my $def = {};
Packit 667938
        my $pre = {};
Packit 667938
        my $app = {};
Packit 667938
        %flags = (default => $def,
Packit 667938
                  prepend => $pre,
Packit 667938
                  append  => $app);
Packit 667938
    }
Packit 667938
Packit 667938
    my $addrouter_ornf = addrouter($opt,
Packit 667938
                   $routers,
Packit 667938
                   \$noofrouter,
Packit 667938
                   \%flags);
Packit 667938
Packit 667938
    Getopt::Long::Configure("permute");
Packit 667938
    GetOptions( $opt,
Packit 667938
        'help|?',
Packit 667938
        'man',
Packit 667938
        'subdirs=s',
Packit 667938
        'no-down',
Packit 667938
        'show-op-down',
Packit 667938
        'noreversedns',
Packit 667938
        'ifref=s',
Packit 667938
        'ifdesc=s',
Packit 667938
        'if-filter=s',
Packit 667938
        'if-template=s',
Packit 667938
        'interfaces!',
Packit 667938
        'host-template=s',
Packit 667938
        'community=s',
Packit 667938
	'username=s',
Packit 667938
	'authkey=s',
Packit 667938
	'authpassword=s',
Packit 667938
	'authprotocol=s',
Packit 667938
	'contextengineid=s',
Packit 667938
	'contextname=s',
Packit 667938
	'privkey=s',
Packit 667938
	'privpassword=s',
Packit 667938
	'privprotocol=s',
Packit 667938
        'snmp-options=s',
Packit 667938
        'dns-domain=s',
Packit 667938
        'version',
Packit 667938
        'output=s',
Packit 667938
        'global=s@',
Packit 667938
        'enable-ipv6',
Packit 667938
        'enablesnmpv3',
Packit 667938
        'use-16bit',
Packit 667938
	'zero-speed=s',
Packit 667938
        '<>', $addrouter_ornf) or pod2usage(2);
Packit 667938
Packit 667938
    die("cfgmaker for mrtg-2.17.7\n") if $$opt{version};
Packit 667938
    pod2usage(-exitval => 0, -verbose => 2) if $$opt{man};
Packit 667938
    pod2usage(-verbose => 1) if not keys %$routers;
Packit 667938
} # end options
Packit 667938
Packit 667938
# The callback routine used by GetOptions to process "non-option
Packit 667938
# strings" (routers) among the arguments is given only ONE argument.
Packit 667938
# However, I want it to be able to specify both the %options hash
Packit 667938
# (for read access) and the %routers hash (for modifying) as well
Packit 667938
# as the router's name.  This makes for three arguments.
Packit 667938
#
Packit 667938
# The solution is to use a closure.  addrouter takes a opt hash, a
Packit 667938
# routers hash, an index to the current number of routers and a flags
Packit 667938
# hash and then returns a function which "remembers" these
Packit 667938
# values (the closure) but also takes an argument (the router name).
Packit 667938
Packit 667938
sub addrouter() {
Packit 667938
    my $opt = shift;
Packit 667938
    my $routers = shift;
Packit 667938
    my $noofrouter = shift;
Packit 667938
    my $flags = shift;
Packit 667938
Packit 667938
    return sub {
Packit 667938
        my $rawname = shift;
Packit 667938
Packit 667938
        $$noofrouter++;  # First increase the number of routers seen.
Packit 667938
Packit 667938
        my ($community,$routername,$routerkey,$snmpopt,$dnsdomain,$tmpname,@tmpsnmp);
Packit 667938
Packit 667938
        # Now make sure that the router is defined with the
Packit 667938
        # proper community, domainname and SNMP options.
Packit 667938
        # Dissect the rawname to find out what it contains.
Packit 667938
Packit 667938
        # First check for community:
Packit 667938
        if ($rawname =~ /^(.+)\@([^@]+)$/) {
Packit 667938
            # Community was given explicitly!
Packit 667938
            $community = $1;
Packit 667938
            $tmpname = $2
Packit 667938
        } else {
Packit 667938
            $community = $$opt{community};
Packit 667938
            $tmpname = $rawname;
Packit 667938
        }
Packit 667938
        # Now separate the router name from the options. We
Packit 667938
        # can't just split on the : character because a numeric
Packit 667938
        # IPv6 address contains a variable number of :'s
Packit 667938
        if( ($tmpname =~ /^(\[.*\]):(.*)$/) || ($tmpname =~ /^(\[.*\])$/) ){
Packit 667938
            # Numeric IPv6 address between []
Packit 667938
            ($routername, $snmpopt) = ($1, $2);
Packit 667938
        } else {
Packit 667938
            # Hostname or numeric IPv4 address
Packit 667938
            ($routername, $snmpopt) = split(':', $tmpname, 2);
Packit 667938
        }
Packit 667938
        @tmpsnmp = split(':', $snmpopt || '');
Packit 667938
Packit 667938
        $routername =~ s/\.$//; # if the hostname ends in a '.' remove it
Packit 667938
                                # it seems to cause trouble in some other
Packit 667938
                                # parts of mrtg
Packit 667938
Packit 667938
        # Now setup the SNMP options.
Packit 667938
        if (not defined $$opt{'snmp-options'}) {
Packit 667938
            $snmpopt = ':' . (join ':', @tmpsnmp);  # No merge needed.
Packit 667938
        } else {
Packit 667938
            my ($t,$o,@s);
Packit 667938
            my @optsnmp = split ':',$$opt{'snmp-options'};
Packit 667938
Packit 667938
            # Trim first element as the SNMP options start
Packit 667938
            # with a colon and thus the first element is a
Packit 667938
            # dummy "" string not corresponding to any SNMP option
Packit 667938
            # (or rather, corresponding to a router, if there had
Packit 667938
            # been one...)
Packit 667938
            shift @optsnmp;
Packit 667938
Packit 667938
            while ((scalar @tmpsnmp > 0)
Packit 667938
               or (scalar @optsnmp > 0)) {
Packit 667938
                $t = shift @tmpsnmp;
Packit 667938
                $o = shift @optsnmp;
Packit 667938
Packit 667938
                if(not defined $t) {$t = "";}
Packit 667938
                if(not defined $o) {$o = "";}
Packit 667938
Packit 667938
                if($t ne "")
Packit 667938
                {
Packit 667938
                    push @s, $t;
Packit 667938
                } else {
Packit 667938
                    push @s, $o;
Packit 667938
                }
Packit 667938
            }
Packit 667938
Packit 667938
            $snmpopt = ':' . (join ':', @s);
Packit 667938
        }
Packit 667938
Packit 667938
        my $newopt={};  # Perhaps unecessary initialization but...
Packit 667938
Packit 667938
        foreach my $o (keys %$opt) {
Packit 667938
            my $ovalue = $$opt{$o};
Packit 667938
Packit 667938
            $$newopt{$o} = $ovalue
Packit 667938
            unless
Packit 667938
                ($o =~ /^fullcmd$/ or
Packit 667938
                 $o =~ /^community$/ or
Packit 667938
                 $o =~ /^snmp-options$/ or
Packit 667938
                 $o =~ /^global$/ or
Packit 667938
                 $o =~ /^output$/
Packit 667938
                 );
Packit 667938
Packit 667938
            # Ok, copy the --globals array from $$opt so we know
Packit 667938
            # that which global(s) to print out into the config.
Packit 667938
            push @{$$newopt{$o}}, @{$$opt{$o}} if ($o =~ /^global$/);
Packit 667938
Packit 667938
            # Go through these --global statements one by one.
Packit 667938
            # If anyone of them contains Options[] for any of the
Packit 667938
            # targets [_], [^] or [_], process those statements
Packit 667938
            # tenderly and populate the $$flags{}{} hashes accordingly.
Packit 667938
            for my $g (@{$$opt{"global"}}) {
Packit 667938
                if ($g =~ /^options\[([_^\$])\]:\s*(.*)$/i){
Packit 667938
                   my ($t,$fs);
Packit 667938
                   $t = $1;
Packit 667938
                   $fs = $2;
Packit 667938
                   $t =~ s/_/default/;
Packit 667938
                   $t =~ s/\^/prepend/;
Packit 667938
                   $t =~ s/\$/append/;
Packit 667938
Packit 667938
                   # If a line like "options[X]:" is found clear
Packit 667938
                   # all flags for that category and then go to next
Packit 667938
                   # --global 'Options[..' line if any.
Packit 667938
                   if ($fs =~ /^\s*$/) {
Packit 667938
                      $$flags{$t} = {};
Packit 667938
                      next;
Packit 667938
                  } else {
Packit 667938
                     for my $f (split /\s*,\s*/,$fs) {
Packit 667938
                        $$flags{$t}{$f} = "set";
Packit 667938
                     }
Packit 667938
                  }
Packit 667938
               }
Packit 667938
            }
Packit 667938
            $$opt{$o} = [] if ($o =~ /^global$/);
Packit 667938
        }
Packit 667938
Packit 667938
        # Now let this router get it's own copy of
Packit 667938
        # the "currently effective" flags.
Packit 667938
        # Note, Options[_] should only be considered
Packit 667938
        # if Options[^] and Options[$] both are absent.
Packit 667938
Packit 667938
        my $newflags = {};
Packit 667938
Packit 667938
        if((0 == keys %{$$flags{prepend}})
Packit 667938
            and (0== keys %{$$flags{append}})) {
Packit 667938
            for my $f (keys %{$$flags{default}}) {
Packit 667938
                $$newflags{$f}="set";
Packit 667938
            }
Packit 667938
        } else {
Packit 667938
            for my $f (keys %{$$flags{prepend}},
Packit 667938
                   keys %{$$flags{append}}) {
Packit 667938
                $$newflags{$f}="set";
Packit 667938
            }
Packit 667938
        }
Packit 667938
Packit 667938
        if(defined $$opt{'dns-domain'}) {
Packit 667938
            $dnsdomain=$$opt{'dns-domain'};
Packit 667938
        } else {
Packit 667938
            $dnsdomain="";
Packit 667938
        }
Packit 667938
Packit 667938
        $routerkey =
Packit 667938
            "${community}\@${routername}"
Packit 667938
            . (($dnsdomain eq "")?"":".")
Packit 667938
                . "${dnsdomain}${snmpopt}";
Packit 667938
Packit 667938
        $$routers{$routerkey}= {
Packit 667938
            # rawname is the unprocessed string from the
Packit 667938
            # command line.
Packit 667938
            rawname     => $rawname,
Packit 667938
Packit 667938
            # opt is the commandline options which are
Packit 667938
            # in effect for THIS particular router.
Packit 667938
            opt         => $newopt,
Packit 667938
Packit 667938
            # noofrouter is the unique number for the
Packit 667938
            # router.  The first router on the command
Packit 667938
            # line is given number 1, the second number 2
Packit 667938
            # and so on.
Packit 667938
            noofrouter  => $$noofrouter,
Packit 667938
Packit 667938
            # flags contains which --global 'Options[^_$]: flags'
Packit 667938
            # are effective for THIS particular router.
Packit 667938
            flags       => $newflags,
Packit 667938
Packit 667938
            # community is the SNMP community used for the router
Packit 667938
            community   => $community,
Packit 667938
Packit 667938
            # snmpopt is the SNMP options on the form
Packit 667938
            # [port[:timeout[:retries[:backoff[:version]]]]]
Packit 667938
            # The empty string simply means that no
Packit 667938
            # specific SNMP options has been given.
Packit 667938
            'snmp-options' => $snmpopt,
Packit 667938
            snmpopt_current => $snmpopt,
Packit 667938
Packit 667938
            # dns-domain is a domain which should be added
Packit 667938
            # to the routers hostname.
Packit 667938
            # e.g if dns-domain is place.xyz and host is router
Packit 667938
            # the host "router.place.xyz" will be polled.
Packit 667938
            # If host is "router.dept" the poll will be against
Packit 667938
            # "router.dept.place.xyz".
Packit 667938
            'dns-domain' => $dnsdomain,
Packit 667938
Packit 667938
            # routername is the routers name as given on the
Packit 667938
            # command line but with SNMP community (if given)
Packit 667938
            # and SNMP options (if given) stripped.
Packit 667938
            #
Packit 667938
            # (Yes, routername COULD be on the form
Packit 667938
            # "host.domain" or "host.subdomain.domain")
Packit 667938
            routername  => $routername,
Packit 667938
Packit 667938
            # routerkey is the same as the has key used for the
Packit 667938
            # router, which is the router name with everything
Packit 667938
            # taken into account: community, dns-domain and
Packit 667938
            # snmp-options.  This is the value used when doing
Packit 667938
            # SNMP communication with the router.
Packit 667938
            routerkey => $routerkey,
Packit 667938
            };
Packit 667938
    }
Packit 667938
} # end addrouter
Packit 667938
Packit 667938
sub html_escape ($) {
Packit 667938
    my $s = shift || '';
Packit 667938
    $s =~ s/&/&/g;
Packit 667938
    $s =~  s/</</g;
Packit 667938
    $s =~  s/>/>/g;
Packit 667938
    $s =~ s/[\n\r]+([^\n\r])/
\n $1/g;
Packit 667938
    return $s;
Packit 667938
} # end html_escape
Packit 667938
Packit 667938
sub oid_pick ($$$;@){
Packit 667938
    my $router = shift;
Packit 667938
    my $v3opt = shift;
Packit 667938
    my @oids = @_;
Packit 667938
    local $SNMP_Session::suppress_warnings = 3;
Packit 667938
    foreach my $oid (@oids){
Packit 667938
        local $SNMP_Session::errmsg = undef;
Packit 667938
        my $counter = snmpget($router,$v3opt,$oid);
Packit 667938
        if (not defined $SNMP_Session::errmsg and defined $counter and $counter ne '' ) {
Packit 667938
            debug('base',"oid_pick - found $oid to work for $router");
Packit 667938
	    return $oid;
Packit 667938
        }	    
Packit 667938
    }
Packit 667938
    debug('base',"oid_pick - none of ".(join ",",@oids)." seem to work for $router");
Packit 667938
    return undef;
Packit 667938
}
Packit 667938
Packit 667938
Packit 667938
sub parsev3 ($) {
Packit 667938
    my $opt = shift;
Packit 667938
    my %v3opt;
Packit 667938
	if (!exists ($$opt{username})) {
Packit 667938
    		die "SMNP V3 requires a --username paramter as part of the User Security Model";
Packit 667938
	} else {
Packit 667938
		$v3opt{username} = $$opt{username};
Packit 667938
	}
Packit 667938
	$v3opt{contextname} = $$opt{contextname} if exists($$opt{contextname});
Packit 667938
	if (exists ($$opt{authkey})) {
Packit 667938
		die "Can't use both an --authkey and --authpassword in the User Security Model" if exists($$opt{authpassword});	
Packit 667938
		$v3opt{authkey} = $$opt{authkey};
Packit 667938
	}
Packit 667938
	if (exists ($$opt{authpassword})) {
Packit 667938
		die "Use of --authpassword requires --contextengineid" if !exists($$opt{contextengineid});
Packit 667938
		$v3opt{authpassword} = $$opt{authpassword};
Packit 667938
	}
Packit 667938
	if (exists ($$opt{authprotocol})) {
Packit 667938
		die "Only sha and md5 are defined for --authprotocol" if $$opt{authprotocol} !~ /^(md5|sha)$/i;
Packit 667938
		die "--authprotocol can only be used with --authpassword or --authkey" if ! exists($$opt{authpassword}) and ! exists($$opt{authkey});
Packit 667938
		($v3opt{authprotocol}) = (lc($$opt{authprotocol}) =~ /^(md5|sha)$/);
Packit 667938
	}
Packit 667938
	if (exists ($$opt{privkey})) {
Packit 667938
		die "Can't use both an --privkey and --privpassword in the User Security Model" if exists($$opt{privpassword});	
Packit 667938
		die "Can't have privacy parameters without authentication in the User security Model" if ! exists($$opt{authpassword}) and ! exists($$opt{authkey});
Packit 667938
		$v3opt{privkey} = $$opt{privkey};
Packit 667938
	}
Packit 667938
	if (exists ($$opt{privpassword})) {
Packit 667938
		die "Use of --privpassword requires --contextengineid" if !exists($$opt{contextengineid});
Packit 667938
		die "Can't have privacy parameters without authentication in the User security Model" if ! exists($$opt{authpassword}) and ! exists($$opt{authkey});
Packit 667938
		$v3opt{privpassword} = $$opt{privpassword};
Packit 667938
	}
Packit 667938
	if (exists ($$opt{privprotocol})) {
Packit 667938
		die "Only des, 3des, 3desede, aes, aes128 are defined for --privprotocol" if $$opt{privprotocol} !~ /^(?:3?des(?:ede)?|aes(?:128)?)$/;
Packit 667938
		die "--privprotocol can only be used with --privpassword or --privkey" if ! exists($$opt{privpassword}) and ! exists($$opt{privkey});
Packit 667938
		$v3opt{privprotocol} = lc($$opt{privprotocol});
Packit 667938
	}
Packit 667938
	return %v3opt;
Packit 667938
}
Packit 667938
		
Packit 667938
	
Packit 667938
sub init () {
Packit 667938
  snmpmapOID('sysObjectID' => '1.3.6.1.2.1.1.2.0',
Packit 667938
             'CiscolocIfDescr' => '1.3.6.1.4.1.9.2.2.1.1.28',
Packit 667938
             'CiscoCatalystPortName' => '1.3.6.1.4.1.9.5.1.4.1.1.4',
Packit 667938
             'ppPortName' => '1.3.6.1.4.1.2272.1.4.10.1.1.35',
Packit 667938
            'vlanTrunkPortDynamicStatus'=> '1.3.6.1.4.1.9.9.46.1.6.1.1.14',
Packit 667938
             'vmVlan' => '1.3.6.1.4.1.9.9.68.1.2.2.1.2',
Packit 667938
             'ifAlias' => '1.3.6.1.2.1.31.1.1.1.18');
Packit 667938
} # end init
Packit 667938
Packit 667938
__END__
Packit 667938
Packit 667938
=pod
Packit 667938
Packit 667938
=head1 NAME
Packit 667938
Packit 667938
cfgmaker - Creates mrtg.cfg files (for mrtg-2.17.7)
Packit 667938
Packit 667938
=head1 SYNOPSIS
Packit 667938
Packit 667938
cfgmaker [options] [community@]router [[options] [community@]router ...]
Packit 667938
Packit 667938
=head1 OPTIONS
Packit 667938
Packit 667938
 --ifref=nr    interface references by Interface Number (default)
Packit 667938
 --ifref=ip                     ... by Ip Address
Packit 667938
 --ifref=eth                        ... by Ethernet Number
Packit 667938
 --ifref=descr                      ... by Interface Description
Packit 667938
 --ifref=name                       ... by Interface Name
Packit 667938
 --ifref=type                       ... by Interface Type
Packit 667938
                You may also use multiple options separated by commas,
Packit 667938
               in which case the first available one is used:
Packit 667938
               e.g.  --ifref=ip,name,nr
Packit 667938
Packit 667938
 --ifdesc=nr       interface description uses Interface Number (default)
Packit 667938
 --ifdesc=ip                        ... uses Ip Address
Packit 667938
 --ifdesc=eth                       ... uses Ethernet Number
Packit 667938
 --ifdesc=descr                     ... uses Interface Description
Packit 667938
 --ifdesc=name                      ... uses Interface Name
Packit 667938
 --ifdesc=catname                   ... uses CatOS Interface Name
Packit 667938
 --ifdesc=ppname                    ... uses Passport Port Name
Packit 667938
 --ifdesc=alias                     ... uses Interface Alias
Packit 667938
 --ifdesc=type                      ... uses Interface Type
Packit 667938
                You may also use multiple options separated by commas,
Packit 667938
               in which case the first available one is used:
Packit 667938
               e.g.  --ifdesc=catname,ppname,descr,alias,ip,name,nr
Packit 667938
Packit 667938
 --if-filter=f     Test every interface against filter f to decide wether
Packit 667938
                   or not to include that interface into the collection.
Packit 667938
                   Currently f is being evaluated as a Perl expression
Packit 667938
                   and it's truth value is used to reject or accept the
Packit 667938
                   interface.
Packit 667938
                   (Experimental, under development, might change)
Packit 667938
Packit 667938
 --if-template=templatefile
Packit 667938
                   Replace the normal target entries for the interfaces
Packit 667938
                   with an entry as specified by the contents in the file
Packit 667938
                   templatefile.  The file is supposed to contain Perl
Packit 667938
                   code to be executed to generate the lines for the
Packit 667938
                   target in the configuration file.
Packit 667938
                   (Experimental, under development, might change)
Packit 667938
Packit 667938
 --host-template=templatefile
Packit 667938
                   In addition to creating targets for a host's interfaces
Packit 667938
                   do also create targets for the host itself as specified
Packit 667938
                   by the contents in the file templatefile.  The file is
Packit 667938
                   supposed to contain Perl code to be executed to generate
Packit 667938
                   the lines for the host related targets (such as CPU,
Packit 667938
                   ping response time measurements etc.) in the config-
Packit 667938
                   uration file.
Packit 667938
                   (Experimental, under development, might change)
Packit 667938
Packit 667938
 --global "x: a"   add global config entries
Packit 667938
Packit 667938
 --no-down         do not look at admin or opr status of interfaces
Packit 667938
Packit 667938
 --show-op-down    show interfaces which are operatively down
Packit 667938
Packit 667938
 --zero-speed=spd  use this speed in bits-per-second as the interface
Packit 667938
                   speed for all interfaces that return a speed of 0
Packit 667938
                   via ifSpeed/ifHighSpeed.  100Mbps = 100000000
Packit 667938
Packit 667938
 --subdirs=format  give each router its own subdirectory, naming each per
Packit 667938
                   "format", in which HOSTNAME and SNMPNAME will be
Packit 667938
                   replaced by the values of those items -- for instance,
Packit 667938
                   --subdirs=HOSTNAME or --subdirs="HOSTNAME (SNMPNAME)"
Packit 667938
Packit 667938
 --noreversedns    do not reverse lookup ip numbers
Packit 667938
Packit 667938
 --community=cmty  Set the default community string to "cmty" instead of
Packit 667938
                   "public".
Packit 667938
Packit 667938
 --enable-ipv6     Enable IPv6 support, if the required libraries are
Packit 667938
                   present. Numeric IPv6 addresses must be enclosed
Packit 667938
                   in square brackets, e.g. public@[2001:760:4::1]:161
Packit 667938
Packit 667938
 --use-16bit       Use 16bit SNMP request IDs to query all routers.
Packit 667938
Packit 667938
 --snmp-options=:[<port>][:[<tmout>][:[<retr>][:[<backoff>][:<ver>]]]]
Packit 667938
Packit 667938
                   Specify default SNMP options to be appended to all
Packit 667938
                   routers following.  Individual fields can be empty.
Packit 667938
                   Routers following might override some or all of the
Packit 667938
           options given to --snmp-options.
Packit 667938
Packit 667938
 --dns-domain=domain
Packit 667938
           Specifies a domain to append to the name of all
Packit 667938
           routers following.
Packit 667938
Packit 667938
 --nointerfaces    Don't do generate any configuration lines for interfaces,
Packit 667938
                   skip the step of gathering interface information and
Packit 667938
                   don't run any interface template code.
Packit 667938
Packit 667938
 --interfaces      Generate configuration lines for interfaces (this is the
Packit 667938
                   default).  The main purpose of this option is to negate
Packit 667938
                   an --nointerfaces appearing earlier on the command line.
Packit 667938
Packit 667938
 --help            brief help message
Packit 667938
 --man             full documentation
Packit 667938
 --version         print the version of cfgmaker
Packit 667938
Packit 667938
 --output=file     output filename default is STDOUT
Packit 667938
Packit 667938
=head1 DESCRIPTION
Packit 667938
Packit 667938
B<Cfgmaker> creates MRTG configuration files based on information
Packit 667938
pulled from a router or another SNMP manageable device.
Packit 667938
Packit 667938
[I<community>B<@>]I<router>
Packit 667938
Packit 667938
I<Community> is the community name of the device you want to create a
Packit 667938
configuration for. If not specified, it defaults to 'B<public>'; you might
Packit 667938
want to try this first if you do not know the community name of a
Packit 667938
device. If you are using the wrong community name you will get no
Packit 667938
response from the device.
Packit 667938
Packit 667938
I<Router> is the DNS name or the IP number of an SNMP-managable device.
Packit 667938
Following the name you can specify 6 further options separated by
Packit 667938
colons.  The full syntax looks like this:
Packit 667938
Packit 667938
B<router>[:[B<prt>][:[B<tmout>][:[B<retr>][:[B<backoff>][:B<vers>]]]]]
Packit 667938
Packit 667938
Of special interest may be the last parameter, B<vers>.  If you set this to
Packit 667938
'2' then your device will be queried with SNMP version 2 requests. This
Packit 667938
allows you to poll the 64 bit traffic counters in the device and will thus work
Packit 667938
much better with fast interfaces (no more counter overrun).  Note that the
Packit 667938
order in which the routers are specified on the command line do matter as
Packit 667938
the same order is used when the configuration file is generated.  The first
Packit 667938
specified router has it's configuration lines genrated first, followed by
Packit 667938
the lines belonging to the next router and so on.
Packit 667938
Packit 667938
Note that the first line of the generated cfg file will contain all the
Packit 667938
commandline options you used for generating it. This is to allow for the
Packit 667938
easy 'regeneration' in case you want to add newhosts or make some other
Packit 667938
global change.
Packit 667938
Packit 667938
=head2 Configuration
Packit 667938
Packit 667938
Except for the B<--output> and B<--global> options, all options affect
Packit 667938
only the routers following them on the command line.  If an option
Packit 667938
specified earlier on the command line reappears later on the command
Packit 667938
line with another value, the new value overrides the old value as far as
Packit 667938
remaining routers are concerned.  This way options might be tailored for
Packit 667938
groups of routers or for individual routers.
Packit 667938
Packit 667938
See B<--output> and B<--global> for how their behaviour is affected by
Packit 667938
where or how many times they appear on the command line.
Packit 667938
Packit 667938
See the B<Examples> below on how to set an option differently for
Packit 667938
multiple routers.
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<--help>
Packit 667938
Packit 667938
Print a brief help message and exit.
Packit 667938
Packit 667938
=item B<--man>
Packit 667938
Packit 667938
Prints the manual page and exits.
Packit 667938
Packit 667938
=item B<--version>
Packit 667938
Packit 667938
Print the version of cfgmaker.  This should match the version of MRTG
Packit 667938
for which config files are being created.
Packit 667938
Packit 667938
=item B<--ifref> B<nr>|B<ip>|B<eth>|B<descr>|B<name>
Packit 667938
Packit 667938
Select the interface identification method.  Default is B<nr> which
Packit 667938
identifies the router interfaces by their number.  Unfortunately the
Packit 667938
interface numbering scheme in an SNMP tree can change. Some routers
Packit 667938
change their numbering when new interfaces are added, others change
Packit 667938
thier numbering every full moon just for fun.
Packit 667938
Packit 667938
To work around this sad problem MRTG can identify interfaces by 4
Packit 667938
other properties. None of these works for all interfaces, but you
Packit 667938
should be able to find one which does fine for you. Note that
Packit 667938
especially ethernet addrsses can be problematic as some routers have
Packit 667938
the same ethernet address on most of their interface cards.
Packit 667938
Packit 667938
Select B<ip> to identify the interface by its IP number. Use B<eth> to
Packit 667938
use the ethernet address for identification. Use B<descr> to use
Packit 667938
the Interface description. Or use B<name> to use the Interface name.
Packit 667938
Packit 667938
You can specify multiple properties if you wish, separated by commas.
Packit 667938
In this case, cfgmaker will use the first item in the list which
Packit 667938
can provide unique identification.  This allows you to specify, for
Packit 667938
example, to use IP address and to use ifName if this is not defined:
Packit 667938
  --ifref ip,name
Packit 667938
Packit 667938
If your chosen method does not allow unique interface identification on
Packit 667938
the device you are querying, B<cfgmaker> will tell you about it.
Packit 667938
Packit 667938
=item B<--ifdesc> B<nr>|B<ip>|B<eth>|B<descr>|B<name>|B<type>|B<alias>
Packit 667938
Packit 667938
Select what to use as the description of the interface.  The description
Packit 667938
appears in the C<Title[]> property for the target as well as the text header
Packit 667938
in the HTML code defined in the target's C<PageTop[]>.  Default is to use
Packit 667938
B<nr> which is just the interface number which isn't always useful
Packit 667938
to the viewer of the graphs.
Packit 667938
Packit 667938
There are 6 other properties which could be used.  Use B<ip> if you want
Packit 667938
to use the interface's IP-address.  Use B<eth> if you want to use the
Packit 667938
interface's ethernet address.  If you want a better description, you can
Packit 667938
use either B<descr>, B<name> or B<alias>.  Exactly what each of these do
Packit 667938
varies between different equipment so you might need to experiment.  For
Packit 667938
instance, for a serial interface on a Cisco router running IOS using B<name>
Packit 667938
might result in C<"S0"> being the interface description , B<descr> might result
Packit 667938
in C<"Serial0"> and B<alias> might result in C<"Link to HQ"> (provided that is
Packit 667938
what is used as the interface's C<description> in the router's configuration).
Packit 667938
Packit 667938
Finally, if you want to describe the interface by it's Btype
Packit 667938
(i.e C<"ethernetCSMA">, C<"propPointtoPoint"> etc) you can use B<type>.
Packit 667938
Packit 667938
You can specify multiple properties if you wish, separated by commas.
Packit 667938
In this case, cfgmaker will use the first item in the list which
Packit 667938
is available for this interface.  This allows you to specify, for
Packit 667938
example, to use any of the different aliases in order of preference.
Packit 667938
Packit 667938
=item B<--if-filter> 'B<filter-expression>'
Packit 667938
Packit 667938
First of all, this is under some development and is experimental.
Packit 667938
Packit 667938
Use this if you want to have better control over what interfaces gets
Packit 667938
included into the configuration.  The B<filter-expression> is evaluated
Packit 667938
as a piece of Perl code and is expected
Packit 667938
to return a truth value.  If true, include the interface and if false,
Packit 667938
exclude the interface.
Packit 667938
Packit 667938
For a further discussion on how these filters work, see the section
Packit 667938
L<Details on Filters> below.
Packit 667938
Packit 667938
=item B<--if-template> B<template-file>
Packit 667938
Packit 667938
First of all, this is under some development and is experimental.
Packit 667938
Packit 667938
Use this if you want to control what the line for each target should look
Packit 667938
like in the configuration file.  The contents of the file B<template-file>
Packit 667938
will be evaluated as a Perl program which generates the lines using certain
Packit 667938
variables for input and output.
Packit 667938
Packit 667938
For a further discussion on how these templates work, see the section
Packit 667938
L<Details on Temaplates> below.
Packit 667938
Packit 667938
=item B<--host-template> B<template-file>
Packit 667938
Packit 667938
First of all, this is under some development and is experimental.
Packit 667938
Packit 667938
Use this if you want to have some extra targets related to the host itself
Packit 667938
such as CPU utilization, ping response time to the host, number of busy
Packit 667938
modems etc.  The contents of the file B<template-file> will be evaluated
Packit 667938
once per host as a Perl program which generates the lines using certain
Packit 667938
variables for input and output.
Packit 667938
Packit 667938
For a further discussion on how these templates work, see the section
Packit 667938
L<Details on Templates> below.
Packit 667938
Packit 667938
=item B<--community> B<community-string>
Packit 667938
Packit 667938
Use this to set the community for the routers following on the command
Packit 667938
line to B<community-string>.  Individual routers might overrride this
Packit 667938
community string by using the syntax B<community>B<@>B<router>.
Packit 667938
Packit 667938
=item B<--enable-ipv6>
Packit 667938
Packit 667938
This option enables IPv6 support. It requires the appropriate perl
Packit 667938
modules; if they are not found then IPv6 is disabled (see the ipv6
Packit 667938
documentation).
Packit 667938
Packit 667938
cfgmaker will use IPv6 or IPv4 depending on the target. If the target
Packit 667938
is a numeric address, the protocol depends on the type of address. If the
Packit 667938
target is a hostname, cfgmaker will try to resolve the name first to an
Packit 667938
IPv6 address then to an IPv4 address.
Packit 667938
Packit 667938
IPv6 numeric addresses must be specified between square braces.
Packit 667938
Packit 667938
For example:
Packit 667938
Packit 667938
 cfgmaker --enable-ipv6 [2001:760:4::1]:165:::2
Packit 667938
Packit 667938
If the target has both an IPv6 address and an IPv4 address with the same
Packit 667938
hostname, cfgmaker first queries the target using IPv6 and falls back to
Packit 667938
IPv4 if it fails. This is useful for targets which don't support SNMP
Packit 667938
over IPv6.
Packit 667938
Packit 667938
=item B<--use-16bit>
Packit 667938
Packit 667938
This option forces the use of 16bit SNMP request IDs.  Some broken SNMP
Packit 667938
agents do not accept 32bit request IDs.  Try to avoid this option as much
Packit 667938
as possible, complain to your agent vendor instead.
Packit 667938
Packit 667938
=item B<--snmp-options>  :[B<port>][:[B<timeout>][:[B<retries>][:[B<backoff>][:B<version>]]]]
Packit 667938
Packit 667938
Use this to set the default SNMP options for all routers following on the
Packit 667938
command line.  Individual values might be omitted as well as trailing
Packit 667938
colons.  Note that routers might override individual (or all) values
Packit 667938
specified by B<--snmp-options> by using the syntax
Packit 667938
Packit 667938
B<router>[:[B<port>][:[B<timeout>][:[B<retries>][:[B<backoff>][:B<version>]]]]]
Packit 667938
Packit 667938
=item B<--global> B<">I<bla: abc>B<">
Packit 667938
Packit 667938
Use this to add global options to the generated config file.
Packit 667938
You can call B<--global> several times to add multiple options.
Packit 667938
The line will appear in the configuration just before the config for
Packit 667938
the next router appearing on the command line.
Packit 667938
Packit 667938
 --global "workdir: /home/mrtg"
Packit 667938
Packit 667938
If you want some default Options you might want to put
Packit 667938
Packit 667938
 --global "options[_]: growright,bits"
Packit 667938
Packit 667938
Specifying B<--global> after the last router on the command line will
Packit 667938
create a line in the configuration file which will appear after all the
Packit 667938
routers.
Packit 667938
Packit 667938
=item B<--noreversedns>
Packit 667938
Packit 667938
Do not try to reverse lookup IP numbers ... a must for DNS free environments.
Packit 667938
Packit 667938
=item B<--no-down>
Packit 667938
Packit 667938
Normally cfgmaker will not include interfaces which are marked
Packit 667938
anything but administratively and operationally UP. With this
Packit 667938
switch you get them all.
Packit 667938
Packit 667938
=item B<--show-op-down>
Packit 667938
Packit 667938
Include interfaces which are operatively down.
Packit 667938
Packit 667938
=item B<--zero-speed> I<speed>
Packit 667938
Packit 667938
Assign this speed in bits-per-second to all interfaces which return 0
Packit 667938
for ifSpeed and ifHighSpeed.  Some switches, notably Foundry equipment,
Packit 667938
return a speed of zero for some interfaces.  For example, to have
Packit 667938
all interfaces reporting zero set to 100Mbps, use
Packit 667938
--zero-speed=100000000.
Packit 667938
Packit 667938
=item B<--subdirs> I<format>
Packit 667938
Packit 667938
Give each router its own subdirectory for the HTML and graphics (or
Packit 667938
.rrd) files.  The directory name is the given I<format> string with a
Packit 667938
couple of pattern replacements.  The string "HOSTNAME" will be
Packit 667938
replaced by the hostname of the router (however you specified it on
Packit 667938
the B<cfgmaker> commandline -- it may be an actual hostname or just an
Packit 667938
IP address), and "SNMPNAME" will be replaced with the device's idea of
Packit 667938
its own name (the same name that appears on the right side of the
Packit 667938
"Title" lines).  For instance, a call like:
Packit 667938
Packit 667938
 cfgmaker --subdirs=HOSTNAME__SNMPNAME public@10.10.0.18
Packit 667938
Packit 667938
would result in the generation of lines looking something like:
Packit 667938
Packit 667938
 Directory[10.10.0.18_1]: 10.10.0.18__fp2200-bothrip-1.3
Packit 667938
Packit 667938
=item B<--output> I<file>
Packit 667938
Packit 667938
Write the output from B<cfgmaker> into the file I<file>. The default
Packit 667938
is to use C<STDOUT>. B<--output> is expected to appear only once on the
Packit 667938
command line. If used multiple times, the file specified by the last
Packit 667938
B<--output> will be used.
Packit 667938
Packit 667938
=item B<--nointerfaces>
Packit 667938
Packit 667938
Don't generate configuration lines for interfaces.
Packit 667938
Packit 667938
This makes cfgmaker skip all steps related to interfaces which means
Packit 667938
it will not do any polling of the router to retrieve interface
Packit 667938
information which speeds up the execution of cfgmaker and it will
Packit 667938
neither run any interface templates.
Packit 667938
Packit 667938
=item B<--interfaces>
Packit 667938
Packit 667938
This makes cfgmaker generate configuration lines for interfaces (the
Packit 667938
default behaviour).
Packit 667938
Packit 667938
The main usage of this option is to negate an --nointerfaces appearing
Packit 667938
earlier on the command line.
Packit 667938
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
=head2 SNMP V3 Options
Packit 667938
Packit 667938
B<Cfgmaker> supports SNMP V3 using the B<Net:SNMP> perl module.  There are optional 
Packit 667938
parameters affecting SNMP operation.
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item --enablesnmpv3 {yes|no}
Packit 667938
Packit 667938
The B<--enablesnmpv3> option is an optional flag to check for the presence of 
Packit 667938
the B<Net::SNMP> libraries.  B<Cfgmaker> will try to determine whether this flag is
Packit 667938
required and will set the values automatically.
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
=head3 SNMPv3 Arguments
Packit 667938
Packit 667938
A SNMP context is a collection of management information accessible by a SNMP
Packit 667938
entity.  An item of management information may exist in more than one context
Packit 667938
and a SNMP entity potentially has access to many contexts.  The combination of
Packit 667938
a contextEngineID and a contextName unambiguously identifies a context within
Packit 667938
an administrative domain.  In a SNMPv3 message, the contextEngineID and
Packit 667938
contextName are included as part of the scopedPDU.  All methods that generate
Packit 667938
a SNMP message optionally take a B<--contextengineid> and B<--contextname>
Packit 667938
argument to configure these fields.
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item Context Engine ID
Packit 667938
Packit 667938
The B<--contextengineid> argument expects a hexadecimal string representing
Packit 667938
the desired contextEngineID.  The string must be 10 to 64 characters (5 to
Packit 667938
32 octets) long and can be prefixed with an optional "0x".  Once the
Packit 667938
B<--contextengineid> is specified it stays with the object until it is changed
Packit 667938
again or reset to default by passing in the undefined value.  By default, the
Packit 667938
contextEngineID is set to match the authoritativeEngineID of the authoritative
Packit 667938
SNMP engine.
Packit 667938
Packit 667938
=item Context Name
Packit 667938
Packit 667938
The contextName is passed as a string which must be 0 to 32 octets in length
Packit 667938
using the B<--contextname> argument.  The contextName stays with the object
Packit 667938
until it is changed.  The contextName defaults to an empty string which
Packit 667938
represents the "default" context.
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
=head3 User-based Security Model Arguments
Packit 667938
Packit 667938
The User-based Security Model (USM) used by SNMPv3 requires that a securityName
Packit 667938
be specified using the B<--username> argument.  The creation of a Net::SNMP
Packit 667938
object with the version set to SNMPv3 will fail if the B<--username> argument
Packit 667938
is not present.  The B<--username> argument expects a string 1 to 32 octets
Packit 667938
in length.
Packit 667938
Packit 667938
Different levels of security are allowed by the User-based Security Model which
Packit 667938
address authentication and privacy concerns.  A SNMPv3 target will
Packit 667938
derive the security level (securityLevel) based on which of the following
Packit 667938
arguments are specified.
Packit 667938
Packit 667938
By default a securityLevel of 'noAuthNoPriv' is assumed.  If the B<--authkey>
Packit 667938
or B<--authpassword> arguments are specified, the securityLevel becomes
Packit 667938
'authNoPriv'.  The B<--authpassword> argument expects a string which is at
Packit 667938
least 1 octet in length.  Optionally, the B<--authkey> argument can be used so
Packit 667938
that a plain text password does not have to be specified in a script.  The
Packit 667938
B<--authkey> argument expects a hexadecimal string produced by localizing the
Packit 667938
password with the authoritativeEngineID for the specific destination device.
Packit 667938
The C<snmpkey> utility included with the Net::SNMP  distribution can be used to create
Packit 667938
the hexadecimal string (see L<snmpkey>).
Packit 667938
Packit 667938
Two different hash algorithms are defined by SNMPv3 which can be used by the
Packit 667938
Security Model for authentication.  These algorithms are HMAC-MD5-96 "MD5"
Packit 667938
(RFC 1321) and HMAC-SHA-96 "SHA-1" (NIST FIPS PUB 180-1).   The default
Packit 667938
algorithm used by the module is HMAC-MD5-96.  This behavior can be changed by
Packit 667938
using the B<--authprotocol> argument.  This argument expects either the string
Packit 667938
'md5' or 'sha' to be passed to modify the hash algorithm.
Packit 667938
Packit 667938
By specifying the arguments B<--privkey> or B<--privpassword> the securityLevel
Packit 667938
associated with the object becomes 'authPriv'.  According to SNMPv3, privacy
Packit 667938
requires the use of authentication.  Therefore, if either of these two
Packit 667938
arguments are present and the B<--authkey> or B<--authpassword> arguments are
Packit 667938
missing, the creation of the object fails.  The B<--privkey> and
Packit 667938
B<--privpassword> arguments expect the same input as the B<--authkey> and
Packit 667938
B<--authpassword> arguments respectively.
Packit 667938
Packit 667938
The User-based Security Model described in RFC 3414 defines a single encryption
Packit 667938
protocol to be used for privacy.  This protocol, CBC-DES "DES" (NIST FIPS PUB
Packit 667938
46-1), is used by default or if the string 'des' is passed to the
Packit 667938
B<--privprotocol> argument.  By working with the Extended Security Options
Packit 667938
Consortium http://www.snmp.com/eso/, the module also supports additional
Packit 667938
protocols which have been defined in draft specifications.  The draft
Packit 667938
http://www.snmp.com/eso/draft-reeder-snmpv3-usm-3desede-00.txt
Packit 667938
defines the support of CBC-3DES-EDE "Triple-DES" (NIST FIPS 46-3) in the
Packit 667938
User-based Security Model.  This protocol can be selected using the
Packit 667938
B<--privprotocol> argument with the string '3desede'.  The draft
Packit 667938
http://www.snmp.com/eso/draft-blumenthal-aes-usm-04.txt
Packit 667938
describes the use of CFB128-AES-128/192/256 "AES" (NIST FIPS PUB 197) in the
Packit 667938
USM. The three AES encryption protocols, differentiated by their key sizes,
Packit 667938
can be selected by passing 'aescfb128', 'aescfb192', or 'aescfb256' to the
Packit 667938
B<-privprotocol> argument.
Packit 667938
Packit 667938
=head2 Details on Filters
Packit 667938
Packit 667938
The purpose of the filters is to decide which interfaces to accept and
Packit 667938
which interfaces to reject.  This decision is done for each interface by
Packit 667938
evaluating the filter expression as a piece of Perl code and investigating
Packit 667938
the result of the evaluation.  If true, accept the interface otherwise
Packit 667938
reject it.
Packit 667938
Packit 667938
When working with filters, remember that Perl has it's own idea of what truth
Packit 667938
and false is.  The empty string "" and the string "0" are false, all other
Packit 667938
strings are true.  This further imples that any integer value of 0 is
Packit 667938
false as well as any undef value.  It also implies that all references
Packit 667938
are considered true.
Packit 667938
Packit 667938
As the filter is evaluated as a Perl expression, several useful constructs
Packit 667938
in Perl are worth mentioning:
Packit 667938
Packit 667938
Expressions might be grouped by using parentheses "()".  Expressions might
Packit 667938
be combined using boolean operators such as the following:
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item "B<and>" (equivalent with "B<&&>")
Packit 667938
Packit 667938
Boolean "and" of the two expressions, is only true if both expressions are
Packit 667938
true.  Example: I<expression1> B<and> I<expression2>
Packit 667938
Packit 667938
=item "B<or>" (equivalent with "B<||>")
Packit 667938
Packit 667938
Boolean "or" of the two expressions, is true if either or both expressions
Packit 667938
are true.  Example: I<expression1> B<or> I<expression2>
Packit 667938
Packit 667938
=item "B<not>" (equivalent with "B")
Packit 667938
Packit 667938
Boolean negation of a single expression.  Example:  B<not> I<expression> .
Packit 667938
Yet another example: BI<expression>
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
(For more details on this I recommend a book on Perl)
Packit 667938
Packit 667938
=head3 Predefined Filter Variables
Packit 667938
Packit 667938
To facilitate, there are a number of predefined values available to use
Packit 667938
in the filter.  Note that these variables are also available when templates
Packit 667938
interfaces are evaluated (but not host templates).
Packit 667938
Packit 667938
Caveat:  All these variables' names begin with a dollar sign  ($), which
Packit 667938
is a syntactic requirement for scalar variables in Perl.  The danger here
Packit 667938
is that the dollar sign in many shells is an active character (often
Packit 667938
used for shell variables exactly as in Perl variables) so it is important
Packit 667938
to ensure that the Perl expression isn't evaluated by the command line
Packit 667938
shell as shell code before being passed to cfgmaker as command line
Packit 667938
arguments.  In shells like Bourne shell, ksh shell or bash shell, placing
Packit 667938
the entire expression within single qoutes will avoid such accidental
Packit 667938
evaluation:
Packit 667938
Packit 667938
 '--if-filter=($default_iftype && $if_admin)'
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<$if_type>
Packit 667938
Packit 667938
This is an integer specifying the interface type as
Packit 667938
per the SNMP standards and as reported by the polled device.  A complete list
Packit 667938
of interface types would be impractical for this document , but there are
Packit 667938
a number predefined varables below.  Normally, cfgmaker puts in the target's
Packit 667938
PageTop this iftype value within paranthesis after the name of the interface
Packit 667938
type. (e.g "propPointToPointSerial (22)").
Packit 667938
Packit 667938
Here's a list of some of the most common interface types by number:
Packit 667938
Packit 667938
   6 ethernetCsmacd
Packit 667938
   7 iso88023Csmacd
Packit 667938
   9 iso88025TokenRing
Packit 667938
  15 fddi
Packit 667938
  19 E1
Packit 667938
  20 basicISDN
Packit 667938
  21 primaryISDN
Packit 667938
  22 propPointToPointSerial
Packit 667938
  23 ppp
Packit 667938
  24 softwareLoopback
Packit 667938
  30 ds3
Packit 667938
  32 frame-relay
Packit 667938
  33 rs232
Packit 667938
  37 atm
Packit 667938
  39 sonet
Packit 667938
  44 frameRelayService
Packit 667938
  46 hssi
Packit 667938
  49 aal5
Packit 667938
  53 propVirtual
Packit 667938
  62 Fast Ethernet (100BaseT)
Packit 667938
  63 ISDN & X.25
Packit 667938
  69 Full Duplex Fast Ethernet (100BaseFX)
Packit 667938
  94 Asymetric Digital Subscriber Loop (ADSL)
Packit 667938
 117 Gigabit Ethernet
Packit 667938
 134 ATM Sub Interface
Packit 667938
Packit 667938
=item B<$default>
Packit 667938
Packit 667938
True if and only if cfgmaker normally should
Packit 667938
accepted the interface based on the interfaces administrative and
Packit 667938
operational state (taking the flags B<--no-down> and B<--show-op-down> into
Packit 667938
account) and it's type (and a few other things).
Packit 667938
Packit 667938
=item B<$default_ifstate>
Packit 667938
Packit 667938
True if and only if cfgmaker would have accepted the
Packit 667938
interface based on it's operational and administrative states (also taking
Packit 667938
into account the presence of the flags B<--no-down> and B<--show-op-down>).
Packit 667938
Packit 667938
=item B<$default_iftype>
Packit 667938
Packit 667938
True if and only if cfgmaker would have accepted the
Packit 667938
interface based on it's type (and a few type specific details in addition).
Packit 667938
Packit 667938
=item B<$if_admin>
Packit 667938
Packit 667938
True if and only if the interface is in an adminstrative up
Packit 667938
state.
Packit 667938
Packit 667938
=item B<$if_oper>
Packit 667938
Packit 667938
True if and only if the interface is in an operational up
Packit 667938
state.
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
A number of variables are also predefined to easily decide if an interface
Packit 667938
belong to a certain cathegory or not.  Below is all those variables listed
Packit 667938
together with which if_type numbers each variable will be true for.  Note
Packit 667938
that some variables refer to other variables as well.
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<$if_is_ethernet>
Packit 667938
Packit 667938
True for ethernet interfaces (nr 6, 7, 26, 62, 69 and 117).
Packit 667938
Packit 667938
=item B<$if_is_isdn>
Packit 667938
Packit 667938
True for various ISDN interface types (nr 20, 21, 63, 75, 76 and 77)
Packit 667938
Packit 667938
=item B<$if_is_dialup>
Packit 667938
Packit 667938
True for dial-up interfaces such as PPP as well
Packit 667938
as ISDN.  (nr 23, 81, 82 and 108 in addition to the numbers of
Packit 667938
B<$if_is_isdn>).
Packit 667938
Packit 667938
=item B<$if_is_atm>
Packit 667938
Packit 667938
True for miscellaneous ATM related interface types (nr 37, 49, 107, 105,
Packit 667938
106, 114 and 134).
Packit 667938
Packit 667938
=item B<$if_is_wan>
Packit 667938
Packit 667938
True for WAN interfaces point to point, Frame Relay and High Speed Serial ( 22,32,44,46)
Packit 667938
Packit 667938
=item B<$if_is_lan>
Packit 667938
Packit 667938
True for LAN interfaces (8, 9, 11, 15, 26, 55, 59, 60 and 115 in addition
Packit 667938
to the numbers of B<$if_is_ethernet>).
Packit 667938
Packit 667938
=item B<$if_is_dsl>
Packit 667938
Packit 667938
True for ADSL, RDSL, HDSL and SDSL (nr 94, 95, 96, 97)
Packit 667938
Packit 667938
=item B<$if_is_loopback>
Packit 667938
Packit 667938
True for software loopback interfaces (nr 24)
Packit 667938
Packit 667938
=item B<$if_is_ciscovlan>
Packit 667938
Packit 667938
True for Cisco VLAN interfaces (interfaces with the
Packit 667938
word Vlan or VLAN in their ifdescs)
Packit 667938
Packit 667938
=item B<$if_vlan_id>
Packit 667938
Packit 667938
Returns the vlan id associated with a specific port
Packit 667938
on Cisco Catalyst switches under both Catalyst OS
Packit 667938
and IOS, and 3Com switches.  If it is not a vlan interface, will return undef.
Packit 667938
Packit 667938
=item B<$if_cisco_trunk>
Packit 667938
Packit 667938
Returns the trunking state of a specific port
Packit 667938
on Cisco Catalyst switches under both Catalyst OS
Packit 667938
and IOS.  Returns "1" if the interface is a trunk, undef otherwise.
Packit 667938
Packit 667938
=item B<$if_MTU>
Packit 667938
Packit 667938
Returns the Maximum Transfer Unit associated with a specific port.
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
Besides that, you can also use the variables defined for templates below.
Packit 667938
Further, all the variables available in cfgmaker is at the scripts disposal
Packit 667938
even if the use of such features is discouraged.  More "shortcuts" in the
Packit 667938
form of variables and functions will be made available in the future instead.
Packit 667938
Packit 667938
=head3 Examples on Filters
Packit 667938
Packit 667938
The following filter will not affect which interfaces get's included or
Packit 667938
excluded, it will make cfgmaker behave as normally.
Packit 667938
Packit 667938
 '--if-filter=$default'
Packit 667938
Packit 667938
The following filter will make cfgmaker exclude PPP (23) interfaces:
Packit 667938
Packit 667938
 '--if-filter=$default && $if_type!=23'
Packit 667938
Packit 667938
The following filter will make cfgmaker behave as usual except that it will
Packit 667938
consider the operational state of an interface irrelevant but still reject
Packit 667938
all interfaces which are administratively down.
Packit 667938
Packit 667938
 '--if-filter=$if_admin && $default_iftype'
Packit 667938
Packit 667938
=head2 Details on Templates
Packit 667938
Packit 667938
The contents of the template files are evaluated as a Perl program.  A
Packit 667938
number or Perl variables are available for the program to read and others
Packit 667938
are used to be written to.
Packit 667938
Packit 667938
As quite a few of the predefined variables has values which are are supposed
Packit 667938
to be used in HTML code some of them have an "HTML-escaped" variant, e.g
Packit 667938
$html_syslocation is the HTML escaped variant of $syslocation.  The HTML
Packit 667938
escaping means that the chars "<", ">" and "&" are replaced by "<",
Packit 667938
">" and "&" and that newlines embedded in the string are prepended
Packit 667938
with "
" and appended with a space character (if a newline is last in the
Packit 667938
string it is not touched).
Packit 667938
Packit 667938
=head3 Writable Template Variables
Packit 667938
Packit 667938
These are the variables available to store the configuration lines in.
Packit 667938
Some of them are initialized prior to the evaluation of the template but
Packit 667938
such content normally is comments for inclusion in the final configuration
Packit 667938
file so those variables might be reset to the empty string in the template
Packit 667938
code to eliminate the comments.  The other way around is also possible, the
Packit 667938
contents of these variables might be extended with further information
Packit 667938
for various reasons such as debugging etc.
Packit 667938
Packit 667938
Once the template has been evaluated, the following happens:  if the
Packit 667938
template is a interface template and the actual interface for some reason
Packit 667938
is rejected and thus needs to be commented out, all the lines in the
Packit 667938
variable B<$target_lines> are turned into comments by adding a hash mark
Packit 667938
("#") at their beginning.  Then all the variables B<$head_lines>,
Packit 667938
B<$problem_lines> , B<$target_lines> and B<$separator_lines>
Packit 667938
are concatenated together to form the lines to add to the configuration file.
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<$target_lines>
Packit 667938
Packit 667938
This variable is the placeholder for the configuration lines created
Packit 667938
by the template.  B<$target_lines> is predefined to be empty when
Packit 667938
the template code is evaluated.
Packit 667938
Packit 667938
=item B<$head_lines>
Packit 667938
Packit 667938
This variable is intended to be the placeholder for the comment line
Packit 667938
appearing just before the target in the configuration file.  It is
Packit 667938
initialized with that comment line before the evaluation of the template
Packit 667938
code and if the template doesn't modify B<$head_lines> during evaluation,
Packit 667938
the comment will look like usual in the config file.
Packit 667938
Packit 667938
=item B<$problem_lines>
Packit 667938
Packit 667938
This variable is intended to be the placholder for the comment lines
Packit 667938
describing any problems which might have been encountered when trying
Packit 667938
to add the target into the configuration.  For host templates it's
Packit 667938
normally not used and for those it's predefined as the empty string.
Packit 667938
For interface templates B<$problem_lines> is predefined with
Packit 667938
the error description comments which cfgmaker normally would use for
Packit 667938
rejected interfaces or as the empty string for accepted interfaces.
Packit 667938
Packit 667938
It is possible to test against B<$problem_lines> to find out if
Packit 667938
an interface will be included or rejected but this is not recommended.
Packit 667938
Test against B<$if_ok> instead.
Packit 667938
Packit 667938
=item B<$separator_lines>
Packit 667938
Packit 667938
This variable is the placeholder for the string to use as the separator
Packit 667938
between the code for individual targets.  The contents of this variable
Packit 667938
is put after each target (so the lines will appear after the end of the
Packit 667938
last target in the config as well).
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
=head3 Predefined Template Variables
Packit 667938
Packit 667938
All the variables below are available for interface templates to use.
Packit 667938
For host templates, only those listed under L<Host and System Variables>
Packit 667938
are available.
Packit 667938
Packit 667938
For interface templates the variables listed under
Packit 667938
L<Predefined Filter Variables> are also available.
Packit 667938
Packit 667938
=head3 Host and System Variables
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<$router_name>
Packit 667938
Packit 667938
This is the fully qualified name for the router.  It is affected by the
Packit 667938
following items on the command line:  the router name itself and
Packit 667938
B<--dns-domain>.
Packit 667938
Packit 667938
=item B<$router_connect>
Packit 667938
Packit 667938
This is the reference string for the router being polled.  It is on the
Packit 667938
form community@router possibly followed by some snmp options.  It is
Packit 667938
affected by the following items on the command line:  the router name
Packit 667938
itself, B<--community>, B<--snmp-options> and B<--dns-domain>.
Packit 667938
(There's no HTML escaped variant available)
Packit 667938
Packit 667938
=item B<$directory_name>
Packit 667938
Packit 667938
This variable should contain the directory name as cfgmaker normally would
Packit 667938
use as the value for the "Directory[]" directive.  The value is determined
Packit 667938
by the B<--subdirs> command line option.  If B<--subdirs> isn't specified
Packit 667938
B<$directory_name> will be the empty string.  (There's no HTML escaped
Packit 667938
variant available)
Packit 667938
Packit 667938
=item B<$syscontact>
Packit 667938
Packit 667938
This variable is the router's SNMP sysContact value.  (HTML escaped
Packit 667938
variant: B<$html_syscontact>)
Packit 667938
Packit 667938
=item B<$sysname>
Packit 667938
Packit 667938
This variable is the router's SNMP sysName value.  (No HTML escaped
Packit 667938
variant available)
Packit 667938
Packit 667938
=item B<$syslocation>
Packit 667938
Packit 667938
This variable is the router's SNMP sysLocation value.  (HTML escaped
Packit 667938
variant: B<$html_syslocation>)
Packit 667938
Packit 667938
=item B<$sysdescr>
Packit 667938
Packit 667938
This variable is the router's SNMP sysDescr value.  It is normally not used
Packit 667938
by cfgmaker but might be useful in a template.  (HTML escaped variant:
Packit 667938
B<$html_sysdescr>)
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
=head3 Interface Target Related Variables
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<$target_name>
Packit 667938
Packit 667938
This is what cfgmaker normally would use as the the name of the target.
Packit 667938
The target name is what is found within the square brackets, "[]", for target
Packit 667938
directives.  (There's no HTML escaped variant available)
Packit 667938
Packit 667938
=item B<$if_ref>
Packit 667938
Packit 667938
This the reference string for the interface.  It is expected to be used
Packit 667938
in the "Target[xyz]" directive to distinguish what interface to use.  The
Packit 667938
value of this variable is affected by the B<--ifref> command line option.
Packit 667938
It is normally used together with B<$router_connect>.
Packit 667938
(There's no HTML escaped variant available)
Packit 667938
Packit 667938
=item B<$if_ok>
Packit 667938
Packit 667938
This variable is true if the interface is going to be included into the
Packit 667938
configuration file, otherwise false.  Don't test against other variables
Packit 667938
such as B<$problem_lines> to find out if an interface will be rejected
Packit 667938
or not, use this B<$if_ok> instead.
Packit 667938
Packit 667938
=item B<$default_target_lines>
Packit 667938
Packit 667938
This variable contains all the target lines which cfgmaker by default outputs
Packit 667938
for this interface.  It's useful if you want to have the "standard target"
Packit 667938
but want to add some extra lines to it by using a template.
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
By default cfgmaker uses the following directives for each target it
Packit 667938
generates: Target[], SetEnv[], MaxBytes[], Title[], PageTop[] and if
Packit 667938
there is any directory specified also the Directory[] directive.
Packit 667938
Packit 667938
To facilitate the creation of templates which generates target configs
Packit 667938
which are similar to the default one, each of the above mentioned
Packit 667938
directive lines have a corresponding variable containing the line as
Packit 667938
cfgmaker would have output it by default.
Packit 667938
Packit 667938
Note that none of these have a HTML escaped variant, text in them is
Packit 667938
HTML escaped where needed.  Also note that they do not have any newline
Packit 667938
at the end.
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<$default_target_directive>
Packit 667938
Packit 667938
This variable contains the default string for the Target[] directive line.
Packit 667938
Packit 667938
=item B<$default_setenv_directive>
Packit 667938
Packit 667938
This variable contains the default string for the SetEnv[] directive line.
Packit 667938
Packit 667938
=item B<$default_directory_directive>
Packit 667938
Packit 667938
This variable contains the default string for the Directory[] directive line
Packit 667938
which means it is an empty string (with no newline) if there's no directory.
Packit 667938
Packit 667938
=item B<$default_maxbytes_directive>
Packit 667938
Packit 667938
This variable contains the default string for the MaxBytes[] directive line.
Packit 667938
Packit 667938
=item B<$default_title_directive>
Packit 667938
Packit 667938
This variable contains the default string for the Title[] directive line.
Packit 667938
Packit 667938
=item B<$default_pagetop_directive>
Packit 667938
Packit 667938
This variable contains the default string for the PageTop[] directive lines.
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
=head3 Interface Network Configuration Variables
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<$if_ip>
Packit 667938
Packit 667938
This variable should contain the IP-address of the interface, if any has
Packit 667938
been assigned to it.  (There's no HTML escaped variant available)
Packit 667938
Packit 667938
=item B<$ifindex>
Packit 667938
Packit 667938
This variable is the SNMP ifIndex for the interface which per definition
Packit 667938
always is an integer.  (There's no HTML escaped variant available)
Packit 667938
Packit 667938
=item B<$if_index>
Packit 667938
Packit 667938
Equivalent with B<$ifindex>.
Packit 667938
Packit 667938
=item B<$if_eth>
Packit 667938
Packit 667938
Contains the ethernet address of the interface, if any.  (There's no HTML
Packit 667938
escaped variant available)
Packit 667938
Packit 667938
=item B<$if_speed>
Packit 667938
Packit 667938
This variable is the speed in bytes/second (with prefixes).  (There's no
Packit 667938
HTML escaped variant available)
Packit 667938
Packit 667938
=item B<$if_speed_str>
Packit 667938
Packit 667938
This variable is a cooked speed description which is either in bits or
Packit 667938
bytes depending on wether or not the bits option is active and also with
Packit 667938
the proper prefix for the speed (k, M, G etc).  (No HTML escaped variant
Packit 667938
available)
Packit 667938
Packit 667938
=item B<$if_type_desc>
Packit 667938
Packit 667938
This variable is a textual description of the interface type.  (HTML
Packit 667938
escaped variant: B<$html_if_type_desc>)
Packit 667938
Packit 667938
=item B<$if_type_num>
Packit 667938
Packit 667938
This variable the integer value corresponding to the interface type (for a
Packit 667938
listing for the value for the more common interface types, see the section
Packit 667938
DETAILS ON FILTERS above).  (No HTML escaped variant available)
Packit 667938
Packit 667938
=item B<$if_dns_name>
Packit 667938
Packit 667938
This is the DNS name for the interface.  (No HTML escaped variant available)
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
=head3 Interface Name, Description and Alias Variables
Packit 667938
Packit 667938
It might seem confusing with both I<Name>, I<Description> and I<Alias> in
Packit 667938
this context and to some extent it is.  I<Name> and I<Description> are
Packit 667938
usually supported on most equipment but how they are used varies, both
Packit 667938
between manufacturers as well as between different cathegories of equipment
Packit 667938
from the same manufacturer.  The I<Alias> is at least supported by Cisco
Packit 667938
IOS, and that variable contains whatever is used in the IOS statement
Packit 667938
called "description" for the interface (not to be confused with the SNMP
Packit 667938
variables for I<Description>).
Packit 667938
Packit 667938
For better control from the command line consider B<$if_title_desc> which contents
Packit 667938
are controlled by the B<--if-descr> command line option.
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<$if_snmp_descr>
Packit 667938
Packit 667938
This variable should contain the "raw" description of the interface as
Packit 667938
determined by the SNMP polling of the router.  (HTML escaped variant:
Packit 667938
B<$html_if_snmp_descr>)
Packit 667938
Packit 667938
=item B<$if_snmp_name>
Packit 667938
Packit 667938
The "raw" name for the interface as provided by SNMP polling.  (HTML escaped
Packit 667938
variant: B<$html_if_snmp_name>)
Packit 667938
Packit 667938
=item B<$if_snmp_alias>
Packit 667938
Packit 667938
The "raw" ifAlias for the interface as provided by SNMP polling. (HTML
Packit 667938
escaped variant: B<$html_if_snmp_alias>)
Packit 667938
Packit 667938
=item B<$if_cisco_descr>
Packit 667938
Packit 667938
The "raw" CiscolocIfDescr for the interface as provided by SNMP polling.
Packit 667938
(HTML escaped variant: B<$html_if_cisco_descr>)
Packit 667938
Packit 667938
=item B<$if_description>
Packit 667938
Packit 667938
This is the "cooked" description string for the interface, taking into account
Packit 667938
the SNMP values found for the interface's RDescr, ifAlias and
Packit 667938
CiscolocIfDescr.  (HTML escaped variant: B<$html_if_description>)
Packit 667938
Packit 667938
=item B<$if_title>
Packit 667938
Packit 667938
The full string cfgmaker by default would have used for the Title[] directive
Packit 667938
in the configuration as well as the content of the topmost H1 tag in the
Packit 667938
PageTop[].  Is composed by the contents of B<$desc_prefix>,
Packit 667938
B<$if_title_desc> and B<$sysname>.
Packit 667938
Packit 667938
As B<$if_title> depends on B<$if_title_desc>, it is possible to indirectly
Packit 667938
control B<$if_title> by using the command line option B<--if-descr>.
Packit 667938
Packit 667938
(HTML escaped variant: B<$html_if_title>)
Packit 667938
Packit 667938
=item B<$if_port_name>
Packit 667938
Packit 667938
If the host is a Cisco Catalyst LAN switch, this variable is the name of
Packit 667938
that port.  (No HTML escaped variant available)
Packit 667938
Packit 667938
=item B<$if_pp_port_name>
Packit 667938
Packit 667938
If the host is a Nortel Passport LAN switch, this variable is the name of
Packit 667938
that port.  (No HTML escaped variant available)
Packit 667938
Packit 667938
=item B<$desc_prefix>
Packit 667938
Packit 667938
This variable is a prefix of the description of what the target is to use in
Packit 667938
the "Title[]" directive and in the H1 section of the "PageTop[]".  Default is
Packit 667938
"Traffic analysis for ".  (HTML escaped variant: B<$html_desc_prefix>)
Packit 667938
Packit 667938
=item B<$if_title_desc>
Packit 667938
Packit 667938
This is the description of the interface normally used by cfgmaker as part
Packit 667938
of the variable B<$if_title>.  The latter is used as the full string in the
Packit 667938
"Title[]" directove and the H1 section in the PageTop[].
Packit 667938
Packit 667938
B<$if_title_desc> is controlled by the command line option B<--if-descr>
Packit 667938
which indirectly controls the contents of B<$if_title>
Packit 667938
Packit 667938
(HTML escaped variant: B<$html_if_title_desc>)
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
=head3 Help Functions for Templates
Packit 667938
Packit 667938
The following functions exists to facilitate the writing of host and
Packit 667938
interface templates.
Packit 667938
Packit 667938
=over
Packit 667938
Packit 667938
=item B<html_escape(I<string>)>
Packit 667938
Packit 667938
B<html_escape()> takes a string as an argument and returns a new string
Packit 667938
where the following substitutions has been done:  the chars "<", ">" and
Packit 667938
"&" are replaced by "<", ">" and "&" and that newlines embedded
Packit 667938
in the string are prepended with "
" and appended with a space character
Packit 667938
(newlines at the end of the string are not touched).
Packit 667938
Packit 667938
=item B<oid_pick($router_connect,$v3opt,"oid1","oid2"...)>
Packit 667938
Packit 667938
This function will try to poll each of the oids specified until
Packit 667938
it is successful or has run out of oids. It will return the name of the
Packit 667938
first oid that worked or undef if it is not successful
Packit 667938
Packit 667938
=back
Packit 667938
Packit 667938
=head3 Example Template Files
Packit 667938
Packit 667938
=head4 Template Example 1: Eliminating Rejected Targets From Appearing
Packit 667938
Packit 667938
This template file generates exactly the same configuration code per
Packit 667938
interface as cfgmaker does by default, with the exception that it eliminates
Packit 667938
all lines (comments as well as config code) for an interface if the
Packit 667938
interface happens to be rejected.
Packit 667938
Packit 667938
 if(not $problem_lines)
Packit 667938
 {
Packit 667938
   $target_lines .= <
Packit 667938
Packit 667938
 Target[$target_name]: $if_ref:$router_connect
Packit 667938
 SetEnv[$target_name]: MRTG_INT_IP="$if_ip" MRTG_INT_DESCR="$if_snmp_descr"
Packit 667938
 ECHO
Packit 667938
Packit 667938
   if ($directory_name) {
Packit 667938
       $target_lines .= "Directory[$target_name]: $directory_name\n";
Packit 667938
   }
Packit 667938
Packit 667938
   $target_lines .= <
Packit 667938
 MaxBytes[$target_name]: $if_speed
Packit 667938
 Title[$target_name]: $html_desc_prefix$html_if_title_desc -- $sysname
Packit 667938
 PageTop[$target_name]: 

$html_desc_prefix$html_if_title_desc -- $sysname

Packit 667938
		
Packit 667938
			
Packit 667938
				
Packit 667938
					System:
Packit 667938
					$sysname in $html_syslocation
Packit 667938
				
Packit 667938
				
Packit 667938
					Maintainer:
Packit 667938
					$html_syscontact
Packit 667938
				
Packit 667938
				
Packit 667938
					Description:
Packit 667938
					$html_if_description
Packit 667938
				
Packit 667938
				
Packit 667938
					ifType:
Packit 667938
					$html_if_type_desc ($if_type_num)
Packit 667938
				
Packit 667938
				
Packit 667938
					ifName:
Packit 667938
					$html_if_snmp_name
Packit 667938
				
Packit 667938
 ECHO
Packit 667938
Packit 667938
   $target_lines .= <
Packit 667938
				
Packit 667938
					Port Name:
Packit 667938
					$if_port_name
Packit 667938
				
Packit 667938
 ECHO
Packit 667938
Packit 667938
   $target_lines .= <
Packit 667938
				
Packit 667938
					Port Name:
Packit 667938
					$if_pp_port_name
Packit 667938
				
Packit 667938
 ECHO
Packit 667938
Packit 667938
   $target_lines .= <
Packit 667938
				
Packit 667938
					Max Speed:
Packit 667938
					$if_speed_str
Packit 667938
				
Packit 667938
 ECHO
Packit 667938
Packit 667938
   $target_lines .= <
Packit 667938
				
Packit 667938
					Ip:
Packit 667938
					$if_ip ($if_dns_name)
Packit 667938
				
Packit 667938
 ECHO
Packit 667938
Packit 667938
   $target_lines .= <
Packit 667938
			
Packit 667938
		
Packit 667938
 ECHO
Packit 667938
 } else {
Packit 667938
   $head_lines="";
Packit 667938
   $problem_lines="";
Packit 667938
   $target_lines="";
Packit 667938
   $separator_lines="";
Packit 667938
 }
Packit 667938
Packit 667938
=head3 Template Example 2: Simplier Version of Example 1
Packit 667938
Packit 667938
Example 1 was partly intended to demonstrate how to customize the generation
Packit 667938
of interface targets but also to provide a hint of how the variables are
Packit 667938
used in the "default" template which one could consider that cfgmaker
Packit 667938
normally uses.
Packit 667938
Packit 667938
If you're only intrested in the easiest way of entirely eliminating those
Packit 667938
reject interfaces, the template below would do the job as well by using
Packit 667938
B<$default_target_lines>.
Packit 667938
Packit 667938
 if($if_ok) {
Packit 667938
  $target_lines = $default_target_lines;
Packit 667938
 } else {
Packit 667938
   $head_lines="";
Packit 667938
   $problem_lines="";
Packit 667938
   $target_lines="";
Packit 667938
   $separator_lines="";
Packit 667938
 }
Packit 667938
Packit 667938
=head3 Template Example 3: Creating CPU Targets for Hosts
Packit 667938
Packit 667938
Below is an example of a host template.
Packit 667938
Packit 667938
 $head_lines .= <
Packit 667938
 #---------------------------------------------------------------------
Packit 667938
 ECHO
Packit 667938
Packit 667938
 my $target_name = $router_name . ".cpu";
Packit 667938
Packit 667938
 $target_lines .= <
Packit 667938
Packit 667938
 YLegend[$target_name]: Percentage CPU load
Packit 667938
 ShortLegend[$target_name]: %
Packit 667938
 Legend1[$target_name]: CPU load in %
Packit 667938
 Legend2[$target_name]:
Packit 667938
 Legend3[$target_name]: Max Observed CPU load
Packit 667938
 Legend4[$target_name]:
Packit 667938
 LegendI[$target_name]:  CPU Load:
Packit 667938
 LegendO[$target_name]:
Packit 667938
 WithPeak[$target_name]: ywm
Packit 667938
 MaxBytes[$target_name]: 100
Packit 667938
 Options[$target_name]: growright, gauge, nopercent
Packit 667938
 Title[$target_name]: $router_name CPU load
Packit 667938
 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
Packit 667938
 PageTop[$target_name]: 

$router_name CPU load

Packit 667938
		
Packit 667938
			
Packit 667938
				
Packit 667938
					System:
Packit 667938
					$router_name in $html_syslocation
Packit 667938
				
Packit 667938
				
Packit 667938
					Maintainer:
Packit 667938
					$html_syscontact
Packit 667938
				
Packit 667938
				
Packit 667938
					Description:
Packit 667938
					$html_sysdescr
Packit 667938
				
Packit 667938
				
Packit 667938
					Resource:
Packit 667938
					CPU.
Packit 667938
				
Packit 667938
			
Packit 667938
		
Packit 667938
 ECHO
Packit 667938
Packit 667938
Packit 667938
=head1 EXAMPLES
Packit 667938
Packit 667938
The first example creates a config file for I<router.place.xyz>:  the router
Packit 667938
has the community name I<public>.  Interfaces get identified by their
Packit 667938
IP number.  Two global options get added to the config file.  The
Packit 667938
config file gets redirected to I<mrtg.conf>.  The '\' signs at the end
Packit 667938
of the line mean that this command should be written on a single line.
Packit 667938
Packit 667938
 cfgmaker --global "WorkDir: /home/tobi"           \
Packit 667938
          --global "Options[_]: growright,bits"    \
Packit 667938
          --ifref=ip                               \
Packit 667938
          public@router.place.xyz > mrtg.cfg
Packit 667938
Packit 667938
Note: if cfgmaker is not in your path, but you are in the directory where
Packit 667938
cfgmaker is stored, you can start it with ./cfgmaker
Packit 667938
Packit 667938
The next example creates a config file for four devices:
Packit 667938
I<router1.place.xyz>, I<router2.place.xyz>, I<switch1.place.xyz> and
Packit 667938
I<switch2.place.xyz> all with the community I<public>.
Packit 667938
Packit 667938
The two routers will have B<--ifref> set to B<descr> whilst the two
Packit 667938
switches will use B<--ifref> set to B<name>.  Further the routers will
Packit 667938
use B<--ifdesc> set to B<alias> and I<switch1.place.xyz> will use
Packit 667938
B<--ifdesc> set to B<descr> whilst I<switch2.place.xyz> use B<name> instead.
Packit 667938
Packit 667938
Finally, there will be two Options lines inserted in the configuration:
Packit 667938
One will be in the beginning, whilst the other will be inserted after
Packit 667938
the lines related to the two routers but before those lines related
Packit 667938
to the switches.
Packit 667938
Packit 667938
 cfgmaker --global "WorkDir: /home/tobi"           \
Packit 667938
          --global "Options[_]: growright,bits"    \
Packit 667938
          --ifref=descr                            \
Packit 667938
          --ifdesc=alias                           \
Packit 667938
          public@router1.place.xyz                 \
Packit 667938
          public@router2.place.xyz                 \
Packit 667938
          --global "Options[_]: growright"         \
Packit 667938
          --ifref=name                             \
Packit 667938
          --ifdesc=descr                           \
Packit 667938
          public@switch1.place.xyz                 \
Packit 667938
          --ifdesc=name                            \
Packit 667938
          public@switch2.place.xyz > mrtg.cfg
Packit 667938
Packit 667938
Packit 667938
The next example demonstrates how to use the B<--community>,
Packit 667938
B<--snmp-options> and B<--dns-domain> to make the command line
Packit 667938
simpler.  All the equipment will use the community I<hidden>, except for
Packit 667938
the ppp-server which use community I<access>.  All equipment uses these
Packit 667938
SNMP options: B<1s timeout>, B<1 retry> and B<SNMP version 2> (B<backoff> and
Packit 667938
B<port> is unspecified which means they use the default values).
Packit 667938
The exception again is the ppp-server which uses B<SNMP version 1>.
Packit 667938
Finally, all the equipment is part of the domain I<place.xyz>, except
Packit 667938
for the ppp-server which is part of the domain I<remote.place.xyz>.
Packit 667938
Note that the latter is achieved simply by specifying the name
Packit 667938
of the ppp-server to be I<ppp-server.B<remote>> .
Packit 667938
Packit 667938
 cfgmaker --global "WorkDir: /home/tobi"           \
Packit 667938
          --global "Options[_]: growright,bits"    \
Packit 667938
          --dns-domain=place.xyz                   \
Packit 667938
          --community=hidden                       \
Packit 667938
          --snmp-options=::1:1::2                  \
Packit 667938
          router1                                  \
Packit 667938
          router2                                  \
Packit 667938
          router3                                  \
Packit 667938
          router4                                  \
Packit 667938
          router5                                  \
Packit 667938
          switch1                                  \
Packit 667938
          switch2                                  \
Packit 667938
          switch3                                  \
Packit 667938
          switch4                                  \
Packit 667938
          switch5                                  \
Packit 667938
          switch6                                  \
Packit 667938
          switch7                                  \
Packit 667938
          access@ppp-server.remote:::::1 > mrtg.cfg
Packit 667938
Packit 667938
Packit 667938
=head1 SEE ALSO
Packit 667938
Packit 667938
L<mrtg-reference>
Packit 667938
Packit 667938
=head1 AUTHOR
Packit 667938
Packit 667938
Tobias Oetiker E<lt>tobi@oetiker.chE<gt> and
Packit 667938
Jakob Ilves E<lt>jakob.ilves@oracle.comE<gt>
Packit 667938
Packit 667938
Packit 667938
=head1 LICENSE
Packit 667938
Packit 667938
GNU General Public License
Packit 667938
Packit 667938
=head1 COPYRIGHT
Packit 667938
Packit 667938
Cfgmaker is Copyright 2000 by Tobias Oetiker E<lt>tobi@oetiker.chE<gt>
Packit 667938
Packit 667938
=cut