mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
规则链结构优化
This commit is contained in:
@@ -29,16 +29,16 @@ func (f createAlarmNodeFactory) Create(id string, meta Metadata) (Node, error) {
|
||||
return decodePath(meta, node)
|
||||
}
|
||||
|
||||
func (n *createAlarmNode) Handle(msg message.Message) error {
|
||||
logrus.Infof("%s handle message '%s'", n.Name(), msg.GetType())
|
||||
func (n *createAlarmNode) Handle(msg *message.Message) error {
|
||||
logrus.Infof("%s handle message '%s'", n.Name(), msg.MsgType)
|
||||
|
||||
created := n.GetLinkedNode("Created")
|
||||
updated := n.GetLinkedNode("Updated")
|
||||
failure := n.GetLinkedNode("Failure")
|
||||
|
||||
alarm := services.DeviceAlarmModelDao.FindOneByType(msg.GetMetadata().GetKeyValue("deviceId").(string), n.AlarmType, "0")
|
||||
alarm := services.DeviceAlarmModelDao.FindOneByType(msg.Metadata.GetValue("deviceId").(string), n.AlarmType, "0")
|
||||
if alarm.DeviceId != "" {
|
||||
marshal, _ := json.Marshal(msg.GetMsg())
|
||||
marshal, _ := json.Marshal(msg.Msg)
|
||||
alarm.Details = string(marshal)
|
||||
err := services.DeviceAlarmModelDao.Update(*alarm)
|
||||
if err != nil {
|
||||
@@ -53,14 +53,14 @@ func (n *createAlarmNode) Handle(msg message.Message) error {
|
||||
} else {
|
||||
alarm = &entity.DeviceAlarm{}
|
||||
alarm.Id = kgo.KStr.Uniqid("a")
|
||||
alarm.DeviceId = msg.GetMetadata().GetKeyValue("deviceId").(string)
|
||||
alarm.ProductId = msg.GetMetadata().GetKeyValue("productId").(string)
|
||||
alarm.Name = msg.GetMetadata().GetKeyValue("deviceName").(string)
|
||||
alarm.DeviceId = msg.Metadata.GetValue("deviceId").(string)
|
||||
alarm.ProductId = msg.Metadata.GetValue("productId").(string)
|
||||
alarm.Name = msg.Metadata.GetValue("deviceName").(string)
|
||||
alarm.Level = n.AlarmSeverity
|
||||
alarm.State = global.ALARMING
|
||||
alarm.Type = n.AlarmType
|
||||
alarm.Time = time.Now()
|
||||
marshal, _ := json.Marshal(msg.GetMsg())
|
||||
marshal, _ := json.Marshal(msg.Msg)
|
||||
alarm.Details = string(marshal)
|
||||
err := services.DeviceAlarmModelDao.Insert(*alarm)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user