|
@ -21,8 +21,8 @@ type consumerAxySkAlarm struct { |
|
|
alarmCache map[string]models.EsAlarm |
|
|
alarmCache map[string]models.EsAlarm |
|
|
//具体配置
|
|
|
//具体配置
|
|
|
Info AXY_SK.ConfigFile |
|
|
Info AXY_SK.ConfigFile |
|
|
InKafka _kafka.KafkaHelper |
|
|
InEs dbOperate.ESHelper |
|
|
OutEs dbOperate.ESHelper |
|
|
OutKafka _kafka.KafkaHelper |
|
|
infoPg *dbOperate.DBHelper |
|
|
infoPg *dbOperate.DBHelper |
|
|
sinkMap sync.Map |
|
|
sinkMap sync.Map |
|
|
lock sync.Mutex |
|
|
lock sync.Mutex |
|
@ -66,24 +66,24 @@ func (the *consumerAxySkAlarm) Initial(cfg string) error { |
|
|
} |
|
|
} |
|
|
func (the *consumerAxySkAlarm) inputInitial() error { |
|
|
func (the *consumerAxySkAlarm) inputInitial() error { |
|
|
//数据入口
|
|
|
//数据入口
|
|
|
the.InKafka = _kafka.KafkaHelper{ |
|
|
the.OutKafka = _kafka.KafkaHelper{ |
|
|
Brokers: the.Info.IoConfig.In.Kafka.Brokers, |
|
|
Brokers: the.Info.IoConfig.Out.Kafka.Brokers, |
|
|
GroupId: the.Info.IoConfig.In.Kafka.GroupId, |
|
|
GroupId: the.Info.IoConfig.Out.Kafka.GroupId, |
|
|
} |
|
|
} |
|
|
the.InKafka.Initial() |
|
|
the.OutKafka.Initial() |
|
|
for _, inTopic := range the.Info.IoConfig.In.Kafka.Topics { |
|
|
for _, inTopic := range the.Info.IoConfig.Out.Kafka.Topics { |
|
|
the.InKafka.Subscribe(inTopic, the.onData) |
|
|
the.OutKafka.Subscribe(inTopic, the.onData) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
the.InKafka.Worker() |
|
|
the.OutKafka.Worker() |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
func (the *consumerAxySkAlarm) outputInitial() error { |
|
|
func (the *consumerAxySkAlarm) outputInitial() error { |
|
|
//数据出口
|
|
|
//数据出口
|
|
|
the.OutEs = *dbOperate.NewESHelper( |
|
|
the.InEs = *dbOperate.NewESHelper( |
|
|
the.Info.IoConfig.Out.Es.Address, |
|
|
the.Info.IoConfig.In.Es.Address, |
|
|
the.Info.IoConfig.Out.Es.Auth.UserName, |
|
|
the.Info.IoConfig.In.Es.Auth.UserName, |
|
|
the.Info.IoConfig.Out.Es.Auth.Password, |
|
|
the.Info.IoConfig.In.Es.Auth.Password, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
@ -105,13 +105,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() { |
|
@ -161,7 +161,7 @@ func (the *consumerAxySkAlarm) judgeSK() string { |
|
|
|
|
|
|
|
|
//配置的结构物的监测因素 去查询
|
|
|
//配置的结构物的监测因素 去查询
|
|
|
esSql := the.getEsAlarmTriggerPartQueryStr(trigger.StructId) |
|
|
esSql := the.getEsAlarmTriggerPartQueryStr(trigger.StructId) |
|
|
alarms, err := the.OutEs.SearchAlarm(the.Info.IoConfig.Out.Es.Index, esSql) |
|
|
alarms, err := the.InEs.SearchAlarm(the.Info.IoConfig.In.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 |
|
@ -224,10 +224,10 @@ func (the *consumerAxySkAlarm) judgeSK() string { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
payload := the.skAlarmInfo(alarmInfoTemplate, level, detail, alarmTime) |
|
|
payload := the.skAlarmInfo(alarmInfoTemplate, level, detail, alarmTime) |
|
|
the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload) |
|
|
the.OutKafka.Publish(the.Info.IoConfig.Out.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.OutKafka.Publish(the.Info.IoConfig.Out.Kafka.AlarmTopic, payload) |
|
|
delete(the.historyStationAlarmMap, sid) |
|
|
delete(the.historyStationAlarmMap, sid) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -358,7 +358,7 @@ func (the *consumerAxySkAlarm) isRuleAlarm(trigger AXY_SK.AlarmTrigger, stationA |
|
|
|
|
|
|
|
|
func (the *consumerAxySkAlarm) updateEsAlarmTriggerHistory(structId int) { |
|
|
func (the *consumerAxySkAlarm) updateEsAlarmTriggerHistory(structId int) { |
|
|
esSql := the.getEsAlarmTriggerHistoryQueryStr(structId) |
|
|
esSql := the.getEsAlarmTriggerHistoryQueryStr(structId) |
|
|
alarms, err := the.OutEs.SearchAlarm(the.Info.IoConfig.Out.Es.Index, esSql) |
|
|
alarms, err := the.InEs.SearchAlarm(the.Info.IoConfig.In.Es.Index, esSql) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Printf("结构物[%d] 查询历史有效AlarmTrigger 异常=>%s", structId, err.Error()) |
|
|
log.Printf("结构物[%d] 查询历史有效AlarmTrigger 异常=>%s", structId, err.Error()) |
|
|
} |
|
|
} |
|
@ -447,7 +447,7 @@ func (the *consumerAxySkAlarm) getEsAlarmTriggerPartQueryStr(structId int) strin |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (the *consumerAxySkAlarm) sinkTask() { |
|
|
func (the *consumerAxySkAlarm) sinkTask() { |
|
|
intervalSec := the.Info.IoConfig.Out.Es.Interval |
|
|
intervalSec := the.Info.IoConfig.In.Es.Interval |
|
|
ticker := time.NewTicker(time.Duration(intervalSec) * time.Second) |
|
|
ticker := time.NewTicker(time.Duration(intervalSec) * time.Second) |
|
|
defer ticker.Stop() |
|
|
defer ticker.Stop() |
|
|
for { |
|
|
for { |
|
@ -475,9 +475,9 @@ func (the *consumerAxySkAlarm) toSink() { |
|
|
return true |
|
|
return true |
|
|
}) |
|
|
}) |
|
|
if len(themes) > 0 { |
|
|
if len(themes) > 0 { |
|
|
index := the.Info.IoConfig.Out.Es.Index |
|
|
index := the.Info.IoConfig.In.Es.Index |
|
|
log.Printf("写入es [%s] %d条", index, len(themes)) |
|
|
log.Printf("写入es [%s] %d条", index, len(themes)) |
|
|
the.OutEs.BulkWriteThemes2Es(index, themes) |
|
|
the.InEs.BulkWriteThemes2Es(index, themes) |
|
|
the.sinkMap.Clear() |
|
|
the.sinkMap.Clear() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -503,9 +503,7 @@ func (the *consumerAxySkAlarm) Work() { |
|
|
}() |
|
|
}() |
|
|
} |
|
|
} |
|
|
func (the *consumerAxySkAlarm) onData(topic string, msg string) bool { |
|
|
func (the *consumerAxySkAlarm) onData(topic string, msg string) bool { |
|
|
//if len(msg) > 80 {
|
|
|
|
|
|
// log.Printf("recv:[%s]:%s ...", topic, msg[:80])
|
|
|
|
|
|
//}
|
|
|
|
|
|
adaptor := adaptors.Adaptor_Savoir_LastTheme{} |
|
|
adaptor := adaptors.Adaptor_Savoir_LastTheme{} |
|
|
|
|
|
|
|
|
needPush := adaptor.Transform(topic, msg) |
|
|
needPush := adaptor.Transform(topic, msg) |
|
|