|
@@ -43,7 +43,6 @@ func (t *TempAlarmNode) Init(ctx ruleEngine.Context, config string) error {
|
|
|
}
|
|
|
|
|
|
func (t *TempAlarmNode) OnMessage(ctx ruleEngine.Context, message *protocol.Message) error {
|
|
|
- deviceId := message.MetaData["device_id"].(string)
|
|
|
if t.evaluateConditions(message) {
|
|
|
err := t.newAlarmMessage(message)
|
|
|
if err != nil {
|
|
@@ -52,14 +51,6 @@ func (t *TempAlarmNode) OnMessage(ctx ruleEngine.Context, message *protocol.Mess
|
|
|
ctx.TellNext(message, protocol.True)
|
|
|
return nil
|
|
|
} else {
|
|
|
- args := rpcs.ArgsGetAlarm{
|
|
|
- DeviceCode: deviceId,
|
|
|
- }
|
|
|
- reply := rpcs.ReplayAlarm{}
|
|
|
- err := server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.DelAlarm", args, &reply)
|
|
|
- if err != nil {
|
|
|
- server.Log.Errorf("device offline error. deviceid: %v, error: %v", reply.AlarmParams.DeviceCode, err)
|
|
|
- }
|
|
|
ctx.TellNext(message, protocol.False)
|
|
|
}
|
|
|
return nil
|
|
@@ -173,6 +164,7 @@ func (t *TempAlarmNode) evaluateConditions(message *protocol.Message) bool {
|
|
|
if rule.LogicalOp == 1 {
|
|
|
for _, r := range results {
|
|
|
if !r {
|
|
|
+ _ = deleteAlarm(deviceId)
|
|
|
return false
|
|
|
}
|
|
|
}
|
|
@@ -181,6 +173,7 @@ func (t *TempAlarmNode) evaluateConditions(message *protocol.Message) bool {
|
|
|
if r {
|
|
|
break
|
|
|
}
|
|
|
+ _ = deleteAlarm(deviceId)
|
|
|
return false
|
|
|
}
|
|
|
}
|
|
@@ -325,3 +318,16 @@ func fillTemplate(template string, values map[string]interface{}) (string, error
|
|
|
}
|
|
|
}), nil
|
|
|
}
|
|
|
+
|
|
|
+func deleteAlarm(deviceId string) error {
|
|
|
+ args := rpcs.ArgsGetAlarm{
|
|
|
+ DeviceCode: deviceId,
|
|
|
+ }
|
|
|
+ reply := rpcs.ReplayAlarm{}
|
|
|
+ err := server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.DelAlarm", args, &reply)
|
|
|
+ if err != nil {
|
|
|
+ server.Log.Errorf("delete error. deviceid: %v, error: %v", reply.AlarmParams.DeviceCode, err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|