Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
0d1bbd8e
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 1 年多
通知
707
Star
9572
Fork
3514
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0d1bbd8e
编写于
2月 22, 2021
作者:
G
gaojun2048
提交者:
GitHub
2月 22, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4814 from CalvinKirs/script_thread
[Improvement][spi-alert]script plugin should contain alert content
上级
f166de17
cf042ccd
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
48 addition
and
19 deletion
+48
-19
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java
...phinscheduler/plugin/alert/script/ScriptAlertChannel.java
+1
-1
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
...he/dolphinscheduler/plugin/alert/script/ScriptSender.java
+10
-4
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java
...e/dolphinscheduler/plugin/alert/script/StreamGobbler.java
+7
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java
...olphinscheduler/plugin/alert/script/ProcessUtilsTest.java
+2
-2
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
...olphinscheduler/plugin/alert/script/ScriptSenderTest.java
+3
-3
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/scriptExample.sh
...duler-alert-script/src/test/script/shell/scriptExample.sh
+16
-2
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/test.sh
...lphinscheduler-alert-script/src/test/script/shell/test.sh
+9
-7
未找到文件。
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java
浏览文件 @
0d1bbd8e
...
...
@@ -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
()
);
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
浏览文件 @
0d1bbd8e
...
...
@@ -37,28 +37,34 @@ public class ScriptSender {
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
)
{
scriptPath
=
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_PATH
);
scriptType
=
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_TYPE
);
userParams
=
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_USER_PARAMS
);
}
AlertResult
sendScriptAlert
(
String
msg
)
{
AlertResult
sendScriptAlert
(
String
title
,
String
content
)
{
AlertResult
alertResult
=
new
AlertResult
();
if
(
ScriptType
.
SHELL
.
getDescp
().
equals
(
scriptType
))
{
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
+
ALERT_TITLE_OPTION
+
"'"
+
title
+
"'"
+
ALERT_CONTENT_OPTION
+
"'"
+
content
+
"'"
+
ALERT_USER_PARAMS_OPTION
+
"'"
+
userParams
+
"'"
};
int
exitCode
=
ProcessUtils
.
executeScript
(
cmd
);
if
(
exitCode
==
0
)
{
...
...
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java
浏览文件 @
0d1bbd8e
...
...
@@ -55,6 +55,13 @@ public class StreamGobbler extends Thread {
}
}
catch
(
IOException
e
)
{
logger
.
error
(
"I/O error occurs {}"
,
e
.
getMessage
());
}
finally
{
try
{
inputBufferReader
.
close
();
inputStreamReader
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
"I/O error occurs {}"
,
e
.
getMessage
());
}
}
}
...
...
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java
浏览文件 @
0d1bbd8e
...
...
@@ -26,9 +26,9 @@ public class ProcessUtilsTest {
private
static
final
String
rootPath
=
System
.
getProperty
(
"user.dir"
);
private
static
final
String
shellFilPath
=
rootPath
+
"/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/
example
.sh"
;
private
static
final
String
shellFilPath
=
rootPath
+
"/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/
test
.sh"
;
private
String
[]
cmd
=
{
"/bin/sh"
,
"-c"
,
shellFilPath
+
"
"
+
"testMsg"
+
" "
+
"userParams
"
};
private
String
[]
cmd
=
{
"/bin/sh"
,
"-c"
,
shellFilPath
+
"
-t 1
"
};
@Test
public
void
testExecuteScript
()
{
...
...
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
浏览文件 @
0d1bbd8e
...
...
@@ -35,7 +35,7 @@ public class ScriptSenderTest {
private
static
final
String
rootPath
=
System
.
getProperty
(
"user.dir"
);
private
static
final
String
shellFilPath
=
rootPath
+
"/src/test/script/shell/script
Test
.sh"
;
private
static
final
String
shellFilPath
=
rootPath
+
"/src/test/script/shell/script
Example
.sh"
;
@Before
public
void
initScriptConfig
()
{
...
...
@@ -49,9 +49,9 @@ public class ScriptSenderTest {
public
void
testScriptSenderTest
()
{
ScriptSender
scriptSender
=
new
ScriptSender
(
scriptConfig
);
AlertResult
alertResult
;
alertResult
=
scriptSender
.
sendScriptAlert
(
"
success
"
);
alertResult
=
scriptSender
.
sendScriptAlert
(
"
test title Kris"
,
"test content
"
);
Assert
.
assertEquals
(
"true"
,
alertResult
.
getStatus
());
alertResult
=
scriptSender
.
sendScriptAlert
(
"error
Msg
"
);
alertResult
=
scriptSender
.
sendScriptAlert
(
"error
msg title"
,
"test content
"
);
Assert
.
assertEquals
(
"false"
,
alertResult
.
getStatus
());
}
...
...
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/
e
xample.sh
→
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/
scriptE
xample.sh
浏览文件 @
0d1bbd8e
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
...
...
@@ -15,11 +16,24 @@
# limitations under the License.
#
while
getopts
t:c:p: opts
;
do
case
$opts
in
t
)
t
=
$OPTARG
;;
c
)
c
=
$OPTARG
;;
p
)
p
=
$OPTARG
;;
?
)
;;
esac
done
msg
=
$1
content
=
$2
# Write your specific logic here
# Set the exit code according to your execution result, and alert needs to use it to judge the status of this alarm result
if
[
"
$t
"
=
"error msg title"
]
then
exit
12
fi
exit
0
exit
0
\ No newline at end of file
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/
scriptT
est.sh
→
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/
t
est.sh
浏览文件 @
0d1bbd8e
...
...
@@ -15,11 +15,13 @@
# limitations under the License.
#
msg
=
$1
content
=
$2
while
getopts
t: opts
;
do
case
$opts
in
t
)
t
=
$OPTARG
;;
?
)
;;
esac
done
echo
"
$t
"
if
[
$msg
=
errorMsg
]
then
exit
12
fi
exit
0
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录