You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2017/07/05 23:48:25 UTC

ambari git commit: AMBARI-20291 - Script-Based Alert Dispatchers support passing more parameters to script (Yao Lei via jonathanhurley)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 b3ec9aab4 -> cba018eb6


AMBARI-20291 - Script-Based Alert Dispatchers support passing more parameters to script (Yao Lei via jonathanhurley)


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

Branch: refs/heads/branch-2.5
Commit: cba018eb6d5c4f2946998d083e92448f5e3770ad
Parents: b3ec9aa
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Mon Mar 6 11:13:34 2017 -0500
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Wed Jul 5 16:41:01 2017 -0700

----------------------------------------------------------------------
 .../dispatchers/AlertScriptDispatcher.java      |  7 +++--
 .../services/AlertNoticeDispatchService.java    |  8 ++++++
 .../dispatchers/AlertScriptDispatcherTest.java  | 28 +++++++++++++++++++-
 3 files changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/cba018eb/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java b/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java
index 907588d..d65a11d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java
@@ -259,13 +259,16 @@ public class AlertScriptDispatcher implements NotificationDispatcher {
     String alertLabel = "\"" + SHELL_ESCAPE.escape(definition.getLabel()) + "\"";
     String alertText = "\"" + SHELL_ESCAPE.escape(alertInfo.getAlertText()) + "\"";
 
+    long alertTimestamp = alertInfo.getAlertTimestamp();
+    String hostName = alertInfo.getHostName(); // null if alert do not run against host
+
     Object[] params = new Object[] { script, definitionName, alertLabel, serviceName,
-        alertState.name(), alertText };
+        alertState.name(), alertText, alertTimestamp, hostName};
 
     String foo = StringUtils.join(params, " ");
 
     // sh -c '/foo/sys_logger.py ambari_server_agent_heartbeat "Agent Heartbeat"
-    // AMBARI CRITICAL "Something went wrong with the host"'
+    // AMBARI CRITICAL "Something went wrong with the host" 1111111 host222'
     return new ProcessBuilder(shellCommand, shellCommandOption, foo);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/cba018eb/ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java b/ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java
index d4ffd4a..906a782 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java
@@ -771,6 +771,14 @@ public class AlertNoticeDispatchService extends AbstractScheduledService {
     }
 
     /**
+     *  Gets the time that the alert was received
+     * @return
+       */
+    public long getAlertTimestamp() {
+      return m_history.getAlertTimestamp();
+    }
+
+    /**
      * Gets the state of the alert.
      *
      * @return

http://git-wip-us.apache.org/repos/asf/ambari/blob/cba018eb/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java b/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java
index 9e0e406..78f8ba0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java
@@ -237,6 +237,8 @@ public class AlertScriptDispatcherTest {
     final String ALERT_SERVICE_NAME = "FOO_SERVICE";
     final String ALERT_TEXT = "Did you know, \"Quotes are hard!!!\"";
     final String ALERT_TEXT_ESCAPED = "Did you know, \\\"Quotes are hard\\!\\!\\!\\\"";
+    final String ALERT_HOST = "mock_host";
+    final long ALERT_TIMESTAMP = 1111111l;
 
     DispatchCallback callback = EasyMock.createNiceMock(DispatchCallback.class);
     AlertNotification notification = new AlertNotification();
@@ -253,6 +255,9 @@ public class AlertScriptDispatcherTest {
     history.setAlertText(ALERT_TEXT);
     history.setAlertState(AlertState.OK);
     history.setServiceName(ALERT_SERVICE_NAME);
+    history.setHostName(ALERT_HOST);
+    history.setAlertTimestamp(ALERT_TIMESTAMP);
+
 
     AlertInfo alertInfo = new AlertInfo(history);
     notification.setAlertInfo(alertInfo);
@@ -272,9 +277,30 @@ public class AlertScriptDispatcherTest {
     buffer.append("\"").append(ALERT_DEFINITION_LABEL).append("\"").append(" ");
     buffer.append(ALERT_SERVICE_NAME).append(" ");
     buffer.append(AlertState.OK).append(" ");
-    buffer.append("\"").append(ALERT_TEXT_ESCAPED).append("\"");
+    buffer.append("\"").append(ALERT_TEXT_ESCAPED).append("\"").append(" ");
+    buffer.append(ALERT_TIMESTAMP).append(" ");
+    buffer.append(ALERT_HOST);
 
     Assert.assertEquals(buffer.toString(), commands.get(2));
+
+    //if hostname is null
+    history.setHostName(null);
+    alertInfo = new AlertInfo(history);
+    notification.setAlertInfo(alertInfo);
+
+    processBuilder = dispatcher.getProcessBuilder(SCRIPT_CONFIG_VALUE, notification);
+    commands = processBuilder.command();
+    buffer = new StringBuilder();
+    buffer.append(SCRIPT_CONFIG_VALUE).append(" ");
+    buffer.append(ALERT_DEFINITION_NAME).append(" ");
+    buffer.append("\"").append(ALERT_DEFINITION_LABEL).append("\"").append(" ");
+    buffer.append(ALERT_SERVICE_NAME).append(" ");
+    buffer.append(AlertState.OK).append(" ");
+    buffer.append("\"").append(ALERT_TEXT_ESCAPED).append("\"").append(" ");
+    buffer.append(ALERT_TIMESTAMP).append(" ");
+    buffer.append("");
+    Assert.assertEquals(buffer.toString(), commands.get(2));
+
   }
 
   /**