#!/usr/bin/perl --
use strict;
use RRDs;
use CGI;
use locale;
my $query = new CGI;
my $hostgroup = $query->param('hostgroup');
my $warning = $query->param('warning');
my $critical = $query->param('critical');
my $interval = $query->param('interval');
if (!$interval) {
$interval=30;
}
my ($i, $start, $end, $defstring, $def, $line, $key, $errstr) = undef;
my ($graphfile, $graph0, $graph1, $graph2, $graph3, $graph4, $title) = undef;
#
# Set Configuration Parameters
#
my $rrddir = "/usr/local/groundwork/feeders/rrd";
#my $rrddir = "/usr/local/nagios/rrd";
my $rrd = "$rrddir/$hostgroup.rrd";
my $graphdir = "/usr/local/groundwork/reports/graphs";
my $graphpath = "/groundwork/reports/graphs";
my $vlabel = "Percent"; # Vertical Label
my $bcolor = "FFFFFF"; # Background Color
sub body() {
my %measurement = (
percent => "#0000FF",
);
#
# Generate the graphs
#
foreach $key (keys %measurement) {
$def .= "\"DEF:$key=$rrd:$key:AVERAGE\", ";
$line .= "\"LINE2:$key$measurement{$key}:$key\", ";
$line .= "\"GPRINT:$key:MIN:(min=%.0lf\", ";
$line .= "\"GPRINT:$key:AVERAGE:ave=%.0lf\", ";
$line .= "\"GPRINT:$key:MAX:max=%.0lf)\" ";
#$line .= "\"STACK:$key$measurement{$key}:$key\", ";
}
$defstring = "$def $line";
$defstring =~ s/,\s$//;
$end = time;
# Graph Last $interval days
$title = "$hostgroup Availability Last $interval Days";
$start = $end - ($interval * 24 * 60 * 60);
$graph0 = $hostgroup."_0.png";
$graphfile = "$graphdir/$graph0";
$title = "\u$title";
my($averages,$xsize,$ysize);
# Change to free float - not set max to 100% - to get finer resolution - P. Loh 3-15-2005
#my $evalstring = '($averages,$xsize,$ysize) = RRDs::graph("$graphfile", "-s", $start, "-e", $end, "--color", "CANVAS#$bcolor", "--vertical-label", $vlabel, "-t", $title, "--lower-limit", 0, "--upper-limit", 100, "-w", 700, "-h", 150, '.$defstring.");";
my $evalstring = '($averages,$xsize,$ysize) = RRDs::graph("$graphfile", "-s", $start, "-e", $end, "--color", "CANVAS#$bcolor", "--vertical-label", $vlabel, "-t", $title, "-w", 500, "-h", 150, '.$defstring.");";
eval($evalstring);
my $err = RRDs::error;
if ($err) {
$errstr .= "$err
";
}
if ($errstr !~ /\w+/) {
my %checked = ();
$checked{$interval} = "checked";
return qq(
|
|||
|
); } else { return qq(
|