diff --git a/alerter/src/main/java/org/dromara/hertzbeat/alert/calculate/CalculateAlarm.java b/alerter/src/main/java/org/dromara/hertzbeat/alert/calculate/CalculateAlarm.java index a55a6b015d5..96ce9cb6705 100644 --- a/alerter/src/main/java/org/dromara/hertzbeat/alert/calculate/CalculateAlarm.java +++ b/alerter/src/main/java/org/dromara/hertzbeat/alert/calculate/CalculateAlarm.java @@ -244,7 +244,7 @@ private void handleRecoveredAlert(long currentTimeMilli, long monitorId, String .priority(CommonConstants.ALERT_PRIORITY_CODE_WARNING) .status(CommonConstants.ALERT_STATUS_CODE_RESTORED) .firstAlarmTime(currentTimeMilli) - .lastAlarmTime(currentTimeMilli) + .lastAlarmTime(notResolvedAlert.getLastAlarmTime()) .triggerTimes(1) .build(); alarmCommonReduce.reduceAndSendAlarm(resumeAlert); @@ -400,7 +400,7 @@ private void handlerAvailableMetrics(long monitorId, String app, CollectRep.Metr .priority(CommonConstants.ALERT_PRIORITY_CODE_WARNING) .status(CommonConstants.ALERT_STATUS_CODE_RESTORED) .firstAlarmTime(currentTimeMill) - .lastAlarmTime(currentTimeMill) + .lastAlarmTime(notResolvedAlert.getLastAlarmTime()) .triggerTimes(1) .build(); alarmCommonReduce.reduceAndSendAlarm(resumeAlert); diff --git a/alerter/src/main/resources/alerter_en_US.properties b/alerter/src/main/resources/alerter_en_US.properties index e6b82b0aa52..2b22b3e7085 100644 --- a/alerter/src/main/resources/alerter_en_US.properties +++ b/alerter/src/main/resources/alerter_en_US.properties @@ -21,6 +21,7 @@ alerter.notify.monitorId = Monitor ID alerter.notify.monitorName = Monitor Name alerter.notify.priority = Alert Priority alerter.notify.triggerTime = Alert Trigger Time +alerter.notify.restoreTime = Alert Restore Time alerter.notify.times = Alert Trigger Times alerter.notify.tags = Alert Labels alerter.notify.content = Alert Content diff --git a/alerter/src/main/resources/alerter_zh_CN.properties b/alerter/src/main/resources/alerter_zh_CN.properties index 6d919a05295..cdf213f7f20 100644 --- a/alerter/src/main/resources/alerter_zh_CN.properties +++ b/alerter/src/main/resources/alerter_zh_CN.properties @@ -21,6 +21,7 @@ alerter.notify.monitorId = 所属监控任务ID alerter.notify.monitorName = 所属任务名称 alerter.notify.priority = 告警级别 alerter.notify.triggerTime = 告警触发时间 +alerter.notify.restoreTime = 告警恢复时间 alerter.notify.times = 告警触发次数 alerter.notify.tags = 告警标签 alerter.notify.content = 内容详情 diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/AbstractAlertNotifyHandlerImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/AbstractAlertNotifyHandlerImpl.java index 95866a79583..1e7a2244797 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/AbstractAlertNotifyHandlerImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/AbstractAlertNotifyHandlerImpl.java @@ -96,6 +96,10 @@ protected String renderContent(NoticeTemplate noticeTemplate, Alert alert) throw model.put("priorityValue", alert.getPriority()); model.put("triggerTimeLabel", bundle.getString("alerter.notify.triggerTime")); model.put("triggerTime", DTF.format(Instant.ofEpochMilli(alert.getLastAlarmTime()).atZone(ZoneId.systemDefault()).toLocalDateTime())); + if (CommonConstants.ALERT_STATUS_CODE_RESTORED == alert.getStatus()) { + model.put("restoreTimeLabel", bundle.getString("alerter.notify.restoreTime")); + model.put("restoreTime", DTF.format(Instant.ofEpochMilli(alert.getFirstAlarmTime()).atZone(ZoneId.systemDefault()).toLocalDateTime())); + } model.put("timesLabel", bundle.getString("alerter.notify.times")); model.put("times", alert.getTimes()); model.put("contentLabel", bundle.getString("alerter.notify.content")); diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/HuaweiCloudSmnAlertNotifyHandlerImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/HuaweiCloudSmnAlertNotifyHandlerImpl.java index 3ff2b64789f..44dc071ca9b 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/HuaweiCloudSmnAlertNotifyHandlerImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/HuaweiCloudSmnAlertNotifyHandlerImpl.java @@ -59,7 +59,7 @@ public void send(NoticeReceiver receiver, NoticeTemplate noticeTemplate, Alert a var response = smnClient.publishMessage(request); log.debug("huaweiCloud smn alert response: {}", response); } catch (Exception e) { - throw new AlertNoticeException("[WebHook Notify Error] " + e.getMessage()); + throw new AlertNoticeException("[Huawei Cloud Smn Notify Error] " + e.getMessage()); } } diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/ServerChanAlertNotifyHandlerImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/ServerChanAlertNotifyHandlerImpl.java index bd567189774..15b25bc5512 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/ServerChanAlertNotifyHandlerImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/ServerChanAlertNotifyHandlerImpl.java @@ -38,7 +38,6 @@ public void send(NoticeReceiver receiver, NoticeTemplate noticeTemplate, Alert a String webHookUrl = String.format(alerterProperties.getServerChanNotifyUrl(), receiver.getServerChanToken()); ResponseEntity responseEntity = restTemplate.postForEntity(webHookUrl, httpEntity, CommonRobotNotifyResp.class); - System.out.println(responseEntity); if (responseEntity.getStatusCode() == HttpStatus.OK) { log.debug("Send ServerChan webHook: {} Success", webHookUrl); } else { diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MailServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MailServiceImpl.java index 5cd3831994f..0c58c5041f6 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MailServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MailServiceImpl.java @@ -36,7 +36,11 @@ import javax.annotation.Resource; import java.io.IOException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Date; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; /** * Mailbox sending service interface implementation class @@ -56,6 +60,7 @@ public class MailServiceImpl implements MailService { protected NoticeConfigService noticeConfigService; private ResourceBundle bundle = ResourceBundleUtil.getBundle("alerter"); + private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Override public String buildAlertHtmlTemplate(final Alert alert, NoticeTemplate noticeTemplate) throws IOException, TemplateException { @@ -82,10 +87,12 @@ public String buildAlertHtmlTemplate(final Alert alert, NoticeTemplate noticeTem model.put("namePriority", bundle.getString("alerter.notify.priority")); model.put("priority", bundle.getString("alerter.priority." + alert.getPriority())); model.put("nameTriggerTime", bundle.getString("alerter.notify.triggerTime")); + model.put("lastTriggerTime", simpleDateFormat.format(new Date(alert.getLastAlarmTime()))); + if (CommonConstants.ALERT_STATUS_CODE_RESTORED == alert.getStatus()) { + model.put("nameRestoreTime", bundle.getString("alerter.notify.restoreTime")); + model.put("restoreTime", simpleDateFormat.format(new Date(alert.getFirstAlarmTime()))); + } model.put("consoleUrl", alerterProperties.getConsoleUrl()); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String triggerTime = simpleDateFormat.format(new Date(alert.getLastAlarmTime())); - model.put("lastTriggerTime", triggerTime); model.put("nameContent", bundle.getString("alerter.notify.content")); model.put("content", alert.getContent()); if (noticeTemplate == null) { diff --git a/manager/src/main/resources/define/app-dns.yml b/manager/src/main/resources/define/app-dns.yml index 45fcec2cff9..7fefdb58814 100644 --- a/manager/src/main/resources/define/app-dns.yml +++ b/manager/src/main/resources/define/app-dns.yml @@ -21,8 +21,8 @@ category: service app: dns # 监控类型国际化名称 name: - zh-CN: DNS服务器 - en-US: DNS Server + zh-CN: DNS服务器监控 + en-US: DNS SERVER MONITORS # The description and help of this monitoring type # 监控类型的帮助描述信息 help: diff --git a/manager/src/main/resources/templates/1-EmailTemplate.html b/manager/src/main/resources/templates/1-EmailTemplate.html index 33a233bdda0..785836e3208 100644 --- a/manager/src/main/resources/templates/1-EmailTemplate.html +++ b/manager/src/main/resources/templates/1-EmailTemplate.html @@ -680,6 +680,19 @@ >${lastTriggerTime} + <#if nameRestoreTime??> + + + + ${nameRestoreTime} + + + ${restoreTime} + + +
${content} diff --git a/manager/src/main/resources/templates/10-WeWorkAppTemplate.txt b/manager/src/main/resources/templates/10-WeWorkAppTemplate.txt index 9b36c38e0f9..095e51c65e9 100644 --- a/manager/src/main/resources/templates/10-WeWorkAppTemplate.txt +++ b/manager/src/main/resources/templates/10-WeWorkAppTemplate.txt @@ -4,4 +4,5 @@ ${targetLabel} : ${target} <#if (monitorName??)>${monitorNameLabel} : ${monitorName} ${priorityLabel} : ${priority} ${triggerTimeLabel} : ${triggerTime} +<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} ${contentLabel} : ${content} \ No newline at end of file diff --git a/manager/src/main/resources/templates/11-HuaweiCloudSmnTemplate.txt b/manager/src/main/resources/templates/11-HuaweiCloudSmnTemplate.txt index 9b36c38e0f9..095e51c65e9 100644 --- a/manager/src/main/resources/templates/11-HuaweiCloudSmnTemplate.txt +++ b/manager/src/main/resources/templates/11-HuaweiCloudSmnTemplate.txt @@ -4,4 +4,5 @@ ${targetLabel} : ${target} <#if (monitorName??)>${monitorNameLabel} : ${monitorName} ${priorityLabel} : ${priority} ${triggerTimeLabel} : ${triggerTime} +<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} ${contentLabel} : ${content} \ No newline at end of file diff --git a/manager/src/main/resources/templates/12-ServerChanTemplate.txt b/manager/src/main/resources/templates/12-ServerChanTemplate.txt index fe2a16ce78a..c51b2add44c 100644 --- a/manager/src/main/resources/templates/12-ServerChanTemplate.txt +++ b/manager/src/main/resources/templates/12-ServerChanTemplate.txt @@ -4,4 +4,5 @@ <#if (monitorName??)>##### **${monitorNameLabel}** : ${monitorName} ##### **${priorityLabel}** : ${priority} ##### **${triggerTimeLabel}** : ${triggerTime} +<#if (restoreTimeLabel??)>##### **${restoreTimeLabel}** : ${restoreTime} ##### **${contentLabel}** : ${content} \ No newline at end of file diff --git a/manager/src/main/resources/templates/2-WebhookTemplate.txt b/manager/src/main/resources/templates/2-WebhookTemplate.txt index 4f4f880970c..581d1be5e41 100644 --- a/manager/src/main/resources/templates/2-WebhookTemplate.txt +++ b/manager/src/main/resources/templates/2-WebhookTemplate.txt @@ -7,6 +7,7 @@ "status": ${status}, "times": ${times}, "triggerTime": "${triggerTime}", + <#if (restoreTime??)>"restoreTime": "${restoreTime}", "tags": { <#list tags as key,value> "${key}": "${value}", diff --git a/manager/src/main/resources/templates/4-WeWorkRobotTemplate.txt b/manager/src/main/resources/templates/4-WeWorkRobotTemplate.txt index 9b36c38e0f9..095e51c65e9 100644 --- a/manager/src/main/resources/templates/4-WeWorkRobotTemplate.txt +++ b/manager/src/main/resources/templates/4-WeWorkRobotTemplate.txt @@ -4,4 +4,5 @@ ${targetLabel} : ${target} <#if (monitorName??)>${monitorNameLabel} : ${monitorName} ${priorityLabel} : ${priority} ${triggerTimeLabel} : ${triggerTime} +<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} ${contentLabel} : ${content} \ No newline at end of file diff --git a/manager/src/main/resources/templates/5-DingTalkRobotTemplate.txt b/manager/src/main/resources/templates/5-DingTalkRobotTemplate.txt index fe2a16ce78a..c51b2add44c 100644 --- a/manager/src/main/resources/templates/5-DingTalkRobotTemplate.txt +++ b/manager/src/main/resources/templates/5-DingTalkRobotTemplate.txt @@ -4,4 +4,5 @@ <#if (monitorName??)>##### **${monitorNameLabel}** : ${monitorName} ##### **${priorityLabel}** : ${priority} ##### **${triggerTimeLabel}** : ${triggerTime} +<#if (restoreTimeLabel??)>##### **${restoreTimeLabel}** : ${restoreTime} ##### **${contentLabel}** : ${content} \ No newline at end of file diff --git a/manager/src/main/resources/templates/6-FlyBookRobotTemplate.txt b/manager/src/main/resources/templates/6-FlyBookRobotTemplate.txt index 787aa16de7f..33d0cd3fc60 100644 --- a/manager/src/main/resources/templates/6-FlyBookRobotTemplate.txt +++ b/manager/src/main/resources/templates/6-FlyBookRobotTemplate.txt @@ -3,4 +3,5 @@ ${targetLabel} : ${target} <#if (monitorName??)>${monitorNameLabel} : ${monitorName} ${priorityLabel} : ${priority} ${triggerTimeLabel} : ${triggerTime} +<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} ${contentLabel} : ${content} \ No newline at end of file diff --git a/manager/src/main/resources/templates/7-TelegramBotTemplate.txt b/manager/src/main/resources/templates/7-TelegramBotTemplate.txt index 9b36c38e0f9..095e51c65e9 100644 --- a/manager/src/main/resources/templates/7-TelegramBotTemplate.txt +++ b/manager/src/main/resources/templates/7-TelegramBotTemplate.txt @@ -4,4 +4,5 @@ ${targetLabel} : ${target} <#if (monitorName??)>${monitorNameLabel} : ${monitorName} ${priorityLabel} : ${priority} ${triggerTimeLabel} : ${triggerTime} +<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} ${contentLabel} : ${content} \ No newline at end of file diff --git a/manager/src/main/resources/templates/8-SlackTemplate.txt b/manager/src/main/resources/templates/8-SlackTemplate.txt index e0b43268ae9..4b22b840808 100644 --- a/manager/src/main/resources/templates/8-SlackTemplate.txt +++ b/manager/src/main/resources/templates/8-SlackTemplate.txt @@ -4,4 +4,5 @@ ${targetLabel} : ${target} <#if (monitorName??)>${monitorNameLabel} : ${monitorName} ${priorityLabel} : ${priority} ${triggerTimeLabel} : ${triggerTime} +<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} ${contentLabel} : ${content} \ No newline at end of file diff --git a/manager/src/main/resources/templates/9-DiscordBotTemplate.txt b/manager/src/main/resources/templates/9-DiscordBotTemplate.txt index 787aa16de7f..33d0cd3fc60 100644 --- a/manager/src/main/resources/templates/9-DiscordBotTemplate.txt +++ b/manager/src/main/resources/templates/9-DiscordBotTemplate.txt @@ -3,4 +3,5 @@ ${targetLabel} : ${target} <#if (monitorName??)>${monitorNameLabel} : ${monitorName} ${priorityLabel} : ${priority} ${triggerTimeLabel} : ${triggerTime} +<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} ${contentLabel} : ${content} \ No newline at end of file