diff --git a/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java b/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java index 86ba188dc97..5ed2c0b194f 100644 --- a/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java +++ b/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java @@ -18,10 +18,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; /** @@ -45,6 +42,8 @@ public class CalculateAlarm { */ private Map triggeredAlertMap; + private ResourceBundle bundle; + public CalculateAlarm (AlerterWorkerPool workerPool, AlerterDataQueue dataQueue, AlertDefineService alertDefineService, MetricsDataExporter dataExporter, AlertMonitorDao monitorDao, AlerterProperties alerterProperties) { @@ -53,6 +52,7 @@ public CalculateAlarm (AlerterWorkerPool workerPool, AlerterDataQueue dataQueue, this.dataExporter = dataExporter; this.alertDefineService = alertDefineService; this.alerterProperties = alerterProperties; + this.bundle = ResourceBundle.getBundle("alerter", Locale.getDefault()); this.triggeredAlertMap = new ConcurrentHashMap<>(128); // 初始化stateAlertMap List monitors = monitorDao.findMonitorsByStatusIn(Arrays.asList(CommonConstants.UN_AVAILABLE_CODE, @@ -67,13 +67,13 @@ public CalculateAlarm (AlerterWorkerPool workerPool, AlerterDataQueue dataQueue, .priority(CommonConstants.ALERT_PRIORITY_CODE_EMERGENCY) .status(CommonConstants.ALERT_STATUS_CODE_PENDING) .target(CommonConstants.AVAILABLE) - .content("Monitoring Availability Emergency Alert: " + CollectRep.Code.UN_AVAILABLE.name()) + .content(this.bundle.getString("alerter.availability.emergency") + ": " + CollectRep.Code.UN_AVAILABLE.name()) .firstTriggerTime(System.currentTimeMillis()) .lastTriggerTime(System.currentTimeMillis()); if (monitor.getStatus() == CommonConstants.UN_REACHABLE_CODE) { alertBuilder .target(CommonConstants.REACHABLE) - .content("Monitoring Reachability Emergency Alert: " + CollectRep.Code.UN_REACHABLE.name()); + .content(this.bundle.getString("alerter.reachability.emergency") + ": " + CollectRep.Code.UN_REACHABLE.name()); } this.triggeredAlertMap.put(String.valueOf(monitor.getId()), alertBuilder.build()); } @@ -130,10 +130,10 @@ private void calculate(CollectRep.MetricsData metricsData) { tags.put(CommonConstants.TAG_MONITOR_ID, String.valueOf(monitorId)); tags.put(CommonConstants.TAG_MONITOR_APP, app); String target = CommonConstants.AVAILABLE; - String content = "Availability Alert Resolved, Monitor Status Normal Now"; + String content = this.bundle.getString("alerter.availability.resolved"); if (CommonConstants.REACHABLE.equals(preAlert.getTarget())) { target = CommonConstants.REACHABLE; - content = "Reachability Alert Resolved, Monitor Status Normal Now"; + content = this.bundle.getString("alerter.reachability.resolved"); } Alert resumeAlert = Alert.builder() .tags(tags) @@ -248,7 +248,7 @@ private void handlerMonitorStatusAlert(String monitorId, String app, CollectRep. .priority(CommonConstants.ALERT_PRIORITY_CODE_EMERGENCY) .status(CommonConstants.ALERT_STATUS_CODE_PENDING) .target(CommonConstants.AVAILABLE) - .content("Monitoring Availability Emergency Alert: " + code.name()) + .content(this.bundle.getString("alerter.availability.emergency") + ": " + code.name()) .firstTriggerTime(currentTimeMill) .lastTriggerTime(currentTimeMill) .nextEvalInterval(alerterProperties.getAlertEvalIntervalBase()) @@ -256,7 +256,7 @@ private void handlerMonitorStatusAlert(String monitorId, String app, CollectRep. if (code == CollectRep.Code.UN_REACHABLE) { alertBuilder .target(CommonConstants.REACHABLE) - .content("Monitoring Reachability Emergency Alert: " + code.name()); + .content(this.bundle.getString("alerter.reachability.emergency") + ": " + code.name()); } Alert alert = alertBuilder.build(); dataQueue.addAlertData(alert.clone()); diff --git a/alerter/src/main/resources/alerter_en_US.properties b/alerter/src/main/resources/alerter_en_US.properties new file mode 100644 index 00000000000..1dbfd56f8cd --- /dev/null +++ b/alerter/src/main/resources/alerter_en_US.properties @@ -0,0 +1,4 @@ +alerter.availability.emergency = Monitoring Availability Emergency Alert +alerter.reachability.emergency = Monitoring Reachability Emergency Alert +alerter.availability.resolved = Availability Alert Resolved, Monitor Status Normal Now +alerter.reachability.resolved = Reachability Alert Resolved, Monitor Status Normal Now \ No newline at end of file diff --git a/alerter/src/main/resources/alerter_zh_CN.properties b/alerter/src/main/resources/alerter_zh_CN.properties new file mode 100644 index 00000000000..23d55cba069 --- /dev/null +++ b/alerter/src/main/resources/alerter_zh_CN.properties @@ -0,0 +1,4 @@ +alerter.availability.emergency = 监控紧急可用性告警 +alerter.reachability.emergency = 监控紧急可达性告警 +alerter.availability.resolved = 可用性告警恢复通知, 监控状态已恢复正常 +alerter.reachability.resolved = 可达性告警恢复通知, 监控状态已恢复正常 \ No newline at end of file diff --git a/manager/pom.xml b/manager/pom.xml index b93f1de5586..7099742046b 100644 --- a/manager/pom.xml +++ b/manager/pom.xml @@ -114,6 +114,7 @@ true application.yml + *.properties sureness.yml banner.txt define/** diff --git a/manager/src/main/java/com/usthe/manager/service/impl/MailServiceImpl.java b/manager/src/main/java/com/usthe/manager/service/impl/MailServiceImpl.java index 3de5972f40f..caa8c727c70 100644 --- a/manager/src/main/java/com/usthe/manager/service/impl/MailServiceImpl.java +++ b/manager/src/main/java/com/usthe/manager/service/impl/MailServiceImpl.java @@ -40,8 +40,8 @@ public String buildAlertHtmlTemplate(final Alert alert) { monitorId = alert.getTags().get(CommonConstants.TAG_MONITOR_ID); monitorName = alert.getTags().get(CommonConstants.TAG_MONITOR_NAME); } - monitorId = monitorId == null? "External alarm, no ID" : monitorId; - monitorName = monitorName == null? "External alarm, no Name" : monitorName; + monitorId = monitorId == null? "External Alarm, No ID" : monitorId; + monitorName = monitorName == null? "External Alarm, No Name" : monitorName; // Introduce thymeleaf context parameters to render pages // 引入thymeleaf上下文参数渲染页面 Context context = new Context();