#!/usr/bin/env perl
#email results of ipp build check to ipp-dev
#email sent if build check fails or build summary file not found
#Bill Giebink 9/08

use strict;
use warnings;

use Email::Send;

my $email="ps-ipp-dev\@ifa.hawaii.edu";

my $today = `date -u +%Y%m%d`;
my $logfile = "/data/ipp003.0/ippTests/buildtest/logs/summlog.$today";

my @logcontents;

#check existence of log file
if (open (FPTR, $logfile)) {
  @logcontents = <FPTR>;
  } else {
  @logcontents = "FAIL: Can't Open File: $logfile\n";
}
close (FPTR);

my $message =<<END;
To: $email
From: giebink\@ifa.hawaii.edu
Subject: ipp build check summary $today

@logcontents

END

#only send message if check FAILs
if (grep {/FAIL/} @logcontents) {
  my $sender = Email::Send->new({mailer => 'SMTP'});
  $sender->mailer_args([Host => 'hale.ifa.hawaii.edu']);
  $sender->send($message);
}
