mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-02 04:08:31 +08:00
[Feature-8138][Task] add at@ msg in the dingtalk task plugin (#8139)
This commit is contained in:
parent
e0dbf3edc6
commit
1fd748f376
@ -64,6 +64,28 @@ public final class DingTalkAlertChannelFactory implements AlertChannelFactory {
|
||||
.setRequired(false)
|
||||
.build())
|
||||
.build();
|
||||
InputParam atMobilesParam = InputParam
|
||||
.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_AT_MOBILES, DingTalkParamsConstants.DING_TALK_AT_MOBILES)
|
||||
.addValidate(Validate.newBuilder()
|
||||
.setRequired(false)
|
||||
.build())
|
||||
.build();
|
||||
InputParam atUserIdsParam = InputParam
|
||||
.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_AT_USERIDS, DingTalkParamsConstants.DING_TALK_AT_USERIDS)
|
||||
.addValidate(Validate.newBuilder()
|
||||
.setRequired(false)
|
||||
.build())
|
||||
.build();
|
||||
RadioParam isAtAll = RadioParam
|
||||
.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_AT_ALL, DingTalkParamsConstants.DING_TALK_AT_ALL)
|
||||
.addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false))
|
||||
.addParamsOptions(new ParamsOptions(STRING_NO, STRING_FALSE, false))
|
||||
.setValue(STRING_FALSE)
|
||||
.addValidate(Validate.newBuilder()
|
||||
.setRequired(false)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
RadioParam isEnableProxy = RadioParam
|
||||
.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE, DingTalkParamsConstants.DING_TALK_PROXY_ENABLE)
|
||||
.addParamsOptions(new ParamsOptions(STRING_YES, STRING_TRUE, false))
|
||||
@ -98,7 +120,7 @@ public final class DingTalkAlertChannelFactory implements AlertChannelFactory {
|
||||
.setPlaceholder("if enable use authentication, you need input password")
|
||||
.build();
|
||||
|
||||
return Arrays.asList(webHookParam, keywordParam, secretParam, isEnableProxy, proxyParam, portParam, userParam, passwordParam);
|
||||
return Arrays.asList(webHookParam, keywordParam, secretParam, atMobilesParam, atUserIdsParam, isAtAll, isEnableProxy, proxyParam, portParam, userParam, passwordParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +30,15 @@ public final class DingTalkParamsConstants {
|
||||
static final String DING_TALK_SECRET = "$t('secret')";
|
||||
static final String NAME_DING_TALK_SECRET = "Secret";
|
||||
|
||||
static final String DING_TALK_AT_MOBILES = "$t('atMobiles')";
|
||||
static final String NAME_DING_TALK_AT_MOBILES = "AtMobiles";
|
||||
|
||||
static final String DING_TALK_AT_USERIDS = "$t('atUserIds')";
|
||||
static final String NAME_DING_TALK_AT_USERIDS = "AtUserIds";
|
||||
|
||||
static final String DING_TALK_AT_ALL = "$t('isAtAll')";
|
||||
static final String NAME_DING_TALK_AT_ALL = "IsAtAll";
|
||||
|
||||
static final String DING_TALK_PROXY = "$t('proxy')";
|
||||
static final String NAME_DING_TALK_PROXY = "Proxy";
|
||||
|
||||
|
@ -39,8 +39,12 @@ import org.apache.http.util.EntityUtils;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
@ -60,6 +64,11 @@ public final class DingTalkSender {
|
||||
private final String url;
|
||||
private final String keyword;
|
||||
private final String secret;
|
||||
|
||||
private final String atMobiles;
|
||||
private final String atUserIds;
|
||||
private final Boolean atAll;
|
||||
|
||||
private final Boolean enableProxy;
|
||||
|
||||
private String proxy;
|
||||
@ -74,11 +83,16 @@ public final class DingTalkSender {
|
||||
url = config.get(DingTalkParamsConstants.NAME_DING_TALK_WEB_HOOK);
|
||||
keyword = config.get(DingTalkParamsConstants.NAME_DING_TALK_KEYWORD);
|
||||
secret = config.get(DingTalkParamsConstants.NAME_DING_TALK_SECRET);
|
||||
|
||||
atMobiles = config.get(DingTalkParamsConstants.NAME_DING_TALK_AT_MOBILES);
|
||||
atUserIds = config.get(DingTalkParamsConstants.NAME_DING_TALK_AT_USERIDS);
|
||||
atAll = Boolean.valueOf(config.get(DingTalkParamsConstants.NAME_DING_TALK_AT_ALL));
|
||||
|
||||
enableProxy = Boolean.valueOf(config.get(DingTalkParamsConstants.NAME_DING_TALK_PROXY_ENABLE));
|
||||
if (Boolean.TRUE.equals(enableProxy)) {
|
||||
port = Integer.parseInt(config.get(DingTalkParamsConstants.NAME_DING_TALK_PORT));
|
||||
proxy = config.get(DingTalkParamsConstants.NAME_DING_TALK_PROXY);
|
||||
user = config.get(DingTalkParamsConstants.DING_TALK_USER);
|
||||
user = config.get(DingTalkParamsConstants.NAME_DING_TALK_USER);
|
||||
password = config.get(DingTalkParamsConstants.NAME_DING_TALK_PASSWORD);
|
||||
}
|
||||
}
|
||||
@ -107,7 +121,7 @@ public final class DingTalkSender {
|
||||
return RequestConfig.custom().setProxy(httpProxy).build();
|
||||
}
|
||||
|
||||
private static String textToJsonString(String text) {
|
||||
private String textToJsonString(String text) {
|
||||
Map<String, Object> items = new HashMap<>();
|
||||
items.put("msgtype", "text");
|
||||
Map<String, String> textContent = new HashMap<>();
|
||||
@ -115,10 +129,26 @@ public final class DingTalkSender {
|
||||
String txt = StringUtils.newStringUtf8(byt);
|
||||
textContent.put("content", txt);
|
||||
items.put("text", textContent);
|
||||
|
||||
setMsgAt(items);
|
||||
return JSONUtils.toJsonString(items);
|
||||
}
|
||||
|
||||
private static AlertResult checkSendDingTalkSendMsgResult(String result) {
|
||||
private void setMsgAt(Map<String, Object> items) {
|
||||
Map<String, Object> at = new HashMap<>();
|
||||
|
||||
String[] atMobileArray = org.apache.dolphinscheduler.spi.utils.StringUtils.isNotBlank(atMobiles) ? atMobiles.split(",") : new String[0];
|
||||
String[] atUserArray = org.apache.dolphinscheduler.spi.utils.StringUtils.isNotBlank(atUserIds) ? atUserIds.split(",") : new String[0];
|
||||
boolean isAtAll = Objects.isNull(atAll) ? false : atAll;
|
||||
|
||||
at.put("atMobiles", atMobileArray);
|
||||
at.put("atUserIds", atUserArray);
|
||||
at.put("isAtAll", isAtAll);
|
||||
|
||||
items.put("at", at);
|
||||
}
|
||||
|
||||
private AlertResult checkSendDingTalkSendMsgResult(String result) {
|
||||
AlertResult alertResult = new AlertResult();
|
||||
alertResult.setStatus("false");
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class DingTalkAlertChannelFactoryTest {
|
||||
DingTalkAlertChannelFactory dingTalkAlertChannelFactory = new DingTalkAlertChannelFactory();
|
||||
List<PluginParams> params = dingTalkAlertChannelFactory.params();
|
||||
JSONUtils.toJsonString(params);
|
||||
Assert.assertEquals(8, params.size());
|
||||
Assert.assertEquals(11, params.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -727,6 +727,9 @@ export default {
|
||||
webHook: 'WebHook',
|
||||
Keyword: 'Keyword',
|
||||
Secret: 'Secret',
|
||||
AtMobiles: '@Mobiles',
|
||||
AtUserIds: '@UserIds',
|
||||
IsAtAll: '@All',
|
||||
Proxy: 'Proxy',
|
||||
receivers: 'Receivers',
|
||||
receiverCcs: 'ReceiverCcs',
|
||||
|
@ -727,6 +727,9 @@ export default {
|
||||
webHook: 'Web钩子',
|
||||
Keyword: '关键词',
|
||||
Secret: '密钥',
|
||||
AtMobiles: '@手机号',
|
||||
AtUserIds: '@用户ID',
|
||||
IsAtAll: '@所有人',
|
||||
Proxy: '代理',
|
||||
receivers: '收件人',
|
||||
receiverCcs: '抄送人',
|
||||
|
Loading…
Reference in New Issue
Block a user