Debian Codegraph @

contrib/mrtg-dynip/mrtg-dynip-sydnet

raw
1 #!/usr/local/bin/perl
2 ##################################################################
3 # Multi Dynamic IP Traffic Grapher contibution to mrtg
4 ##################################################################
5 #
6 # Created by John Heenan <[email protected]>
7 #
8 # Available from http://www.heenan.ironbark.id.au/mrtg-dynip
9 #
10 ##################################################################
11 #
12 # Distributed under the GPL copyleft of GNU
13 #
14 # mrtg-dynip, v 0.41b 1997/10/25
15 #
16 # Copyright John Heenan, with exception of datestr subroutine
17 # (copied from mrtg executable) and much of internal_walk
18 # subroutine (manner of using snmp modules copied from an example
19 # by Simon Lenine)
20 #
21 ###################################################################
22
23 #Mrtg-dynip is a contribution to MRTG, enabling MRTG to generate multi
24 #interface traffic graphs for IP interfaces on hosts that do not provide
25 #consistent SNMP target numbers for their interfaces. Such IP interfaces
26 #include IP active serial interfaces attached to modems in a PPP dial in
27 #environment. The hosts must run snmp agents. For completeness, information
28 #about interface devices with unvarying SNMP target numbers, such as
29 #ethernet cards, can be configured to be included.
30
31 #Mrtg-dynip's configuration is simplest where static (or fixed) IP is not
32 #used for dial into a rotary modem pool.
33
34 #Mrtg-dynip can be considred to have sophisticated modem bank monitoring
35 #capacity, when the modems carry PPP or SLIP traffic.
36
37 #Regenerates a named 'mrtg.cfg' file to ensure snmp data remains with a
38 #consistent IP number, or overridable IP number of a real physical device
39 #in a dial in IP environment, rather than with an interface name which
40 #can get assinged to different real physical devices, and runs mrtg on
41 #the generated file.
42
43 #Generates a web index file of stats web pages.
44
45 #Please see the section 6 of the FAQ for this version for information on
46 #for differences in interpreting graphs between some devices
47
48 #Briefly, to someone dialling in, dynamic IP means when they dial a rotary
49 #number they do not get a consistent IP address. To the service provider it
50 #means a unique IP number is assinged to each telephone line/modem/port.
51
52 #To someone dialling in, static or fixed IP means that their user name is
53 #approved to use a unique IP address, whether they dial into a rotary for
54 #a modem bank or into a non rotary number. To the service provider, it means
55 #if someone is dialling into a rotary for a modem pool, they allow the modem
56 #port use a unique approved IP number for that user, that overrides the IP
57 #address used when a dial in user does not request a fixed or static IP.
58
59 #The public community should be used, however the public community on a
60 #particular host does not need to be named 'public'. This is catered for.
61
62 #There is a large 'TODO' list for this contribution, including
63 #testing use of the 'ifLastChange' snmp object.
64
65 #SET UP
66
67 #Runs independently of an existing configured mrtg installation. Following
68 #the commented example will make the set up clearer. The examples are for a
69 #live ISP using web page http://www.stats.syd.net.au, you must change values
70 #for your own use
71
72 # 0 Ensure the path to the perl binary is set correctly on first line
73 # 1 $HTTP_Work_Dir ** Must set
74 # 2 $HTTP_index_file Default index.html may be OK if unique
75 # 3 $mrtg_Dir ** Must set
76 # 4 $mrtgcfg_Dir Setting to $mrtgDir is probably OK
77 # 5 $mrtgcfg_file Default mrtg-dynip.cfg should be OK
78 # 6 $update Default will work (five minutes)
79 # 7 $community_default Default for this default may be OK (public)
80 # 8 $email Set to "" to show nothing
81 # 9 $home_page Set to "" to show nothing
82 # 10 $home_page_descr Set to "" to show nothing
83 # 11 $suicidal Non zero: bomb out if there are problems
84 # 12 $firewall_masq_tran_if Best to leave as 0 (zero) if sufficient
85 # 13 $use_non_dyn_IP_for_tty Safe to set to 0 (the non set value)
86 # 14 $Dir_PID Must set if 13 is non zero
87 # 15 External settings if 13 is set to non zero
88 # 16 $interfaces ** Must set
89
90 #Ensure mrtg-dynip has executable permission. See below as to where
91 #mrtg-dynip may need to be installed.
92
93 #Place a crontab entry, consistent with update time, similar to
94 #0,5,10,15,20,25,30,35,40,45,50,55 * * * * <next line continued here>
95 #cd /usr/src/mrtg/mrtg-2.5/; date >>/var/log/mrtg-dynip.log;
96 #<continues previous line> ./mrtg-dynip >>/var/log/mrtg-dynip.log 2>&1
97 #
98 #Redirecting standard output and error to a log file with an indication
99 #of time from 'date' is valuable for sorting out errors and preventing
100 #messages from being emailed to the root account.
101 #
102 #If Perl5 snmp modules are not installed in standard libraries and
103 #the internal 'walk' is being used, then it is necessary to ensure
104 #mrtg-dynip in installed in, and run from, a directory where the modules
105 #are, typically the same directory the mrtg executable is in.
106
107 #The most difficult part in a dynamic IP environment may be choosing the IP
108 #addresses to use for the scaler constant $interfaces, as you must ensure
109 #the IP address used will always correspond to the physical interface
110 #device, unless exception facility configured in.
111
112 #For Internet Service Providers running ppp dial in lines, the choice will
113 #be clear. The IP addressess to use will be the 'remote' IP part of the
114 #command line options for the real physical device (:remote_ip in
115 #/etc/ppp/options.ttyXY file), unless static or fixed IP is allowed to
116 #override this. For dial out lines that can get a variable 'remote' IP, you
117 #should be able to control what remote IP you get, no matter who you dial
118 #into and what remote IP they may offer you, by configuring a remote IP as
119 #for a dial in line above.
120
121 #If the final negotiated ppp address pair as seen by your machine,
122 #local_ip:remote_ip, is equal to a_ip:b_ip, then the local_ip:remote_ip as
123 #seen by the other machine is b_ip:a_ip. Since the remote IP seen by your
124 #side of the line is the local IP as seen and negotiated by the machine on
125 #the other side of the line, you can choose whatever remote IP address suits
126 #your side of the connection. Specifying a 'remote' IP other than 0.0.0.0
127 #will, by default with pppd, result in an IP the other machine will have to
128 #accept as their local to succesfully negotiate a connection. However it is
129 #two way: the other machine can do the same to you for its corresponding
130 #'remote' IP. Hence mrtg-dynip can work on both machines.
131
132 #Please note: If you have interface devices which register ppp10 or
133 #above, your snmp daemon may not supply information. This is not due
134 #to a bug in mrtg, the snmp modules or this mrtg-dynip.
135
136 #Latest version of this software should be available from
137 #http://www.heenan.ironbark.id.au/source/mrtg-dynip
138 #The configuration herein is provivded as an example only.
139 #This file is used to generate http://www.stats.syd.net.au.
140
141 ######## Start of configuration section, numbered 0 to 16.
142
143 ######## Set this, 0
144 #Check the perl path is correct on the very first line!
145
146 ######## Set this, 1
147 #Define $WorkDir to be the directory for web pages and data to be housed
148 #Ensure each directory path ends with a seperator. If intending to run on
149 #an NT machine, then ensure the directory seperator is '\\' instead of '/'
150 $HTTP_Work_Dir='/var/lib/httpd/htdocs/mrtg/';
151
152 ######## Set this, 2
153 #Define name of index html file, only condition is that it not the same name
154 #as a html that will be regenerated. All names of generated files contain
155 #an IP address.
156 $HTTP_index_file='index.html';
157
158 ####### Set this, 3
159 #Set to full directory path the mrtg executable is in. Place this file
160 #it if that is where the Perl 5 snmp modules are and $use_internal_walk
161 #will not be set to 1 (see below).
162 #Ensure each directory path ends with a seperator. If intending to run on
163 #an NT machine, then ensure the directory seperator is '\\' instead of '/'
164 $mrtg_Dir="/usr/src/mrtg/mrtg-2.5/";
165
166 ####### Set this, 4
167 #Set to full directory path the 'mrtg.cfg' file below is to be placed in.
168 #The default choice is to choose same directory as for $mrtg_Dir above
169 #Ensure each directory path ends with a seperator. If intending to run on
170 #an NT machine, then ensure the directory seperator is '\\' instead of '/'
171 ###$mrtgcfg_Dir="/usr/src/mrtg/mrtg-2.5/";
172 $mrtgcfg_Dir=$mrtg_Dir;
173
174 ####### Set this, 5
175 #Set the name you would like the 'mrtg.cfg' file to be. By locating or
176 #naming differently from existing 'mrtg.cfg' files, you can run this
177 #software independently of your existing mrtg installation.
178 $mrtgcfg_file="mrtg-dynip.cfg";
179
180 ####### Set this, 6
181 #Set this to update interval in amount of minutes. Ensure when this file
182 #is run from crond and that the cron run inteval matches this update
183 #interval
184 $update=5;
185
186 ######## Set this, 7
187 #Default community "public" may be sufficient. The community defined here
188 #is the default community to use if no community is defined in the
189 #for a particular interface in configuration of $interface in section 12.
190 $community_default="public";
191
192 ######## Set this, 8
193 #Email address of network manager(s). Ensure a '\' appears before
194 #'@' in email address, as in example.
195 #$email=""; #No attempt to display if null
196 $email="admin\@syd.net.au";
197
198 ######## Set this, 9
199 #Web address of home page for your system, do not include http:// at start
200 #$home_page=""; #No attempt to display if null
201 $home_page="www.syd.net.au";
202
203 ######## Set this, 10
204 #Text for clickable link to home page of your system
205 #$home_page_descr=""; #No attempt to display if null
206 $home_page_descr="SydNet Internet and Network Services";
207
208 ######## Set this, 11
209 #Set to a non zero if you want the program to die if there are problems
210 #with responses from agents or hosts. Useful in testing phase.
211 #$suicidal = 0; #Program is to soldier on if there are no responses from a host
212 $suicidal = 1; #Program is to bomb out if there are problems with reponses
213
214 ######## Set this, 12
215 #Set this to a non zero if you have interfaces with the same IP number on
216 #different masquerading firewall, or address translation, routers/hosts,
217 #otherwise leave as 0. This adds the name of the host to all web page file
218 #names as well as the IP addresses. Avoid using this option as its use make
219 #it more difficult to keep track of interface data.
220 #$firewall_masq_tran_if = 1;
221 $firewall_masq_tran_if = 0;
222
223 ######## Set this, 13
224 #If you have hosts upon which you do not make it a requirement that an
225 #interface device uses a partciular IP number (that is you might provide
226 #fixed IP address use into a rotary modem pool) then you can set this option
227 #on and set item 17 appropriately. Set to zero not to use, non zero to use
228 $use_non_dyn_IP_for_tty=1;
229 #$use_non_dyn_IP_for_tty=0;
230
231 ######## Set this, 14
232 #If you set option 13 above, then set to full directory path external
233 #process will place a single line with the IP address into a file
234 #with name that includes name of SNMP hsot and physical interface device
235 #name.
236 #
237 #Ensure each directory path ends with a seperator. If intending to run on an
238 #NT machine, then ensure the directory seperator is '\\' instead of '/'
239 $Dir_PID="/var/run/";
240
241 ######## Set this, 15
242 #If you haVe set option 13 above then you need to ensure
243 #an external program provides required information from whatever
244 #hosts you indicate in 16 are ports that can have their preferred
245 #IP overridden.
246 #
247 #For UNIX style localhosts the following lines can be inserted in
248 #/etc/ppp/ip-up and /etc/ppp/ipdown. Following a reboot stale
249 #files should be removed automatically by startup, lest the machine
250 #crashed. For hosts other than the host upon which this script is
251 #running, ip-up and ip-down will need to be modified to ensure the
252 #information goes to /var/run of appropriate host. This can be done
253 #using remote shell or other mechanisms, such as remote copy, nfs,
254 #auto processed email and special client/server networking.
255 #
256 #It is vital the 'host_name' for writing to /var/run/, as indicated in
257 #/var/run/mrtg-dynip.host_name~~ttyXY, matches exactly the equivalent
258 #host name in mrtg-dynip. This 'host_name' may be a single name,
259 #a dotted name or a dotted numeric IP address.
260 #
261 #/etc/ppp/ip-up for a localhost running a bash shell can include
262 #
263 #tty_name="$2"
264 #IP_remote="$5"
265 #/bin/echo $IP_remote > /var/run/mrtg-dynip.localhost~~${tty_name##/*/}
266 #
267 #The name of the file must exactly matched that sought for.
268 #
269 #/etc/ppp/ip-down for a localhost running a bash shell can include
270 #
271 #tty_name=$2
272 #/bin/rm -f /var/run/mrtg-dynip.localhost~~${tty_name##/*/}
273
274 ######## Set this, 16
275 #A pair of lines between blank lines represents an interface on a
276 #particular host.
277 #
278 #You can comment out a single pair of lines with a '#' or any non digit
279 #(except whitespace) as the first character of a pair of lines.
280 #
281 #The first line has the following format
282 #'n' 'IP-addr' 'if-speed' 'snmp host' 'snmp community'
283 #
284 #The second line has the following format
285 # 'Any free text description of interface'
286 #
287 #The items must not be enclosed by '"' or '''. Plese see example
288 #below before reading any further. Any whitespace or combination
289 #of whitespace (tabs or spaces) can seperate the items. However it
290 #is important the two lines with 'END_OF_INTERFACES' end without
291 #whitespace.
292 #
293 #'n' is place this entry is to appear in the index of interfaces web file.
294 #The number of digits should be the same for each interface, for example
295 #use sequence 000 010 020 for successive numbers. You can temporarily
296 #take an interface out of consideration by placing any non digit
297 #(except whitespace) before these digits, for example replace 010
298 #by N010 or #010
299 #
300 #'IP-addr' is a consistent IP address of a physical interface. Exceptions
301 #can be catered for. If you allow fixed (or static) IP into the physical
302 #interface to override, then you can ensure the line is still marked active
303 #in addition to the static IP entry being marked active. To ensure this
304 #occurs, append '~~ttyXY' to the IP address where ttyXY is the value
305 #returned by ${tty_name##/*/} for the phyical device (or port) as indicated
306 #in section 15. To keep a value in place, even if the port is not part of
307 #an IP overridable rotary pool, append a '~' to the end, such that complete
308 #appendage to the IP address is now '~~ttyXY~'. You can keep the appendages
309 #even if you turn off, or do nor use, $use_non_dyn_IP_for_tty.
310 #
311 #'if-speed' is the interface speed in integer bits/sec. K and M multipliers
312 #for Kb/s and Mb/s can be used (see example). If you want to use decimal
313 #values then rewrite with a lower multiplier, for example write
314 #33.3K as 34099 (integer portion of 33.3 multiplied by 1024).
315 #
316 #'snmp host' is a common and consistent DNS name, or IP address, for
317 #interfaces that belong to a particular machine. For efficiency of snmp
318 #agent use it is better all interfaces that belong to a particular machine
319 #use a consistent name.
320 #
321 #'snmp community' is the community name of the 'public' community
322 #for an interface (the public community does not have to be named
323 #'public'). This vale does not have to be set: if this value is
324 #not set then the value of $community_default is used instead.
325 #
326 #'Any free text description of the interface ' on the second line
327 #is as indicated. It need not begin with whitepace (tabs or spaces).
328 #
329 #For dynamic IP interfaces, you must use unvarying 'remote' IPs as indicated
330 #above. Virtual interface devices should not be used, they provide the same
331 #statistics as the real interface they are a virtual interface of.
332
333 #The configuration herein is provivded as an example only.
334 #This file is used to generate http://www.stats.syd.net.au.
335
336 {
337 $interfaces = <<END_OF_INTERFACES
338
339 010 139.130.36.136 64K 203.35.74.100
340 SydNet - Telstra Internet link: 64K ISDN router interface connected 14 October 1997
341
342 020 203.35.74.101 10M localhost
343 Ethernet interface on machine for permanent links and dial up lines
344
345 040 203.35.74.9~~ttyC9~ 33K localhost
346 Permanent link for user pmw
347
348 050 203.35.74.120~~ttyC10~ 33K localhost
349 Permanent link for machine chaosorb.syd.net.au
350
351 060 203.35.74.11~~ttyC11~ 33K localhost
352 Permanent link for domain arty.com.au
353
354 073 203.35.74.108 33K localhost
355 Static IP address for SydNet technical and sys admin staff member
356
357 076 203.35.74.107 33K localhost
358 Static IP address for SydNet security staff member
359
360 079 203.35.74.105 33 localhost
361 Static IP address for non permanent rotary dial in user foo
362
363 081 203.35.74.109 33K localhost
364 Static IP address for non permanent rotary dial in user kebo
365
366 101 203.35.74.1~~ttyC1 33K localhost
367 Rotary dial up line 1
368
369 102 203.35.74.2~~ttyC2 33K localhost
370 Rotary dial up line 2
371
372 103 203.35.74.3~~ttyC3 33K localhost
373 Rotary dial up line 3
374
375 104 203.35.74.4~~ttyC4 33K localhost
376 Rotary dial up line 4
377
378 105 203.35.74.5~~ttyC5 33K localhost
379 Rotary dial up line 5
380
381 106 203.35.74.6~~ttyC6 33K localhost
382 Rotary dial up line 6
383
384 107 203.35.74.7~~ttyC7 33K localhost
385 Rotary dial up line 7
386
387 108 203.35.74.8~~ttyC8 33K localhost
388 Rotary dial up line 8
389
390 109 203.35.74.10~~ttyC0 33K localhost
391 Rotary dial up line 9
392
393 END_OF_INTERFACES
394 }
395
396 #Convenient record of tty to dynamic IP mappings on localhost
397 #ttyC0 203.35.74.10
398 #ttyC1 203.35.74.1
399 #ttyC2 203.35.74.2
400 #ttyC3 203.35.74.3
401 #ttyC4 203.35.74.4
402 #ttyC5 203.35.74.5
403 #ttyC6 203.35.74.6
404 #ttyC7 203.35.74.7
405 #ttyC8 203.35.74.8
406 #ttyC9~ 203.35.74.9
407 #ttyC10~ 203.35.74.120
408 #ttyC11~ 203.35.74.11
409 #ttyC12 203.35.74.12
410 #ttyC13 203.35.74.13
411 #ttyC14 203.35.74.14
412 #ttyC15 203.35.74.15
413
414 ###### You have reached the end of the configuration section, there is no
415 #need to make any adjustments below for normal operation.
416
417 @lines = split(/\n/,$interfaces);
418 $line=0;
419 while ($line <= $#lines)
420 {
421 @elements = split (" ",$lines[$line]);
422 if (defined ($elements[3]))
423 {
424 $order=$elements[0];
425 ($ip,$tty) = split (/~~/,$elements[1]);
426 $speed = $elements[2];
427 $snmp_host = $elements[3];
428 $community = defined ($elements[4]) ? $elements[4] : $community_default;
429 $descr=$lines[$line+1];
430 $descr =~ s/^\s*//;
431 $ip_descr{$ip."@".$snmp_host} = [$order,$speed,$community,$descr];
432 $snmp_comm_host{$community."@".$snmp_host}{$ip}=1;
433 $dyn_port{$snmp_host."~~".$tty} = $ip if ($use_non_dyn_IP_for_tty && $tty && $tty !~ /~$/);
434 $line=$line+2;
435 }
436 else
437 {
438 $line++;
439 }
440 }
441
442 #Use Simon Leinen's Perl 5 snmp modules included with mrtg
443 #consistent with manner Simon uses in examples
444 {
445 &snmp_get_response;
446 }
447
448 if ($use_non_dyn_IP_for_tty != 0)
449 {
450 foreach $tty (keys(%dyn_port))
451 {
452 if ( -e $Dir_PID."mrtg-dynip.".$tty )
453 {
454 ($snmp_host) = split (/~~/,$tty);
455 if ( (defined($target{$dyn_port{$tty}."@".$snmp_host})) == 0)
456 {
457 $ip_active = `cat $Dir_PID"mrtg-dynip."$tty`;
458 $ip_active =~ s/\s+$//;
459 if (defined ( $target{$ip_active."@".$snmp_host}))
460 {
461 $target{$dyn_port{$tty}."@".$snmp_host} = $target{$ip_active."@".$snmp_host};
462 }
463 }
464 }
465 }
466 }
467
468 open MRTGCFG, ">$mrtg_Dir"."$mrtgcfg_file"
469 || die "$mrtg_Dir"."$mrtgcfg_file file could not be opened\n";
470
471 $ip_descr_ptr = \%ip_descr;
472
473 foreach $ip_i (keys(%target))
474 {
475 if ($$ip_descr_ptr{$ip_i}->[0] =~ /^\d/)
476 {
477 ($speed_fig,$speed_mult) = $$ip_descr_ptr{$ip_i}->[1] =~ /^(\d+)(\D*)/;
478 if ($speed_mult =~ /M|m/)
479 {
480 $scale = int ( $speed_fig * 1024 * 1024 / 8 );
481 }
482 elsif ($speed_mult =~ /K|k/)
483 {
484 $scale = int ( $speed_fig * 1024 / 8 );
485 }
486 elsif ( $speed_mult eq "" )
487 {
488 $scale = int ( $speed_fig / 8 );
489 }
490 else
491 {
492 die("Incorrect speed format in scaler constant $interfaces\n");
493 }
494
495 ($ip_if,$host) = split (/@/,$ip_i);
496 if ($firewall_masq_tran_if != 0)
497 {
498 $snmp_target=$ip_i;
499 }
500 else
501 {
502 $snmp_target=$ip_if;
503 }
504
505 print MRTGCFG <<END
506 Target[$snmp_target]: $target{$ip_i}:$$ip_descr_ptr{$ip_i}->[2]\@$host
507 MaxBytes[$snmp_target]: $scale
508 Title[$snmp_target]: Traffic Analysis through interface device with IP address $ip_if of host $host
509 PageTop[$snmp_target]: <H1>Stats for interface device with description $$ip_descr_ptr{$ip_i}->[3]</H1>
510
511 END
512 }
513 }
514 {
515 print MRTGCFG <<END
516
517 WorkDir: $HTTP_Work_Dir
518 END
519 }
520 close MRTGCFG;
521
522 $interval = $update * 60;
523 $expires = gmtime (time + $interval + 60);
524 $now=&datestr(time);
525
526 open MRTGCFGWEB, ">$HTTP_Work_Dir"."$HTTP_index_file"
527 || die "Mrtg web index file could not be created\n";
528 {
529 print MRTGCFGWEB <<END
530 <HTML><HEAD>
531 <META HTTP-EQUIV=\"Refresh\" CONTENT=\"$interval\">
532 <META HTTP-EQUIV=\"Expires\" CONTENT=\"$expires GMT\">
533
534 <TITLE>Index of stats pages for interface devices on interfaces described below</TITLE>
535 </HEAD>
536 <BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000">
537 <FONT FACE="Arial,Helvetica">
538 <H1>Active and inactive interace device stats on interfaces described below</H1>
539 This page last updated on $now<p>
540 END
541 }
542
543 if ($home_page && $home_page_descr)
544 {
545 print MRTGCFGWEB <<END
546 <p>
547 A network management service courtesy of <a href=\"http://$home_page\">
548 $home_page_descr</a>
549 <p>
550 END
551 }
552
553 if ($email)
554 {
555 print MRTGCFGWEB <<END
556 <p>
557 Information and contact address: network management at email
558 <a href=\"mailto:$email\">$email</a>
559 <p>
560 END
561 }
562
563 {
564 print MRTGCFGWEB <<END
565 <p>
566 Static IP address and rotary line both marked active if line
567 in use by a static IP address
568 <p>
569 END
570 }
571
572 {
573 print MRTGCFGWEB <<END
574 </FONT>
575 <table>
576 END
577 }
578
579 foreach $ip_i (keys %ip_descr)
580 {
581 $ip_order{$$ip_descr_ptr{$ip_i}->[0]} = $ip_i if ($$ip_descr_ptr{$ip_i}->[0] =~ /^\d/);
582 }
583
584 foreach $i (sort (keys %ip_order))
585 {
586 $ip_i = $ip_order{$i};
587
588 if ($firewall_masq_tran_if != 0)
589 {
590 $file_name=$ip_i;
591 }
592 else
593 {
594 ($file_name) = split (/@/,$ip_i);
595 }
596
597 if ( defined ($target{$ip_i}) )
598 {
599 print MRTGCFGWEB <<END
600 <tr><td><FONT FACE="Arial,Helvetica">ACTIVE</FONT></td> <td><FONT FACE="Arial,Helvetica"><A HREF=\"$file_name.html\">$$ip_descr_ptr{$ip_i}->[3]</a></FONT></td></tr>
601 END
602 }
603 else
604 {
605 print MRTGCFGWEB <<END
606 <tr><td><FONT FACE="Arial,Helvetica">INACTIVE</FONT></td> <td><FONT FACE="Arial,Helvetica"><A HREF=\"$file_name.html\">$$ip_descr_ptr{$ip_i}->[3]</a></td></FONT></tr>
607 END
608 }
609 }
610 {
611 print MRTGCFGWEB <<END
612 </table>
613 <FONT FACE="Arial,Helvetica">
614 <p> This web page (but not the web pages above)
615 generated by mrtg-dynip, version 0.41b, 1997/10/25
616 created by <br>John Heenan, <a
617 href="mailto:john\@heenan.ironbark.id.au">john\@heenan.ironbark.id.au</a>
618
619 <P>Mrtg-dynip is a contribution to MRTG, enabling MRTG to generate multi
620 interface traffic graphs for IP interfaces on hosts that do not provide
621 consistent SNMP target numbers for their interfaces. Such IP interfaces
622 include IP active serial interfaces attached to modems in a PPP dial in
623 environment. The hosts must run snmp agents. For completeness, information
624 about interface devices with unvarying SNMP target numbers, such as
625 ethernet cards, can be configured to be included.<P>
626
627 Mrtg-dynip can be considred to have sophisticated modem bank monitoring
628 capacity, when the modems carry PPP or SLIP traffic.<P>
629
630 This web page and web pages above, auto update details, and refresh, every
631 $update minutes.<p>
632
633 Source code for the latest non beta version of the mrtg-dynip software
634 contribution is available from <a
635 href="http://www.heenan.ironbark.id.au/source/mrtg-dynip">
636 http://www.heenan.ironbark.id.au/source/mrtg-dynip</a><p>
637 END
638 }
639
640 print MRTGCFGWEB "</FONT></BODY></HTML>","\n";
641
642 close MRTGCFGWEB;
643
644 exec ("$mrtg_Dir"."mrtg $mrtgcfg_Dir"."$mrtgcfg_file");
645
646 sub datestr {
647 ($time) = shift(@_) || return 0;
648 ($wday) = ('Sunday','Monday','Tuesday','Wednesday',
649 'Thursday','Friday','Saturday')[(localtime($time))[6]];
650 ($month) = ('January','February' ,'March' ,'April' ,
651 'May' , 'June' , 'July' , 'August' , 'September' ,
652 'October' ,
653 'November' , 'December' )[(localtime($time))[4]];
654 ($mday,$year,$hour,$min) = (localtime($time))[3,5,2,1];
655 if ($min<10) {$min = "0$min";}
656 return "$wday, $mday $month ".($year+1900)." at $hour:$min";
657 }
658
659 sub snmp_get_response
660 {
661 use BER;
662 use SNMP_Session;
663
664 SOLDIER_ON: foreach $comm_host (keys (%snmp_comm_host))
665 {
666 ($community,$host) = split (/@/,$comm_host);
667 if ($session = SNMP_Session->open ($host, $community, 161))
668 {
669 @ipRouteIfIndex = split ('\.', '1.3.6.1.2.1.4.21.1.2');
670 @ipAdEntIfIndex = split ('\.', '1.3.6.1.2.1.4.20.1.2');
671 $if_route_index_index = encode_oid (@ipRouteIfIndex);
672 $if_index_index = encode_oid (@ipAdEntIfIndex);
673
674 @oids = ($if_route_index_index);
675 for (;;) {
676 if ($session->getnext_request_response (@oids)) {
677 $response = $session->pdu_buffer;
678 ($bindings) = $session->decode_get_response ($response);
679 @next_oids = ();
680 ($binding,$bindings) = decode_sequence ($bindings);
681 ($oid,$value) = decode_by_template ($binding, "%O%@");
682 last unless BER::encoded_oid_prefix_p ($if_route_index_index, $oid);
683 push @next_oids, $oid;
684 ($ip_if) = pretty_print ($oid) =~ /.*\.(\d+\.\d+\.\d+\.\d+)$/;
685 $target_i = pretty_print ($value);
686 $target{$ip_if."@".$host} = $target_i if ( defined ($snmp_comm_host{$community."@".$host}{$ip_if}) );
687 } else
688 {
689 die ("Suicide: no response from community $community on host $host","\n") if ($suicidal != 0);
690 print ("Soldiering on: no response from community $community on host $host","\n");
691 $session->close ();
692 last SOLDIER_ON;
693 }
694 @oids = @next_oids;
695 }
696
697 @oids = ($if_index_index);
698 for (;;) {
699 if ($session->getnext_request_response (@oids)) {
700 $response = $session->pdu_buffer;
701 ($bindings) = $session->decode_get_response ($response);
702 @next_oids = ();
703 ($binding,$bindings) = decode_sequence ($bindings);
704 ($oid,$value) = decode_by_template ($binding, "%O%@");
705 last unless BER::encoded_oid_prefix_p ($if_index_index, $oid);
706 push @next_oids, $oid;
707 ($ip_if) = pretty_print ($oid) =~ /.*\.(\d+\.\d+\.\d+\.\d+)$/;
708 $target_i = pretty_print ($value);
709 $target{$ip_if."@".$host} = $target_i if ( defined ($snmp_comm_host{$community."@".$host}{$ip_if}) );
710 } else
711 {
712 die ("Suicide: no response from community $community on host $host","\n") if ($suicidal != 0);
713 print ("Soldiering on: no response from community $community on host $host","\n");
714 $session->close ();
715 last SOLDIER_ON;
716 }
717 @oids = @next_oids;
718 }
719 $session->close ();
720 }
721 else
722 {
723 die ("Suicide: unable to open SNMP session to community $community on host $host","\n") if ($suicidal != 0);
724 print ("Soldiering on: unable to open SNMP session to community $community on host $host","\n");
725 }
726 }
727 }