X-Git-Url: https://git.exim.org/buildfarm-server.git/blobdiff_plain/8300080b490ebbaa1d9b9176d864b0ea62e7fd2a..a78d9bf85e4e91b05abc18852c06e3ba65aff0aa:/cgi-bin/eximstatus.pl diff --git a/cgi-bin/eximstatus.pl b/cgi-bin/eximstatus.pl index b57655c..0184ae8 100755 --- a/cgi-bin/eximstatus.pl +++ b/cgi-bin/eximstatus.pl @@ -9,6 +9,7 @@ See accompanying License file for license details =cut use strict; +use URI::Escape; use vars qw($dbhost $dbname $dbuser $dbpass $dbport $all_stat $fail_stat $change_stat $green_stat @@ -24,19 +25,21 @@ use CGI; use Digest::SHA1 qw(sha1_hex); use MIME::Base64; use DBI; -use DBD::mysql; +use DBD::Pg; use Data::Dumper; use Mail::Send; use Time::ParseDate; use Storable qw(thaw); -require "$ENV{BFConfDir}/BuildFarmWeb.pl"; -my $buildlogs = "$ENV{BFConfDir}/buildlogs"; +use FindBin qw($RealBin); +require "$RealBin/../BuildFarmWeb.pl"; + +my $buildlogs = "$RealBin/../buildlogs"; die "no dbname" unless $dbname; die "no dbuser" unless $dbuser; -my $dsn="dbi:mysql:dbname=$dbname"; +my $dsn="dbi:Pg:dbname=$dbname"; $dsn .= ";host=$dbhost" if $dbhost; $dsn .= ";port=$dbport" if $dbport; @@ -74,7 +77,7 @@ if (open($brhandle,"../htdocs/branches_of_interest.txt")) my $content = - "branch=$branch&res=$res&stage=$stage&animal=$animal&". + 'branch=' . uri_escape($branch) . "&res=$res&stage=$stage&animal=$animal&". "ts=$ts&log=$log&conf=$conf"; my $extra_content = @@ -90,14 +93,15 @@ unless ($animal && $ts && $stage && $sig) } -unless ($branch =~ /^(HEAD|REL\d+_\d+_STABLE)$/) -{ - print - "Status: 492 bad branch parameter $branch\nContent-Type: text/plain\n\n", - "bad branch parameter $branch\n"; - exit; - -} +# Want to allow all kinds of named branches +#unless ($branch =~ /^(HEAD|REL\d+_\d+_STABLE)$/) +#{ +# print +# "Status: 492 bad branch parameter $branch\nContent-Type: text/plain\n\n", +# "bad branch parameter $branch\n"; +# exit; +# +#} my $db = DBI->connect($dsn,$dbuser,$dbpass); @@ -188,7 +192,7 @@ if ($log =~/Last file mtime in snapshot: (.*)/) if ($snaptime < ($last_branch_time - 86400)) { print "Status: 493 snapshot too old: $1\nContent-Type: text/plain\n\n"; - print "snapshot to old: $1\n"; + print "snapshot too old: $1\n"; $db->disconnect; exit; } @@ -226,7 +230,7 @@ if ($log_archive) chomp $githeadref; close $githead; } - # unlink $archname; + unlink $archname; } my $config_flags; @@ -296,6 +300,10 @@ if (@config_flags) @config_flags = grep {! m/=/ } @config_flags; map {s/\s+//g; $_=qq("$_"); } @config_flags; push @config_flags,'git' if $client_conf->{scm} eq 'git'; + push(@config_flags, 'doc') + if (defined $client_conf->{'optional_steps'}->{'make-doc'}); + push(@config_flags, 'test') + if (defined $client_conf->{'optional_steps'}->{'test'}); $config_flags = '{' . join(',',@config_flags) . '}' ; } @@ -304,10 +312,10 @@ my $scmurl = $client_conf->{scm_url}; my $logst = <begin_work; -$db->do("select set_local_error_terse()"); +#$db->do("select set_local_error_terse()"); $sth=$db->prepare($logst); @@ -335,13 +343,13 @@ $sth->bind_param(7,$branch); $sth->bind_param(8,$changed_this_run); $sth->bind_param(9,$changed_since_success); $sth->bind_param(10,$log_file_names); -#$sth->bind_param(11,$log_archive,{ pg_type => DBD::mysql::PG_BYTEA }); -$sth->bind_param(11,undef,{ pg_type => DBD::mysql::PG_BYTEA }); +#$sth->bind_param(11,$log_archive,{ pg_type => DBD::Pg::PG_BYTEA }); +$sth->bind_param(11,undef,{ pg_type => DBD::Pg::PG_BYTEA }); $sth->bind_param(12,$config_flags); $sth->bind_param(13,$scm); $sth->bind_param(14,$scmurl); $sth->bind_param(15,$githeadref); -$sth->bind_param(16,$frozen_sconf,{ pg_type => DBD::mysql::PG_BYTEA }); +$sth->bind_param(16,$frozen_sconf,{ pg_type => DBD::Pg::PG_BYTEA }); $sqlres = $sth->execute; @@ -439,15 +447,16 @@ $db->do("delete from dashboard_mat"); $db->do("insert into dashboard_mat select * from dashboard_mat_data"); $db->commit; -if ($stage ne 'OK') -{ - $db->begin_work; - # prevent occasional duplication by forcing serialization of this operation - $db->do("lock table nrecent_failures in share row exclusive mode"); - $db->do("delete from nrecent_failures"); - $db->do("insert into nrecent_failures select bs.sysname, bs.snapshot, bs.branch from build_status bs where bs.stage <> 'OK' and bs.snapshot > now() - interval '90 days'"); - $db->commit; -} + +#if ($stage ne 'OK') # On Exim build farm nrecent_failures is a view, not table... comment out +#{ +# $db->begin_work; +# # prevent occasional duplication by forcing serialization of this operation +# $db->do("lock table nrecent_failures in share row exclusive mode"); +# $db->do("delete from nrecent_failures"); +# $db->do("insert into nrecent_failures select bs.sysname, bs.snapshot, bs.branch from build_status bs where bs.stage <> 'OK' and bs.snapshot > now() - interval '90 days'"); +# $db->commit; +#} $db->disconnect; @@ -528,7 +537,7 @@ my $me = `id -un`; chomp($me); my $host = `hostname`; chomp ($host); $host = $default_host unless ($host =~ m/[.]/ || !defined($default_host)); -my $from_addr = "PG Build Farm <$me\@$host>"; +my $from_addr = "Exim Build Farm <$me\@$host>"; $from_addr =~ tr /\r\n//d; my $msg = new Mail::Send; @@ -536,13 +545,13 @@ my $msg = new Mail::Send; $msg->to(@$mailto); $msg->bcc(@$bcc_stat) if (@$bcc_stat); -$msg->subject("PGBuildfarm member $animal Branch $branch $stat_type $stage"); +$msg->subject("Exim BuildFarm member $animal Branch $branch $stat_type $stage"); $msg->set('From',$from_addr); my $fh = $msg->open; print $fh <close; +use HTTP::Tiny; +use JSON::PP; +HTTP::Tiny->new(timeout => 5)->post( + 'http://127.0.0.1:2567/api/message', { + headers => {'content-type' => 'application/json'}, + content => encode_json({ + gateway => 'exim-builds', + username => '', + text => "$animal [$branch]: @{[lc $stat_type]}: @{[lc $stage]}; commit: https://git.exim.org/@{[substr $githeadref, 0, 10]}", + }), + } +); + exit if ($stage eq $prev_stat); $mailto = [@$change_stat]; @@ -575,12 +597,12 @@ $stat_type = $prev_stat ne 'OK' ? "changed from $prev_stat failure to $stage" : $stat_type = "New member: $stage" if $prev_stat eq 'NEW'; $stat_type .= " failure" if $stage ne 'OK'; -$msg->subject("PGBuildfarm member $animal Branch $branch Status $stat_type"); +$msg->subject("Exim BuildFarm member $animal Branch $branch Status $stat_type"); $msg->set('From',$from_addr); $fh = $msg->open; print $fh <close; + +HTTP::Tiny->new(timeout => 5)->post( + 'http://127.0.0.1:2567/api/message', { + headers => {'content-type' => 'application/json'}, + content => encode_json({ + gateway => 'exim-builds', + username => '', + text => "$animal [$branch]: status @{[lc $stat_type]}; $url/cgi-bin/show_history.pl?nm=$animal&br=$branch", + }), + } +);