Browse Source

update 历史告警 纪录控制

dev
lucas 20 hours ago
parent
commit
1d2ef80451
  1. 49
      consumers/consumerAxySkAlarm.go

49
consumers/consumerAxySkAlarm.go

@ -110,13 +110,13 @@ func (the *consumerAxySkAlarm) monitorInitial() error {
for taskName, cron := range the.Info.Monitor { for taskName, cron := range the.Info.Monitor {
switch taskName { switch taskName {
case "cron": case "cron":
the.monitor.RegisterTask(cron, the.updateTriggerConfig) //the.monitor.RegisterTask(cron, the.updateTriggerConfig)
default: default:
log.Printf("定时任务[%s],cron=[%s] 无匹配", taskName, cron) log.Printf("定时任务[%s],cron=[%s] 无匹配", taskName, cron)
} }
} }
//测试用 //测试用
//the.updateTriggerConfig() the.updateTriggerConfig()
return nil return nil
} }
func (the *consumerAxySkAlarm) updateTriggerConfig() { func (the *consumerAxySkAlarm) updateTriggerConfig() {
@ -192,7 +192,7 @@ func (the *consumerAxySkAlarm) judgeSK() string {
log.Printf("测点[%s]本次已经触发过[%s],不再重复触发", sid, v) log.Printf("测点[%s]本次已经触发过[%s],不再重复触发", sid, v)
continue continue
} }
isAlarm, level, detail := the.isRuleAlarm(trigger, stationAlarmInfo) isAlarm, level, detail, alarmTime := the.isRuleAlarm(trigger, stationAlarmInfo)
println(isAlarm, level, detail) println(isAlarm, level, detail)
var alarmInfoTemplate *models.EsAlarm var alarmInfoTemplate *models.EsAlarm
if stationAlarmInfo.Alarm3007 != nil { if stationAlarmInfo.Alarm3007 != nil {
@ -205,9 +205,6 @@ func (the *consumerAxySkAlarm) judgeSK() string {
conditionStr := fmt.Sprintf("st:%d,f:%d,level:%d", conditionStr := fmt.Sprintf("st:%d,f:%d,level:%d",
trigger.StructId, trigger.FactorId, level) trigger.StructId, trigger.FactorId, level)
onceTriggerStationAlarmMap[sid] = conditionStr onceTriggerStationAlarmMap[sid] = conditionStr
//纪录历史告警
payload, now := the.skAlarmInfo(alarmInfoTemplate, level, detail)
//判断历史有没有 //判断历史有没有
if v, ok := the.historyStationAlarmMap[sid]; ok { if v, ok := the.historyStationAlarmMap[sid]; ok {
if v.AlarmLevel > level { //低等级告警过滤 if v.AlarmLevel > level { //低等级告警过滤
@ -215,32 +212,34 @@ func (the *consumerAxySkAlarm) judgeSK() string {
continue continue
} }
if !v.Time.After(now) { if !v.Time.After(alarmTime) {
log.Printf("测点[%s]本次触发时刻[%s] 对比历史有效时刻[%s] 非新", sid, log.Printf("测点[%s]本次触发时刻[%s] 对比历史有效时刻[%s] 非新", sid,
v.Time.Format("2006-01-02 15:04:05"), now.Format("2006-01-02 15:04:05")) v.Time.Format("2006-01-02 15:04:05"), alarmTime.Format("2006-01-02 15:04:05"))
continue continue
} }
} }
//纪录历史告警
payload := the.skAlarmInfo(alarmInfoTemplate, level, detail, alarmTime)
the.historyStationAlarmMap[sid] = AXY_SK.HistoryAlarm{ the.historyStationAlarmMap[sid] = AXY_SK.HistoryAlarm{
SourceId: sid, SourceId: sid,
Condition: conditionStr, Condition: conditionStr,
AlarmLevel: level, AlarmLevel: level,
Time: now, Time: alarmTime,
} }
the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload) the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload)
} else { } else {
payload := the.skAlarmElimination(alarmInfoTemplate, level, detail) payload := the.skAlarmElimination(alarmInfoTemplate, level, detail)
the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload) the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload)
delete(the.historyStationAlarmMap, sid)
} }
} }
} }
return "" return ""
} }
func (the *consumerAxySkAlarm) skAlarmInfo(alarmInfoTemplate *models.EsAlarm, level int, detail string) ([]byte, time.Time) { func (the *consumerAxySkAlarm) skAlarmInfo(alarmInfoTemplate *models.EsAlarm, level int, detail string, alarmTime time.Time) []byte {
now := time.Now()
alarmMsg := models.KafkaAlarm{ alarmMsg := models.KafkaAlarm{
MessageMode: "AlarmGeneration", MessageMode: "AlarmGeneration",
StructureId: alarmInfoTemplate.StructureId, StructureId: alarmInfoTemplate.StructureId,
@ -250,14 +249,14 @@ func (the *consumerAxySkAlarm) skAlarmInfo(alarmInfoTemplate *models.EsAlarm, le
AlarmTypeCode: "3077", AlarmTypeCode: "3077",
AlarmCode: fmt.Sprintf("3077000%d", level), AlarmCode: fmt.Sprintf("3077000%d", level),
Content: detail, Content: detail,
Time: now.Format("2006-01-02T15:04:05+0800"), Time: alarmTime.Format("2006-01-02T15:04:05+0800"),
SourceTypeId: 2, // 0:DTU, 1:传感器, 2:测点 SourceTypeId: 2, // 0:DTU, 1:传感器, 2:测点
Sponsor: "goInOut_axySkAlarm", Sponsor: "goInOut_axySkAlarm",
Extras: nil, Extras: nil,
SubDevices: nil, SubDevices: nil,
} }
payload, _ := json.Marshal(alarmMsg) payload, _ := json.Marshal(alarmMsg)
return payload, now return payload
} }
func (the *consumerAxySkAlarm) skAlarmElimination(alarmInfoTemplate *models.EsAlarm, level int, detail string) []byte { func (the *consumerAxySkAlarm) skAlarmElimination(alarmInfoTemplate *models.EsAlarm, level int, detail string) []byte {
alarmMsg := models.KafkaAlarm{ alarmMsg := models.KafkaAlarm{
@ -279,9 +278,10 @@ func (the *consumerAxySkAlarm) skAlarmElimination(alarmInfoTemplate *models.EsAl
return payload return payload
} }
func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationAlarm AXY_SK.StationAlarmGroup) (bool, int, string) { func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationAlarm AXY_SK.StationAlarmGroup) (bool, int, string, time.Time) {
level := 0 level := 0
detail := "" detail := ""
dt := time.Time{}
//3007和3008都要有 //3007和3008都要有
if trigger.Rule == 0 { if trigger.Rule == 0 {
isAlarm := true isAlarm := true
@ -296,6 +296,9 @@ func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationA
if len(detail) > 0 { if len(detail) > 0 {
detail += "且 " detail += "且 "
} }
if stationAlarm.Alarm3007.EndTime.After(dt) {
dt = stationAlarm.Alarm3007.EndTime
}
detail += stationAlarm.Alarm3007.Detail detail += stationAlarm.Alarm3007.Detail
} }
@ -310,7 +313,9 @@ func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationA
detail += "且 " detail += "且 "
} }
detail += stationAlarm.Alarm3008.Detail detail += stationAlarm.Alarm3008.Detail
if stationAlarm.Alarm3008.EndTime.After(dt) {
dt = stationAlarm.Alarm3008.EndTime
}
} }
} }
@ -318,7 +323,7 @@ func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationA
if isAlarm { if isAlarm {
level = trigger.AlarmLevel level = trigger.AlarmLevel
} }
return isAlarm, level, detail return isAlarm, level, detail, dt
} }
//3007和3008 任何一个 //3007和3008 任何一个
@ -331,11 +336,17 @@ func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationA
if stationAlarm.Alarm3007.CurrentLevel > trigger.AlarmLevel { if stationAlarm.Alarm3007.CurrentLevel > trigger.AlarmLevel {
isAlarm = true isAlarm = true
detail += stationAlarm.Alarm3007.Detail detail += stationAlarm.Alarm3007.Detail
if stationAlarm.Alarm3007.EndTime.After(dt) {
dt = stationAlarm.Alarm3007.EndTime
}
} }
case 1: case 1:
if stationAlarm.Alarm3008.CurrentLevel > trigger.AlarmLevel { if stationAlarm.Alarm3008.CurrentLevel > trigger.AlarmLevel {
isAlarm = true isAlarm = true
detail += stationAlarm.Alarm3008.Detail detail += stationAlarm.Alarm3008.Detail
if stationAlarm.Alarm3008.EndTime.After(dt) {
dt = stationAlarm.Alarm3008.EndTime
}
} }
} }
@ -344,9 +355,9 @@ func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationA
break break
} }
} }
return isAlarm, level, detail return isAlarm, level, detail, dt
} }
return false, level, detail return false, level, detail, dt
} }
func (the *consumerAxySkAlarm) getEsAlarmTriggerQueryStr(structId int) string { func (the *consumerAxySkAlarm) getEsAlarmTriggerQueryStr(structId int) string {

Loading…
Cancel
Save