|
|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
+import me.chanjar.weixin.cp.api.WxCpGroupRobotService;
|
|
|
import me.chanjar.weixin.cp.api.WxCpService;
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
|
|
@@ -57,6 +58,11 @@ public class CoinServiceImpl implements CoinService {
|
|
|
*/
|
|
|
public static final String JOB_ALARM_MODE_CHAT_BOT = "2";
|
|
|
|
|
|
+ /**
|
|
|
+ * 任务告警方式(1:应用文本卡片,2:群聊机器人文本消息)
|
|
|
+ */
|
|
|
+ public static String JOB_ALARM_MODE = "1";
|
|
|
+
|
|
|
// 所有REST请求的header都必须包含以下key:
|
|
|
private static final Map<String, String> basicHeaderMap = new HashMap<>();
|
|
|
// 主域名 URL
|
|
|
@@ -162,24 +168,43 @@ public class CoinServiceImpl implements CoinService {
|
|
|
@Override
|
|
|
@Async("coinTaskExecutor")
|
|
|
public void monitorAlarm(JSONObject order) {
|
|
|
- String title = "监控告警明细";
|
|
|
- String content = order.getString("symbol") + "触发";
|
|
|
- String logUrl = "https://lvzhiqiang.top";
|
|
|
- String btnTxt = "日志详情";
|
|
|
-
|
|
|
- WxCpMessage wxCpMessage = WxCpMessage.TEXTCARD().agentId(properties.getAgentId())
|
|
|
- .toUser("LvZhiQiang")
|
|
|
- .toParty("")
|
|
|
- .toTag("")
|
|
|
- .title(title).description(content)
|
|
|
- .url(logUrl).btnTxt(btnTxt)
|
|
|
- .build();
|
|
|
- try {
|
|
|
- log.info("企业微信推送消息,send message: {}", wxCpMessage);
|
|
|
- WxCpMessageSendResult sendResult = wxCpService.getMessageService().send(wxCpMessage);
|
|
|
- log.info("企业微信推送消息成功,send result: {}", sendResult);
|
|
|
- } catch (WxErrorException e) {
|
|
|
- log.error("企业微信推送消息失败!Detail: ", e);
|
|
|
+ // 判断告警模式
|
|
|
+ String jobAlarmMode = JOB_ALARM_MODE;
|
|
|
+
|
|
|
+ // 文本卡片模式发消息
|
|
|
+ if (JOB_ALARM_MODE_APP_TEXT_CARD.equals(jobAlarmMode)) {
|
|
|
+ String title = "监控告警明细";
|
|
|
+ String content = order.getString("symbol") + "触发";
|
|
|
+ String logUrl = "https://lvzhiqiang.top";
|
|
|
+ String btnTxt = "日志详情";
|
|
|
+
|
|
|
+ WxCpMessage wxCpMessage = WxCpMessage.TEXTCARD().agentId(properties.getAgentId())
|
|
|
+ .toUser("LvZhiQiang")
|
|
|
+ .toParty("")
|
|
|
+ .toTag("")
|
|
|
+ .title(title).description(content)
|
|
|
+ .url(logUrl).btnTxt(btnTxt)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ log.info("企业微信推送消息,send message: {}", wxCpMessage);
|
|
|
+ WxCpMessageSendResult sendResult = wxCpService.getMessageService().send(wxCpMessage);
|
|
|
+ log.info("企业微信推送消息成功,send result: {}", sendResult);
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ log.error("企业微信推送消息失败!Detail: ", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 调用企业微信群聊机器人发消息
|
|
|
+ if (JOB_ALARM_MODE_CHAT_BOT.equals(jobAlarmMode)) {
|
|
|
+ WxCpGroupRobotService groupRobotService = wxCpService.getGroupRobotService();
|
|
|
+ String webhookUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=082970da-2a33-422a-81f6-15f9bde87940";
|
|
|
+ String content = order.getString("symbol") + "触发";
|
|
|
+ try {
|
|
|
+ log.info("企业微信推送消息,send content: {}, userIdSet: {}", content, "LvZhiQiang");
|
|
|
+ groupRobotService.sendText(webhookUrl, content, Collections.singletonList("LvZhiQiang"), Collections.emptyList());
|
|
|
+ log.info("企业微信推送消息成功");
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ log.error("企业微信推送消息失败!Detail: ", e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|