eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ralp...@apache.org
Subject incubator-eagle git commit: EAGLE-570: Refactor to make sure alert engine publisher only have general feature
Date Sun, 09 Oct 2016 04:51:40 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master 91643e84d -> ae8857772


EAGLE-570: Refactor to make sure alert engine publisher only have general feature

Author: Zeng, Bryant
Reviwer: ralphsu

This closes #479


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/ae885777
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/ae885777
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/ae885777

Branch: refs/heads/master
Commit: ae88577723ea85cf261d773e5983b85094b4e195
Parents: 91643e8
Author: mizeng <mizeng@ebaysf.com>
Authored: Sun Oct 9 11:09:37 2016 +0800
Committer: Ralph, Su <suliangfei@gmail.com>
Committed: Sun Oct 9 12:50:11 2016 +0800

----------------------------------------------------------------------
 .../publisher/impl/AlertSlackPublisher.java     | 44 ++------------------
 .../resources/router/publishments-slack.json    |  3 +-
 2 files changed, 5 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ae885777/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/impl/AlertSlackPublisher.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/impl/AlertSlackPublisher.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/impl/AlertSlackPublisher.java
index a52d558..9be0054 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/impl/AlertSlackPublisher.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/impl/AlertSlackPublisher.java
@@ -44,7 +44,6 @@ public class AlertSlackPublisher extends AbstractPublishPlugin {
 
     private SlackSession session;
     private String slackChannels;
-    private String urlTemplate;
     private String severitys;
 
     @Override
@@ -55,7 +54,6 @@ public class AlertSlackPublisher extends AbstractPublishPlugin {
             Map<String, String> slackConfig = new HashMap<>(publishment.getProperties());
             final String token = slackConfig.get(PublishConstants.TOKEN).trim();
             slackChannels = slackConfig.get(PublishConstants.CHANNELS).trim();
-            urlTemplate = slackConfig.get(PublishConstants.URL_TEMPLATE).trim();
             severitys = slackConfig.get(PublishConstants.SEVERITYS).trim();
 
             if (StringUtils.isNotEmpty(token)) {
@@ -82,11 +80,6 @@ public class AlertSlackPublisher extends AbstractPublishPlugin {
         for (AlertStreamEvent outputEvent: outputEvents) {
             String message = "";
             String severity = "";
-            String docId = "";
-            String device = "";
-            String deviceType = "";
-            String colo = "";
-            String component = "";
             String color = "";
             // only user defined severity level alert will send to Slack;
             boolean publishToSlack = false;
@@ -107,21 +100,6 @@ public class AlertSlackPublisher extends AbstractPublishPlugin {
                 if (colName.equalsIgnoreCase("message")) {
                     message = outputEvent.getData()[i].toString();
                 }
-                if (colName.equalsIgnoreCase("docId")) {
-                    docId = outputEvent.getData()[i].toString();
-                }
-                if (colName.equalsIgnoreCase("df_device") || colName.equalsIgnoreCase("entity")
|| colName.equalsIgnoreCase("hostname")) {
-                    device = outputEvent.getData()[i].toString();
-                }
-                if (colName.equalsIgnoreCase("df_type") || colName.equalsIgnoreCase("entityType"))
{
-                    deviceType = outputEvent.getData()[i].toString();
-                }
-                if (colName.equalsIgnoreCase("dc")) {
-                    colo = outputEvent.getData()[i].toString();
-                }
-                if (colName.equalsIgnoreCase("component")) {
-                    component = outputEvent.getData()[i].toString();
-                }
             }
 
             if (publishToSlack) {
@@ -139,28 +117,14 @@ public class AlertSlackPublisher extends AbstractPublishPlugin {
                             break;
                     }
 
-                    String messageToSlack = String.format("*New Alert from Device [%s] and
Component [%s]!*", device, component);
+                    // here to be generic, only publish message like "CRITICAL  port-1 is
down" to Slack
+                    String messageToSlack = String.format("%s %s", severity, message);
                     SlackAttachment attachment = new SlackAttachment();
                     attachment.setColor(color);
-                    attachment.setFooter("Alert Engine");
-                    attachment.addField("Severity", severity, false);
-                    attachment.addField("Message", message, false);
-                    attachment.addField("Device", device, false);
-                    attachment.addField("Device Type", deviceType, false);
-                    attachment.addField("Colo", colo, false);
-                    attachment.addField("Alert Policy", event.getPolicyId(), false);
-                    attachment.addField("Doc Id", docId, false);
-
-                    if (StringUtils.isNotEmpty(urlTemplate)) {
-                        try {
-                            attachment.addField("Link to Alert Console", String.format(urlTemplate,
docId), false);
-                        } catch (Exception e) {
-                            LOG.warn("There's an error when processing Alert Console Link!");
-                        }
-                    }
+                    attachment.setText(messageToSlack);
 
                     for (String slackChannel: slackChannels.split(",")) {
-                        sendMessageToAChannel(session, slackChannel, messageToSlack, attachment);
+                        sendMessageToAChannel(session, slackChannel, null, attachment);
                     }
                 } catch (Exception e) {
                     status.successful = false;

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/ae885777/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/resources/router/publishments-slack.json
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/resources/router/publishments-slack.json
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/resources/router/publishments-slack.json
index 3c49b48..dee7106 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/resources/router/publishments-slack.json
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/resources/router/publishments-slack.json
@@ -8,8 +8,7 @@
     "properties": {
       "token": "your token",
       "channels": "your channel1, your channel2",
-      "severitys": "CRITICAL",
-      "urltemplate": "your template/?id=%s"
+      "severitys": "CRITICAL"
     },
     "dedupIntervalMin": "PT1M",
     "dedupFields": [


Mime
View raw message