c9c0db7626a7619b56ec54f78d55574b01edc26d
[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           from buildsystems 
71           where status = 'approved'
72                 and name = ?
73
74 EOS
75 ;
76         $sth=$db->prepare($statement);
77         $sth->execute($system);
78         $info_row=$sth->fetchrow_hashref;
79         $sysinfo = join(" ",@$row);
80         $sth->finish;
81         $db->disconnect;
82 }
83
84 foreach my $chgd ($changed_this_run,$changed_since_success)
85 {
86     my @lines = split(/!/,$chgd);
87     foreach (@lines)
88     {
89         next unless m!^pgsql/!;
90         s!(^\S+)(\s+)(\S+)!<a href="http://anoncvs.postgresql.org/cvsweb.cgi/$1?rev=$3">$1$2$3</a>!;
91     }
92     $chgd = join("\n",@lines);
93     $chgd ||= 'not recorded';
94         
95 }
96
97 $conf =~ s/\@/ [ a t ] /g;
98 map {s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; s/\"/&quot;/g;} ($log,$conf);
99 # map {s/!/\n/g} ($changed_this_run,$changed_since_success);
100
101
102 use POSIX qw(ceil);
103 my $lrfactor = 6;
104 my $logrows = ceil(scalar(@log_file_names)/$lrfactor);
105 my $logcells = $lrfactor * $logrows;
106
107 my $heading_done;
108 my $urldt = uri_escape($logdate);
109
110 my $cell = 0;
111
112
113
114 print "Content-Type: text/html\n\n";
115
116 if ($stage eq 'OK')
117 {
118         print <<EOHTML;
119 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
120         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
121 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
122 <head>
123         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
124     <title>PostgreSQL BuildFarm | Configuration summary for system "$system"</title>
125         <link rel="icon" type="image/png" href="/elephant-icon.png" />
126     <link rel="stylesheet" rev="stylesheet" href="/inc/pgbf.css" charset="utf-8" />
127 </head>
128 <body>
129 <div id="wrapper">
130 <div id="banner">
131 <a href="/index.html"><img src="/inc/pgbuildfarm-banner.png" alt="PostgreSQL BuildFarm" width="800" height="73" /></a>
132 <div id="nav">
133 <ul>
134     <li id="home"><a href="/index.html" title="PostgreSQL BuildFarm Home">Home</a></li>
135     <li id="status"><a href="/cgi-bin/show_status.pl" title="Current results">Status</a></li>
136     <li id="members"><a href="/cgi-bin/show_members.pl" title="Platforms tested">Members</a></li>
137     <li id="register"><a href="/register.html" title="Join PostgreSQL BuildFarm">Register</a></li>
138     <li id="pgfoundry"><a href="http://pgfoundry.org/projects/pgbuildfarm/">PGFoundry</a></li>
139 </ul>
140 </div><!-- nav -->
141 </div><!-- banner -->
142 <div id="main">
143 <h1>PostgreSQL Build Farm Log</h1>
144 <table align="top" cellspacing="0">
145     <tr>
146         <th class="head" rowspan="2">System Information</th>
147         <th>Farm member</th>
148         <th>Branch</th>
149         <th>OS</th>
150         <th>Compiler</th>
151         <th>Architecture</th>
152         <th>Owner</th>
153     </tr>
154     <tr>
155         <td>$system</td>
156         <td><a href="/cgi-bin/show_history.pl?nm=$system&amp;br=$branch">$branch</a></td>
157         <td>$info_row->{operating_system} $info_row->{os_version}</td>
158         <td>$info_row->{compiler} $info_row->{compiler_version}</td>
159         <td>$info_row->{architecture}</td>
160         <td>$info_row->{owner_email}</td>
161     </tr>
162     </table>
163 EOHTML
164
165 for my $logstage (@log_file_names)
166 {
167     print "<br /> <table><tr><th class='head' rowspan='4'>Stage Logs</th>\n"
168         unless $heading_done;
169     $heading_done = 1;
170     $cell++;
171     $logstage =~ s/\.log$//;
172     print "<tr>\n" if ($cell > 1 && $cell % $lrfactor == 1);
173     print "<td><a href='show_stage_log.pl?nm=$system&amp;dt=$urldt&amp;stg=$logstage'>$logstage</a></td>\n";
174     print "</tr>\n" if ($cell % $lrfactor == 0);
175 }
176
177 if ($cell)
178 {
179     foreach my $rcell ($cell+1 .. $logcells)
180     {
181         print "<tr>\n" if ($rcell > 1 && $rcell % $lrfactor == 1);
182         print "<td>&nbsp;</td>\n";
183         print "</tr>\n" if ($rcell % $lrfactor == 0);
184     }
185     print "</table>\n";
186 }
187
188 print <<EOHTML;
189 </table>
190 <h2>Configuration summary for system "$system"</h2>
191 <h3>Status 'OK' on snapshot taken $logdate</h3>
192 <pre>
193 $conf
194 </pre>
195 <h3>Files changed this run</h3>
196 <pre>
197 $changed_this_run
198 </pre>
199 EOHTML
200 print <<EOHTML if ($log);
201 <h3>Log</h3>
202 <pre>
203 $log
204 </pre>
205 EOHTML
206     print <<EOHTML;
207 </div><!-- main -->
208 <hr />
209 <p style="text-align: center;">
210 Hosting for the PostgreSQL Buildfarm is generously 
211 provided by: 
212 <a href="http://www.commandprompt.com">CommandPrompt, 
213 The PostgreSQL Company</a>
214 </p>
215 </div><!-- wrapper -->
216 </body>
217 </html>
218 EOHTML
219 ;
220
221         exit;
222 }
223
224 print <<EOHTML;
225 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
226         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
227 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
228 <head>
229         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
230     <title>PostgreSQL BuildFarm | Log for system "$system" failure on snapshot taken $logdate</title>
231     <link rel="stylesheet" rev="stylesheet" href="/inc/pgbf.css" charset="utf-8" />
232 </head>
233 <body>
234 <div id="wrapper">
235 <div id="banner">
236 <a href="/index.html"><img src="/inc/pgbuildfarm-banner.png" alt="PostgreSQL BuildFarm" width="800" height="73" /></a>
237 <div id="nav">
238 <ul>
239     <li id="home"><a href="/index.html" title="PostgreSQL BuildFarm Home">Home</a></li>
240     <li id="status"><a href="/cgi-bin/show_status.pl" title="Status Page">Status</a></li>
241     <li id="members"><a href="/cgi-bin/show_members.pl" title="Status Page">Members</a></li>
242     <li id="register"><a href="/register.html" title="Register">Register</a></li>
243     <li id="pgfoundry"><a href="http://pgfoundry.org/projects/pgbuildfarm/">PGFoundry</a></li>
244 </ul>
245 </div><!-- nav -->
246 </div><!-- banner -->
247 <div id="main">
248     <h1>PostgreSQL Build Farm Log</h1>
249 <h1>Details for system "$system" failure at stage $stage on snapshot taken $logdate</h1>
250 <table cellspacing="0">
251     <tr>
252         <th class="head" rowspan="2">System Information</th>
253         <th>Farm member</th>
254         <th>Branch</th>
255         <th>OS</th>
256         <th>Compiler</th>
257         <th>Architecture</th>
258         <th>Owner</th>
259     </tr>
260     <tr>
261         <td>$system</td>
262         <td><a href="/cgi-bin/show_history.pl?nm=$system&amp;br=$branch">$branch</a></td>
263         <td>$info_row->{operating_system} $info_row->{os_version}</td>
264         <td>$info_row->{compiler} $info_row->{compiler_version}</td>
265         <td>$info_row->{architecture}</td>
266         <td>$info_row->{owner_email}</td>
267     </tr>
268     </table>
269 EOHTML
270
271 for my $logstage (@log_file_names)
272 {
273     print "<br /> <table><tr><th class='head' rowspan='4'>Stage Logs</th>\n"
274         unless $heading_done;
275     $heading_done = 1;
276     $cell++;
277     $logstage =~ s/\.log$//;
278     print "<tr>\n" if ($cell > 1 && $cell % $lrfactor == 1);
279     print "<td><a href='show_stage_log.pl?nm=$system&amp;dt=$urldt&amp;stg=$logstage'>$logstage</a></td>\n";
280     print "</tr>\n" if ($cell % $lrfactor == 0);
281 }
282
283 if ($cell)
284 {
285     foreach my $rcell ($cell+1 .. $logcells)
286     {
287         print "<tr>\n" if ($rcell > 1 && $rcell % $lrfactor == 1);
288         print "<td>&nbsp;</td>\n";
289         print "</tr>\n" if ($rcell % $lrfactor == 0);
290     }
291     print "</table>\n";
292 }
293
294 print <<EOHTML;
295 <h3>Configuration summary</h3>
296 <pre>
297 $conf
298 </pre>
299 <h3>Files changed this run</h3>
300 <pre>
301 $changed_this_run
302 </pre>
303 <h3>Files changed since last success</h3>
304 <pre>
305 $changed_since_success
306 </pre>
307 <h3>Log</h3>
308 <pre>
309 $log
310 </pre>
311 </div><!-- main -->
312 <hr />
313 <p style="text-align: center;">
314 Hosting for the PostgreSQL Buildfarm is generously 
315 provided by: 
316 <a href="http://www.commandprompt.com">CommandPrompt, 
317 The PostgreSQL Company</a>
318 </p>
319 </div><!-- wrapper -->
320 </body>
321 </html>
322 EOHTML
323 ;
324
325
326
327