7 |
use CGI qw/:standard/; |
use CGI qw/:standard/; |
8 |
use POSIX qw(strftime); |
use POSIX qw(strftime); |
9 |
|
|
10 |
my $debug = 1; |
my $debug = 0; |
11 |
my $width = 600; |
|
12 |
my $use_js = 1; |
my $width = 600; # width of bar |
13 |
|
my $height = 12; # height of bar |
14 |
|
my $use_js = 1; # use JavaScript pop-up |
15 |
|
|
16 |
# status colors |
# status colors |
17 |
my %cols = ( |
my %cols = ( |
27 |
'Mount Request' => '128,128,255', |
'Mount Request' => '128,128,255', |
28 |
); |
); |
29 |
|
|
30 |
|
my $int_t = (12 * 60 * 60); # interval to display on one screen |
31 |
|
my $min_l = 3; # min length of bar segment (in pixels) |
32 |
|
|
33 |
#--- no user servicable parts below this line |
#--- no user servicable parts below this line |
34 |
|
|
35 |
# time range |
# time range |
36 |
|
|
37 |
my $day_t = (24 * 60 * 60); # 24h interval |
my ($from_t,$to_t) = (time()-$int_t,time()); |
|
|
|
|
my ($from_t,$to_t) = (time()-$day_t,time()); |
|
38 |
|
|
39 |
$to_t = param('to_t') if (param('to_t')); |
$to_t = param('to_t') if (param('to_t')); |
40 |
$from_t = param('from_t') if (param('from_t')); |
$from_t = param('from_t') if (param('from_t')); |
41 |
|
|
42 |
my $to=strftime("%Y-%m-%d %H:%M:%S",localtime ($to_t)); |
# round to nearest minute |
43 |
my $from=strftime("%Y-%m-%d %H:%M:%S",localtime ($from_t)); |
$to_t = $to_t - ($to_t % 60); |
44 |
|
$from_t = $from_t - ($from_t % 60) + 60; |
45 |
|
|
46 |
|
my $to=strftime("%Y-%m-%d %H:%M",localtime ($to_t)); |
47 |
|
my $from=strftime("%Y-%m-%d %H:%M",localtime ($from_t)); |
48 |
|
|
49 |
|
|
50 |
# keep count of each status |
# keep count of each status |
54 |
print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n"; |
print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n"; |
55 |
# create picture using GD |
# create picture using GD |
56 |
use GD; |
use GD; |
57 |
my $im = new GD::Image(1,8); |
my $im = new GD::Image(1,$height); |
58 |
my $back = $im->colorAllocate(255,255,255); |
my $back = $im->colorAllocate(255,255,255); |
59 |
$im->transparent($back); |
$im->transparent($back); |
60 |
my ($r,$g,$b) = split(/,/,param('pic')); |
my ($r,$g,$b) = split(/,/,param('pic')); |
105 |
|
|
106 |
print "<table>"; |
print "<table>"; |
107 |
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>"; |
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>"; |
108 |
print mknav(($from_t-$day_t),$to_t,'<small><<</small>'),$from; |
print mknav(($from_t-$int_t),$to_t,'<small><<</small>'),$from; |
109 |
print mknav(($from_t+$day_t),$to_t,'<small>>></small>') if ($from_t+$day_t < $to_t); |
print mknav(($from_t+$int_t),$to_t,'<small>>></small>') if ($from_t+$int_t < $to_t); |
110 |
print "</td><td align=right>"; |
print "</td><td align=right>"; |
111 |
print mknav($from_t,($to_t-$day_t),'<small><<</small>') if ($to_t-$day_t > $from_t); |
print mknav($from_t,($to_t-$int_t),'<small><<</small>') if ($to_t-$int_t > $from_t); |
112 |
print $to,mknav($from_t,($to_t+$day_t),'<small>>></small>'),"</td></tr>\n"; |
print $to,mknav($from_t,($to_t+$int_t),'<small>>></small>'),"</td></tr>\n"; |
113 |
|
|
114 |
my $fix_d = 0; # used to fix graph len |
my $fix_d = 0; # used to fix graph len |
|
my $min_l = 3; # min length; |
|
115 |
|
|
116 |
sub bar { |
sub bar { |
117 |
my $l = shift @_; # lenght of event utime |
my $l = shift @_; # lenght of event utime |
128 |
$fix_d = 0; |
$fix_d = 0; |
129 |
} |
} |
130 |
|
|
131 |
print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<br> alt:$alt\n" if ($debug); |
print STDERR "bar[$status] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug); |
132 |
|
|
133 |
my $html = "<img src=\"".$q->url(-relative=>1)."?pic="; |
my $html = "<img src=\"".$q->url(-relative=>1)."?pic="; |
134 |
|
|
140 |
$html .= '220,220,220'; |
$html .= '220,220,220'; |
141 |
} |
} |
142 |
|
|
143 |
$html .= "\" width=\"$size\" height=\"12\""; |
$html .= "\" width=\"$size\" height=\"$height\""; |
144 |
if ($use_js && $alt) { |
if ($use_js && $alt) { |
145 |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
146 |
} elsif ($alt) { |
} elsif ($alt) { |
151 |
return($html); |
return($html); |
152 |
} |
} |
153 |
|
|
154 |
my $sql = "select start,finish,specification,status |
my $sql = "select start,finish,specification,status,user_group_host, |
155 |
|
type,sessionid,device,host |
156 |
from gantt |
from gantt |
157 |
where (start < '$from' and finish > '$from') or |
where (start < '$from' and finish > '$from') or |
158 |
(start > '$from' and start < '$to') |
(start > '$from' and start < '$to') |
159 |
order by specification |
order by device,specification |
160 |
"; |
"; |
161 |
|
|
162 |
my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr; |
my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr; |
169 |
$sth->execute() || die "sql: $sql ".$dbh->errstr; |
$sth->execute() || die "sql: $sql ".$dbh->errstr; |
170 |
|
|
171 |
while(my $row = $sth->fetchrow_hashref) { |
while(my $row = $sth->fetchrow_hashref) { |
172 |
if ($row->{specification} ne $curr_spec) { |
if (!defined $curr_spec || $row->{specification} ne $curr_spec) { |
173 |
|
|
174 |
if ($curr_t < $to_t && $curr_spec) { |
if ($curr_t < $to_t && $curr_spec) { |
175 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
176 |
print STDERR "[filler $curr_t:$t]" if ($debug); |
print STDERR "[end filler $curr_t:$t]" if ($debug); |
177 |
print bar($t); |
print bar($t); |
178 |
} |
} |
179 |
|
|
180 |
print "</td></tr>\n" if ($curr_t != 0); |
print "</td></tr>\n" if ($curr_t != $from_t); |
181 |
print "<tr><td>", $row->{specification},"</td><td colspan=2>"; |
print "<tr><td>", $row->{specification},"</td><td colspan=2>"; |
182 |
|
|
183 |
$curr_t = $from_t; # init timeline |
$curr_t = $from_t; # init timeline |
190 |
|
|
191 |
if ($start_t > $curr_t) { |
if ($start_t > $curr_t) { |
192 |
my $t = $start_t - $curr_t; |
my $t = $start_t - $curr_t; |
193 |
print STDERR "[filler $curr_t:$t]" if ($debug); |
print STDERR "[middle filler $curr_t:$t]" if ($debug); |
194 |
print bar($t); |
print bar($t); |
195 |
$curr_t = $start_t; |
$curr_t = $start_t; |
196 |
} |
} |
206 |
$less = "<<"; |
$less = "<<"; |
207 |
} |
} |
208 |
|
|
|
next if ($fin_t > $to_t); |
|
|
|
|
209 |
if ($fin_t > $to_t) { |
if ($fin_t > $to_t) { |
210 |
# $len -= ($fin_t - $to_t); |
# $len -= ($fin_t - $to_t); |
211 |
$len = ($to_t - $curr_t); |
$len = ($to_t - $curr_t); |
213 |
} |
} |
214 |
|
|
215 |
print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug); |
print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug); |
216 |
print bar($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status}); |
|
217 |
|
my $alt = $row->{start}." - ".$row->{finish}."<br>"; |
218 |
|
$alt =~ s/:\d\d\.\d+//g; |
219 |
|
$alt =~ s/\s+/ /g; |
220 |
|
$alt .= $row->{type}." <b>".$row->{status}."</b><br>". |
221 |
|
$row->{user_group_host}." <i>".$row->{sessionid}."</i><br>". |
222 |
|
$row->{device}." on ".$row->{host}; |
223 |
|
print bar($len,$row->{status},$alt); |
224 |
|
|
225 |
$curr_t += $len; |
$curr_t += $len; |
226 |
|
|
228 |
|
|
229 |
} |
} |
230 |
|
|
231 |
|
if ($curr_t == $from_t) { # no entries in database! |
232 |
|
print "<tr><td></td><td colspan=2>"; |
233 |
|
} |
234 |
|
|
235 |
if ($curr_t < $to_t ) { |
if ($curr_t < $to_t ) { |
236 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
237 |
print STDERR "[filler $curr_t:$t]" if ($debug); |
print STDERR "[last_line filler $curr_t:$t]" if ($debug); |
238 |
print bar($t); |
print bar($t); |
239 |
} |
} |
240 |
|
|
251 |
print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n"; |
print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n"; |
252 |
foreach my $status (keys %count) { |
foreach my $status (keys %count) { |
253 |
#foreach my $status (keys %cols) { |
#foreach my $status (keys %cols) { |
254 |
print "<tr bgcolor=#e0e0e0><td><small>$status</small></td><td><small>",$count{$status},"</small></td><td>",bar($count{$status},$status),"</td></tr>\n" if ($status ne ""); |
print "<tr bgcolor=#e0e0e0><td><small>$status</small></td><td><small>",$count{$status}-1,"</small></td><td>",bar($count{$status},$status),"</td></tr>\n" if ($status ne ""); |
255 |
|
# -1 in line above is a cludge to display correct number on |
256 |
|
# occurences on graph and without one on legend! |
257 |
} |
} |
258 |
print "</table>\n</body></html>"; |
print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a>.</p></body></html>"; |
259 |
|
|