X-Git-Url: https://git.exim.org/buildfarm-server.git/blobdiff_plain/809e6559569cdd40f73f40718da1d387333477d1..e3549578550de6d60f76f1399246fcc8821b44d8:/bf-alerts.pl?ds=inline diff --git a/bf-alerts.pl b/bf-alerts.pl index c118cc4..c038f96 100755 --- a/bf-alerts.pl +++ b/bf-alerts.pl @@ -1,5 +1,13 @@ #!/usr/bin/perl +=comment + +Copyright (c) 2003-2010, Andrew Dunstan + +See accompanying License file for license details + +=cut + use strict; use Digest::SHA1 qw(sha1_hex); @@ -8,13 +16,16 @@ use DBI; use DBD::Pg; use Data::Dumper; use Mail::Send; -use Safe; +use Storable qw(thaw); use vars qw($dbhost $dbname $dbuser $dbpass $dbport $all_stat $fail_stat $change_stat $green_stat + $default_host ); -require "$ENV{BFConfDir}/BuildFarmWeb.pl"; + +use FindBin qw($RealBin); +require "$RealBin/BuildFarmWeb.pl"; die "no dbname" unless $dbname; die "no dbuser" unless $dbuser; @@ -44,7 +55,7 @@ my $sth = $db->prepare(q[ SELECT DISTINCT ON (sysname, branch) sysname, branch, extract(epoch from snapshot at time zone 'GMT')::int as snapshot, - conf_sum as config + frozen_conf as config FROM build_status s join buildsystems b on (s.sysname = b.name) WHERE NOT b.no_alerts and snapshot > current_timestamp - interval '30 days' @@ -107,14 +118,7 @@ print "starting alert run: $lts\n"; foreach my $sysbranch (@last_heard) { - # eval the config in a Safe container to protect ourselves - my $container = new Safe; - my $sconf = $sysbranch->{config}; - unless ($sconf =~ s/.*(\$Script_Config)/$1/ms ) - { - $sconf = '$Script_Config={};'; - } - my $client_conf = $container->reval("$sconf;"); + my $client_conf = thaw $sysbranch->{config}; my %client_alert_settings = %{ $client_conf->{alerts} || {} }; my $setting = $client_alert_settings{$sysbranch->{branch}}; @@ -193,8 +197,11 @@ my $addr_sth = $db->prepare(q[ my $me = `id -un`; chomp $me; +my $host = `hostname`; chomp ($host); +$host = $default_host unless ($host =~ m/[.]/ || !defined($default_host)); -my $host = `hostname`; chomp $host; +my $from_addr = "Exim BuildFarm <$me\@$host>"; +$from_addr =~ tr /\r\n//d; @@ -216,7 +223,7 @@ foreach my $clearme (@need_cleared) } my $msg = new Mail::Send; - $msg->set('From',"PG Build Farm <$me\@$host>"); + $msg->set('From',$from_addr); $addr_sth->execute($animal); @@ -227,7 +234,7 @@ foreach my $clearme (@need_cleared) # $sth->finish; $msg->to($mailto); - $msg->subject("PGBuildfarm member $animal Branch $branch Alert cleared"); + $msg->subject("Exim BuildFarm member $animal Branch $branch Alert cleared"); my $fh = $msg->open; print $fh "\n\n$text\n"; $fh->close; @@ -235,16 +242,16 @@ foreach my $clearme (@need_cleared) print "alert cleared $animal $branch\n"; } -foreach my $clearme (@need_alerts) +foreach my $needme (@need_alerts) { - my ($sysbranch, $setting) = @$clearme; + my ($sysbranch, $setting) = @$needme; my ($animal, $branch) = ($sysbranch->{sysname},$sysbranch->{branch}); my $hours = sprintf("%.2f",($now - $sysbranch->{snapshot}) / 3600); my $text = "$sysbranch->{sysname} has not reported " . "on $sysbranch->{branch} for $hours hours."; my $msg = new Mail::Send; - $msg->set('From',"PG Build Farm <$me\@$host>"); + $msg->set('From',$from_addr); $addr_sth->execute($animal); @@ -256,7 +263,7 @@ foreach my $clearme (@need_alerts) $msg->to($mailto); - $msg->subject("PGBuildfarm member $animal Branch $branch " . + $msg->subject("Exim BuildFarm member $animal Branch $branch " . "Alert notification"); my $fh = $msg->open; print $fh "\n\n$text\n";