Blame contrib/mrtg-dynip/mrtg-dynip-sydnet

Packit 667938
#!/usr/local/bin/perl
Packit 667938
##################################################################
Packit 667938
# Multi Dynamic IP Traffic Grapher contibution to mrtg
Packit 667938
##################################################################
Packit 667938
#
Packit 667938
# Created by John Heenan <john@heenan.ironbark.id.au>
Packit 667938
#
Packit 667938
# Available from http://www.heenan.ironbark.id.au/mrtg-dynip
Packit 667938
#
Packit 667938
##################################################################
Packit 667938
#
Packit 667938
# Distributed under the GPL copyleft of GNU
Packit 667938
#
Packit 667938
# mrtg-dynip, v 0.41b 1997/10/25
Packit 667938
# 
Packit 667938
# Copyright John Heenan, with exception of datestr subroutine
Packit 667938
# (copied from mrtg executable) and much of internal_walk
Packit 667938
# subroutine (manner of using snmp modules copied from an example
Packit 667938
# by Simon Lenine)
Packit 667938
#
Packit 667938
###################################################################
Packit 667938
Packit 667938
#Mrtg-dynip is a contribution to MRTG, enabling MRTG to generate multi
Packit 667938
#interface traffic graphs for IP interfaces on hosts that do not provide
Packit 667938
#consistent SNMP target numbers for their interfaces.  Such IP interfaces
Packit 667938
#include IP active serial interfaces attached to modems in a PPP dial in
Packit 667938
#environment. The hosts must run snmp agents.  For completeness, information
Packit 667938
#about interface devices with unvarying SNMP target numbers, such as
Packit 667938
#ethernet cards, can be configured to be included.
Packit 667938
Packit 667938
#Mrtg-dynip's configuration is simplest where static (or fixed) IP is not
Packit 667938
#used for dial into a rotary modem pool.
Packit 667938
Packit 667938
#Mrtg-dynip can be considred to have sophisticated modem bank monitoring
Packit 667938
#capacity, when the modems carry PPP or SLIP traffic.
Packit 667938
Packit 667938
#Regenerates a named 'mrtg.cfg' file to ensure snmp data remains with a
Packit 667938
#consistent IP number, or overridable IP number of a real physical device
Packit 667938
#in a dial in IP environment, rather than with an interface name which
Packit 667938
#can get assinged to different real physical devices, and runs mrtg on
Packit 667938
#the generated file.
Packit 667938
Packit 667938
#Generates a web index file of stats web pages. 
Packit 667938
Packit 667938
#Please see the section 6 of the FAQ for this version for information on
Packit 667938
#for differences in interpreting graphs between some devices
Packit 667938
Packit 667938
#Briefly, to someone dialling in, dynamic IP means when they dial a rotary 
Packit 667938
#number they do not get a consistent IP address. To the service provider it 
Packit 667938
#means a unique IP number is assinged to each telephone line/modem/port.
Packit 667938
Packit 667938
#To someone dialling in, static or fixed IP means that their user name is
Packit 667938
#approved to use a unique IP address, whether they dial into a rotary for
Packit 667938
#a modem bank or into a non rotary number.  To the service provider, it means
Packit 667938
#if someone is dialling into a rotary for a modem pool, they allow the modem
Packit 667938
#port use a unique approved IP number for that user, that overrides the IP
Packit 667938
#address used when a dial in user does not request a fixed or static IP.
Packit 667938
Packit 667938
#The public community should be used, however the public community on a
Packit 667938
#particular host does not need to be named 'public'.  This is catered for.
Packit 667938
Packit 667938
#There is a large 'TODO' list for this contribution, including 
Packit 667938
#testing use of the 'ifLastChange' snmp object.
Packit 667938
Packit 667938
#SET UP
Packit 667938
Packit 667938
#Runs independently of an existing configured mrtg installation.  Following
Packit 667938
#the commented example will make the set up clearer.  The examples are for a
Packit 667938
#live ISP using web page http://www.stats.syd.net.au, you must change values
Packit 667938
#for your own use
Packit 667938
 
Packit 667938
#  0   Ensure the path to the perl binary is set correctly on first line
Packit 667938
#  1   $HTTP_Work_Dir         ** Must set
Packit 667938
#  2   $HTTP_index_file       Default index.html may be OK if unique
Packit 667938
#  3   $mrtg_Dir              ** Must set
Packit 667938
#  4   $mrtgcfg_Dir           Setting to $mrtgDir is probably OK
Packit 667938
#  5   $mrtgcfg_file          Default mrtg-dynip.cfg should be OK
Packit 667938
#  6   $update		      Default will work (five minutes)
Packit 667938
#  7   $community_default     Default for this default may be OK (public)
Packit 667938
#  8   $email		      Set to "" to show nothing
Packit 667938
#  9   $home_page	      Set to "" to show nothing
Packit 667938
# 10   $home_page_descr       Set to "" to show nothing
Packit 667938
# 11   $suicidal              Non zero: bomb out if there are problems
Packit 667938
# 12   $firewall_masq_tran_if Best to leave as 0 (zero) if sufficient
Packit 667938
# 13   $use_non_dyn_IP_for_tty Safe to set to 0 (the non set value)
Packit 667938
# 14   $Dir_PID		      Must set if 13 is non zero
Packit 667938
# 15   External settings if 13 is set to non zero
Packit 667938
# 16   $interfaces             ** Must set
Packit 667938
Packit 667938
#Ensure mrtg-dynip has executable permission.  See below as to where
Packit 667938
#mrtg-dynip may need to be installed.
Packit 667938
Packit 667938
#Place a crontab entry, consistent with update time, similar to
Packit 667938
#0,5,10,15,20,25,30,35,40,45,50,55 * * * *  <next line continued here> 
Packit 667938
#cd /usr/src/mrtg/mrtg-2.5/; date >>/var/log/mrtg-dynip.log;
Packit 667938
#<continues previous line> ./mrtg-dynip >>/var/log/mrtg-dynip.log 2>&1
Packit 667938
#
Packit 667938
#Redirecting standard output and error to a log file with an indication
Packit 667938
#of time from 'date' is valuable for sorting out errors and preventing
Packit 667938
#messages from being emailed to the root account.
Packit 667938
#
Packit 667938
#If Perl5 snmp modules are not installed in standard libraries and 
Packit 667938
#the internal 'walk' is being used, then it is necessary to ensure
Packit 667938
#mrtg-dynip in installed in, and run from, a directory where the modules
Packit 667938
#are, typically the same directory the mrtg executable is in. 
Packit 667938
Packit 667938
#The most difficult part in a dynamic IP environment may be choosing the IP
Packit 667938
#addresses to use for the scaler constant $interfaces, as you must ensure
Packit 667938
#the IP address used will always correspond to the physical interface
Packit 667938
#device, unless exception facility configured in.
Packit 667938
Packit 667938
#For Internet Service Providers running ppp dial in lines, the choice will
Packit 667938
#be clear.  The IP addressess to use will be the 'remote' IP part of the
Packit 667938
#command line options for the real physical device (:remote_ip in
Packit 667938
#/etc/ppp/options.ttyXY file), unless static or fixed IP is allowed to
Packit 667938
#override this.  For dial out lines that can get a variable 'remote' IP, you
Packit 667938
#should be able to control what remote IP you get, no matter who you dial
Packit 667938
#into and what remote IP they may offer you, by configuring a remote IP as
Packit 667938
#for a dial in line above.
Packit 667938
Packit 667938
#If the final negotiated ppp address pair as seen by your machine,
Packit 667938
#local_ip:remote_ip, is equal to a_ip:b_ip, then the local_ip:remote_ip as
Packit 667938
#seen by the other machine is b_ip:a_ip. Since the remote IP seen by your
Packit 667938
#side of the line is the local IP as seen and negotiated by the machine on
Packit 667938
#the other side of the line, you can choose whatever remote IP address suits
Packit 667938
#your side of the connection.  Specifying a 'remote' IP other than 0.0.0.0
Packit 667938
#will, by default with pppd, result in an IP the other machine will have to
Packit 667938
#accept as their local to succesfully negotiate a connection.  However it is
Packit 667938
#two way: the other machine can do the same to you for its corresponding
Packit 667938
#'remote' IP.  Hence mrtg-dynip can work on both machines.
Packit 667938
Packit 667938
#Please note: If you have interface devices which register ppp10 or 
Packit 667938
#above, your snmp daemon may not supply information.  This is not due 
Packit 667938
#to a bug in mrtg, the snmp modules or this mrtg-dynip.
Packit 667938
Packit 667938
#Latest version of this software should be available from
Packit 667938
#http://www.heenan.ironbark.id.au/source/mrtg-dynip
Packit 667938
#The configuration herein is provivded as an example only. 
Packit 667938
#This file is used to generate http://www.stats.syd.net.au. 
Packit 667938
Packit 667938
######## Start of configuration section, numbered 0 to 16.
Packit 667938
Packit 667938
######## Set this, 0
Packit 667938
#Check the perl path is correct on the very first line!
Packit 667938
Packit 667938
######## Set this, 1
Packit 667938
#Define $WorkDir to be the directory for web pages and data to be housed
Packit 667938
#Ensure each directory path ends with a seperator. If intending to run on 
Packit 667938
#an NT machine, then ensure the directory seperator is '\\' instead of '/'
Packit 667938
$HTTP_Work_Dir='/var/lib/httpd/htdocs/mrtg/';
Packit 667938
Packit 667938
########  Set this, 2
Packit 667938
#Define name of index html file, only condition is that it not the same name
Packit 667938
#as a html that will be regenerated.  All names of generated files contain
Packit 667938
#an IP address.
Packit 667938
$HTTP_index_file='index.html';
Packit 667938
Packit 667938
####### Set this, 3
Packit 667938
#Set to full directory path the mrtg executable is in.  Place this file
Packit 667938
#it if that is where the Perl 5 snmp modules are and $use_internal_walk
Packit 667938
#will not be set to 1 (see below).
Packit 667938
#Ensure each directory path ends with a seperator. If intending to run on
Packit 667938
#an NT machine, then ensure the directory seperator is '\\' instead of '/'
Packit 667938
$mrtg_Dir="/usr/src/mrtg/mrtg-2.5/";
Packit 667938
Packit 667938
####### Set this, 4
Packit 667938
#Set to full directory path the 'mrtg.cfg' file below is to be placed in.
Packit 667938
#The default choice is to choose same directory as for $mrtg_Dir above
Packit 667938
#Ensure each directory path ends with a seperator. If intending to run on
Packit 667938
#an NT machine, then ensure the directory seperator is '\\' instead of '/'
Packit 667938
###$mrtgcfg_Dir="/usr/src/mrtg/mrtg-2.5/";
Packit 667938
$mrtgcfg_Dir=$mrtg_Dir;
Packit 667938
Packit 667938
####### Set this, 5
Packit 667938
#Set the name you would like the 'mrtg.cfg' file to be.  By locating or
Packit 667938
#naming differently from existing 'mrtg.cfg' files, you can run this
Packit 667938
#software independently of your existing mrtg installation.
Packit 667938
$mrtgcfg_file="mrtg-dynip.cfg";
Packit 667938
Packit 667938
####### Set this, 6
Packit 667938
#Set this to update interval in amount of minutes.  Ensure when this file
Packit 667938
#is run from crond and that the cron run inteval matches this update 
Packit 667938
#interval
Packit 667938
$update=5;
Packit 667938
Packit 667938
######## Set this, 7
Packit 667938
#Default community "public" may be sufficient. The community defined here
Packit 667938
#is the default community to use if no community is defined in the
Packit 667938
#for a particular interface in configuration of $interface in section 12.
Packit 667938
$community_default="public";
Packit 667938
Packit 667938
######## Set this, 8
Packit 667938
#Email address of network manager(s).  Ensure a '\' appears before
Packit 667938
#'@' in email address, as in example.
Packit 667938
#$email="";         #No attempt to display if null
Packit 667938
$email="admin\@syd.net.au";
Packit 667938
Packit 667938
######## Set this, 9
Packit 667938
#Web address of home page for your system, do not include http:// at start
Packit 667938
#$home_page="";  	#No attempt to display if null   
Packit 667938
$home_page="www.syd.net.au";
Packit 667938
Packit 667938
######## Set this, 10         
Packit 667938
#Text for clickable link to home page of your system
Packit 667938
#$home_page_descr="";  	#No attempt to display if null    
Packit 667938
$home_page_descr="SydNet Internet and Network Services";
Packit 667938
Packit 667938
######## Set this, 11
Packit 667938
#Set to a non zero if you want the program to die if there are problems
Packit 667938
#with responses from agents or hosts. Useful in testing phase.
Packit 667938
#$suicidal = 0; #Program is to soldier on if there are no responses from a host
Packit 667938
$suicidal = 1; #Program is to bomb out if there are problems with reponses
Packit 667938
Packit 667938
######## Set this, 12
Packit 667938
#Set this to a non zero if you have interfaces with the same IP number on
Packit 667938
#different masquerading firewall, or address translation, routers/hosts,
Packit 667938
#otherwise leave as 0.  This adds the name of the host to all web page file
Packit 667938
#names as well as the IP addresses.  Avoid using this option as its use make
Packit 667938
#it more difficult to keep track of interface data. 
Packit 667938
#$firewall_masq_tran_if = 1;
Packit 667938
$firewall_masq_tran_if = 0;
Packit 667938
Packit 667938
######## Set this, 13
Packit 667938
#If you have hosts upon which you do not make it a requirement that an
Packit 667938
#interface device uses a partciular IP number (that is you might provide
Packit 667938
#fixed IP address use into a rotary modem pool) then you can set this option
Packit 667938
#on and set item 17 appropriately.  Set to zero not to use, non zero to use
Packit 667938
$use_non_dyn_IP_for_tty=1;
Packit 667938
#$use_non_dyn_IP_for_tty=0;
Packit 667938
Packit 667938
######## Set this, 14
Packit 667938
#If you set option 13 above, then set to full directory path external
Packit 667938
#process will place a single line with the IP address into a file
Packit 667938
#with name that includes name of SNMP hsot and physical interface device
Packit 667938
#name.
Packit 667938
#
Packit 667938
#Ensure each directory path ends with a seperator. If intending to run on an
Packit 667938
#NT machine, then ensure the directory seperator is '\\' instead of '/'
Packit 667938
$Dir_PID="/var/run/";
Packit 667938
Packit 667938
######## Set this, 15
Packit 667938
#If you haVe set option 13 above then you need to ensure
Packit 667938
#an external program provides required information from whatever
Packit 667938
#hosts you indicate in 16 are ports that can have their preferred
Packit 667938
#IP overridden.  
Packit 667938
#
Packit 667938
#For UNIX style localhosts the following lines can be inserted in
Packit 667938
#/etc/ppp/ip-up and /etc/ppp/ipdown.  Following a reboot stale
Packit 667938
#files should be removed automatically by startup, lest the machine
Packit 667938
#crashed.  For hosts other than the host upon which this script is 
Packit 667938
#running, ip-up and ip-down will need to be modified to ensure the 
Packit 667938
#information goes to /var/run of appropriate host.  This can be done 
Packit 667938
#using remote shell or other mechanisms, such as remote copy, nfs, 
Packit 667938
#auto processed email and special client/server networking.
Packit 667938
#
Packit 667938
#It is vital the 'host_name' for writing to /var/run/, as indicated in
Packit 667938
#/var/run/mrtg-dynip.host_name~~ttyXY, matches exactly the equivalent
Packit 667938
#host name in mrtg-dynip. This 'host_name' may be a single name,
Packit 667938
#a dotted name or a dotted numeric IP address.
Packit 667938
#
Packit 667938
#/etc/ppp/ip-up for a localhost running a bash shell can include
Packit 667938
#
Packit 667938
#tty_name="$2"
Packit 667938
#IP_remote="$5"
Packit 667938
#/bin/echo $IP_remote > /var/run/mrtg-dynip.localhost~~${tty_name##/*/}
Packit 667938
#
Packit 667938
#The name of the file must exactly matched that sought for.  
Packit 667938
#
Packit 667938
#/etc/ppp/ip-down for a localhost running a bash shell can include
Packit 667938
#
Packit 667938
#tty_name=$2
Packit 667938
#/bin/rm -f /var/run/mrtg-dynip.localhost~~${tty_name##/*/}
Packit 667938
Packit 667938
######## Set this, 16
Packit 667938
#A pair of lines between blank lines represents an interface on a 
Packit 667938
#particular host.  
Packit 667938
#
Packit 667938
#You can comment out a single pair of lines with a '#' or any non digit
Packit 667938
#(except whitespace) as the first character of a pair of lines.
Packit 667938
#
Packit 667938
#The first line has the following format
Packit 667938
#'n' 'IP-addr' 'if-speed' 'snmp host' 'snmp community'
Packit 667938
#
Packit 667938
#The second line has the following format
Packit 667938
#	'Any free text description of interface'
Packit 667938
# 
Packit 667938
#The items must not be enclosed by '"' or '''.  Plese see example
Packit 667938
#below before reading any further. Any whitespace or combination
Packit 667938
#of whitespace (tabs or spaces) can seperate the items. However it
Packit 667938
#is important the two lines with 'END_OF_INTERFACES' end without
Packit 667938
#whitespace. 
Packit 667938
#
Packit 667938
#'n' is place this entry is to appear in the index of interfaces web file.
Packit 667938
#The number of digits should be the same for each interface, for example
Packit 667938
#use sequence 000 010 020 for successive numbers. You can temporarily
Packit 667938
#take an interface out of consideration by placing any non digit 
Packit 667938
#(except whitespace) before these digits, for example replace 010 
Packit 667938
#by N010 or #010
Packit 667938
#
Packit 667938
#'IP-addr' is a consistent IP address of a physical interface. Exceptions
Packit 667938
#can be catered for.  If you allow fixed (or static) IP into the physical
Packit 667938
#interface to override, then you can ensure the line is still marked active
Packit 667938
#in addition to the static IP entry being marked active.  To ensure this
Packit 667938
#occurs, append '~~ttyXY' to the IP address where ttyXY is the value
Packit 667938
#returned by ${tty_name##/*/} for the phyical device (or port) as indicated
Packit 667938
#in section 15.  To keep a value in place, even if the port is not part of
Packit 667938
#an IP overridable rotary pool, append a '~' to the end, such that complete
Packit 667938
#appendage to the IP address is now '~~ttyXY~'.  You can keep the appendages
Packit 667938
#even if you turn off, or do nor use, $use_non_dyn_IP_for_tty.
Packit 667938
#
Packit 667938
#'if-speed' is the interface speed in integer bits/sec. K and M multipliers
Packit 667938
#for Kb/s and Mb/s can be used (see example). If you want to use decimal
Packit 667938
#values then rewrite with a lower multiplier, for example write 
Packit 667938
#33.3K as  34099 (integer portion of 33.3 multiplied by 1024).
Packit 667938
#
Packit 667938
#'snmp host' is a common and consistent DNS name, or IP address, for
Packit 667938
#interfaces that belong to a particular machine.  For efficiency of snmp
Packit 667938
#agent use it is better all interfaces that belong to a particular machine
Packit 667938
#use a consistent name.
Packit 667938
#
Packit 667938
#'snmp community' is the community name of the 'public' community
Packit 667938
#for an interface (the public community does not have to be named 
Packit 667938
#'public').  This vale does not have to be set: if this value is 
Packit 667938
#not set then the value of $community_default is used instead.
Packit 667938
#
Packit 667938
#'Any free text description of the interface ' on the second line
Packit 667938
#is as indicated.  It need not begin with whitepace (tabs or spaces).
Packit 667938
#
Packit 667938
#For dynamic IP interfaces, you must use unvarying 'remote' IPs as indicated
Packit 667938
#above.  Virtual interface devices should not be used, they provide the same
Packit 667938
#statistics as the real interface they are a virtual interface of.
Packit 667938
Packit 667938
#The configuration herein is provivded as an example only.
Packit 667938
#This file is used to generate http://www.stats.syd.net.au.
Packit 667938
Packit 667938
{
Packit 667938
$interfaces = <
Packit 667938
Packit 667938
010     139.130.36.136   	64K     203.35.74.100
Packit 667938
        SydNet - Telstra Internet link: 64K ISDN router interface connected 14 October 1997
Packit 667938
Packit 667938
020     203.35.74.101   	10M     localhost
Packit 667938
        Ethernet interface on machine for permanent links and dial up lines
Packit 667938
Packit 667938
040     203.35.74.9~~ttyC9~	33K     localhost
Packit 667938
        Permanent link for user pmw
Packit 667938
Packit 667938
050     203.35.74.120~~ttyC10~	33K     localhost
Packit 667938
        Permanent link for machine chaosorb.syd.net.au
Packit 667938
Packit 667938
060     203.35.74.11~~ttyC11~ 	33K     localhost
Packit 667938
        Permanent link for domain arty.com.au
Packit 667938
Packit 667938
073     203.35.74.108     	33K	localhost
Packit 667938
	Static IP address for SydNet technical and sys admin staff member
Packit 667938
Packit 667938
076     203.35.74.107     	33K	localhost
Packit 667938
	Static IP address for SydNet security staff member
Packit 667938
Packit 667938
079     203.35.74.105     	33	localhost
Packit 667938
        Static IP address for non permanent rotary dial in user foo
Packit 667938
Packit 667938
081     203.35.74.109     	33K     localhost
Packit 667938
        Static IP address for non permanent rotary dial in user kebo
Packit 667938
Packit 667938
101     203.35.74.1~~ttyC1	33K     localhost
Packit 667938
	Rotary dial up line 1
Packit 667938
Packit 667938
102     203.35.74.2~~ttyC2	33K     localhost
Packit 667938
	Rotary dial up line 2
Packit 667938
Packit 667938
103     203.35.74.3~~ttyC3     	33K     localhost
Packit 667938
	Rotary dial up line 3
Packit 667938
Packit 667938
104     203.35.74.4~~ttyC4     	33K     localhost
Packit 667938
	Rotary dial up line 4
Packit 667938
Packit 667938
105     203.35.74.5~~ttyC5     	33K     localhost
Packit 667938
	Rotary dial up line 5
Packit 667938
Packit 667938
106     203.35.74.6~~ttyC6     	33K     localhost
Packit 667938
	Rotary dial up line 6
Packit 667938
Packit 667938
107     203.35.74.7~~ttyC7     	33K     localhost
Packit 667938
	Rotary dial up line 7
Packit 667938
Packit 667938
108     203.35.74.8~~ttyC8     	33K     localhost
Packit 667938
	Rotary dial up line 8
Packit 667938
Packit 667938
109     203.35.74.10~~ttyC0     33K     localhost
Packit 667938
	Rotary dial up line 9
Packit 667938
Packit 667938
END_OF_INTERFACES
Packit 667938
}
Packit 667938
Packit 667938
#Convenient record of tty to dynamic IP mappings on localhost
Packit 667938
#ttyC0        203.35.74.10
Packit 667938
#ttyC1        203.35.74.1
Packit 667938
#ttyC2        203.35.74.2
Packit 667938
#ttyC3        203.35.74.3
Packit 667938
#ttyC4        203.35.74.4
Packit 667938
#ttyC5        203.35.74.5
Packit 667938
#ttyC6        203.35.74.6
Packit 667938
#ttyC7        203.35.74.7
Packit 667938
#ttyC8        203.35.74.8
Packit 667938
#ttyC9~       203.35.74.9
Packit 667938
#ttyC10~      203.35.74.120
Packit 667938
#ttyC11~      203.35.74.11
Packit 667938
#ttyC12       203.35.74.12
Packit 667938
#ttyC13       203.35.74.13
Packit 667938
#ttyC14       203.35.74.14
Packit 667938
#ttyC15       203.35.74.15
Packit 667938
Packit 667938
###### You have reached the end of the configuration section, there is no
Packit 667938
#need to make any adjustments below for normal operation.
Packit 667938
Packit 667938
@lines = split(/\n/,$interfaces);
Packit 667938
$line=0;
Packit 667938
while ($line <= $#lines)
Packit 667938
{ 
Packit 667938
  @elements = split (" ",$lines[$line]);
Packit 667938
  if (defined ($elements[3]))
Packit 667938
  {
Packit 667938
    $order=$elements[0];
Packit 667938
    ($ip,$tty) = split (/~~/,$elements[1]);
Packit 667938
    $speed = $elements[2];
Packit 667938
    $snmp_host = $elements[3];
Packit 667938
    $community = defined ($elements[4]) ? $elements[4] : $community_default;
Packit 667938
    $descr=$lines[$line+1];
Packit 667938
    $descr =~ s/^\s*//;
Packit 667938
    $ip_descr{$ip."@".$snmp_host} = [$order,$speed,$community,$descr];
Packit 667938
    $snmp_comm_host{$community."@".$snmp_host}{$ip}=1;
Packit 667938
    $dyn_port{$snmp_host."~~".$tty} = $ip if ($use_non_dyn_IP_for_tty && $tty && $tty !~ /~$/);
Packit 667938
    $line=$line+2;
Packit 667938
  }
Packit 667938
  else
Packit 667938
  {
Packit 667938
    $line++;
Packit 667938
  }
Packit 667938
}
Packit 667938
Packit 667938
#Use Simon Leinen's Perl 5 snmp modules included with mrtg
Packit 667938
#consistent with manner Simon uses in examples
Packit 667938
{
Packit 667938
&snmp_get_response;
Packit 667938
}
Packit 667938
Packit 667938
if ($use_non_dyn_IP_for_tty != 0)
Packit 667938
{
Packit 667938
  foreach $tty (keys(%dyn_port))
Packit 667938
  {
Packit 667938
     if ( -e $Dir_PID."mrtg-dynip.".$tty )
Packit 667938
     {
Packit 667938
      ($snmp_host) = split (/~~/,$tty);
Packit 667938
      if ( (defined($target{$dyn_port{$tty}."@".$snmp_host})) == 0)
Packit 667938
      {
Packit 667938
        $ip_active = `cat $Dir_PID"mrtg-dynip."$tty`;
Packit 667938
	$ip_active =~ s/\s+$//;
Packit 667938
	if (defined ( $target{$ip_active."@".$snmp_host}))
Packit 667938
	{
Packit 667938
$target{$dyn_port{$tty}."@".$snmp_host} = $target{$ip_active."@".$snmp_host};
Packit 667938
	}
Packit 667938
      }
Packit 667938
    }
Packit 667938
  }  
Packit 667938
}
Packit 667938
Packit 667938
open MRTGCFG, ">$mrtg_Dir"."$mrtgcfg_file"
Packit 667938
         || die "$mrtg_Dir"."$mrtgcfg_file file could not be opened\n";
Packit 667938
Packit 667938
$ip_descr_ptr = \%ip_descr;
Packit 667938
Packit 667938
foreach $ip_i (keys(%target))
Packit 667938
{
Packit 667938
if ($$ip_descr_ptr{$ip_i}->[0] =~ /^\d/) 
Packit 667938
{
Packit 667938
($speed_fig,$speed_mult) = $$ip_descr_ptr{$ip_i}->[1] =~ /^(\d+)(\D*)/;
Packit 667938
if ($speed_mult =~ /M|m/)
Packit 667938
{
Packit 667938
  $scale = int ( $speed_fig * 1024 * 1024 / 8 );
Packit 667938
}
Packit 667938
elsif ($speed_mult =~ /K|k/)
Packit 667938
{
Packit 667938
  $scale = int ( $speed_fig * 1024 / 8 );
Packit 667938
}
Packit 667938
elsif ( $speed_mult eq "" )
Packit 667938
{
Packit 667938
  $scale = int ( $speed_fig / 8 );
Packit 667938
}
Packit 667938
else
Packit 667938
{
Packit 667938
  die("Incorrect speed format in scaler constant $interfaces\n");
Packit 667938
}
Packit 667938
Packit 667938
($ip_if,$host) = split (/@/,$ip_i);
Packit 667938
if ($firewall_masq_tran_if != 0)
Packit 667938
{
Packit 667938
$snmp_target=$ip_i;
Packit 667938
}
Packit 667938
else
Packit 667938
{
Packit 667938
$snmp_target=$ip_if;
Packit 667938
}
Packit 667938
Packit 667938
print MRTGCFG <
Packit 667938
Target[$snmp_target]: $target{$ip_i}:$$ip_descr_ptr{$ip_i}->[2]\@$host
Packit 667938
MaxBytes[$snmp_target]: $scale
Packit 667938
Title[$snmp_target]: Traffic Analysis through interface device with IP address $ip_if of host $host
Packit 667938
PageTop[$snmp_target]: 

Stats for interface device with description $$ip_descr_ptr{$ip_i}->[3]

Packit 667938
Packit 667938
END
Packit 667938
}
Packit 667938
}
Packit 667938
{
Packit 667938
print MRTGCFG <
Packit 667938
Packit 667938
WorkDir: $HTTP_Work_Dir
Packit 667938
END
Packit 667938
}
Packit 667938
close MRTGCFG;
Packit 667938
Packit 667938
$interval = $update * 60;
Packit 667938
$expires = gmtime (time + $interval + 60);
Packit 667938
$now=&datestr(time);
Packit 667938
Packit 667938
open MRTGCFGWEB, ">$HTTP_Work_Dir"."$HTTP_index_file"
Packit 667938
	 || die "Mrtg web index file could not be created\n";
Packit 667938
{
Packit 667938
print MRTGCFGWEB <
Packit 667938
<HTML><HEAD> 
Packit 667938
<META HTTP-EQUIV=\"Refresh\" CONTENT=\"$interval\">
Packit 667938
<META HTTP-EQUIV=\"Expires\" CONTENT=\"$expires GMT\"> 
Packit 667938
Packit 667938
<TITLE>Index of stats pages for interface devices on interfaces described below</TITLE>
Packit 667938
</HEAD>
Packit 667938
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000"> 
Packit 667938
<FONT FACE="Arial,Helvetica">
Packit 667938

Active and inactive interace device stats on interfaces described below

Packit 667938
This page last updated on $now

Packit 667938
END
Packit 667938
}
Packit 667938
Packit 667938
if ($home_page && $home_page_descr)
Packit 667938
{
Packit 667938
print MRTGCFGWEB <
Packit 667938

Packit 667938
A network management service courtesy of 
Packit 667938
$home_page_descr
Packit 667938

Packit 667938
END
Packit 667938
}
Packit 667938
Packit 667938
if ($email)
Packit 667938
{
Packit 667938
print MRTGCFGWEB <
Packit 667938

Packit 667938
Information and contact address: network management at email 
Packit 667938
$email
Packit 667938

Packit 667938
END
Packit 667938
}
Packit 667938
Packit 667938
{
Packit 667938
print MRTGCFGWEB <
Packit 667938

Packit 667938
Static IP address and rotary line both marked active if line 
Packit 667938
in use by a static IP address 
Packit 667938

Packit 667938
END
Packit 667938
}
Packit 667938
Packit 667938
{
Packit 667938
print MRTGCFGWEB <
Packit 667938
</FONT>
Packit 667938
Packit 667938
END
Packit 667938
}
Packit 667938
Packit 667938
foreach $ip_i (keys %ip_descr)
Packit 667938
{
Packit 667938
$ip_order{$$ip_descr_ptr{$ip_i}->[0]} = $ip_i if ($$ip_descr_ptr{$ip_i}->[0] =~ /^\d/);
Packit 667938
}
Packit 667938
Packit 667938
foreach $i (sort (keys %ip_order))
Packit 667938
{
Packit 667938
$ip_i = $ip_order{$i};
Packit 667938
Packit 667938
if ($firewall_masq_tran_if != 0)
Packit 667938
{
Packit 667938
$file_name=$ip_i;
Packit 667938
}
Packit 667938
else
Packit 667938
{
Packit 667938
($file_name) = split (/@/,$ip_i);
Packit 667938
}
Packit 667938
Packit 667938
if ( defined ($target{$ip_i}) )
Packit 667938
{
Packit 667938
print MRTGCFGWEB <
Packit 667938
<FONT FACE="Arial,Helvetica">ACTIVE</FONT> <FONT FACE="Arial,Helvetica">$$ip_descr_ptr{$ip_i}->[3]</FONT>
Packit 667938
END
Packit 667938
}
Packit 667938
else
Packit 667938
{
Packit 667938
print MRTGCFGWEB <
Packit 667938
<FONT FACE="Arial,Helvetica">INACTIVE</FONT> <FONT FACE="Arial,Helvetica">$$ip_descr_ptr{$ip_i}->[3]</FONT>
Packit 667938
END
Packit 667938
}
Packit 667938
}
Packit 667938
{
Packit 667938
print MRTGCFGWEB <
Packit 667938
Packit 667938
<FONT FACE="Arial,Helvetica">
Packit 667938

This web page (but not the web pages above)

Packit 667938
generated by mrtg-dynip, version 0.41b, 1997/10/25
Packit 667938
created by 
John Heenan,
Packit 667938
href="mailto:john\@heenan.ironbark.id.au">john\@heenan.ironbark.id.au
Packit 667938
Packit 667938

Mrtg-dynip is a contribution to MRTG, enabling MRTG to generate multi

Packit 667938
interface traffic graphs for IP interfaces on hosts that do not provide
Packit 667938
consistent SNMP target numbers for their interfaces.  Such IP interfaces
Packit 667938
include IP active serial interfaces attached to modems in a PPP dial in
Packit 667938
environment. The hosts must run snmp agents.  For completeness, information
Packit 667938
about interface devices with unvarying SNMP target numbers, such as
Packit 667938
ethernet cards, can be configured to be included.

Packit 667938
Packit 667938
Mrtg-dynip can be considred to have sophisticated modem bank monitoring
Packit 667938
capacity, when the modems carry PPP or SLIP traffic.

Packit 667938
Packit 667938
This web page and web pages above, auto update details, and refresh, every
Packit 667938
$update minutes.

Packit 667938
Packit 667938
Source code for the latest non beta version of the mrtg-dynip software
Packit 667938
contribution is available from 
Packit 667938
href="http://www.heenan.ironbark.id.au/source/mrtg-dynip">
Packit 667938
http://www.heenan.ironbark.id.au/source/mrtg-dynip

Packit 667938
END
Packit 667938
}
Packit 667938
Packit 667938
print MRTGCFGWEB "</FONT></BODY></HTML>","\n";
Packit 667938
Packit 667938
close MRTGCFGWEB; 
Packit 667938
Packit 667938
exec ("$mrtg_Dir"."mrtg $mrtgcfg_Dir"."$mrtgcfg_file");
Packit 667938
Packit 667938
sub datestr {
Packit 667938
($time) = shift(@_) || return 0;
Packit 667938
($wday) = ('Sunday','Monday','Tuesday','Wednesday',
Packit 667938
                'Thursday','Friday','Saturday')[(localtime($time))[6]];
Packit 667938
($month) = ('January','February' ,'March' ,'April' ,
Packit 667938
                 'May' , 'June' , 'July' , 'August' , 'September' ,
Packit 667938
                 'October' ,
Packit 667938
                 'November' , 'December' )[(localtime($time))[4]];
Packit 667938
($mday,$year,$hour,$min) = (localtime($time))[3,5,2,1];
Packit 667938
if ($min<10) {$min = "0$min";}
Packit 667938
return "$wday, $mday $month ".($year+1900)." at $hour:$min";
Packit 667938
}
Packit 667938
Packit 667938
sub snmp_get_response
Packit 667938
{
Packit 667938
use BER;
Packit 667938
use SNMP_Session;
Packit 667938
Packit 667938
SOLDIER_ON: foreach $comm_host (keys (%snmp_comm_host))
Packit 667938
{
Packit 667938
($community,$host) = split (/@/,$comm_host);
Packit 667938
if ($session = SNMP_Session->open ($host, $community, 161))
Packit 667938
{
Packit 667938
@ipRouteIfIndex = split ('\.', '1.3.6.1.2.1.4.21.1.2');
Packit 667938
@ipAdEntIfIndex = split ('\.', '1.3.6.1.2.1.4.20.1.2');
Packit 667938
$if_route_index_index = encode_oid (@ipRouteIfIndex);
Packit 667938
$if_index_index = encode_oid (@ipAdEntIfIndex);
Packit 667938
Packit 667938
  @oids = ($if_route_index_index);
Packit 667938
  for (;;) {
Packit 667938
    if ($session->getnext_request_response (@oids)) {
Packit 667938
        $response = $session->pdu_buffer;
Packit 667938
        ($bindings) = $session->decode_get_response ($response);
Packit 667938
        @next_oids = ();
Packit 667938
        ($binding,$bindings) = decode_sequence ($bindings);
Packit 667938
        ($oid,$value) = decode_by_template ($binding, "%O%@");
Packit 667938
        last unless BER::encoded_oid_prefix_p ($if_route_index_index, $oid);
Packit 667938
        push @next_oids, $oid;
Packit 667938
        ($ip_if) = pretty_print ($oid) =~ /.*\.(\d+\.\d+\.\d+\.\d+)$/;
Packit 667938
        $target_i = pretty_print ($value);
Packit 667938
        $target{$ip_if."@".$host} = $target_i if ( defined ($snmp_comm_host{$community."@".$host}{$ip_if}) );
Packit 667938
    } else 
Packit 667938
        {
Packit 667938
          die ("Suicide: no response from community $community on host $host","\n") if ($suicidal != 0);
Packit 667938
          print ("Soldiering on: no response from community $community on host $host","\n");
Packit 667938
          $session->close ();
Packit 667938
          last SOLDIER_ON;
Packit 667938
        }
Packit 667938
    @oids = @next_oids;
Packit 667938
  }
Packit 667938
Packit 667938
  @oids = ($if_index_index);
Packit 667938
  for (;;) {
Packit 667938
    if ($session->getnext_request_response (@oids)) {
Packit 667938
        $response = $session->pdu_buffer;
Packit 667938
        ($bindings) = $session->decode_get_response ($response);
Packit 667938
        @next_oids = ();
Packit 667938
        ($binding,$bindings) = decode_sequence ($bindings);
Packit 667938
        ($oid,$value) = decode_by_template ($binding, "%O%@");
Packit 667938
        last unless BER::encoded_oid_prefix_p ($if_index_index, $oid);
Packit 667938
        push @next_oids, $oid;
Packit 667938
        ($ip_if) = pretty_print ($oid) =~ /.*\.(\d+\.\d+\.\d+\.\d+)$/;
Packit 667938
        $target_i = pretty_print ($value);
Packit 667938
        $target{$ip_if."@".$host} = $target_i if ( defined ($snmp_comm_host{$community."@".$host}{$ip_if}) );
Packit 667938
    } else 
Packit 667938
        {
Packit 667938
          die ("Suicide: no response from community $community on host $host","\n") if ($suicidal != 0);
Packit 667938
          print ("Soldiering on: no response from community $community on host $host","\n");
Packit 667938
	  $session->close ();
Packit 667938
          last SOLDIER_ON;
Packit 667938
        }
Packit 667938
    @oids = @next_oids;
Packit 667938
  }
Packit 667938
$session->close ();
Packit 667938
}
Packit 667938
else
Packit 667938
  {
Packit 667938
     die ("Suicide: unable to open SNMP session to community $community on host $host","\n") if ($suicidal != 0);
Packit 667938
     print ("Soldiering on: unable to open SNMP session to community $community on host $host","\n");
Packit 667938
  }
Packit 667938
}
Packit 667938
}