update(REQ-2516) - 新增内置钉钉告警控制

This commit is contained in:
wangli 2024-06-19 11:23:06 +08:00
parent b085fbd6f1
commit 1f96e581d8
5 changed files with 140 additions and 11 deletions

View File

@ -20,20 +20,25 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-engine-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cn.axzo.framework.rocketmq</groupId>
<artifactId>axzo-common-rocketmq</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-tools</artifactId>
<version>4.9.1</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-engine-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,12 +1,74 @@
package cn.axzo.workflow.starter.mq.monitor;
import cn.axzo.workflow.starter.handler.monitor.BroadcastDLQReporter;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import lombok.SneakyThrows;
import org.apache.rocketmq.common.admin.TopicOffset;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
/**
* TODO
* Starter 内置的 Broadcast DLQ 钉钉通知
*
* @author wangli
* @since 2024/6/19 11:04
*/
public class AlertBroadcastDLQReporter implements BroadcastDLQReporter {
private static final Logger log = LoggerFactory.getLogger(AlertBroadcastDLQReporter.class);
private final String dingtalk_robot_webhook = "https://oapi.dingtalk.com/robot/send?access_token=341ee2907f3ebc15dc495fb7771a646230058710999fec7838066c109849878e";
private final String profile;
private final String applicationName;
public AlertBroadcastDLQReporter(Environment environment) {
this.profile = environment.getProperty("spring.profiles.active");
this.applicationName = environment.getProperty("spring.application.name");
}
@Override
public void process(TopicOffset v) {
log.warn("found DLQ");
long count = v.getMaxOffset() - v.getMinOffset();
if (count > 0) {
sendDingTalk(count);
}
}
@SneakyThrows
public void sendDingTalk(Long count) {
DingTalkClient client = new DefaultDingTalkClient(dingtalk_robot_webhook);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle("Notice Env: " + profile);
markdown.setText("#### [" + profile + "]环境[" + applicationName + "]发现“DLQ”数据(Rpc)\n" +
"> ###### 1. 如需查看详情,[请点击这里](" + findDomain() + "m) \n" +
"> ###### 2. 如需调整 MQ DLQ 的监控状态: \n" +
"[关闭监控](" + findDomain() + "m/set?status=false) \n | " +
"[开启监控](" + findDomain() + "m/set?status=true) \n" +
"> 积累条数:" + count + " \n");
request.setMarkdown(markdown);
log.warn(markdown.getText());
OapiRobotSendResponse response = client.execute(request);
}
private String findDomain() {
switch (profile) {
case "dev":
return "https://dev-app.axzo.cn/" + applicationName + "/web/we/s/";
case "test":
return "https://test-api.axzo.cn/" + applicationName + "/web/we/s/";
case "pre":
return "https://pre-api.axzo.cn/" + applicationName + "/web/we/s/";
case "live":
return "https://live-api.axzo.cn/" + applicationName + "/web/we/s/";
default:
return "https://api.axzo.cn/" + applicationName + "/web/we/s/";
}
}
}

View File

@ -1,12 +1,74 @@
package cn.axzo.workflow.starter.mq.monitor;
import cn.axzo.workflow.starter.handler.monitor.RpcDLQReporter;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import lombok.SneakyThrows;
import org.apache.rocketmq.common.admin.TopicOffset;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
/**
* TODO
* Starter 内置的 Rpc DLQ 钉钉通知
*
* @author wangli
* @since 2024/6/19 11:04
*/
public class AlertRcpDLQReporter implements RpcDLQReporter {
private static final Logger log = LoggerFactory.getLogger(AlertRcpDLQReporter.class);
private final String dingtalk_robot_webhook = "https://oapi.dingtalk.com/robot/send?access_token=341ee2907f3ebc15dc495fb7771a646230058710999fec7838066c109849878e";
private final String profile;
private final String applicationName;
public AlertRcpDLQReporter(Environment environment) {
this.profile = environment.getProperty("spring.profiles.active");
this.applicationName = environment.getProperty("spring.application.name");
}
@Override
public void process(TopicOffset v) {
log.warn("found DLQ");
long count = v.getMaxOffset() - v.getMinOffset();
if (count > 0) {
sendDingTalk(count);
}
}
@SneakyThrows
public void sendDingTalk(Long count) {
DingTalkClient client = new DefaultDingTalkClient(dingtalk_robot_webhook);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle("Notice Env: " + profile);
markdown.setText("#### [" + profile + "]环境[" + applicationName + "]发现“DLQ”数据(Rpc)\n" +
"> ###### 1. 如需查看详情,[请点击这里](" + findDomain() + "m) \n" +
"> ###### 2. 如需调整 MQ DLQ 的监控状态: \n" +
"[关闭监控](" + findDomain() + "m/set?status=false) \n | " +
"[开启监控](" + findDomain() + "m/set?status=true) \n" +
"> 积累条数:" + count + " \n");
request.setMarkdown(markdown);
log.warn(markdown.getText());
OapiRobotSendResponse response = client.execute(request);
}
private String findDomain() {
switch (profile) {
case "dev":
return "https://dev-app.axzo.cn/" + applicationName + "/web/we/s/";
case "test":
return "https://test-api.axzo.cn/" + applicationName + "/web/we/s/";
case "pre":
return "https://pre-api.axzo.cn/" + applicationName + "/web/we/s/";
case "live":
return "https://live-api.axzo.cn/" + applicationName + "/web/we/s/";
default:
return "https://api.axzo.cn/" + applicationName + "/web/we/s/";
}
}
}

View File

@ -52,8 +52,8 @@ public class WorkflowEngineStarterDefaultMQMonitor implements SmartLifecycle {
this.defaultMQAdminExt = mqAdminExtObjectProvider.getIfAvailable();
this.environment = environment;
if (workflowEngineStarterProperties.getAlert()) {
this.broadcastDLQProcessor = new AlertBroadcastDLQReporter();
this.rpcDLQProcessor = new AlertRcpDLQReporter();
this.broadcastDLQProcessor = new AlertBroadcastDLQReporter(environment);
this.rpcDLQProcessor = new AlertRcpDLQReporter(environment);
} else {
this.broadcastDLQProcessor = broadcastDLQProcessorObjectProvider.getIfAvailable(() -> new BroadcastDLQReporter() {
});

View File

@ -133,8 +133,8 @@ public class WorkflowEngineStarterMQMonitorController {
return CommonResponse.success("未开启·死信队列·的监控,如需,请设置 workflow.engine.starter.enableDlqMonitor = true 后再重试!");
}
if (status) {
monitor.setBroadcastDLQProcessor(new AlertBroadcastDLQReporter());
monitor.setRpcDLQProcessor(new AlertRcpDLQReporter());
monitor.setBroadcastDLQProcessor(new AlertBroadcastDLQReporter(environment));
monitor.setRpcDLQProcessor(new AlertRcpDLQReporter(environment));
return CommonResponse.success("开启 DLQ 钉钉通知");
} else {
monitor.setBroadcastDLQProcessor(broadcastDLQProcessorObjectProvider.getIfAvailable(() -> new BroadcastDLQReporter() {