From 95e1f4886567dfbe4c5933db0fde522d8743fccf Mon Sep 17 00:00:00 2001 From: Morgan Aldridge Date: Thu, 10 Dec 2015 12:47:56 -0500 Subject: [PATCH] Imported v0.4 from 2002-01-09 from https://www.fi.muni.cz/~kas/mrtg-rrd/ --- ChangeLog | 74 +++++++++++++++++++++---------- FAQ | 25 ++++++++++- Makefile | 4 +- TODO | 9 ++-- mrtg-rrd.cgi | 121 +++++++++++++++++++++++++++++++++------------------ 5 files changed, 161 insertions(+), 72 deletions(-) diff --git a/ChangeLog b/ChangeLog index d68d852..a815119 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,24 +1,52 @@ -$Id: ChangeLog,v 1.2 2002/01/04 17:13:26 kas Exp $ - -Fri Jan 4 18:00:39 CET 2002 - -Directory mode almost fully implemented. -Bumped the version number to 0.3 - - -Wed Jan 2 17:57:31 CET 2002 - -The Directory[] directive is now visible in the URL. - - -Tue Dec 18 14:06:29 CET 2001 - -Implemented the following mrtg.cfg directives: - Unscaled, WithPeak, XZoom, YZoom -Fixed the wrong behaviour of XScale, YScale. -Added $version as the separate variable. -Fixed the global options so that the graph still starts at y_min=0, even - if there is no time when the variable is near 0. -Fixed the [^], [_], and [$] behaviour for multiple configuration files - (the value should not remain defined from the previous cfg. file). +$Id: ChangeLog,v 1.6 2002/01/09 16:32:30 kas Exp $ + + +=================================================================== +RELEASE 0.4 + +* Wed Jan 9 13:50:29 CET 2002 + Fixed the incorrect behaviour when IconDir is not set. Now it displays + the icons from the same directory where the script is located. + Fixed the misplaced lc() in the config dir name (bug reported by + Peter Banfi). + Added few bug-hunting tips to the FAQ. + Reformated the ChangeLog to the more readable/structured form. + Implemented the double-column directory output. When the directory + contains both subdirectories and graphs, the directory index + consists of two sections - subdirs first and then graphs. + The HTML files contain the RCS id of the script in comment in the + banner part. + Bumped the version number to 0.4 + +* Tue Jan 8 10:03:41 CET 2002 + Older versions of RRDtool do not grok the "-g" switch. Added testing + the $RRDs::VERSION. + +* Mon Jan 7 16:10:39 CET 2002 + Configuration file directives can have values including whitespace + (thanks to Petr Prazak for discovering this). + Added checking of the RRD::graph's error code (as suggested by + Petr Prazak). + + +=================================================================== +RELEASE 0.3 + +* Fri Jan 4 18:00:39 CET 2002 + Directory mode almost fully implemented. + Bumped the version number to 0.3 + +* Wed Jan 2 17:57:31 CET 2002 + The Directory[] directive is now visible in the URL. + +* Tue Dec 18 14:06:29 CET 2001 + Implemented the following mrtg.cfg directives: + Unscaled, WithPeak, XZoom, YZoom + Fixed the wrong behaviour of XScale, YScale. + Added $version as the separate variable. + Fixed the global options so that the graph still starts at y_min=0, + even if there is no time when the variable is near 0. + Fixed the [^], [_], and [$] behaviour for multiple configuration files + (the value should not remain defined from the previous + cfg. file). diff --git a/FAQ b/FAQ index cd32725..cad1bf2 100644 --- a/FAQ +++ b/FAQ @@ -1,4 +1,4 @@ -$Id: FAQ,v 1.4 2002/01/04 17:18:17 kas Exp $ +$Id: FAQ,v 1.6 2002/01/09 16:32:30 kas Exp $ Q: What is this? A: The mrtg-rrd.cgi scripts is a replacement for the 14all.cgi script @@ -33,6 +33,29 @@ A: Point your browser to the http://your.server/cgi-bin/mrtg-rrd.cgi/ezwf.html CGI name, then your resource name -- ezwf here -- and a ".html" extension). +Q: It does not work. What should I do? +A: The author is willing to help you in his spare time, but you must give + as more information as you can (error messages, maybe HTML files + it outputs, etc). Please state clearly what are you doing and when + and how the mrtg-rrd behaviour starts to differ from what you + are expecting. + +Q: It does not display the MRTG banner images at the bottom of the page. +A: Either put the icons to the same directory as mrtg-rrd.cgi, or try to + set the IconDir: directive in mrtg.cfg. You have to have the + PNG versions of the images in that directory (mrtg-rrd currently + does not use GIFs). + +Q: It does not display the graphs, just the HTML files. What should I do? +A: The mrtg-rrd (i.e. the HTTP server under which it runs) need the write + access to the directory where the graph images are to be created. + Images are created either in the WorkDir: directory, or in the + ImageDir: directory, if the ImageDir: is set. + Set the ImageDir: directive to some separate directory + (it does not need to be visible inside the WWW tree) and make this + directory writable either by user or group under which the HTTP server + runs. + Q1: It is slow. How can I speed it up? Q2: I want to use FastCGI/mod_perl/Apache::Registry. I don't want to use CGI. A: The mrtg-rrd.cgi is written in a mod_perl friendly way. It can be diff --git a/Makefile b/Makefile index 373fd26..88ad7fe 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ -# $Id: Makefile,v 1.3 2002/01/04 17:16:05 kas Exp $ +# $Id: Makefile,v 1.4 2002/01/09 16:32:30 kas Exp $ FILES = COPYING FAQ TODO Makefile mrtg-rrd.cgi ChangeLog TARGETS = mrtg-rrd.fcgi -VERSION = 0.3 +VERSION = 0.4 all: $(TARGETS) diff --git a/TODO b/TODO index 5a244af..0aac71b 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -$Id: TODO,v 1.3 2002/01/04 17:13:27 kas Exp $ +$Id: TODO,v 1.6 2002/01/09 16:32:30 kas Exp $ Unimplemented mrtg.cfg directives ================================= @@ -33,13 +33,16 @@ Exact time of the previous VRULE (for month and year graphs). The MRTG-like legend on the X axis of the daily graph (every 2nd hour instead of every 6th our and ":00" appended). +Two-columned directory index? Suggested by Peter Banfi. + +The CGI speedup methods other than FastCGI (speedycgi?). + Known bugs ========== -* It should complain if the RRD::graph() fails. * Directory mode does not honour the "Suppress[]: d" and refers to the daily graph unconditionally. * Directory mode does not generate the "WIDHT=" and "HEIGHT=" parameters to the tag. - +* kMG[]: is not implemented diff --git a/mrtg-rrd.cgi b/mrtg-rrd.cgi index 0134f5f..5ea814d 100755 --- a/mrtg-rrd.cgi +++ b/mrtg-rrd.cgi @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: mrtg-rrd.cgi,v 1.6 2002/01/04 17:13:27 kas Exp $ +# $Id: mrtg-rrd.cgi,v 1.12 2002/01/09 17:31:55 kas Exp $ # # mrtg-rrd.cgi: The script for generating graphs for MRTG statistics. # @@ -35,15 +35,15 @@ use vars qw(@config_files @all_config_files %targets %config $config_time %directories $version); # EDIT THIS to reflect all your MRTG config files -BEGIN { @config_files = qw(/home/fadmin/mrtg/new/mrtg.cfg); } +BEGIN { @config_files = qw(/home/fadmin/mrtg/mrtg.cfg); } -$version = '0.3'; +$version = '0.4'; sub handler ($) { my ($q) = @_; - try_read_config(); + try_read_config($q->url()); my $path = $q->path_info(); $path =~ s/^\///; @@ -218,6 +218,7 @@ sub html_graph($$$$$) } my @percent = do_percent($tgt, \@values); + my @relpercent = do_relpercent($tgt, \@values); my @nv; for my $val (@values) { @@ -266,13 +267,13 @@ EOF print <<"EOF"; Max  Percentage: -  $percent[6] +  $relpercent[0] Average  Percentage: -  $percent[7] +  $relpercent[1] Current  Percentage: -  $percent[8] +  $relpercent[2] EOF } print <<'EOF'; @@ -285,7 +286,7 @@ sub do_percent($$) { my ($tgt, $values) = @_; - my @percent = ('', '', '', '', '', '', '', '', ''); + my @percent = ('', '', '', '', '', ''); return @percent if defined $tgt->{options}{nopercent}; @@ -296,16 +297,25 @@ sub do_percent($$) $percent[$val] = ' (' . $p . '%)'; } - if (defined $tgt->{options}{dorelpercent}) { - for my $val (0..2) { - $percent[6+$val] = sprintf("%.1f", - $values->[2*$val+1] * 100 / $values->[2*$val]) - if $values->[2*$val] > 0; - $percent[6+$val] ||= 0; - $percent[6+$val] .= ' %'; - } + @percent; +} + +sub do_relpercent($$) +{ + my ($tgt, $values) = @_; + + my @percent = ('', '', ''); + + return @percent unless defined $tgt->{options}{dorelpercent}; + + for my $val (0..2) { + $percent[$val] = sprintf("%.1f", + $values->[2*$val+1] * 100 / $values->[2*$val]) + if $values->[2*$val] > 0; + $percent[$val] ||= 0; + $percent[$val] .= ' %'; } - + @percent; } @@ -395,6 +405,9 @@ sub do_image($$) @{$target->{args}}, "VRULE:$oldsec#ff0000", "VRULE:$seconds#ff0000", @local_args_end); + my $rrd_error = RRDs::error; + print_error("RRDs::graph failed, $rrd_error") if defined $rrd_error; + # In array context just return the values return @rv if wantarray; @@ -583,8 +596,15 @@ sub common_args($$$) @args; } -sub try_read_config() +sub try_read_config($) { + my ($prefix) = (@_); + + # Verify the version of RRDtool: + if (!defined $RRDs::VERSION || $RRDs::VERSION < 1.000331) { + print_error("Please install more up-to date RRDtool - need at least 1.000331"); + } + my $read_cfg; if (!defined $config_time) { $read_cfg = 1; @@ -617,7 +637,6 @@ sub try_read_config() %config = ( refresh => 300, interval => 300, - icondir => '.', ); %targets = (); @@ -645,6 +664,11 @@ sub try_read_config() # use lib $config{libadd} # } + unless (defined $config{icondir}) { + $prefix =~ s/\/[^\/]*$//; + $config{icondir} = $prefix; + } + parse_directories(); $config_time = time; @@ -706,8 +730,8 @@ sub read_mrtg_config($$$) push @all_config_files, $1; read_mrtg_config($1, $def, $order); next; - } elsif (/^([\w\d]+) *: *(\S*)$/) { - my ($opt, $val) = (lc($1), lc($2)); + } elsif (/^([\w\d]+) *: *(\S.*)$/) { + my ($opt, $val) = (lc($1), $2); $config{$opt} = $val; next; } @@ -726,23 +750,16 @@ sub parse_directories { my $prefix = ''; for my $component (split /\/+/, $dir) { - add_dir($prefix, $component); + push (@{$directories{$prefix}{subdir}}, $component) + unless defined + $directories{$prefix.$component}; $prefix .= $component . '/'; } - add_dir($dir, $name); - + push (@{$directories{$dir}{target}}, $name); } } -sub add_dir($$) { - my ($dir, $name) = @_; - - @{$directories{$dir}} = () unless defined $directories{$dir}; - push (@{$directories{$dir}}, $name) - unless defined $directories{$dir.$name}; -} - sub print_dir($) { my ($dir) = @_; @@ -755,28 +772,46 @@ sub print_dir($) { MRTG: Directory $dir1 -

MRTG graphs and subdirectories in directory $dir1

+EOF + my $subdirs_printed; + if (defined @{$directories{$dir}{subdir}}) { + $subdirs_printed = 1; + print <MRTG subdirectories in the directory $dir1
    EOF - for my $item (@{$directories{$dir}}) { - if (defined $targets{$item}) { + for my $item (@{$directories{$dir}{subdir}}) { + print "
  • $item/\n"; + } + + print "
\n"; + } + if (defined @{$directories{$dir}{target}}) { + print "
\n" if defined $subdirs_printed; + print <MRTG graphs in the directory $dir1 + + +EOF + my $odd; + for my $item (@{$directories{$dir}{target}}) { my $itemname = $item; $itemname = $targets{$item}{title} if defined $targets{$item}{title}; + print " \n" unless $odd; print <$itemname
+
EOF - } else { - print <$item/ -EOF - } + print " \n" if $odd; + $odd = !$odd; + } + print " \n
$itemname
$item

+
\n"; } - print "\n"; print_banner(); print "\n\n"; } @@ -823,7 +858,7 @@ version 2.9.17 EOF - + print '', "\n"; } sub dump_targets() {