Browse Source

[alert-script]alert msg should contains content

pull/3/MERGE
CalvinKirs 4 years ago
parent
commit
6b56a78909
  1. 2
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java
  2. 9
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
  3. 6
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
  4. 9
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh
  5. 18
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptTest.sh

2
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java

@ -36,6 +36,6 @@ public class ScriptAlertChannel implements AlertChannel {
if (null == paramsMap) {
return new AlertResult("false", "ding talk params is null");
}
return new ScriptSender(paramsMap).sendScriptAlert(alertData.getTitle());
return new ScriptSender(paramsMap).sendScriptAlert(alertData.getTitle(),alertData.getContent());
}
}

9
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java

@ -43,23 +43,22 @@ public class ScriptSender {
userParams = config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS);
}
//fixme
AlertResult sendScriptAlert(String msg) {
AlertResult sendScriptAlert(String title, String content) {
AlertResult alertResult = new AlertResult();
if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) {
return executeShellScript(msg);
return executeShellScript(title, content);
}
return alertResult;
}
private AlertResult executeShellScript(String msg) {
private AlertResult executeShellScript(String title, String content) {
AlertResult alertResult = new AlertResult();
alertResult.setStatus("false");
if (Boolean.TRUE.equals(OSUtils.isWindows())) {
alertResult.setMessage("shell script not support windows os");
return alertResult;
}
String[] cmd = {"/bin/sh", "-c", scriptPath + " " + msg + " " + userParams};
String[] cmd = {"/bin/sh", "-c", scriptPath + " -alertTitle " + title+" -alertContent " + content + " alertUserParams " + userParams};
int exitCode = ProcessUtils.executeScript(cmd);
if (exitCode == 0) {

6
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java

@ -41,7 +41,7 @@ public class ScriptSenderTest {
public void initScriptConfig() {
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_TYPE, String.valueOf(ScriptType.SHELL.getCode()));
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS, "userParams");
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS, "test user params");
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_PATH, shellFilPath);
}
@ -49,9 +49,9 @@ public class ScriptSenderTest {
public void testScriptSenderTest() {
ScriptSender scriptSender = new ScriptSender(scriptConfig);
AlertResult alertResult;
alertResult = scriptSender.sendScriptAlert("success");
alertResult = scriptSender.sendScriptAlert("testtitleKrisKi", "testcontent");
Assert.assertEquals("true", alertResult.getStatus());
alertResult = scriptSender.sendScriptAlert("errorMsg");
alertResult = scriptSender.sendScriptAlert("errorMsgtitle ", "testcontent");
Assert.assertEquals("false", alertResult.getStatus());
}

9
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh

@ -16,8 +16,15 @@
#
msg=$1
title=$1
content=$2
userParams=$3
echo "$title"
echo "$content"
echo "$userParams"
# Write your specific logic here

18
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptTest.sh

@ -15,10 +15,24 @@
# limitations under the License.
#
msg=$1
title=$1
content=$2
userParams=$3
if [ $msg = errorMsg ]
echo title
echo "last"
echo $title
echo $content
echo $userParams
done
if [ $title = errorMsg ]
then
exit 12
fi

Loading…
Cancel
Save