push notifications to IRC #exim-builds
[buildfarm-server.git] / cgi-bin / eximstatus.pl
index df25467a0ed0f945b052d247d96d873f35ad95cd..0184ae854f77adcb81298b2043d433b6357d1116 100755 (executable)
@@ -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
@@ -76,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 = 
@@ -191,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;   
     }
@@ -311,10 +312,10 @@ my $scmurl = $client_conf->{scm_url};
 
 my $logst = <<EOSQL;
     insert into build_status 
-      (sysname, snapshot,status, stage, log,conf_sum, branch,
+      (sysname, snapshot, status, stage, log, conf_sum, branch,
        changed_this_run, changed_since_success, 
-       log_archive_filenames , log_archive, build_flags, scm, scmurl, 
-       git_head_ref,frozen_conf)
+       log_archive_filenames, log_archive, build_flags, scm, scmurl, 
+       git_head_ref, frozen_conf)
     values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
 EOSQL
 ;
@@ -446,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;
 
@@ -566,6 +568,19 @@ EOMAIL
 
 $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];
@@ -603,3 +618,14 @@ For more information, see $url/cgi-bin/show_history.pl?nm=$animal&br=$branch
 EOMAIL
 
 $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",
+        }),
+    }
+);