Browse Source

[Improvement][spi-alert]script plugin should contain alert content

fix alert params contain space not parse

fix  stream not close
pull/3/MERGE
CalvinKirs 4 years ago
parent
commit
4275bde927
  1. 8
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
  2. 4
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
  3. 26
      dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptTest.sh

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

@ -37,6 +37,12 @@ public class ScriptSender {
private String userParams; private String userParams;
private static final String ALERT_TITLE_OPTION = " -t ";
private static final String ALERT_CONTENT_OPTION = " -c ";
private static final String ALERT_USER_PARAMS_OPTION = " -p ";
ScriptSender(Map<String, String> config) { ScriptSender(Map<String, String> config) {
scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH); scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH);
scriptType = Integer.parseInt(config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE)); scriptType = Integer.parseInt(config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE));
@ -58,7 +64,7 @@ public class ScriptSender {
alertResult.setMessage("shell script not support windows os"); alertResult.setMessage("shell script not support windows os");
return alertResult; return alertResult;
} }
String[] cmd = {"/bin/sh", "-c", scriptPath + " -alertTitle " + title+" -alertContent " + content + " alertUserParams " + userParams}; String[] cmd = {"/bin/sh", "-c", scriptPath + ALERT_TITLE_OPTION + "'" + title + "'" + ALERT_CONTENT_OPTION + "'" + content + "'" + ALERT_USER_PARAMS_OPTION + "'" + userParams + "'"};
int exitCode = ProcessUtils.executeScript(cmd); int exitCode = ProcessUtils.executeScript(cmd);
if (exitCode == 0) { if (exitCode == 0) {

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

@ -49,9 +49,9 @@ public class ScriptSenderTest {
public void testScriptSenderTest() { public void testScriptSenderTest() {
ScriptSender scriptSender = new ScriptSender(scriptConfig); ScriptSender scriptSender = new ScriptSender(scriptConfig);
AlertResult alertResult; AlertResult alertResult;
alertResult = scriptSender.sendScriptAlert("testtitleKrisKi", "testcontent"); alertResult = scriptSender.sendScriptAlert("test title Kris", "test content");
Assert.assertEquals("true", alertResult.getStatus()); Assert.assertEquals("true", alertResult.getStatus());
alertResult = scriptSender.sendScriptAlert("errorMsgtitle ", "testcontent"); alertResult = scriptSender.sendScriptAlert("error msg title", "test content");
Assert.assertEquals("false", alertResult.getStatus()); Assert.assertEquals("false", alertResult.getStatus());
} }

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

@ -1,3 +1,4 @@
#!/bin/bash
# #
# Licensed to the Apache Software Foundation (ASF) under one or more # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with # contributor license agreements. See the NOTICE file distributed with
@ -15,25 +16,18 @@
# limitations under the License. # limitations under the License.
# #
title=$1 while getopts t:c:p: opts; do
content=$2 case $opts in
userParams=$3 t) t=$OPTARG ;;
echo "last" c) c=$OPTARG ;;
echo $alertTitle p) p=$OPTARG ;;
?) ;;
echo "last" esac
echo $title
echo $content
echo $userParams
done done
if [ $title = errorMsg ] if [ "$t" = "error msg title" ]
then then
exit 12 exit 12
fi fi
exit 0
exit 0 exit 0
Loading…
Cancel
Save