#!/usr/local/gnu/bin/perl5 # -*- mode: Perl -*- ################################################################## # Multi Router Traffic Grapher: Index Generator ################################################################## # # This reads a mrtg.cfg file form std input or cmdline argument # and it takes a regexp on the cmdline to specify which # targets to look at. # # from this info it produces a router index on std out. # ################################################################## # Created by Tobias Oetiker # Modifications by Laurie Gellatly # Distributed under the GNU copyleft # # $Id: index,v 1.1.1.1 2002/02/26 10:16:36 oetiker Exp $ ################################################################## $regexp = pop @ARGV; $Title = pop @ARGV; if (defined($Title) && -f $Title) { push(@ARGV, $Title); $Title = "$Title Overview ($regexp)"; } if (! -f $ARGV[0]) { print " USAGE: index <regular expression> This tool will read the contents of the mrtg.cfg file and will return the HTML code of a webpage contanig the 'daily' graphs of all the routers whose titles match the regular expression. NOTE: you have to adjust this tool to your needs as the HTML contains our logo and our name ... "; exit ; } #slurp the cfg file while(<>) { s/\t/ /g; #replace tabs by spac next if /^\s+$/; #ignore white space next if /^\s*\#/; #ignore comments if (/$regexp/i && ! /\[\^\]/ && ! /\[\$\]/ && /^title\[([^\]]+)\]:\s*(.*\S)/i) { $router=lc($1); $arg=$2; $titles{$router} = $arg; next; } if (/^directory\[([^\]]+)\]:\s*(.*\S)/i) { $arg = $2; $tmp = lc($1); $dirs{$tmp} = "$arg/"; } if ($router && /^pagetop\[([^\]]+)\]:\s*(.*\S)/i) { next; } if ($router && /^\s+(.*?)<\/H1>/) { $titles{$router} .= " $1"; } $router = ''; } $Today=datestr(time); print <<ECHO; <HTML> <HEAD> <TITLE>$Title

$Title

These statistics were last updated $Today ECHO foreach $router (sort {$titles{$a} cmp $titles{$b}} keys %titles) { $dirs{$router} = "" if (!defined($dirs{$router})); $rdir = $dirs{$router}; print <$titles{$router}


ECHO } '$Revision: 1.1.1.1 $ ' =~ /Revision: (\S*)/; $rev=$1; '$Date: 2002/02/26 10:16:36 $ ' =~ /Date: (\S*)/; $date=$1; print <
$rev-$date Tobias Oetiker <oetiker\@ee.ethz.ch> and Dave Rand <dlr\@bungi.com>
Back to Main Router List
ECHO sub datestr { my ($time) = shift(@_) || return 0; my ($wday) = ('Sunday','Monday','Tuesday','Wednesday', 'Thursday','Friday','Saturday')[(localtime($time))[6]]; my ($month) = ('January','February' ,'March' ,'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' )[(localtime($time))[4]]; my ($mday,$year,$hour,$min) = (localtime($time))[3,5,2,1]; if ($min<10) {$min = "0$min";} return "$wday, $mday $month ".($year+1900)." at $hour:$min"; }