#!/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(

2 days    7 days    14 days    30 days
); } else { return qq( ); } } print "Content-type: text/html \n\n"; print qq( \u$hostgroup Availability ); print body(); print qq(
\u$hostgroup Errors!

The following occurred while generating the report:

$errstr
); __END__ "#E6E6FA", #=> "lavender", "#FF0000", #=> "red", # Starting here at index 1 "#00FF00", #=> "green", "#0000FF", #=> "blue", "#FFFF00", #=> "yellow", "#40E0D0", #=> "turquoise", "#00FFFF", #=> "cyan", "#006400", #=> "dark green", "#98FB98", #=> "pale green", "#FFD700", #=> "gold", "#A52A2A", #=> "brown", "#FFA500", #=> "orange", "#000080", #=> "navy", "#FFC0CB", #=> "pink", "#B03060", #=> "maroon", "#FF00FF", #=> "magenta", "#A020F0", #=> "purple", "#000000", #=> "black", "#BEBEBE" #=> "gray", my $evalstring = '($averages,$xsize,$ysize) = RRDs::graph($graphfile,"--start",$start,"--end",$end, "-t","Multi-Parameter Graph", "-w",600,"-h","300",'.$defstring.");"; my($averages,$xsize,$ysize) = RRDs::graph($graphfile, "--start", $start, "--end", $end, "-t", "Multi-Parameter Graph", "-w",600,"-h","300", $defstring); #print qq($graphfile --start $start --end $end -t "Multi-Parameter Graph" -w 600 -h 300 $defstring); # my $graphstring = qw($graphfile --start $start --end $end -t "Multi-Parameter Graph" -w 600 -h 300 $defstring); my $graphstring = qq("$graphfile", "-s=$start", "-e=$end","-t=Multi-Parameter Graph", "-w=600", "-h=300", $defstring);