结合logback集成钉钉机器人监控日志异常状态

1 结合logback发送钉钉群消息

Maven快速集成

<dependency>
    <groupId>com.midoujia.dingbot</groupId>
    <artifactId>spring-boot-dingbot</artifactId>
    <version>1.0.0</version>
</dependency>

配置

申请Key说明文档:https://open.dingtalk.com/document/robots/custom-robot-access

ding:
  bot-url: https://oapi.dingtalk.com/robot/send
  bot-key: SECaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bot-token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bot-enabled: true
  trigger-words:
    - 异常
    - OutofMemoryError
    - Java heap space

logback配置

<!--配置自定义的日志处理了-->
<appender name="WlcLog" class="com.midoujia.dingbot.configuration.CusLogLogbackAppender">
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
        <level>ERROR</level>
        <onMatch>ACCEPT</onMatch>
        <onMismatch>DENY</onMismatch>
    </filter>
</appender>
<root level="info">
<appender-ref ref="WlcLog"/>
</root>

2 单独自定义使用dingbot

Maven快速集成

<dependency>
    <groupId>com.midoujia.dingbot</groupId>
    <artifactId>spring-boot-dingbot</artifactId>
    <version>1.0.0</version>
</dependency>

配置

ding:
  bot-url: https://oapi.dingtalk.com/robot/send
  bot-key: SECaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bot-token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

使用

@Autowired
private DingBotApi dingBotApi;DingBotApi dingBotApi = DingBean.getBean(DingBotApi.class);

DingBotApi接口说明

public interface DingBotApi {

    /** 测试消息发送接口 */
    String sendMarkdownMsgTest(String botUrl, String botKey, String botToken, String content);

    /** 消息发送普通文本接口 */
    String sendTextMsg(String content);

    /** 消息发送link类型文本接口 */
    String sendLinkMsg(String title, String content, String picUrl, String messageUrl);

    /** 消息发送markdown类型文本接口 */
    String sendMarkdownMsg(String title, String content);

    /** 消息发送ActionCard类型文本接口 */
    String sendActionCardMsg(String title, String content, String singleURL);

    /** 消息发送FeedCard类型文本接口 */
    String sendFeedCardMsg(List<DingContent> dingContent);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值