Revision d150e4ed
Added by Hamish Coleman over 15 years ago
- ID d150e4ed35d0ec8db1b942046ab7bc798580f537
indexmrtg.cgi | ||
---|---|---|
my $warnings;
|
||
my $db = {}; # storage for all tests found
|
||
|
||
$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;
|
||
$db->{global}{graph}{mtime} = 0; # Scan for newest graph and save info for later
|
||
$db->{hide}{mrtg}{global}{postfix}{xsize} = 500;
|
||
$db->{hide}{mrtg}{global}{postfix}{ysize} = 135;
|
||
|
||
sub config_save_val($$$$) {
|
||
my ($filename,$name,$var,$val) = @_;
|
||
... | ... | |
|
||
# Save any default initializers
|
||
if ($name eq '_') {
|
||
$db->{mrtg}{global}{postfix}{$var} = $val;
|
||
$db->{hide}{mrtg}{global}{postfix}{$var} = $val;
|
||
return;
|
||
}
|
||
if ($name eq '^') {
|
||
$db->{mrtg}{global}{prefix}{$var} = $val;
|
||
$db->{hide}{mrtg}{global}{prefix}{$var} = $val;
|
||
return;
|
||
}
|
||
|
||
... | ... | |
|
||
#TODO - instantiate new tests from all of the "_"/"^" defaults
|
||
|
||
push @{$db->{sequence}}, $unique_name;
|
||
push @{$db->{hide}{sequence}}, $unique_name;
|
||
|
||
$db->{graph}->{$unique_name}->{name} = $name;
|
||
$db->{graph}->{$unique_name}->{definedby} = $filename;
|
||
$db->{graph}->{$unique_name}->{sequence} = @{$db->{sequence}};
|
||
$db->{graph}->{$unique_name}->{sequence} = @{$db->{hide}{sequence}};
|
||
|
||
$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}{img}{xsize} = $db->{hide}{mrtg}{global}{postfix}{xsize};
|
||
$db->{graph}{$unique_name}{img}{ysize} = $db->{hide}{mrtg}{global}{postfix}{ysize};
|
||
|
||
}
|
||
$db->{mrtg}{target}{$unique_name}{$var} = $val;
|
||
$db->{hide}{mrtg}{target}{$unique_name}{$var} = $val;
|
||
}
|
||
|
||
# Load one or more files
|
||
... | ... | |
}
|
||
|
||
#TODO - multi-line values
|
||
#TODO - reset the {mrtg}{global} vars
|
||
#TODO - reset the {hide}{mrtg}{global} vars
|
||
|
||
while(<$fh>){
|
||
|
||
... | ... | |
my $var=lc $1;
|
||
my $val=$2;
|
||
|
||
$db->{mrtg}{global}{$var}=$val;
|
||
$db->{hide}{mrtg}{global}{$var}=$val;
|
||
}
|
||
|
||
# TODO - Handle extra statements:
|
||
... | ... | |
sub config_read_filesystem() {
|
||
|
||
# TODO - also check the other directory statements
|
||
if ($db->{mrtg}{global}{workdir}) {
|
||
chdir $db->{mrtg}{global}{workdir};
|
||
if ($db->{hide}{mrtg}{global}{workdir}) {
|
||
chdir $db->{hide}{mrtg}{global}{workdir};
|
||
}
|
||
|
||
# check and update details for all known tests;
|
||
for my $i (keys %{$db->{graph}}) {
|
||
my $graph = $db->{graph}->{$i};
|
||
my $graphname = $graph->{name};
|
||
my $mrtg = $db->{mrtg}{target}{$i};
|
||
my $mrtg = $db->{hide}{mrtg}{target}{$i};
|
||
|
||
# Default is GIF, unless a PNG file exists
|
||
$mrtg->{_imagetype} = 'gif';
|
||
... | ... | |
$graph->{img}{mtime} = $mtime;
|
||
|
||
# find the newest file
|
||
if ($mtime > $db->{mrtg}{gifdone}) {
|
||
$db->{mrtg}{gifdone} = $mtime;
|
||
if ($mtime > $db->{global}{graph}{mtime}) {
|
||
$db->{global}{graph}{mtime} = $mtime;
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
|
||
$db->{graph}{$name}{tag}{hosttype} = $hosttype;
|
||
$db->{hosttype}->{$hosttype}->{$host}++;
|
||
$db->{hide}{hosttype}->{$hosttype}->{$host}++;
|
||
}
|
||
|
||
for my $hosttype (keys %{$db->{hosttype}}) {
|
||
if ((keys %{$db->{hosttype}->{$hosttype}})<2) {
|
||
delete $db->{hosttype}->{$hosttype};
|
||
for my $hosttype (keys %{$db->{hide}{hosttype}}) {
|
||
if ((keys %{$db->{hide}{hosttype}->{$hosttype}})<2) {
|
||
delete $db->{hide}{hosttype}->{$hosttype};
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
# 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 + $db->{mrtg}{gifdone} - time; # predict how long until next update
|
||
my $refresh = $interval + $guardband + $db->{global}{graph}{mtime} - time; # predict how long until next update
|
||
$refresh = $interval if $refresh <= $guardband;
|
||
my $expires = gmtime (time + $interval * 2 + $guardband);
|
||
|
||
$db->{global}{expires} = "$expires GMT";
|
||
$db->{global}{refresh} = $refresh;
|
||
|
||
print "\n",JSON->new->utf8(1)->pretty(1)->canonical(1)->encode($db),"\n";
|
||
$db->{global}{graph}{expires} = "$expires GMT";
|
||
$db->{global}{graph}{refresh} = $refresh;
|
||
$db->{global}{sequence} = @{$db->{hide}{sequence}};
|
||
|
||
if (param('debug')) {
|
||
print "\n",Dumper(\$db),"\n";
|
||
}
|
||
|
||
# Remove objects that are not intended to be public
|
||
delete $db->{hide};
|
||
|
||
print "\n",JSON->new->utf8(1)->pretty(1)->canonical(1)->encode($db),"\n";
|
||
|
||
|
Also available in: Unified diff
Hide non public objects, rename global items to be more obvious