From 084783df5c9d2a7aa4fd61d548663b349af8de37 Mon Sep 17 00:00:00 2001 From: lucas Date: Fri, 4 Jul 2025 17:10:54 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=9B=B4=E6=96=B0=20=E7=BB=84?= =?UTF-8?q?=E5=90=88=E5=91=8A=E8=AD=A6=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...‰©äº‘es告警组åˆèšé›†to触å‘爆闪.go | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/adaptors/知物云es告警组åˆèšé›†to触å‘爆闪.go b/adaptors/知物云es告警组åˆèšé›†to触å‘爆闪.go index 105229c..7f3bff7 100644 --- a/adaptors/知物云es告警组åˆèšé›†to触å‘爆闪.go +++ b/adaptors/知物云es告警组åˆèšé›†to触å‘爆闪.go @@ -3,6 +3,7 @@ package adaptors import ( "encoding/json" "fmt" + "slices" "goInOut/consumers/AlarmCombination" @@ -23,8 +24,8 @@ type Adaptor_ZWY_AlarmCombin struct { } func (the Adaptor_ZWY_AlarmCombin) Transform(config AlarmCombination.CombinationInfo, rawMsg string) []NeedPush { + //20250704è‹çŽ®ç¡®è®¤ å°æ¡ä»¶æœ‰ä¸€ä¸ªå‘Šè­¦å°±ç®—有效,至少2ä¸ªå°æ¡ä»¶å‘Šè­¦ï¼Œ 触å‘大告警 log.Printf("è§£æžæ•°æ®") - configItems := config.ConfigItems esAggData := AlarmCombination.EsAggAlarm{} esAggData.Aggregations.GroupBySensor.Buckets = []AlarmCombination.BucketsSensorDataCount{} var needPush []NeedPush @@ -33,19 +34,34 @@ func (the Adaptor_ZWY_AlarmCombin) Transform(config AlarmCombination.Combination log.Printf("è§£æž es proxy æ•°æ®å¼‚常: %s", err.Error()) return nil } - pointsCount := 0 - for _, item := range configItems { - pointsCount += len(item.StationIds) - } - esAggPointsCount := len(esAggData.Aggregations.GroupBySensor.Buckets) - if esAggPointsCount < pointsCount { - log.Printf("es èšé›†æŸ¥è¯¢å‘Šè­¦æ•°=%d < é…置测点数 %d", esAggPointsCount, pointsCount) + detailMsg := "" + itemAlarmCounts := 0 // >=2有效 + for _, esBucket := range esAggData.Aggregations.GroupBySensor.Buckets { + stationId, _ := strconv.Atoi(esBucket.Key) + for _, item := range config.ConfigItems { + found := slices.Contains(item.StationIds, stationId) + if found { + itemAlarmCounts += 1 + if len(detailMsg) > 0 { + detailMsg += "," + } + detailMsg += fmt.Sprintf("测点[%d]触å‘[f=%d]有效告警组", stationId, item.FactorId) + log.Printf("") + break + } + } + + } + + if itemAlarmCounts < 2 { + log.Printf("es èšé›†æŸ¥è¯¢å‘Šè­¦ç»„æ•°=%d < 2", esAggPointsCount) return nil } - msg := fmt.Sprintf("组åˆå‘Šè­¦[%s]生效,存在%d个ä¸åŒæµ‹ç‚¹çš„告警", config.Name, esAggPointsCount) - log.Println(msg) + msg := fmt.Sprintf("组åˆå‘Šè­¦[%s]生效,有效触å‘çš„2组 详情=>%s", config.Name, detailMsg) + + log.Printf(msg) prefix := "zh-" sourceId := prefix + strconv.Itoa(config.Id) alarmMsg := models.KafkaAlarm{