xiaomizhou2 commented on code in PR #3312:
URL: https://github.com/apache/hertzbeat/pull/3312#discussion_r2068208914


##########
hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/UptimeKumaExternAlertServiceImpl.java:
##########
@@ -0,0 +1,101 @@
+package org.apache.hertzbeat.alert.service.impl;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.hertzbeat.alert.dto.UptimeKumaExternAlert;
+import org.apache.hertzbeat.alert.reduce.AlarmCommonReduce;
+import org.apache.hertzbeat.alert.service.ExternAlertService;
+import org.apache.hertzbeat.common.constants.CommonConstants;
+import org.apache.hertzbeat.common.entity.alerter.SingleAlert;
+import org.apache.hertzbeat.common.util.JsonUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * uptime-kuma external alarm service impl
+ */
+@Slf4j
+@Service
+public class UptimeKumaExternAlertServiceImpl implements ExternAlertService {
+
+    @Autowired
+    private AlarmCommonReduce alarmCommonReduce;
+
+    @Override
+    public void addExternAlert(String content) {
+        UptimeKumaExternAlert alert = JsonUtil.fromJson(content, 
UptimeKumaExternAlert.class);
+        if (alert == null) {
+            log.warn("parse extern alert content failed! content: {}", 
content);
+            return;
+        }
+        SingleAlert singleAlert = new 
UptimeKumaAlertConverter().convert(alert);
+        alarmCommonReduce.reduceAndSendAlarm(singleAlert);
+    }
+
+    /**
+     * Converter: UptimeKuma alert to SingleAlert
+     */
+    public static class UptimeKumaAlertConverter {
+
+        /**
+         * Convert UptimeKuma alert to SingleAlert
+         */
+        public SingleAlert convert(UptimeKumaExternAlert alert) {
+            // 构建基本信息
+            SingleAlert.SingleAlertBuilder builder = SingleAlert.builder()
+                    .status(convertStatus(alert.getHeartbeat().getStatus()))
+                    .startAt(parseTime(alert.getHeartbeat().getTime()))
+                    .activeAt(parseTime(alert.getHeartbeat().getTime()))
+                    .triggerTimes(1);
+
+            // 构建标签
+            Map<String, String> labels = new HashMap<>();
+            labels.put("__source__", "uptime_kuma");
+            labels.put("monitor_id", 
String.valueOf(alert.getMonitor().getId()));
+            labels.put("monitor_name", alert.getMonitor().getName());
+
+            // 构建注解

Review Comment:
   好的



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to