From 073718ba64ac0e76e2ee3857644319f2e829e47c Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Tue, 19 Dec 2017 09:50:30 +0000
Subject: [PATCH] Task #11385: mail to seperate to/bcc adresses. only mention
 'could not find mail adresses' remark in successful mails

---
 .../lib/ingestjobmanagementserver.py               | 14 +++++++++-----
 .../LTAIngestServerCommon/config.py                |  8 ++++++--
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/lib/ingestjobmanagementserver.py b/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/lib/ingestjobmanagementserver.py
index f5a355e9831..c9f0ff9ca12 100644
--- a/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/lib/ingestjobmanagementserver.py
+++ b/LTA/LTAIngest/LTAIngestServer/LTAIngestAdminServer/lib/ingestjobmanagementserver.py
@@ -24,7 +24,7 @@ from lofar.lta.ingest.common.job import *
 from lofar.lta.ingest.common.config import DEFAULT_INGEST_NOTIFICATION_BUSNAME, DEFAULT_INGEST_NOTIFICATION_PREFIX
 from lofar.lta.ingest.server.config import DEFAULT_INGEST_BUSNAME, DEFAULT_INGEST_SERVICENAME
 from lofar.lta.ingest.common.config import DEFAULT_BROKER
-from lofar.lta.ingest.server.config import JOBS_DIR, MAX_NR_OF_RETRIES, FINISHED_NOTIFICATION_MAILING_LIST, DEFAULT_JOB_PRIORITY
+from lofar.lta.ingest.server.config import JOBS_DIR, MAX_NR_OF_RETRIES, FINISHED_NOTIFICATION_MAILING_LIST, FINISHED_NOTIFICATION_BCC_MAILING_LIST, DEFAULT_JOB_PRIORITY
 from lofar.lta.ingest.server.config import DEFAULT_JOBMANAGER_NOTIFICATION_QUEUENAME
 from lofar.lta.ingest.server.config import DEFAULT_INGEST_JOBS_QUEUENAME, DEFAULT_INGEST_JOBS_FOR_TRANSER_QUEUENAME
 from lofar.messaging import CommandMessage, EventMessage, FromBus, ToBus
@@ -1082,8 +1082,8 @@ Total Files: %(total)i
                     if project_details and 'author_email' in project_details:
                         extra_mail_addresses.append(project_details['author_email'])
 
-            if not extra_mail_addresses:
-                report += '\n\nCould not find any PI\'s/Contact-author\'s email address in MoM to sent this email to.'
+                if not extra_mail_addresses:
+                    report += '\n\nCould not find any PI\'s/Contact-author\'s email address in MoM to sent this email to.'
 
         except Exception as e:
             msg = 'error while trying to get PI\'s/Contact-author\'s email address for %s: %s' % (job_group_id, e)
@@ -1100,7 +1100,8 @@ Total Files: %(total)i
         mailing_list += submitters + extra_mail_addresses
         if mailing_list:
             # make it a csv list of addresses
-            mailing_list = ','.join(mailing_list)
+            mailing_list_csv = ','.join(mailing_list)
+            bcc_mailing_list_csv = ','.join(FINISHED_NOTIFICATION_BCC_MAILING_LIST)
             projects = set([j['Project'] for j in done_group_jobs if 'Project' in j])
 
             subject = "Ingest Export job %s of project %s " % (job_group_id, '/'.join(projects))
@@ -1116,7 +1117,10 @@ Total Files: %(total)i
                 len(done_group_jads),
                 100.0 * len(unfinished_group_jads) / len(done_group_jads))
 
-            if os.system('echo "%s"|mailx -s "%s" %s' % (report, subject, mailing_list)) == 0:
+            if os.system('echo "%s"|mailx -s "%s" %s %s' % (report,
+                                                            subject,
+                                                            '-b ' + bcc_mailing_list_csv if bcc_mailing_list_csv else '',
+                                                            mailing_list_csv)) == 0:
                 logger.info('sent notification email for export job %s to %s', job_group_id, mailing_list)
             else:
                 logger.error('failed sending a notification email for export job %s to %s', job_group_id, mailing_list)
diff --git a/LTA/LTAIngest/LTAIngestServer/LTAIngestServerCommon/config.py b/LTA/LTAIngest/LTAIngestServer/LTAIngestServerCommon/config.py
index 4e770da9472..b3094795ab8 100644
--- a/LTA/LTAIngest/LTAIngestServer/LTAIngestServerCommon/config.py
+++ b/LTA/LTAIngest/LTAIngestServer/LTAIngestServerCommon/config.py
@@ -32,7 +32,11 @@ GLOBUS_TIMEOUT = 1800
 
 TRANSFER_TIMEOUT = 300
 
-FINISHED_NOTIFICATION_MAILING_LIST=['schaap@astron.nl','softwaresupport@astron.nl']
+FINISHED_NOTIFICATION_MAILING_LIST = []
 if isProductionEnvironment():
-    FINISHED_NOTIFICATION_MAILING_LIST += ['observer@astron.nl','sos@astron.nl']
+    FINISHED_NOTIFICATION_MAILING_LIST += ['sos@astron.nl']
+
+FINISHED_NOTIFICATION_BCC_MAILING_LIST=['schaap@astron.nl','softwaresupport@astron.nl']
+if isProductionEnvironment():
+    FINISHED_NOTIFICATION_BCC_MAILING_LIST += ['observer@astron.nl']
 
-- 
GitLab