--- db2gantt.cgi 2002/09/18 14:00:18 1.22 +++ db2gantt.cgi 2003/06/26 20:36:48 1.28 @@ -10,6 +10,10 @@ my $debug = 0; +# comment out following field if you don't want links to omni reports +# or haven't installed repgen.pl +my $repgen_url="/omni/"; # URL to pages with rptgen.pl + my $width = 600; # width of bar my $height = 15; # height of bar my $use_js = 1; # use JavaScript pop-up @@ -28,6 +32,7 @@ 'Completed/Failure' => '128,0,128', 'Mount Request' => '128,128,255', 'Mount/Errors' => '255,64,128', + 'Mount/Failures' => '255,128,192', ); my $int_t = (12 * 60 * 60); # interval to display on one screen @@ -35,14 +40,25 @@ #--- no user servicable parts below this line -# time range - -$int_t = m_round($int_t); +my $q=new CGI; my ($from_t,$to_t) = (time()-$int_t,time()); -$to_t = param('to_t') if (param('to_t')); $from_t = param('from_t') if (param('from_t')); +$to_t = param('to_t') if (param('to_t')); + +if (param('f-1')) { + $from_t = $from_t - param('int_f-1') || $int_t; +} elsif (param('f+1')) { + $from_t = $from_t + param('int_f+1') || $int_t; +} elsif (param('t-1')) { + $to_t = $from_t - param('int_t-1') || $int_t; +} elsif (param('t+1')) { + $to_t = $from_t + $int_t; +} + +# time range +$int_t = m_round($int_t); # round to nearest minute sub m_round { @@ -69,7 +85,7 @@ $im->transparent($back); my $col = path_info(); $col =~ s,/,,g; my ($r,$g,$b) = split(/,/,$col); - my $col = $im->colorAllocate($r,$g,$b); + $col = $im->colorAllocate($r,$g,$b); $im->fill(0,0,$col); print "Content-Length: ",length($im->png),"\n\n"; binmode STDOUT; @@ -77,6 +93,9 @@ exit; } +# open DBI connection +my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr; + print "Content-type: text/html Cache-Control: max-age=60, must-revalidate @@ -97,33 +116,43 @@ '; } -print ""; +print " +
+ + +"; # all vars ending in *_t have utime in them. # my $len_t = $to_t - $from_t; -die "interval must be positive and bigger than 1 sec !" if ($len_t < 1); - -my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr; -my $q=new CGI; +die "interval must be positive and bigger than 1 sec !" if (abs($len_t) < 1); sub mknav { my $f = shift @_; # from_t my $t = shift @_; # to_t + my $d = shift @_; # delta my $ch = shift @_; # char - return "url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch"; + return " + + + "; + #return "url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch"; } print ""; print "\n"; +print mknav($from_t,$to_t,'t-1','<<') if ($to_t+$int_t > $from_t); +print $to,mknav($from_t,$to_t,'t+1','>>'),"\n"; # draw hour grid sub hour_grid { @@ -207,14 +236,23 @@ print STDERR "bar[$col] len:$l s scale:",($len_t/$width)," size:$size px
alt:$alt\n" if ($debug); - my $html = "url(-relative=>1)."/$col\" width=\"$size\" height=\"$h\""; + my $html; + + my ($html_end, $img_end) = ("",""); + if ($repgen_url && $alt =~ m#(\d\d\d\d)/(\d\d)/(\d\d)-(\d+)#) { + $html .= ""; + $html_end .= ""; + $img_end .= " border=0"; + } + + $html .= "url(-relative=>1)."/$col\" width=\"$size\" height=\"$h\""; if ($use_js && $alt) { $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; } elsif ($alt) { $html .= " alt=\"$alt\""; } - $html .= ">"; + $html .= "$img_end>$html_end"; return($html); } @@ -228,10 +266,11 @@ "; my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr; +print STDERR "sql: $sql\n" if ($debug); my %spec; # specification hash -my $curr_spec; +my $curr_spec = ""; my $curr_t = $from_t; $sth->execute() || die "sql: $sql ".$dbh->errstr; @@ -263,6 +302,8 @@ $last_var = $v; } } + # fix division by zero + $max_use++ if ($max_use == 0); my $h = $last_var / $max_use * $height; my $c = 255 - int (255 * $last_var / $max_use); print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1) if ($len); @@ -312,7 +353,10 @@ # init vars for next line ($fix_s,$fix_d) = (0,0); # init fix vars for bar - html_spec if ($curr_spec ne ""); + if ($curr_spec ne "") { + $curr_spec =~ s/ +/ /g; + html_spec; + } $curr_t = $from_t; # init timeline $curr_spec = $row->{specification}; @@ -405,10 +449,15 @@ # label and usage -$len_t = 50; # disable bar scaling print "
\nColors for statuses and usage (#):\n"; print "
Specification"; -print mknav(($from_t-$int_t),$to_t,'<<'),$from; -print mknav(($from_t+$int_t),$to_t,'>>') if ($from_t+$int_t < $to_t); +print mknav($from_t,$to_t,'f-1','<<'),$from; +print mknav($from_t,$to_t,'f+1','>>') if ($from_t+$int_t < $to_t); print ""; -print mknav($from_t,($to_t-$int_t),'<<') if ($to_t-$int_t > $from_t); -print $to,mknav($from_t,($to_t+$int_t),'>>'),"
\n"; +my $max = 0; +foreach my $status (keys %count) { + $max = $count{$status} if ($count{$status} > $max); +} +$len_t = $max ; # disable bar scaling + foreach my $status (keys %count) { #foreach my $status (keys %cols) { print "\n" if ($status ne ""); @@ -417,5 +466,4 @@ # it will first evaluate bar sub (thus increasing number by one) and # then display number (wrongly). } -print "
status#color
$status",$count{$status}*1,"",bar($count{$status},$status),"
\n

Reload url(-relative=>1),"\">current or see help.

"; - +print "
\n

Reload url(-relative=>1),"\">current or see help.

";