Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
25cbcc17
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 1 年多
通知
704
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
25cbcc17
编写于
1月 30, 2021
作者:
F
felix.wang
提交者:
GitHub
1月 30, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[BUG][Alert]fix alert plugin DingTalkSender (#4629)
* fix DingTalkSender * optimize context
上级
09feb5c0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
83 addition
and
95 deletion
+83
-95
dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java
...eduler/plugin/alert/dingtalk/DingTalkParamsConstants.java
+16
-28
dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java
...olphinscheduler/plugin/alert/dingtalk/DingTalkSender.java
+66
-66
dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java
...inscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java
+1
-1
未找到文件。
dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkParamsConstants.java
浏览文件 @
25cbcc17
...
...
@@ -22,36 +22,24 @@ package org.apache.dolphinscheduler.plugin.alert.dingtalk;
*/
public
class
DingTalkParamsConstants
{
static
final
String
DING_TALK_PROXY_ENABLE
=
"isEnableProxy"
;
static
final
String
DING_TALK_WEB_HOOK
=
"webhook"
;
static
final
String
NAME_DING_TALK_WEB_HOOK
=
"WebHook"
;
static
final
String
DING_TALK_KEYWORD
=
"keyword"
;
static
final
String
NAME_DING_TALK_KEYWORD
=
"Keyword"
;
static
final
String
NAME_DING_TALK_PROXY_ENABLE
=
"IsEnableProxy"
;
static
final
String
DING_TALK_PROXY
=
"proxy"
;
static
final
String
NAME_DING_TALK_PROXY
=
"Proxy"
;
static
final
String
DING_TALK_PORT
=
"port"
;
static
final
String
NAME_DING_TALK_PORT
=
"Port"
;
static
final
String
DING_TALK_USER
=
"user"
;
static
final
String
NAME_DING_TALK_USER
=
"User"
;
static
final
String
DING_TALK_PASSWORD
=
"password"
;
static
final
String
NAME_DING_TALK_PASSWORD
=
"Password"
;
private
DingTalkParamsConstants
()
{
throw
new
IllegalStateException
(
"Utility class"
);
}
static
final
String
DING_TALK_WEB_HOOK
=
"dingtalk.webhook"
;
static
final
String
NAME_DING_TALK_WEB_HOOK
=
"dingTalkWebHook"
;
static
final
String
DING_TALK_KEYWORD
=
"dingtalk.keyword"
;
static
final
String
NAME_DING_TALK_KEYWORD
=
"dingTalkKeyword"
;
public
static
final
String
DING_TALK_PROXY_ENABLE
=
"dingtalk.isEnableProxy"
;
static
final
String
NAME_DING_TALK_PROXY_ENABLE
=
"dingTalkIsEnableProxy"
;
static
final
String
DING_TALK_PROXY
=
"dingtalk.proxy"
;
static
final
String
NAME_DING_TALK_PROXY
=
"dingTalkProxy"
;
static
final
String
DING_TALK_PORT
=
"dingtalk.port"
;
static
final
String
NAME_DING_TALK_PORT
=
"dingTalkPort"
;
static
final
String
DING_TALK_USER
=
"dingtalk.user"
;
static
final
String
NAME_DING_TALK_USER
=
"dingTalkUser"
;
static
final
String
DING_TALK_PASSWORD
=
"dingtalk.password"
;
static
final
String
NAME_DING_TALK_PASSWORD
=
"dingTalkPassword"
;
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java
浏览文件 @
25cbcc17
...
...
@@ -75,51 +75,6 @@ public class DingTalkSender {
}
public
AlertResult
sendDingTalkMsg
(
String
msg
,
String
charset
)
{
AlertResult
alertResult
;
try
{
String
resp
=
sendMsg
(
msg
,
charset
);
return
checkSendDingTalkSendMsgResult
(
resp
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"send ding talk alert msg exception : {}"
,
e
.
getMessage
());
alertResult
=
new
AlertResult
();
alertResult
.
setStatus
(
"false"
);
alertResult
.
setMessage
(
"send ding talk alert fail."
);
}
return
alertResult
;
}
private
String
sendMsg
(
String
msg
,
String
charset
)
throws
IOException
{
String
msgToJson
=
textToJsonString
(
msg
+
"#"
+
keyword
);
HttpPost
httpPost
=
constructHttpPost
(
url
,
msgToJson
,
charset
);
CloseableHttpClient
httpClient
;
if
(
Boolean
.
TRUE
.
equals
(
enableProxy
))
{
httpClient
=
getProxyClient
(
proxy
,
port
,
user
,
password
);
RequestConfig
rcf
=
getProxyConfig
(
proxy
,
port
);
httpPost
.
setConfig
(
rcf
);
}
else
{
httpClient
=
getDefaultClient
();
}
try
{
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpPost
);
String
resp
;
try
{
HttpEntity
entity
=
response
.
getEntity
();
resp
=
EntityUtils
.
toString
(
entity
,
charset
);
EntityUtils
.
consume
(
entity
);
}
finally
{
response
.
close
();
}
logger
.
info
(
"Ding Talk send {}, resp: {}"
,
msg
,
resp
);
return
resp
;
}
finally
{
httpClient
.
close
();
}
}
private
static
HttpPost
constructHttpPost
(
String
url
,
String
msg
,
String
charset
)
{
HttpPost
post
=
new
HttpPost
(
url
);
StringEntity
entity
=
new
StringEntity
(
msg
,
charset
);
...
...
@@ -155,27 +110,6 @@ public class DingTalkSender {
return
JSONUtils
.
toJsonString
(
items
);
}
public
static
class
DingTalkSendMsgResponse
{
private
Integer
errcode
;
private
String
errmsg
;
public
Integer
getErrcode
()
{
return
errcode
;
}
public
void
setErrcode
(
Integer
errcode
)
{
this
.
errcode
=
errcode
;
}
public
String
getErrmsg
()
{
return
errmsg
;
}
public
void
setErrmsg
(
String
errmsg
)
{
this
.
errmsg
=
errmsg
;
}
}
private
static
AlertResult
checkSendDingTalkSendMsgResult
(
String
result
)
{
AlertResult
alertResult
=
new
AlertResult
();
alertResult
.
setStatus
(
"false"
);
...
...
@@ -201,4 +135,70 @@ public class DingTalkSender {
return
alertResult
;
}
public
AlertResult
sendDingTalkMsg
(
String
title
,
String
content
)
{
AlertResult
alertResult
;
try
{
String
resp
=
sendMsg
(
title
,
content
);
return
checkSendDingTalkSendMsgResult
(
resp
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"send ding talk alert msg exception : {}"
,
e
.
getMessage
());
alertResult
=
new
AlertResult
();
alertResult
.
setStatus
(
"false"
);
alertResult
.
setMessage
(
"send ding talk alert fail."
);
}
return
alertResult
;
}
private
String
sendMsg
(
String
title
,
String
content
)
throws
IOException
{
String
msgToJson
=
textToJsonString
(
title
+
content
+
"#"
+
keyword
);
HttpPost
httpPost
=
constructHttpPost
(
url
,
msgToJson
,
"UTF-8"
);
CloseableHttpClient
httpClient
;
if
(
Boolean
.
TRUE
.
equals
(
enableProxy
))
{
httpClient
=
getProxyClient
(
proxy
,
port
,
user
,
password
);
RequestConfig
rcf
=
getProxyConfig
(
proxy
,
port
);
httpPost
.
setConfig
(
rcf
);
}
else
{
httpClient
=
getDefaultClient
();
}
try
{
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpPost
);
String
resp
;
try
{
HttpEntity
entity
=
response
.
getEntity
();
resp
=
EntityUtils
.
toString
(
entity
,
"UTF-8"
);
EntityUtils
.
consume
(
entity
);
}
finally
{
response
.
close
();
}
logger
.
info
(
"Ding Talk send title :{},content : {}, resp: {}"
,
title
,
content
,
resp
);
return
resp
;
}
finally
{
httpClient
.
close
();
}
}
public
static
class
DingTalkSendMsgResponse
{
private
Integer
errcode
;
private
String
errmsg
;
public
Integer
getErrcode
()
{
return
errcode
;
}
public
void
setErrcode
(
Integer
errcode
)
{
this
.
errcode
=
errcode
;
}
public
String
getErrmsg
()
{
return
errmsg
;
}
public
void
setErrmsg
(
String
errmsg
)
{
this
.
errmsg
=
errmsg
;
}
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/test/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSenderTest.java
浏览文件 @
25cbcc17
...
...
@@ -50,7 +50,7 @@ public class DingTalkSenderTest {
dingTalkSender
.
sendDingTalkMsg
(
"keyWord+Welcome"
,
"UTF-8"
);
dingTalkConfig
.
put
(
DingTalkParamsConstants
.
NAME_DING_TALK_PROXY_ENABLE
,
"true"
);
dingTalkSender
=
new
DingTalkSender
(
dingTalkConfig
);
AlertResult
alertResult
=
dingTalkSender
.
sendDingTalkMsg
(
"
keyWord+Welcome"
,
"UTF-8
"
);
AlertResult
alertResult
=
dingTalkSender
.
sendDingTalkMsg
(
"
title"
,
"content test
"
);
Assert
.
assertEquals
(
"false"
,
alertResult
.
getStatus
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录