support sys notes
[buildfarm-server.git] / cgi-bin / show_log.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5 use Template;
6 use CGI;
7 use URI::Escape;
8
9 use vars qw($dbhost $dbname $dbuser $dbpass $dbport @log_file_names);
10
11
12 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
13 #require "BuildFarmWeb.pl";
14
15 die "no dbname" unless $dbname;
16 die "no dbuser" unless $dbuser;
17
18 my $dsn="dbi:Pg:dbname=$dbname";
19 $dsn .= ";host=$dbhost" if $dbhost;
20 $dsn .= ";port=$dbport" if $dbport;
21
22 my $query = new CGI;
23
24 my $system = $query->param('nm'); $system =~ s/[^a-zA-Z0-9_ -]//g;
25 my $logdate = $query->param('dt'); $logdate =~ s/[^a-zA-Z0-9_ -]//g;
26
27 my $log = "";
28 my $conf = "";
29 my ($stage,$changed_this_run,$changed_since_success,$sysinfo,$branch);
30
31 use vars qw($info_row);
32
33 if ($system && $logdate)
34 {
35
36         my $db = DBI->connect($dsn,$dbuser,$dbpass);
37
38         die $DBI::errstr unless $db;
39
40         my $statement = <<EOS;
41
42   select log,conf_sum,stage, changed_this_run, changed_since_success,branch,
43       log_archive_filenames
44   from build_status
45   where sysname = ? and snapshot = ?
46
47 EOS
48 ;
49         my $sth=$db->prepare($statement);
50         $sth->execute($system,$logdate);
51         my $row=$sth->fetchrow_arrayref;
52         $log=$row->[0];
53         $conf=$row->[1] || "not recorded" ;
54         $stage=$row->[2] || "unknown";
55         $changed_this_run = $row->[3];
56         $changed_since_success = $row->[4];
57         $branch = $row->[5];
58         my $log_file_names = $row->[6];
59         $log_file_names =~ s/^\{(.*)\}$/$1/;
60         @log_file_names=split(',',$log_file_names)
61             if $log_file_names;
62         $sth->finish;
63
64         $statement = <<EOS;
65
66           select operating_system, os_version, 
67                  compiler, compiler_version, 
68                  architecture,
69                  replace(owner_email,'\@',' [ a t ] ') as owner_email,
70                  sys_notes_ts::date AS sys_notes_date, sys_notes
71           from buildsystems 
72           where status = 'approved'
73                 and name = ?
74
75 EOS
76 ;
77         $sth=$db->prepare($statement);
78         $sth->execute($system);
79         $info_row=$sth->fetchrow_hashref;
80         # $sysinfo = join(" ",@$row);
81         $sth->finish;
82         $db->disconnect;
83 }
84
85 foreach my $chgd ($changed_this_run,$changed_since_success)
86 {
87     my @lines = split(/!/,$chgd);
88     foreach (@lines)
89     {
90         next unless m!^pgsql/!;
91         s!(^\S+)(\s+)(\S+)!<a href="http://anoncvs.postgresql.org/cvsweb.cgi/$1?rev=$3">$1$2$3</a>!;
92     }
93     $chgd = join("\n",@lines);
94     $chgd ||= 'not recorded';
95         
96 }
97
98 $conf =~ s/\@/ [ a t ] /g;
99 map {s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; s/\"/&quot;/g;} ($log,$conf);
100 # map {s/!/\n/g} ($changed_this_run,$changed_since_success);
101
102
103 use POSIX qw(ceil);
104 my $lrfactor = 6;
105 my $logrows = ceil(scalar(@log_file_names)/$lrfactor);
106 my $logcells = $lrfactor * $logrows;
107
108 my $heading_done;
109 my $urldt = uri_escape($logdate);
110
111 my $cell = 0;
112
113
114
115 print "Content-Type: text/html\n\n";
116
117 if ($stage eq 'OK')
118 {
119         print <<EOHTML;
120 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
121         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
122 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
123 <head>
124         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
125     <title>PostgreSQL BuildFarm | Configuration summary for system "$system"</title>
126         <link rel="icon" type="image/png" href="/elephant-icon.png" />
127     <link rel="stylesheet" rev="stylesheet" href="/inc/pgbf.css" charset="utf-8" />
128 </head>
129 <body>
130 <div id="wrapper">
131 <div id="banner">
132 <a href="/index.html"><img src="/inc/pgbuildfarm-banner.png" alt="PostgreSQL BuildFarm" width="800" height="73" /></a>
133 <div id="nav">
134 <ul>
135     <li id="home"><a href="/index.html" title="PostgreSQL BuildFarm Home">Home</a></li>
136     <li id="status"><a href="/cgi-bin/show_status.pl" title="Current results">Status</a></li>
137     <li id="members"><a href="/cgi-bin/show_members.pl" title="Platforms tested">Members</a></li>
138     <li id="register"><a href="/register.html" title="Join PostgreSQL BuildFarm">Register</a></li>
139     <li id="pgfoundry"><a href="http://pgfoundry.org/projects/pgbuildfarm/">PGFoundry</a></li>
140 </ul>
141 </div><!-- nav -->
142 </div><!-- banner -->
143 <div id="main">
144 <h1>PostgreSQL Build Farm Log</h1>
145 <table align="top" cellspacing="0">
146     <tr>
147         <th class="head" rowspan="2">System Information</th>
148         <th>Farm member</th>
149         <th>Branch</th>
150         <th>OS</th>
151         <th>Compiler</th>
152         <th>Architecture</th>
153         <th>Owner</th>
154     </tr>
155     <tr>
156         <td>$system</td>
157         <td><a href="/cgi-bin/show_history.pl?nm=$system&amp;br=$branch">$branch</a></td>
158         <td>$info_row->{operating_system} $info_row->{os_version}</td>
159         <td>$info_row->{compiler} $info_row->{compiler_version}</td>
160         <td>$info_row->{architecture}</td>
161         <td>$info_row->{owner_email}</td>
162     </tr>
163     </table>
164 EOHTML
165
166     if ($info_row->{sys_notes})
167     {
168         print <<EOHTML;
169     <br />
170     <table>
171      <tr>
172        <th class="head" rowspan="2">System Notes</th>
173        <th>Date</th>
174        <th>Notes</th>
175      </tr>
176      <tr>
177       <td>$info_row->{sys_notes_date}</td>
178       <td>$info_row->{sys_notes}</td>
179      </tr>
180    </table>
181 EOHTML
182
183     }
184
185 for my $logstage (@log_file_names)
186 {
187     print "<br /> <table><tr><th class='head' rowspan='$logrows'>Stage Logs</th>\n"
188         unless $heading_done;
189     $heading_done = 1;
190     $cell++;
191     $logstage =~ s/\.log$//;
192     print "<tr>\n" if ($cell > 1 && $cell % $lrfactor == 1);
193     print "<td><a href='show_stage_log.pl?nm=$system&amp;dt=$urldt&amp;stg=$logstage'>$logstage</a></td>\n";
194     print "</tr>\n" if ($cell % $lrfactor == 0);
195 }
196
197 if ($cell)
198 {
199     foreach my $rcell ($cell+1 .. $logcells)
200     {
201         print "<tr>\n" if ($rcell > 1 && $rcell % $lrfactor == 1);
202         print "<td>&nbsp;</td>\n";
203         print "</tr>\n" if ($rcell % $lrfactor == 0);
204     }
205     print "</table>\n";
206 }
207
208 print <<EOHTML;
209 </table>
210 <h2>Configuration summary for system "$system"</h2>
211 <h3>Status 'OK' on snapshot taken $logdate</h3>
212 <pre>
213 $conf
214 </pre>
215 <h3>Files changed this run</h3>
216 <pre>
217 $changed_this_run
218 </pre>
219 EOHTML
220 print <<EOHTML if ($log);
221 <h3>Log</h3>
222 <pre>
223 $log
224 </pre>
225 EOHTML
226     print <<EOHTML;
227 </div><!-- main -->
228 <hr />
229 <p style="text-align: center;">
230 Hosting for the PostgreSQL Buildfarm is generously 
231 provided by: 
232 <a href="http://www.commandprompt.com">CommandPrompt, 
233 The PostgreSQL Company</a>
234 </p>
235 </div><!-- wrapper -->
236 </body>
237 </html>
238 EOHTML
239 ;
240
241         exit;
242 }
243
244 print <<EOHTML;
245 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
246         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
247 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
248 <head>
249         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
250     <title>PostgreSQL BuildFarm | Log for system "$system" failure on snapshot taken $logdate</title>
251     <link rel="stylesheet" rev="stylesheet" href="/inc/pgbf.css" charset="utf-8" />
252 </head>
253 <body>
254 <div id="wrapper">
255 <div id="banner">
256 <a href="/index.html"><img src="/inc/pgbuildfarm-banner.png" alt="PostgreSQL BuildFarm" width="800" height="73" /></a>
257 <div id="nav">
258 <ul>
259     <li id="home"><a href="/index.html" title="PostgreSQL BuildFarm Home">Home</a></li>
260     <li id="status"><a href="/cgi-bin/show_status.pl" title="Status Page">Status</a></li>
261     <li id="members"><a href="/cgi-bin/show_members.pl" title="Status Page">Members</a></li>
262     <li id="register"><a href="/register.html" title="Register">Register</a></li>
263     <li id="pgfoundry"><a href="http://pgfoundry.org/projects/pgbuildfarm/">PGFoundry</a></li>
264 </ul>
265 </div><!-- nav -->
266 </div><!-- banner -->
267 <div id="main">
268     <h1>PostgreSQL Build Farm Log</h1>
269 <h1>Details for system "$system" failure at stage $stage on snapshot taken $logdate</h1>
270 <table cellspacing="0">
271     <tr>
272         <th class="head" rowspan="2">System Information</th>
273         <th>Farm member</th>
274         <th>Branch</th>
275         <th>OS</th>
276         <th>Compiler</th>
277         <th>Architecture</th>
278         <th>Owner</th>
279     </tr>
280     <tr>
281         <td>$system</td>
282         <td><a href="/cgi-bin/show_history.pl?nm=$system&amp;br=$branch">$branch</a></td>
283         <td>$info_row->{operating_system} $info_row->{os_version}</td>
284         <td>$info_row->{compiler} $info_row->{compiler_version}</td>
285         <td>$info_row->{architecture}</td>
286         <td>$info_row->{owner_email}</td>
287     </tr>
288   </table>
289 EOHTML
290
291     if ($info_row->{sys_notes})
292     {
293         print <<EOHTML;
294     <br />
295     <table>
296      <tr>
297        <th class="head" rowspan="2">System Notes</th>
298        <th>Date</th>
299        <th>Notes</th>
300      </tr>
301      <tr>
302       <td>$info_row->{sys_notes_date}</td>
303       <td>$info_row->{sys_notes}</td>
304      </tr>
305    </table>
306 EOHTML
307
308     }
309
310 for my $logstage (@log_file_names)
311 {
312     print "<br /> <table><tr><th class='head' rowspan='4'>Stage Logs</th>\n"
313         unless $heading_done;
314     $heading_done = 1;
315     $cell++;
316     $logstage =~ s/\.log$//;
317     print "<tr>\n" if ($cell > 1 && $cell % $lrfactor == 1);
318     print "<td><a href='show_stage_log.pl?nm=$system&amp;dt=$urldt&amp;stg=$logstage'>$logstage</a></td>\n";
319     print "</tr>\n" if ($cell % $lrfactor == 0);
320 }
321
322 if ($cell)
323 {
324     foreach my $rcell ($cell+1 .. $logcells)
325     {
326         print "<tr>\n" if ($rcell > 1 && $rcell % $lrfactor == 1);
327         print "<td>&nbsp;</td>\n";
328         print "</tr>\n" if ($rcell % $lrfactor == 0);
329     }
330     print "</table>\n";
331 }
332
333 print <<EOHTML;
334 <h3>Configuration summary</h3>
335 <pre>
336 $conf
337 </pre>
338 <h3>Files changed this run</h3>
339 <pre>
340 $changed_this_run
341 </pre>
342 <h3>Files changed since last success</h3>
343 <pre>
344 $changed_since_success
345 </pre>
346 <h3>Log</h3>
347 <pre>
348 $log
349 </pre>
350 </div><!-- main -->
351 <hr />
352 <p style="text-align: center;">
353 Hosting for the PostgreSQL Buildfarm is generously 
354 provided by: 
355 <a href="http://www.commandprompt.com">CommandPrompt, 
356 The PostgreSQL Company</a>
357 </p>
358 </div><!-- wrapper -->
359 </body>
360 </html>
361 EOHTML
362 ;
363
364
365
366