Skip to content

Commit

Permalink
update alarm notice wework app send content ui (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Sep 24, 2023
1 parent edb6710 commit 5321887
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public CollectRep.MetricsData pollMetricsDataToPersistentStorage() throws Interr
@Override
public CollectRep.MetricsData pollMetricsDataToRealTimeStorage() throws InterruptedException {
CollectRep.MetricsData realTimeMetricsData = metricsDataToRealTimeStorageQueue.poll();
if (realTimeMetricsData != null) {
return realTimeMetricsData;
}
lock4.lockInterruptibly();
try {
ConsumerRecords<Long, CollectRep.MetricsData> records = metricsDataToRealTimeStorageConsumer.poll(Duration.ofSeconds(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.dromara.hertzbeat.common.entity.alerter.Alert;
import org.dromara.hertzbeat.common.entity.manager.NoticeReceiver;
import org.dromara.hertzbeat.common.util.JsonUtil;
import org.dromara.hertzbeat.manager.component.alerter.AlertNotifyHandler;
import org.dromara.hertzbeat.manager.pojo.dto.WeChatAppDTO;
import org.dromara.hertzbeat.manager.pojo.dto.WeChatAppReq;
import org.dromara.hertzbeat.manager.support.exception.AlertNoticeException;
Expand All @@ -28,7 +27,7 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class WeChatAppAlertNotifyHandlerImpl implements AlertNotifyHandler {
public class WeWorkAppAlertNotifyHandlerImpl extends AbstractAlertNotifyHandlerImpl {

/**
* send weChat app message url
Expand All @@ -45,11 +44,6 @@ public class WeChatAppAlertNotifyHandlerImpl implements AlertNotifyHandler {
*/
private static final String DEFAULT_ALL = "@all";

/**
* send message type
*/
private static final String DEFAULT_TYPE = "text";

private final RestTemplate restTemplate;

@Override
Expand All @@ -62,13 +56,13 @@ public void send(NoticeReceiver receiver, Alert alert) throws AlertNoticeExcepti
ResponseEntity<WeChatAppReq> entityResponse = restTemplate.getForEntity(String.format(SECRET_URL, corpId, appSecret), WeChatAppReq.class);
if (Objects.nonNull(entityResponse.getBody())) {
String accessToken = entityResponse.getBody().getAccessToken();
WeChatAppDTO.TextDTO textDTO = new WeChatAppDTO.TextDTO();
textDTO.setContent(generateContent(alert));
WeChatAppDTO.MarkdownDTO markdown = new WeChatAppDTO.MarkdownDTO();
markdown.setContent(renderContent(alert));
WeChatAppDTO weChatAppDTO = WeChatAppDTO.builder()
.toUser(DEFAULT_ALL)
.msgType(DEFAULT_TYPE)
.msgType(WeChatAppDTO.MARKDOWN)
.markdown(markdown)
.agentId(agentId)
.text(textDTO)
.build();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
Expand Down Expand Up @@ -98,4 +92,8 @@ private String generateContent(Alert alert){
return JsonUtil.toJson(contentMap);
}

@Override
protected String templateName() {
return "alertNotifyWeWorkApp";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
/**
* WeChatAppDTO
* @author hdd
* @create 2023/04/05
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WeChatAppDTO {

/**
* markdown格式
*/
public static final String MARKDOWN = "markdown";

@JsonProperty(value = "touser")
private String toUser;

Expand All @@ -32,9 +36,23 @@ public class WeChatAppDTO {
@JsonProperty(value = "agentid")
private Integer agentId;


/**
* text message
*/
private TextDTO text;

/**
* markdown消息
*/
private MarkdownDTO markdown;

@Data
public static class MarkdownDTO {
/**
* 消息内容
*/
private String content;
}

@Data
public static class TextDTO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ public void deleteMonitor(long id) throws RuntimeException {
paramDao.deleteParamsByMonitorId(id);
tagMonitorBindDao.deleteTagMonitorBindsByMonitorId(id);
alertDefineBindDao.deleteAlertDefineMonitorBindsByMonitorIdEquals(id);
collectorMonitorBindDao.deleteCollectorMonitorBindsByMonitorId(id);
collectJobScheduling.cancelAsyncCollectJob(monitor.getJobId());
applicationContext.publishEvent(new MonitorDeletedEvent(applicationContext, monitor.getId()));
}
Expand All @@ -581,6 +582,7 @@ public void deleteMonitors(Set<Long> ids) throws RuntimeException {
for (Monitor monitor : monitors) {
// delete tag 删除监控对应的标签
tagService.deleteMonitorSystemTags(monitor);
collectorMonitorBindDao.deleteCollectorMonitorBindsByMonitorId(monitor.getId());
collectJobScheduling.cancelAsyncCollectJob(monitor.getJobId());
applicationContext.publishEvent(new MonitorDeletedEvent(applicationContext, monitor.getId()));
}
Expand Down
7 changes: 7 additions & 0 deletions manager/src/main/resources/templates/alertNotifyWeWorkApp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<font color="info">[(${title})]</font>
[(${targetLabel})] : <font color="info">[(${target})]</font>
[# th:if="${monitorId != null}"][(${monitorIdLabel})] : [(${monitorId})][/]
[# th:if="${monitorName != null}"][(${monitorNameLabel})] : [(${monitorName})][/]
[(${priorityLabel})] : <font color="warning">[(${priority})]</font>
[(${triggerTimeLabel})] : [(${triggerTime})]
[(${contentLabel})] : [(${content})]
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class WeChatAppAlertNotifyHandlerImplTest extends AbstractSpringIntegrati


@Resource
private WeChatAppAlertNotifyHandlerImpl weChatAppAlertNotifyHandler;
private WeWorkAppAlertNotifyHandlerImpl weChatAppAlertNotifyHandler;


@Test
Expand Down

0 comments on commit 5321887

Please sign in to comment.