Skip to content

Commit

Permalink
alert notice add monitor host (#1515)
Browse files Browse the repository at this point in the history
Co-authored-by: tomsun28 <tomsun28@outlook.com>
  • Loading branch information
yqxxgh and tomsun28 committed Jan 26, 2024
1 parent 56ee5d8 commit d371077
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 5 deletions.
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 @@ -19,6 +19,7 @@ alerter.notify.title = HertzBeat Alert Notify
alerter.notify.target = Monitor Target
alerter.notify.monitorId = Monitor ID
alerter.notify.monitorName = Monitor Name
alerter.notify.monitorHost = Monitor Host
alerter.notify.priority = Alert Priority
alerter.notify.triggerTime = Alert Trigger Time
alerter.notify.restoreTime = Alert Restore Time
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 @@ -19,6 +19,7 @@ alerter.notify.title = HertzBeat告警通知
alerter.notify.target = 告警目标对象
alerter.notify.monitorId = 所属监控任务ID
alerter.notify.monitorName = 所属任务名称
alerter.notify.monitorHost = 所属任务主机
alerter.notify.priority = 告警级别
alerter.notify.triggerTime = 告警触发时间
alerter.notify.restoreTime = 告警恢复时间
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ public interface CommonConstants {
*/
String TAG_MONITOR_NAME = "monitorName";

/**
* 内有标签: monitorHost 任务主机
*/
String TAG_MONITOR_HOST = "monitorHost";

/**
* 内有标签: policyId 告警阈值规则ID
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class NoticeTemplate {
"${targetLabel} : ${target}\n" +
"<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>\n" +
"<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>\n" +
"<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>\n" +
"${priorityLabel} : ${priority}\n" +
"${triggerTimeLabel} : ${triggerTime}\n" +
"${contentLabel} : ${content}", accessMode = READ_WRITE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ protected String renderContent(NoticeTemplate noticeTemplate, Alert alert) throw
if (monitorName != null) {
model.put("monitorName", monitorName);
}
String monitorHost = alert.getTags().get(CommonConstants.TAG_MONITOR_HOST);
if (monitorHost != null) {
model.put("monitorHost", monitorHost);
}
String thresholdId = alert.getTags().get(CommonConstants.TAG_THRESHOLD_ID);
if (thresholdId != null) {
model.put("thresholdId", thresholdId);
Expand All @@ -88,6 +92,7 @@ protected String renderContent(NoticeTemplate noticeTemplate, Alert alert) throw
model.put("status", alert.getStatus());
model.put("monitorIdLabel", bundle.getString("alerter.notify.monitorId"));
model.put("monitorNameLabel", bundle.getString("alerter.notify.monitorName"));
model.put("monitorHostLabel", bundle.getString("alerter.notify.monitorHost"));
model.put("target", alert.getTarget());
model.put("targetLabel", bundle.getString("alerter.notify.target"));
model.put("priorityLabel", bundle.getString("alerter.notify.priority"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public void store(Alert alert) {
if (!tags.containsKey(CommonConstants.TAG_MONITOR_NAME)) {
tags.put(CommonConstants.TAG_MONITOR_NAME, monitor.getName());
}
if (!tags.containsKey(CommonConstants.TAG_MONITOR_HOST)) {
tags.put(CommonConstants.TAG_MONITOR_HOST, monitor.getHost());
}
if (monitor.getStatus() == CommonConstants.UN_MANAGE_CODE) {
// When monitoring is not monitored, ignore and silence its alarm messages
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,25 @@ public String buildAlertHtmlTemplate(final Alert alert, NoticeTemplate noticeTem
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
String monitorId = null;
String monitorName = null;
String monitorHost = null;
if (alert.getTags() != null) {
monitorId = alert.getTags().get(CommonConstants.TAG_MONITOR_ID);
monitorName = alert.getTags().get(CommonConstants.TAG_MONITOR_NAME);
monitorHost = alert.getTags().get(CommonConstants.TAG_MONITOR_HOST);
}
monitorId = monitorId == null ? "External Alarm, No ID" : monitorId;
monitorName = monitorName == null ? "External Alarm, No Name" : monitorName;
monitorHost = monitorHost == null ? "External Alarm, No Host" : monitorHost;
// Introduce context parameters to render pages
Map<String, String> model = new HashMap<>(16);
model.put("nameTitle", bundle.getString("alerter.notify.title"));
model.put("nameMonitorId", bundle.getString("alerter.notify.monitorId"));
model.put("nameMonitorName", bundle.getString("alerter.notify.monitorName"));
model.put("nameMonitorHost", bundle.getString("alerter.notify.monitorHost"));
model.put("target", alert.getTarget());
model.put("monitorId", monitorId);
model.put("monitorName", monitorName);
model.put("monitorHost", monitorHost);
model.put("nameTarget", bundle.getString("alerter.notify.target"));
model.put("nameConsole", bundle.getString("alerter.notify.console"));
model.put("namePriority", bundle.getString("alerter.notify.priority"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public boolean sendTestMsg(NoticeReceiver noticeReceiver) {
Map<String, String> tags = new HashMap<>(8);
tags.put(CommonConstants.TAG_MONITOR_ID, "100");
tags.put(CommonConstants.TAG_MONITOR_NAME, "100Name");
tags.put(CommonConstants.TAG_MONITOR_HOST, "127.0.0.1");
tags.put(CommonConstants.TAG_THRESHOLD_ID, "200");
Alert alert = new Alert();
alert.setTags(tags);
Expand Down
15 changes: 13 additions & 2 deletions manager/src/main/resources/templates/1-EmailTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -658,15 +658,26 @@
<span>${monitorName}</span>
</td>
</tr>
<tr>
<td align="right"
style="padding-right: 10px; color: #817878; font-weight: 500;">
<span>
${nameMonitorHost}
</span>
</td>
<td>
<span>${monitorHost}</span>
</td>
</tr>
<tr>
<td align="right"
style="padding-right: 10px; color: #817878; font-weight: 500;">
<span>
${namePriority}
</span>
</td>
<td><span
>${priority}</span>
<td>
<span>${priority}</span>
</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
${targetLabel} : ${target}
<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
${targetLabel} : ${target}
<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
##### **${targetLabel}** : ${target}
<#if (monitorId??)>##### **${monitorIdLabel}** : ${monitorId} </#if>
<#if (monitorName??)>##### **${monitorNameLabel}** : ${monitorName} </#if>
<#if (monitorHost??)>##### **${monitorHostLabel}** : ${monitorHost} </#if>
##### **${priorityLabel}** : ${priority}
##### **${triggerTimeLabel}** : ${triggerTime}
<#if (restoreTimeLabel??)>##### **${restoreTimeLabel}** : ${restoreTime} </#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
${targetLabel} : ${target}
<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
##### **${targetLabel}** : ${target}
<#if (monitorId??)>##### **${monitorIdLabel}** : ${monitorId} </#if>
<#if (monitorName??)>##### **${monitorNameLabel}** : ${monitorName} </#if>
<#if (monitorHost??)>##### **${monitorHostLabel}** : ${monitorHost} </#if>
##### **${priorityLabel}** : ${priority}
##### **${triggerTimeLabel}** : ${triggerTime}
<#if (restoreTimeLabel??)>##### **${restoreTimeLabel}** : ${restoreTime} </#if>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
${targetLabel} : ${target}
<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
${targetLabel} : ${target}
<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
Expand Down
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 @@ -2,6 +2,7 @@
${targetLabel} : ${target}
<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
${targetLabel} : ${target}
<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>
<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>
<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>
${priorityLabel} : ${priority}
${triggerTimeLabel} : ${triggerTime}
<#if (restoreTimeLabel??)>${restoreTimeLabel} : ${restoreTime} </#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void send() {
"##### **${targetLabel}** : ${target}\n" +
"<#if (monitorId??)>##### **${monitorIdLabel}** : ${monitorId} </#if>\n" +
"<#if (monitorName??)>##### **${monitorNameLabel}** : ${monitorName} </#if>\n" +
"<#if (monitorHost??)>##### **${monitorHostLabel}** : ${monitorHost} </#if>\n" +
"##### **${priorityLabel}** : ${priority}\n" +
"##### **${triggerTimeLabel}** : ${triggerTime}\n" +
"##### **${contentLabel}** : ${content}");
Expand All @@ -49,6 +50,7 @@ void send() {
Map<String, String> map = new HashMap<>();
map.put(CommonConstants.TAG_MONITOR_ID, "Mock monitor id");
map.put(CommonConstants.TAG_MONITOR_NAME, "Mock monitor name");
map.put(CommonConstants.TAG_MONITOR_HOST, "Mock monitor Host");
alert.setTags(map);
alert.setContent("mock content");
alert.setPriority((byte) 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void send() {
noticeTemplate.setContent("${targetLabel} : ${target}\n" +
"<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>\n" +
"<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>\n" +
"<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>\n" +
"${priorityLabel} : ${priority}\n" +
"${triggerTimeLabel} : ${triggerTime}\n" +
"${contentLabel} : ${content}");
Expand All @@ -51,7 +52,8 @@ void send() {
alert.setTarget("Mock Target");
var map = Map.of(
CommonConstants.TAG_MONITOR_ID, "Mock monitor id",
CommonConstants.TAG_MONITOR_NAME, "Mock monitor name"
CommonConstants.TAG_MONITOR_NAME, "Mock monitor name",
CommonConstants.TAG_MONITOR_HOST, "Mock monitor host"
);
alert.setTags(map);
alert.setContent("mock content");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void send() {
noticeTemplate.setContent("{targetLabel} : ${target}\n" +
"<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>\n" +
"<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>\n" +
"<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>\n" +
"${priorityLabel} : ${priority}\n" +
"${triggerTimeLabel} : ${triggerTime}\n" +
"${contentLabel} : ${content}");
Expand All @@ -48,6 +49,7 @@ void send() {
Map<String, String> map = new HashMap<>();
map.put(CommonConstants.TAG_MONITOR_ID, "Mock monitor id");
map.put(CommonConstants.TAG_MONITOR_NAME, "Mock monitor name");
map.put(CommonConstants.TAG_MONITOR_HOST, "Mock monitor host");
alert.setTags(map);
alert.setContent("mock content");
alert.setPriority((byte) 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void send() throws InterruptedException {
"${targetLabel} : ${target}\n" +
"<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>\n" +
"<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>\n" +
"<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>\n" +
"${priorityLabel} : ${priority}\n" +
"${triggerTimeLabel} : ${triggerTime}\n" +
"${contentLabel} : ${content}");
Expand All @@ -87,7 +88,8 @@ void send() throws InterruptedException {
alert.setTarget("Mock Target");
var map = Map.of(
CommonConstants.TAG_MONITOR_ID, "Mock monitor id",
CommonConstants.TAG_MONITOR_NAME, "Mock monitor name"
CommonConstants.TAG_MONITOR_NAME, "Mock monitor name",
CommonConstants.TAG_MONITOR_HOST, "Mock monitor host"
);
alert.setTags(map);
alert.setContent("mock content");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ void send() {
"${targetLabel} : ${target}\n" +
"<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>\n" +
"<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>\n" +
"<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>\n" +
"${priorityLabel} : ${priority}\n" +
"${triggerTimeLabel} : ${triggerTime}\n" +
"${contentLabel} : ${content}");
var map = Map.of(
CommonConstants.TAG_MONITOR_ID, "Mock monitor id",
CommonConstants.TAG_MONITOR_NAME, "Mock monitor name"
CommonConstants.TAG_MONITOR_NAME, "Mock monitor name",
CommonConstants.TAG_MONITOR_HOST, "Mock monitor host"
);
alert.setTags(map);
alert.setContent("mock content");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ void send() {
"${targetLabel} : ${target}\n" +
"<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>\n" +
"<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>\n" +
"<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>\n" +
"${priorityLabel} : ${priority}\n" +
"${triggerTimeLabel} : ${triggerTime}\n" +
"${contentLabel} : ${content}");
Map<String, String> map = new HashMap<>();
map.put(CommonConstants.TAG_MONITOR_ID, "Mock monitor id");
map.put(CommonConstants.TAG_MONITOR_NAME, "Mock monitor name");
map.put(CommonConstants.TAG_MONITOR_HOST, "Mock monitor host");
alert.setTags(map);
alert.setContent("mock content");
alert.setPriority((byte) 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void send() {
Map<String, String> map = new HashMap<>();
map.put(CommonConstants.TAG_MONITOR_ID, "Mock monitor id");
map.put(CommonConstants.TAG_MONITOR_NAME, "Mock monitor name");
map.put(CommonConstants.TAG_MONITOR_HOST, "Mock monitor host");
alert.setTags(map);
alert.setContent("mock content");
alert.setPriority((byte) 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ void send() {
"${targetLabel} : ${target}\n" +
"<#if (monitorId??)>${monitorIdLabel} : ${monitorId} </#if>\n" +
"<#if (monitorName??)>${monitorNameLabel} : ${monitorName} </#if>\n" +
"<#if (monitorHost??)>${monitorHostLabel} : ${monitorHost} </#if>\n" +
"${priorityLabel} : ${priority}\n" +
"${triggerTimeLabel} : ${triggerTime}\n" +
"${contentLabel} : ${content}");
Map<String, String> map = new HashMap<>();
map.put(CommonConstants.TAG_MONITOR_ID, "Mock monitor id");
map.put(CommonConstants.TAG_MONITOR_NAME, "Mock monitor name");
map.put(CommonConstants.TAG_MONITOR_HOST, "Mock monitor host");
alert.setTags(map);
alert.setContent("mock content");
alert.setPriority((byte) 0);
Expand Down

0 comments on commit d371077

Please sign in to comment.