Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alarm trigger time for alarm restore #1464

Merged
merged 17 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions alerter/src/main/resources/alerter_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions alerter/src/main/resources/alerter_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 内容详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void send(NoticeReceiver receiver, NoticeTemplate noticeTemplate, Alert a
String webHookUrl = String.format(alerterProperties.getServerChanNotifyUrl(), receiver.getServerChanToken());
ResponseEntity<CommonRobotNotifyResp> responseEntity = restTemplate.postForEntity(webHookUrl,
httpEntity, CommonRobotNotifyResp.class);
System.out.println(responseEntity);
if (responseEntity.getStatusCode() == HttpStatus.OK) {
log.debug("Send ServerChan webHook: {} Success", webHookUrl);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions manager/src/main/resources/define/app-dns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions manager/src/main/resources/templates/1-EmailTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,19 @@
>${lastTriggerTime}</span>
</td>
</tr>
<#if nameRestoreTime??>
<tr>
<td align="right"
style="padding-right: 10px; color: #817878; font-weight: 500;">
<span>
${nameRestoreTime}
</span>
</td>
<td><span
>${restoreTime}</span>
</td>
</tr>
</#if>
</table>
<br><span
>${content}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ${targetLabel} : ${target}
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
${contentLabel} : ${content}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ${targetLabel} : ${target}
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
${contentLabel} : ${content}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<#if (monitorName??)>##### **${monitorNameLabel}** : ${monitorName} </#if>
##### **${priorityLabel}** : ${priority}
##### **${triggerTimeLabel}** : ${triggerTime}
<#if (restoreTimeLabel??)>##### **${restoreTimeLabel}** : ${restoreTime} </#if>
##### **${contentLabel}** : ${content}
1 change: 1 addition & 0 deletions manager/src/main/resources/templates/2-WebhookTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"status": ${status},
"times": ${times},
"triggerTime": "${triggerTime}",
<#if (restoreTime??)>"restoreTime": "${restoreTime}",</#if>
"tags": {
<#list tags as key,value>
"${key}": "${value}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ${targetLabel} : ${target}
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
${contentLabel} : ${content}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<#if (monitorName??)>##### **${monitorNameLabel}** : ${monitorName} </#if>
##### **${priorityLabel}** : ${priority}
##### **${triggerTimeLabel}** : ${triggerTime}
<#if (restoreTimeLabel??)>##### **${restoreTimeLabel}** : ${restoreTime} </#if>
##### **${contentLabel}** : ${content}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ${targetLabel} : ${target}
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
${contentLabel} : ${content}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ${targetLabel} : ${target}
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
${contentLabel} : ${content}
1 change: 1 addition & 0 deletions manager/src/main/resources/templates/8-SlackTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ${targetLabel} : ${target}
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
${contentLabel} : ${content}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ${targetLabel} : ${target}
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
${contentLabel} : ${content}
Loading