This is an automated email from the ASF dual-hosted git repository.

Duansg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git


The following commit(s) were added to refs/heads/master by this push:
     new e6ceea94f8 maintenance: normalize Zabbix alert identity (#4284)
e6ceea94f8 is described below

commit e6ceea94f8a11974f3e7bb851fab447c83065d9b
Author: Logic <[email protected]>
AuthorDate: Mon Aug 3 13:37:02 2026 +0800

    maintenance: normalize Zabbix alert identity (#4284)
    
    Co-authored-by: Duansg <[email protected]>
---
 .../service/impl/ZabbixExternAlertServiceImpl.java |  1 +
 .../impl/ZabbixExternAlertServiceImplTest.java}    | 48 ++++++++++++----------
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git 
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImpl.java
 
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImpl.java
index 76deddfce8..0be0e07250 100644
--- 
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImpl.java
+++ 
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImpl.java
@@ -42,6 +42,7 @@ public class ZabbixExternAlertServiceImpl implements 
ExternAlertService {
             log.warn("parse extern alert content failed! content: {}", 
content);
             return;
         }
+        alert.setId(null);
         alarmCommonReduce.reduceAndSendAlarm(alert);
     }
 
diff --git 
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImpl.java
 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImplTest.java
similarity index 50%
copy from 
hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImpl.java
copy to 
hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImplTest.java
index 76deddfce8..1db711ac0d 100644
--- 
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImpl.java
+++ 
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/impl/ZabbixExternAlertServiceImplTest.java
@@ -17,36 +17,42 @@
 
 package org.apache.hertzbeat.alert.service.impl;
 
-import lombok.extern.slf4j.Slf4j;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.verify;
+
 import org.apache.hertzbeat.alert.reduce.AlarmCommonReduce;
-import org.apache.hertzbeat.alert.service.ExternAlertService;
 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 org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
 
 /**
- * zabbix external alarm service impl
+ * Test case for {@link ZabbixExternAlertServiceImpl}.
  */
-@Slf4j
-@Service
-public class ZabbixExternAlertServiceImpl implements ExternAlertService {
+@ExtendWith(MockitoExtension.class)
+class ZabbixExternAlertServiceImplTest {
 
-    @Autowired
+    @Mock
     private AlarmCommonReduce alarmCommonReduce;
 
-    @Override
-    public void addExternAlert(String content) {
-        SingleAlert alert = JsonUtil.fromJson(content, SingleAlert.class);
-        if (alert == null) {
-            log.warn("parse extern alert content failed! content: {}", 
content);
-            return;
-        }
-        alarmCommonReduce.reduceAndSendAlarm(alert);
-    }
+    @InjectMocks
+    private ZabbixExternAlertServiceImpl externAlertService;
+
+    @Test
+    void ignoresExternalPersistenceIdentity() {
+        SingleAlert incoming = SingleAlert.builder()
+                .id(123L)
+                .fingerprint("zabbix-alert")
+                .build();
+
+        externAlertService.addExternAlert(JsonUtil.toJson(incoming));
 
-    @Override
-    public String supportSource() {
-        return "zabbix";
+        ArgumentCaptor<SingleAlert> alertCaptor = 
ArgumentCaptor.forClass(SingleAlert.class);
+        verify(alarmCommonReduce).reduceAndSendAlarm(alertCaptor.capture());
+        assertNull(alertCaptor.getValue().getId());
     }
 }


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

Reply via email to