Skip to content

Commit

Permalink
Imported v0.4 from 2002-01-09 from https://www.fi.muni.cz/~kas/mrtg-rrd/
Browse files Browse the repository at this point in the history
  • Loading branch information
morgant committed Dec 10, 2015
1 parent de3adcf commit 95e1f48
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 72 deletions.
74 changes: 51 additions & 23 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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).

25 changes: 24 additions & 1 deletion FAQ
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
9 changes: 6 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
@@ -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
=================================
Expand Down Expand Up @@ -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 <IMG> tag.

* kMG[]: <empty> is not implemented
121 changes: 78 additions & 43 deletions mrtg-rrd.cgi
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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/^\///;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -266,13 +267,13 @@ EOF
print <<"EOF";
</TR><TR>
<TD ALIGN=RIGHT><SMALL>Max <FONT COLOR="$tgt->{col5}">&nbsp;Percentage:</FONT></SMALL></TD>
<TD ALIGN=RIGHT><SMALL>&nbsp;$percent[6]</SMALL></TD>
<TD ALIGN=RIGHT><SMALL>&nbsp;$relpercent[0]</SMALL></TD>
<TD WIDTH=5></TD>
<TD ALIGN=RIGHT><SMALL>Average <FONT COLOR="$tgt->{col5}">&nbsp;Percentage:</FONT></SMALL></TD>
<TD ALIGN=RIGHT><SMALL>&nbsp;$percent[7]</SMALL></TD>
<TD ALIGN=RIGHT><SMALL>&nbsp;$relpercent[1]</SMALL></TD>
<TD WIDTH=5></TD>
<TD ALIGN=RIGHT><SMALL>Current <FONT COLOR="$tgt->{col5}">&nbsp;Percentage:</FONT></SMALL></TD>
<TD ALIGN=RIGHT><SMALL>&nbsp;$percent[8]</SMALL></TD>
<TD ALIGN=RIGHT><SMALL>&nbsp;$relpercent[2]</SMALL></TD>
EOF
}
print <<'EOF';
Expand All @@ -285,7 +286,7 @@ sub do_percent($$)
{
my ($tgt, $values) = @_;

my @percent = ('', '', '', '', '', '', '', '', '');
my @percent = ('', '', '', '', '', '');

return @percent if defined $tgt->{options}{nopercent};

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -617,7 +637,6 @@ sub try_read_config()
%config = (
refresh => 300,
interval => 300,
icondir => '.',
);

%targets = ();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) = @_;

Expand All @@ -755,28 +772,46 @@ sub print_dir($) {
<HEAD>
<TITLE>MRTG: Directory $dir1</TITLE>
</HEAD>
<H1>MRTG graphs and subdirectories in directory $dir1</H1>
EOF
my $subdirs_printed;
if (defined @{$directories{$dir}{subdir}}) {
$subdirs_printed = 1;
print <<EOF;
<H1>MRTG subdirectories in the directory $dir1</H1>
<UL>
EOF
for my $item (@{$directories{$dir}}) {
if (defined $targets{$item}) {
for my $item (@{$directories{$dir}{subdir}}) {
print "<LI><A HREF=\"$item/\">$item/</A>\n";
}

print "</UL>\n";
}
if (defined @{$directories{$dir}{target}}) {
print "<HR>\n" if defined $subdirs_printed;
print <<EOF;
<H1>MRTG graphs in the directory $dir1</H1>
<TABLE BORDER=0 WIDTH=100%>
EOF
my $odd;
for my $item (@{$directories{$dir}{target}}) {
my $itemname = $item;
$itemname = $targets{$item}{title}
if defined $targets{$item}{title};
print " <TR>\n" unless $odd;
print <<EOF;
<LI><A HREF="$item.html">$itemname<BR>
<TD><A HREF="$item.html">$itemname<BR>
<IMG SRC="$item-day.png" BORDER=0 ALIGN=TOP VSPACE=10 ALT="$item">
</A><BR CLEAR=ALL>
</TD>
EOF
} else {
print <<EOF;
<LI><A HREF="$item/">$item/</A>
EOF
}
print " </TR>\n" if $odd;
$odd = !$odd;
}
print " </TR>\n</TABLE>\n";
}

print "</UL>\n";
print_banner();
print "</BODY>\n</HTML>\n";
}
Expand Down Expand Up @@ -823,7 +858,7 @@ version 2.9.17</font></td>
</tr>
</table>
EOF

print '<!--$Id: mrtg-rrd.cgi,v 1.12 2002/01/09 17:31:55 kas Exp $-->', "\n";
}

sub dump_targets() {
Expand Down

0 comments on commit 95e1f48

Please sign in to comment.