Revision 7d6cf686
Added by Hamish Coleman almost 16 years ago
- ID 7d6cf686f4dad31938fdd32f95f24390e5c23357
indexmrtg.cgi | ||
---|---|---|
);
|
||
|
||
# FIXME - globals
|
||
my $gifdone = 0; # Scan for newest graph and save info for later
|
||
my $warnings;
|
||
my $db = {}; # storage for all tests found
|
||
|
||
$db->{mrtg}{default}{post}{xsize} = 500;
|
||
$db->{mrtg}{default}{post}{ysize} = 135;
|
||
$db->{mrtg}{gifdone} = 0; # Scan for newest graph and save info for later
|
||
$db->{mrtg}{global}{postfix}{xsize} = 500;
|
||
$db->{mrtg}{global}{postfix}{ysize} = 135;
|
||
|
||
sub config_save_val($$$$) {
|
||
my ($filename,$name,$var,$val) = @_;
|
||
... | ... | |
|
||
# Save any default initializers
|
||
if ($name eq '_') {
|
||
$db->{mrtg}{default}{post}{$var} = $val;
|
||
$db->{mrtg}{global}{postfix}{$var} = $val;
|
||
return;
|
||
}
|
||
if ($name eq '^') {
|
||
$db->{mrtg}{default}{pre}{$var} = $val;
|
||
$db->{mrtg}{global}{prefix}{$var} = $val;
|
||
return;
|
||
}
|
||
|
||
... | ... | |
my $unique_name = $name;
|
||
my $unique_id = 1;
|
||
while (defined $db->{graph}->{$unique_name}
|
||
&& $db->{graph}->{$unique_name}->{srcfile} ne $filename) {
|
||
&& $db->{graph}->{$unique_name}->{definedby} ne $filename) {
|
||
$unique_name = $name . '_' . $unique_id;
|
||
$unique_id++;
|
||
}
|
||
... | ... | |
push @{$db->{sequence}}, $unique_name;
|
||
|
||
$db->{graph}->{$unique_name}->{name} = $name;
|
||
$db->{graph}->{$unique_name}->{srcfile} = $filename;
|
||
$db->{graph}->{$unique_name}->{definedby} = $filename;
|
||
$db->{graph}->{$unique_name}->{sequence} = @{$db->{sequence}};
|
||
|
||
$db->{graph}{$unique_name}{img}{xsize} = $db->{mrtg}{default}{post}{xsize};
|
||
$db->{graph}{$unique_name}{img}{ysize} = $db->{mrtg}{default}{post}{ysize};
|
||
$db->{graph}{$unique_name}{img}{xsize} = $db->{mrtg}{global}{postfix}{xsize};
|
||
$db->{graph}{$unique_name}{img}{ysize} = $db->{mrtg}{global}{postfix}{ysize};
|
||
|
||
}
|
||
$db->{graph}{$unique_name}{mrtg}{$var} = $val;
|
||
$db->{mrtg}{target}{$unique_name}{$var} = $val;
|
||
}
|
||
|
||
# Load one or more files
|
||
... | ... | |
}
|
||
|
||
#TODO - multi-line values
|
||
#TODO - reset the {mrtg}{global} vars
|
||
|
||
while(<$fh>){
|
||
|
||
... | ... | |
|
||
config_save_val($filename,$name,$var,$val);
|
||
|
||
} elsif ( $_ =~ /^([^#[][^[]+):\s*(.+)$/ ) {
|
||
# its a global statement
|
||
my $var=lc $1;
|
||
my $val=$2;
|
||
|
||
$db->{mrtg}{global}{$var}=$val;
|
||
}
|
||
|
||
# TODO - Handle extra statements:
|
||
# Include
|
||
# WorkDir
|
||
# WorkDir - see config_read_filesystem
|
||
# LogDir
|
||
# ##HC Magic for baseurl
|
||
}
|
||
... | ... | |
# any other filesystem details for them.
|
||
#
|
||
sub config_read_filesystem() {
|
||
|
||
# TODO - also check the other directory statements
|
||
if ($db->{mrtg}{global}{workdir}) {
|
||
chdir $db->{mrtg}{global}{workdir};
|
||
}
|
||
|
||
# check and update details for all known tests;
|
||
for my $i (keys %{$db->{graph}}) {
|
||
my $name = $db->{graph}->{$i};
|
||
my $testname = $name->{name};
|
||
|
||
# TODO - check workdir and validate it here
|
||
my $graph = $db->{graph}->{$i};
|
||
my $graphname = $graph->{name};
|
||
my $mrtg = $db->{mrtg}{target}{$i};
|
||
|
||
# Default is GIF, unless a PNG file exists
|
||
$name->{mrtg}{_imagetype} = 'gif';
|
||
if ( -e "$testname-day.png" ) {
|
||
$name->{mrtg}{_imagetype} = "png";
|
||
$mrtg->{_imagetype} = 'gif';
|
||
if ( -e "$graphname-day.png" ) {
|
||
$mrtg->{_imagetype} = "png";
|
||
}
|
||
|
||
# TODO - determine correct URL prefix
|
||
# TODO - change the filename based on the displayed period
|
||
my $filename = $testname . "-day." . $name->{mrtg}{_imagetype};
|
||
my $filename = $graphname . "-day." . $mrtg->{_imagetype};
|
||
$graph->{img}{URL} = $filename;
|
||
|
||
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
|
||
$atime,$mtime,$ctime,$blksize,$blocks)
|
||
... | ... | |
next;
|
||
}
|
||
|
||
$name->{_mtime} = $mtime;
|
||
# TODO - move these to a better function
|
||
$graph->{URL} = $graphname . '.html';
|
||
$graph->{title} = $mrtg->{title};
|
||
|
||
$graph->{img}{mtime} = $mtime;
|
||
|
||
# FIXME - global
|
||
# find the newest file
|
||
if ($mtime > $gifdone) {
|
||
$gifdone = $mtime;
|
||
if ($mtime > $db->{mrtg}{gifdone}) {
|
||
$db->{mrtg}{gifdone} = $mtime;
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
}
|
||
|
||
sub maketree_srcfile($$) {
|
||
sub maketree_definedby($$) {
|
||
my ($name,$sequence) = @_;
|
||
|
||
# config files
|
||
my $srcfile = $db->{graph}->{$name}->{srcfile};
|
||
my $definedby = $db->{graph}->{$name}->{definedby};
|
||
|
||
my @srcpath = split /\//,$srcfile;
|
||
my @srcpath = split /\//,$definedby;
|
||
|
||
shift @srcpath; # remove initial slash
|
||
|
||
... | ... | |
|
||
for my $name (keys %{$db->{graph}}) {
|
||
my $sequence = $db->{graph}->{$name}->{sequence};
|
||
maketree_srcfile($name,$sequence);
|
||
maketree_definedby($name,$sequence);
|
||
maketree_grouphosttest($name,$sequence);
|
||
# TODO - parse the Target setting and create trees
|
||
# TODO - parse magic comments and create trees here
|
||
... | ... | |
|
||
config_load_file(@config_files);
|
||
config_read_filesystem();
|
||
maketree();
|
||
|
||
|
||
# Time the next update to occur a little while after the next interval completes
|
||
my $interval = 300; # 5 min update interval
|
||
my $guardband = 15; # updates occur this many seconds after predicted gif completion
|
||
my $refresh = $interval + $guardband + $gifdone - time; # predict how long until next update
|
||
my $refresh = $interval + $guardband + $db->{mrtg}{gifdone} - time; # predict how long until next update
|
||
$refresh = $interval if $refresh <= $guardband;
|
||
my $expires = gmtime (time + $interval * 2 + $guardband);
|
||
|
Also available in: Unified diff
Structure of indexmrtg is now mostly right