You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2020/10/17 18:00:27 UTC

[GitHub] [incubator-dolphinscheduler] CalvinKirs commented on a change in pull request #3869: [feature#3356] alert-spi support DingTalk&WeChat

CalvinKirs commented on a change in pull request #3869:
URL: https://github.com/apache/incubator-dolphinscheduler/pull/3869#discussion_r506967992



##########
File path: dolphinscheduler-alert-plugin/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannel.java
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.plugin.alert.dingtalk;
+
+import org.apache.dolphinscheduler.spi.alert.AlertChannel;
+import org.apache.dolphinscheduler.spi.alert.AlertData;
+import org.apache.dolphinscheduler.spi.alert.AlertInfo;
+import org.apache.dolphinscheduler.spi.alert.AlertResult;
+import org.apache.dolphinscheduler.spi.params.base.PluginParams;
+import org.apache.dolphinscheduler.spi.utils.JSONUtils;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DingTalkAlertChannel
+ */
+public class DingTalkAlertChannel implements AlertChannel {
+    private static final Logger logger = LoggerFactory.getLogger(DingTalkAlertChannel.class);
+
+    @Override
+    public AlertResult process(AlertInfo alertInfo) {
+
+        AlertData alertData = alertInfo.getAlertData();
+        String alertParams = alertInfo.getAlertParams();
+        List<PluginParams> pluginParams = JSONUtils.toList(alertParams, PluginParams.class);
+        Map<String, String> paramsMap = new HashMap<>();
+        for (PluginParams param : pluginParams) {
+            paramsMap.put(param.getName(), param.getValue().toString());
+        }
+        AlertResult alertResult = new AlertResult();
+        alertResult.setStatus(Boolean.toString(Boolean.TRUE));
+        DingTalkSender dingTalkSender = new DingTalkSender(paramsMap);
+        try {
+            dingTalkSender.sendDingTalkMsg(alertData.getTitle(), alertData.getContent());
+        } catch (IOException e) {
+            alertResult.setStatus(Boolean.toString(Boolean.FALSE));
+            logger.error(e.getMessage(), e);

Review comment:
       Thank you for your suggestion. I will judge the response parameters of DingTalk.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org