Skip to content

Commit

Permalink
[manager,alerter] support wework, dingDing, flyBook webhook url setti…
Browse files Browse the repository at this point in the history
…ng config (#213)
  • Loading branch information
tomsun28 committed Jan 16, 2024
1 parent 9b63b46 commit 325956b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
42 changes: 41 additions & 1 deletion alerter/src/main/java/com/usthe/alert/AlerterProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.stereotype.Component;

/**
* 数据仓储配置属性
* alerter config
*
* @author tom
* @date 2021/11/24 10:38
Expand All @@ -15,9 +15,25 @@ public class AlerterProperties {

/**
* 告警内容控制台链接
* Alarm content console link
*/
private String consoleUrl = "https://console.tancloud.cn";

/**
* WeWork webhook url
*/
private String weWorkWebHookUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=";

/**
* DingDing talk webhook url
*/
private String dingTalkWebHookUrl = "https://oapi.dingtalk.com/robot/send?access_token=";

/**
* FlyBook webhook url
*/
private String flyBookWebHookUrl = "https://open.feishu.cn/open-apis/bot/v2/hook/";

/**
* 告警评估时间间隔起始基数 每下一次乘2 单位毫秒
* base of alert eval interval time, unit:ms. The next time is 2 times the previous time.
Expand Down Expand Up @@ -49,6 +65,30 @@ public void setConsoleUrl(String url) {
this.consoleUrl = url;
}

public String getWeWorkWebHookUrl() {
return weWorkWebHookUrl;
}

public void setWeWorkWebHookUrl(String weWorkWebHookUrl) {
this.weWorkWebHookUrl = weWorkWebHookUrl;
}

public String getDingTalkWebHookUrl() {
return dingTalkWebHookUrl;
}

public void setDingTalkWebHookUrl(String dingTalkWebHookUrl) {
this.dingTalkWebHookUrl = dingTalkWebHookUrl;
}

public String getFlyBookWebHookUrl() {
return flyBookWebHookUrl;
}

public void setFlyBookWebHookUrl(String flyBookWebHookUrl) {
this.flyBookWebHookUrl = flyBookWebHookUrl;
}

public long getAlertEvalIntervalBase() {
return alertEvalIntervalBase;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.usthe.manager.component.alerter.impl;

import com.usthe.alert.AlerterProperties;
import com.usthe.common.entity.alerter.Alert;
import com.usthe.common.entity.manager.NoticeReceiver;
import com.usthe.common.util.CommonConstants;
Expand Down Expand Up @@ -28,8 +29,11 @@
@RequiredArgsConstructor
@Slf4j
final class DingTalkRobotAlertNotifyHandlerImpl implements AlertNotifyHandler {

private final RestTemplate restTemplate;

private final AlerterProperties alerterProperties;

@Override
public void send(NoticeReceiver receiver, Alert alert) {
String monitorId = null;
Expand Down Expand Up @@ -62,7 +66,7 @@ public void send(NoticeReceiver receiver, Alert alert) {
markdownDTO.setText(contentBuilder.toString());
markdownDTO.setTitle("HertzBeat告警通知");
dingTalkWebHookDto.setMarkdown(markdownDTO);
String webHookUrl = DingTalkWebHookDto.WEBHOOK_URL + receiver.getAccessToken();
String webHookUrl = alerterProperties.getDingTalkWebHookUrl() + receiver.getAccessToken();
try {
ResponseEntity<String> entity = restTemplate.postForEntity(webHookUrl, dingTalkWebHookDto, String.class);
if (entity.getStatusCode() == HttpStatus.OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void send(NoticeReceiver receiver, Alert alert) {
zhCn.setTitle("[HertzBeat告警通知]");
zhCn.setContent(contents);
flyBookWebHookDto.setContent(content);
String webHookUrl = FlyBookWebHookDto.WEBHOOK_URL + receiver.getWechatId();
String webHookUrl = alerterProperties.getFlyBookWebHookUrl() + receiver.getWechatId();
try {
ResponseEntity<String> entity = restTemplate.postForEntity(webHookUrl, flyBookWebHookDto, String.class);
if (entity.getStatusCode() == HttpStatus.OK) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.usthe.manager.component.alerter.impl;

import com.usthe.alert.AlerterProperties;
import com.usthe.common.entity.alerter.Alert;
import com.usthe.common.entity.manager.NoticeReceiver;
import com.usthe.common.util.CommonConstants;
Expand Down Expand Up @@ -28,8 +29,11 @@
@RequiredArgsConstructor
@Slf4j
final class WeWorkRobotAlertNotifyHandlerImpl implements AlertNotifyHandler {

private final RestTemplate restTemplate;

private final AlerterProperties alerterProperties;

@Override
public void send(NoticeReceiver receiver, Alert alert) {
String monitorId = null;
Expand Down Expand Up @@ -62,7 +66,7 @@ public void send(NoticeReceiver receiver, Alert alert) {
content.append("内容详情 : ").append(alert.getContent());
markdownDTO.setContent(content.toString());
weWorkWebHookDTO.setMarkdown(markdownDTO);
String webHookUrl = WeWorkWebHookDto.WEBHOOK_URL + receiver.getWechatId();
String webHookUrl = alerterProperties.getWeWorkWebHookUrl() + receiver.getWechatId();
try {
ResponseEntity<String> entity = restTemplate.postForEntity(webHookUrl, weWorkWebHookDTO, String.class);
if (entity.getStatusCode() == HttpStatus.OK) {
Expand Down

0 comments on commit 325956b

Please sign in to comment.