Browse Source

update 调整双控处理

dev
lucas 24 hours ago
parent
commit
1d89844106
  1. 18
      consumers/consumerAxySkAlarm.go

18
consumers/consumerAxySkAlarm.go

@ -109,11 +109,13 @@ func (the *consumerAxySkAlarm) monitorInitial() error {
log.Printf("定时任务[%s],cron=[%s] 无匹配", taskName, cron) log.Printf("定时任务[%s],cron=[%s] 无匹配", taskName, cron)
} }
} }
//测试用
//the.updateTriggerConfig()
return nil return nil
} }
func (the *consumerAxySkAlarm) updateTriggerConfig() { func (the *consumerAxySkAlarm) updateTriggerConfig() {
log.Printf("--> 定时 查询pg 更新 双控配置信息") log.Printf("--> 定时 查询pg 更新 双控配置信息")
sql := `SELECT at.* FROM t_alarm_trigger as at;` sql := `SELECT at.* FROM t_alarm_trigger as at order by at.struct_id, at.factor_id,at.alarm_level asc;`
err := the.infoPg.Query(&the.configAlarmTrigger, sql) err := the.infoPg.Query(&the.configAlarmTrigger, sql)
if err != nil { if err != nil {
log.Printf("查询数据库异常:err-> %s", err.Error()) log.Printf("查询数据库异常:err-> %s", err.Error())
@ -149,10 +151,12 @@ func (the *consumerAxySkAlarm) updateTriggerStationConfig() {
} }
func (the *consumerAxySkAlarm) judgeSK() string { func (the *consumerAxySkAlarm) judgeSK() string {
for _, trigger := range the.configAlarmTrigger { previousTriggerStationAlarmMap := map[string]string{} //同factorId_stationId 触发了高等级 不触发低等级(查询已排序)
for i, trigger := range the.configAlarmTrigger {
log.Printf("开始处理--> 第[%d] id=%d trigger配置", i, trigger.Id)
//配置的结构物的监测因素 去查询 //配置的结构物的监测因素 去查询
esSql := the.getEsAlarmTriggerQueryStr(trigger.StructId) esSql := the.getEsAlarmTriggerQueryStr(trigger.StructId)
alarms, err := the.OutEs.SearchAlarm("native_sk_alarms", esSql) alarms, err := the.OutEs.SearchAlarm(the.Info.IoConfig.Out.Es.Index, esSql)
if err != nil { if err != nil {
log.Printf("es查询异常err -> %s", err.Error()) log.Printf("es查询异常err -> %s", err.Error())
continue continue
@ -177,6 +181,10 @@ func (the *consumerAxySkAlarm) judgeSK() string {
//判断是否满足告警 //判断是否满足告警
for sid, stationAlarmInfo := range stationAlarmMap { for sid, stationAlarmInfo := range stationAlarmMap {
log.Printf("判断测点[%s] 是否满足双控告警", sid) log.Printf("判断测点[%s] 是否满足双控告警", sid)
if v, ok := previousTriggerStationAlarmMap[sid]; ok {
log.Printf("测点[%s]本次已经触发过[%s],不再重复触发", sid, v)
continue
}
isAlarm, level, detail := the.isRuleAlarm(trigger, stationAlarmInfo) isAlarm, level, detail := the.isRuleAlarm(trigger, stationAlarmInfo)
println(isAlarm, level, detail) println(isAlarm, level, detail)
var alarmInfoTemplate *models.EsAlarm var alarmInfoTemplate *models.EsAlarm
@ -187,6 +195,8 @@ func (the *consumerAxySkAlarm) judgeSK() string {
alarmInfoTemplate = stationAlarmInfo.Alarm3008 alarmInfoTemplate = stationAlarmInfo.Alarm3008
} }
if isAlarm && alarmInfoTemplate != nil { if isAlarm && alarmInfoTemplate != nil {
previousTriggerStationAlarmMap[sid] = fmt.Sprintf("st:%d,f:%d,level:%d",
trigger.StructId, trigger.FactorId, level)
payload := the.skAlarmInfo(alarmInfoTemplate, level, detail) payload := the.skAlarmInfo(alarmInfoTemplate, level, detail)
the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload) the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload)
} else { } else {
@ -288,10 +298,12 @@ func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationA
case 0: case 0:
if stationAlarm.Alarm3007.CurrentLevel > trigger.AlarmLevel { if stationAlarm.Alarm3007.CurrentLevel > trigger.AlarmLevel {
isAlarm = true isAlarm = true
detail += stationAlarm.Alarm3007.Detail
} }
case 1: case 1:
if stationAlarm.Alarm3008.CurrentLevel > trigger.AlarmLevel { if stationAlarm.Alarm3008.CurrentLevel > trigger.AlarmLevel {
isAlarm = true isAlarm = true
detail += stationAlarm.Alarm3008.Detail
} }
} }

Loading…
Cancel
Save