update(REQ-2516) - 新增内置钉钉告警控制
This commit is contained in:
parent
b085fbd6f1
commit
1f96e581d8
@ -20,20 +20,25 @@
|
|||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>${project.groupId}</groupId>
|
|
||||||
<artifactId>workflow-engine-api</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.axzo.framework.rocketmq</groupId>
|
<groupId>cn.axzo.framework.rocketmq</groupId>
|
||||||
<artifactId>axzo-common-rocketmq</artifactId>
|
<artifactId>axzo-common-rocketmq</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.rocketmq</groupId>
|
<groupId>org.apache.rocketmq</groupId>
|
||||||
<artifactId>rocketmq-tools</artifactId>
|
<artifactId>rocketmq-tools</artifactId>
|
||||||
<version>4.9.1</version>
|
<version>4.9.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>workflow-engine-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,12 +1,74 @@
|
|||||||
package cn.axzo.workflow.starter.mq.monitor;
|
package cn.axzo.workflow.starter.mq.monitor;
|
||||||
|
|
||||||
import cn.axzo.workflow.starter.handler.monitor.BroadcastDLQReporter;
|
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
|
* @author wangli
|
||||||
* @since 2024/6/19 11:04
|
* @since 2024/6/19 11:04
|
||||||
*/
|
*/
|
||||||
public class AlertBroadcastDLQReporter implements BroadcastDLQReporter {
|
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/";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,74 @@
|
|||||||
package cn.axzo.workflow.starter.mq.monitor;
|
package cn.axzo.workflow.starter.mq.monitor;
|
||||||
|
|
||||||
import cn.axzo.workflow.starter.handler.monitor.RpcDLQReporter;
|
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
|
* @author wangli
|
||||||
* @since 2024/6/19 11:04
|
* @since 2024/6/19 11:04
|
||||||
*/
|
*/
|
||||||
public class AlertRcpDLQReporter implements RpcDLQReporter {
|
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/";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,8 +52,8 @@ public class WorkflowEngineStarterDefaultMQMonitor implements SmartLifecycle {
|
|||||||
this.defaultMQAdminExt = mqAdminExtObjectProvider.getIfAvailable();
|
this.defaultMQAdminExt = mqAdminExtObjectProvider.getIfAvailable();
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
if (workflowEngineStarterProperties.getAlert()) {
|
if (workflowEngineStarterProperties.getAlert()) {
|
||||||
this.broadcastDLQProcessor = new AlertBroadcastDLQReporter();
|
this.broadcastDLQProcessor = new AlertBroadcastDLQReporter(environment);
|
||||||
this.rpcDLQProcessor = new AlertRcpDLQReporter();
|
this.rpcDLQProcessor = new AlertRcpDLQReporter(environment);
|
||||||
} else {
|
} else {
|
||||||
this.broadcastDLQProcessor = broadcastDLQProcessorObjectProvider.getIfAvailable(() -> new BroadcastDLQReporter() {
|
this.broadcastDLQProcessor = broadcastDLQProcessorObjectProvider.getIfAvailable(() -> new BroadcastDLQReporter() {
|
||||||
});
|
});
|
||||||
|
|||||||
@ -133,8 +133,8 @@ public class WorkflowEngineStarterMQMonitorController {
|
|||||||
return CommonResponse.success("未开启·死信队列·的监控,如需,请设置 workflow.engine.starter.enableDlqMonitor = true 后再重试!");
|
return CommonResponse.success("未开启·死信队列·的监控,如需,请设置 workflow.engine.starter.enableDlqMonitor = true 后再重试!");
|
||||||
}
|
}
|
||||||
if (status) {
|
if (status) {
|
||||||
monitor.setBroadcastDLQProcessor(new AlertBroadcastDLQReporter());
|
monitor.setBroadcastDLQProcessor(new AlertBroadcastDLQReporter(environment));
|
||||||
monitor.setRpcDLQProcessor(new AlertRcpDLQReporter());
|
monitor.setRpcDLQProcessor(new AlertRcpDLQReporter(environment));
|
||||||
return CommonResponse.success("开启 DLQ 钉钉通知");
|
return CommonResponse.success("开启 DLQ 钉钉通知");
|
||||||
} else {
|
} else {
|
||||||
monitor.setBroadcastDLQProcessor(broadcastDLQProcessorObjectProvider.getIfAvailable(() -> new BroadcastDLQReporter() {
|
monitor.setBroadcastDLQProcessor(broadcastDLQProcessorObjectProvider.getIfAvailable(() -> new BroadcastDLQReporter() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user