forked from mmitch/rrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_html.pl
executable file
·79 lines (60 loc) · 1.75 KB
/
make_html.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl -w
#
# Generate HTML pages for rrd stats
#
use strict;
use warnings;
# parse configuration file
my %conf;
eval(`cat ~/.rrd-conf.pl`);
# set variables
my $path = $conf{OUTPATH};
my @rrd = @{$conf{MAKEHTML_MODULES}};
my @time = qw(hour day week year);
# other files to include
my @MORE = qw(make_html.gz Makefile.gz sample.conf.gz);
sub insert_links($);
foreach my $time (@time) {
my $file = "$path/$time.html";
print "generating `$file'\n";
open HTML, '>', $file or die "can't open `$file': $!";
my $time2 = $time . "ly";
$time2 =~ s/yly$/ily/;
print HTML "<html><head><title>$time2 statistics</title>";
print HTML "<meta http-equiv=\"refresh\" content=\"150; URL=$time.html\">";
print HTML "</head><body>";
insert_links($time);
foreach my $rrd (@rrd) {
print HTML "<img src=\"$rrd-$time.png\" alt=\"$rrd (last $time)\" align=\"top\">";
}
print HTML "<hr>";
insert_links($time);
print HTML "<p><small>Get the scripts here:";
opendir SCRIPTS, $path or die "can't opendir `$path': $!";
my %scripts_no_dups = map { $_ => 1 } ((sort grep /\.gz$/, readdir SCRIPTS), @MORE);
foreach my $script ( sort keys %scripts_no_dups ) {
print HTML " <a href=\"$script\">$script</a>";
}
closedir SCRIPTS or die "can't closedir `$path': $!";
print HTML "</p></body></html>";
close HTML or die "can't close `$file': $!";
}
sub insert_links($)
{
my $time = shift;
my $bar = 0;
print HTML "<p>[";
foreach my $linktime (@time) {
if ($bar) {
print HTML "|";
} else {
$bar = 1;
}
if ($linktime eq $time) {
print HTML " $linktime ";
} else {
print HTML " <a href=\"$linktime.html\">$linktime</a> ";
}
}
print HTML "]</p><hr>";
}