This is an automated email from the ASF dual-hosted git repository.

akshayrai09 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 5e525d0  [TE] Exclude template/blacklist emails before sending out 
alert (#4601)
5e525d0 is described below

commit 5e525d095cfc5d5aa20a2f3de4f9f46d15c4fa22
Author: Akshay Rai <[email protected]>
AuthorDate: Tue Sep 10 08:33:54 2019 -0700

    [TE] Exclude template/blacklist emails before sending out alert (#4601)
    
    * [TE] Exclude template/blacklist emails before sending out alert
    
    * Addressed comments
---
 .../detection/alert/scheme/DetectionEmailAlerter.java | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git 
a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/alert/scheme/DetectionEmailAlerter.java
 
b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/alert/scheme/DetectionEmailAlerter.java
index 88f99af..db875db 100644
--- 
a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/alert/scheme/DetectionEmailAlerter.java
+++ 
b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/alert/scheme/DetectionEmailAlerter.java
@@ -20,6 +20,7 @@
 package org.apache.pinot.thirdeye.detection.alert.scheme;
 
 import com.google.common.base.Preconditions;
+import java.util.Arrays;
 import java.util.HashSet;
 import org.apache.pinot.thirdeye.alert.commons.EmailContentFormatterFactory;
 import org.apache.pinot.thirdeye.alert.commons.EmailEntity;
@@ -71,6 +72,8 @@ public class DetectionEmailAlerter extends 
DetectionAlertScheme {
   private static final String PROP_EMAIL_TEMPLATE = "template";
   private static final String PROP_EMAIL_SUBJECT_STYLE = "subject";
 
+  List<String> emailBlacklist = new 
ArrayList<>(Arrays.asList("[email protected]", "[email protected]"));
+
   private ThirdEyeAnomalyConfiguration teConfig;
 
   public DetectionEmailAlerter(DetectionAlertConfigDTO config, 
ThirdEyeAnomalyConfiguration thirdeyeConfig,
@@ -87,6 +90,13 @@ public class DetectionEmailAlerter extends 
DetectionAlertScheme {
     return recipients;
   }
 
+  private Set<String> removeBlacklisted(Set<String> recipients, 
Collection<String> emailBlacklist) {
+    if (recipients != null) {
+      recipients.removeAll(emailBlacklist);
+    }
+    return recipients;
+  }
+
   private void configureAdminRecipients(DetectionAlertFilterRecipients 
recipients) {
     if (recipients.getCc() == null) {
       recipients.setCc(new HashSet<>());
@@ -106,6 +116,14 @@ public class DetectionEmailAlerter extends 
DetectionAlertScheme {
     }
   }
 
+  private void blacklistRecipients(DetectionAlertFilterRecipients recipients) {
+    if (recipients != null && !emailBlacklist.isEmpty()) {
+      recipients.setTo(removeBlacklisted(recipients.getTo(), emailBlacklist));
+      recipients.setCc(removeBlacklisted(recipients.getCc(), emailBlacklist));
+      recipients.setBcc(removeBlacklisted(recipients.getBcc(), 
emailBlacklist));
+    }
+  }
+
   private void validateAlert(DetectionAlertFilterRecipients recipients, 
Set<MergedAnomalyResultDTO> anomalies) {
     Preconditions.checkNotNull(recipients);
     Preconditions.checkNotNull(anomalies);
@@ -189,6 +207,7 @@ public class DetectionEmailAlerter extends 
DetectionAlertScheme {
   private void sendEmail(DetectionAlertFilterRecipients recipients, 
Set<MergedAnomalyResultDTO> anomalies) throws Exception {
     configureAdminRecipients(recipients);
     whitelistRecipients(recipients);
+    blacklistRecipients(recipients);
     validateAlert(recipients, anomalies);
 
     Map<String, Object> emailParams = 
ConfigUtils.getMap(this.config.getAlertSchemes().get(PROP_EMAIL_SCHEME));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to