• 钉钉机器人告警小记


    1、配置钉钉机器人

    ①安全设置常使用关键词

    ②使用outgoing机制,配置post地址和token,作为回调

    2、使用钉钉机器人发送消息

    自动化用例跑批通知、告警等

    public static void sendMsg(String title, String message, String url, List<String> list) {
            OapiRobotSendRequest request = new OapiRobotSendRequest();
            DingTalkClient client = new DefaultDingTalkClient(url);
            try {
                request.setMsgtype("text");
                OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
                text.setContent(title + message);
                request.setText(text);
                OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
    //            at.setIsAtAll(true);
                at.setAtMobiles(list);
                request.setAt(at);
                client.execute(request, key, appSecret);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

     3、艾特钉钉机器人,接收消息进行处理

    官方文档:https://open.dingtalk.com/document/robots/receive-message
    请求地址与钉钉机器人的post地址一致
     1 @RestController
     2 @EnableAutoConfiguration
     3 @RequestMapping("/ding")
     4 @Slf4j
     5 public class DingAt {
     6     @CrossOrigin
     7     @RequestMapping(value = "/jenkins", method = RequestMethod.POST)
     8     @org.springframework.web.bind.annotation.ResponseBody
     9    public static void DingTalk(@RequestBody DingTalkChatVo dingTalkChatVo)  {
    10         final String senderNick = dingTalkChatVo.getSenderNick();
    11         log.info("[收到钉钉消息][{}][{}][{}]", senderNick, dingTalkChatVo.getContentMsg(), dingTalkChatVo.toJsonStr());
    12                if (dingTalkChatVo.getContentMsg().equals("hi")){
    13             DingdingControl.sendMsg("","你也hi","url");
    14         }else if(dingTalkChatVo.getContentMsg().equals("测试")){
    15             DingdingControl.sendMsg("","收到","url");
    16         }
    17     }





  • 相关阅读:
    Java学习二十九天
    Java学习二十八天
    47. Permutations II 全排列可重复版本
    46. Permutations 全排列,无重复
    subset ii 子集 有重复元素
    339. Nested List Weight Sum 339.嵌套列表权重总和
    251. Flatten 2D Vector 平铺二维矩阵
    217. Contains Duplicate数组重复元素
    209. Minimum Size Subarray Sum 结果大于等于目标的最小长度数组
    438. Find All Anagrams in a String 查找字符串中的所有Anagrams
  • 原文地址:https://www.cnblogs.com/x495122903/p/15726777.html
Copyright © 2020-2023  润新知