Browse Source

update 更新 最新爆闪组合告警

dev
lucas 10 hours ago
parent
commit
cf36d846da
  1. 17
      adaptors/知物云es告警组合聚集to触发爆闪.go
  2. 7
      consumers/AlarmCombination/dataModel.go
  3. 35
      consumers/consumerAlarmCombination.go

17
adaptors/知物云es告警组合聚集to触发爆闪.go

@ -20,7 +20,7 @@ import (
type Adaptor_ZWY_AlarmCombin struct {
//一些必要信息
Info map[string]string
Info map[int]string
}
func (the Adaptor_ZWY_AlarmCombin) Transform(config AlarmCombination.CombinationInfo, rawMsg string) []NeedPush {
@ -43,13 +43,18 @@ func (the Adaptor_ZWY_AlarmCombin) Transform(config AlarmCombination.Combination
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 stationName, ok := the.Info[stationId]; ok {
if itemAlarmCounts < 2 {
detailMsg += stationName
}
itemAlarmCounts += 1
} else {
log.Printf("测点[%d]无匹配的名称", stationId)
}
}
}
@ -59,7 +64,7 @@ func (the Adaptor_ZWY_AlarmCombin) Transform(config AlarmCombination.Combination
log.Printf("es 聚集查询告警组数=%d < 2", esAggPointsCount)
return nil
}
msg := fmt.Sprintf("组合告警[%s]生效,有效触发的前2组:%s", config.Name, detailMsg)
msg := fmt.Sprintf("组合告警[%s]产生,有效触发测点:%s 等,共%d个", config.Name, detailMsg, itemAlarmCounts)
log.Printf(msg)
prefix := "zh-"

7
consumers/AlarmCombination/dataModel.go

@ -21,3 +21,10 @@ type ConfigItems struct {
FactorId int `json:"factorId"`
StationIds []int `json:"stationIds"`
}
type StationInfo struct {
Id int `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Structure string `json:"structure" db:"structure"`
Factor int `json:"factor" db:"factor"`
}

35
consumers/consumerAlarmCombination.go

@ -10,6 +10,7 @@ import (
"goInOut/monitors"
"gopkg.in/yaml.v3"
"log"
"strings"
"time"
)
@ -25,6 +26,7 @@ type consumerAlarmCombination struct {
infoPg *dbOperate.DBHelper
//数据库配置信息
combinationInfo []AlarmCombination.CombinationInfo
stationIdName map[int]string
}
func (the *consumerAlarmCombination) LoadConfigJson(cfgStr string) {
@ -80,7 +82,9 @@ func (the *consumerAlarmCombination) OutputInitial() error {
func (the *consumerAlarmCombination) infoComponentInitial() error {
//数据出口
pgConnStr := the.Info.QueryComponent.Pg.Connect
//redisConnStr := the.Info.QueryComponent.Redis.Address
the.infoPg = dbOperate.NewDBHelper("postgres", pgConnStr)
//the.infoRedis = dbOperate.NewRedisHelper("", redisConnStr)
return nil
}
func (the *consumerAlarmCombination) Work() {
@ -111,7 +115,9 @@ func (the *consumerAlarmCombination) Work() {
func (the *consumerAlarmCombination) getAdaptor() (adaptor adaptors.Adaptor_ZWY_AlarmCombin) {
return adaptors.Adaptor_ZWY_AlarmCombin{}
return adaptors.Adaptor_ZWY_AlarmCombin{
Info: the.stationIdName,
}
}
func (the *consumerAlarmCombination) getEs1minAlarmData() {
@ -150,19 +156,46 @@ func (the *consumerAlarmCombination) updateCombinationInfo() {
log.Printf("查询数据库异常:err-> %s", err.Error())
return
}
var stationIds []int
for i, info := range the.combinationInfo {
err := json.Unmarshal([]byte(info.ConfigStr), &info.ConfigItems)
if err != nil {
return
}
the.combinationInfo[i].ConfigItems = info.ConfigItems
for _, item := range info.ConfigItems {
stationIds = append(stationIds, item.StationIds...)
}
}
log.Printf("共刷新%d条配置", len(the.combinationInfo))
//每次重新赋值
the.stationIdName = the.queryStationNameByIds(stationIds)
//立即触发
the.getEs1minAlarmData()
}
func (the *consumerAlarmCombination) queryStationNameByIds(stationIds []int) map[int]string {
strIds := make([]string, len(stationIds))
for i, num := range stationIds {
strIds[i] = fmt.Sprint(num)
}
idStr := strings.Join(strIds, ",")
sqlStation := fmt.Sprintf(`SELECT id,structure,name,factor FROM "t_sensor" where id in(%s)`, idStr)
var stationInfos []AlarmCombination.StationInfo
err := the.infoPg.Query(&stationInfos, sqlStation)
idNames := map[int]string{}
if err != nil {
log.Printf("查询数据库异常:err-> %s", err.Error())
return idNames
}
for _, info := range stationInfos {
idNames[info.Id] = info.Name
}
return idNames
}
func (the *consumerAlarmCombination) getESAlarmAggQueryStr(onceConfig AlarmCombination.CombinationInfo) string {
structureId := onceConfig.StructId
var allStationId []int

Loading…
Cancel
Save