|
|
@ -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) |
|
|
|
|
|
|
|
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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
esAggPointsCount := len(esAggData.Aggregations.GroupBySensor.Buckets) |
|
|
|
} |
|
|
|
|
|
|
|
if esAggPointsCount < pointsCount { |
|
|
|
log.Printf("es 聚集查询告警数=%d < 配置测点数 %d", esAggPointsCount, pointsCount) |
|
|
|
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{ |
|
|
|