|
|
@ -109,11 +109,13 @@ func (the *consumerAxySkAlarm) monitorInitial() error { |
|
|
|
log.Printf("定时任务[%s],cron=[%s] 无匹配", taskName, cron) |
|
|
|
} |
|
|
|
} |
|
|
|
//测试用
|
|
|
|
//the.updateTriggerConfig()
|
|
|
|
return nil |
|
|
|
} |
|
|
|
func (the *consumerAxySkAlarm) updateTriggerConfig() { |
|
|
|
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) |
|
|
|
if err != nil { |
|
|
|
log.Printf("查询数据库异常:err-> %s", err.Error()) |
|
|
@ -149,10 +151,12 @@ func (the *consumerAxySkAlarm) updateTriggerStationConfig() { |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|
alarms, err := the.OutEs.SearchAlarm("native_sk_alarms", esSql) |
|
|
|
alarms, err := the.OutEs.SearchAlarm(the.Info.IoConfig.Out.Es.Index, esSql) |
|
|
|
if err != nil { |
|
|
|
log.Printf("es查询异常err -> %s", err.Error()) |
|
|
|
continue |
|
|
@ -177,6 +181,10 @@ func (the *consumerAxySkAlarm) judgeSK() string { |
|
|
|
//判断是否满足告警
|
|
|
|
for sid, stationAlarmInfo := range stationAlarmMap { |
|
|
|
log.Printf("判断测点[%s] 是否满足双控告警", sid) |
|
|
|
if v, ok := previousTriggerStationAlarmMap[sid]; ok { |
|
|
|
log.Printf("测点[%s]本次已经触发过[%s],不再重复触发", sid, v) |
|
|
|
continue |
|
|
|
} |
|
|
|
isAlarm, level, detail := the.isRuleAlarm(trigger, stationAlarmInfo) |
|
|
|
println(isAlarm, level, detail) |
|
|
|
var alarmInfoTemplate *models.EsAlarm |
|
|
@ -187,6 +195,8 @@ func (the *consumerAxySkAlarm) judgeSK() string { |
|
|
|
alarmInfoTemplate = stationAlarmInfo.Alarm3008 |
|
|
|
} |
|
|
|
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) |
|
|
|
the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload) |
|
|
|
} else { |
|
|
@ -288,10 +298,12 @@ func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationA |
|
|
|
case 0: |
|
|
|
if stationAlarm.Alarm3007.CurrentLevel > trigger.AlarmLevel { |
|
|
|
isAlarm = true |
|
|
|
detail += stationAlarm.Alarm3007.Detail |
|
|
|
} |
|
|
|
case 1: |
|
|
|
if stationAlarm.Alarm3008.CurrentLevel > trigger.AlarmLevel { |
|
|
|
isAlarm = true |
|
|
|
detail += stationAlarm.Alarm3008.Detail |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|