mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化] 添加清除规则链debug日志接口,修复日志读取长度
This commit is contained in:
@@ -16,6 +16,12 @@ func GetDebugData(ruleId, nodeId string) []message.DebugData {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ClearDebugData(ruleId, nodeId string) {
|
||||
if data, ok := ruleChainDebugData.Data[ruleId]; ok {
|
||||
data.Clear(nodeId)
|
||||
}
|
||||
}
|
||||
|
||||
func GetDebugDataPage(page, pageSize int, ruleId, nodeId string) (int64, []message.DebugData) {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
@@ -26,7 +32,7 @@ func GetDebugDataPage(page, pageSize int, ruleId, nodeId string) (int64, []messa
|
||||
total := len(data.Get(nodeId).Items)
|
||||
end := offset + pageSize
|
||||
if end >= total {
|
||||
end = total - 1
|
||||
end = total
|
||||
}
|
||||
return int64(total), data.Get(nodeId).Items[offset:end]
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func NewMessage(user, messageType string, msg Msg, metadata Metadata) *Message {
|
||||
MsgType: messageType,
|
||||
Msg: msg,
|
||||
Metadata: metadata,
|
||||
DeBugChan: make(chan DebugData, 100),
|
||||
DeBugChan: make(chan DebugData),
|
||||
EndDeBugChan: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (t *Message) Debug(nodeId, nodeName, debugType, error string) {
|
||||
logrus.Infof("%s handle message '%s'", nodeName, t.MsgType)
|
||||
}
|
||||
debug := DebugData{
|
||||
Ts: time.Now().Format("2006-01-02 15:04:05.000"),
|
||||
Ts: time.Now().Format("2006-01-02 15:04:05"),
|
||||
NodeId: nodeId,
|
||||
MsgId: t.Id,
|
||||
DebugType: debugType,
|
||||
|
||||
@@ -41,8 +41,8 @@ func (n *createAlarmNode) Handle(msg *message.Message) error {
|
||||
alarm.Details = string(marshal)
|
||||
err = services.DeviceAlarmModelDao.Update(*alarm)
|
||||
if err == nil {
|
||||
n.Debug(msg, message.DEBUGOUT, "")
|
||||
if updated != nil {
|
||||
n.Debug(msg, message.DEBUGOUT, "")
|
||||
return updated.Handle(msg)
|
||||
}
|
||||
}
|
||||
@@ -62,8 +62,8 @@ func (n *createAlarmNode) Handle(msg *message.Message) error {
|
||||
alarm.Details = string(marshal)
|
||||
err = services.DeviceAlarmModelDao.Insert(*alarm)
|
||||
if err == nil {
|
||||
n.Debug(msg, message.DEBUGOUT, "")
|
||||
if created != nil {
|
||||
n.Debug(msg, message.DEBUGOUT, "")
|
||||
return created.Handle(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ func (f scriptFilterNodeFactory) Create(id string, meta Properties) (Node, error
|
||||
|
||||
func (n *scriptFilterNode) Handle(msg *message.Message) error {
|
||||
n.Debug(msg, message.DEBUGIN, "")
|
||||
|
||||
trueLabelNode := n.GetLinkedNode("True")
|
||||
falseLabelNode := n.GetLinkedNode("False")
|
||||
failureLabelNode := n.GetLinkedNode("Failure")
|
||||
@@ -32,18 +33,18 @@ func (n *scriptFilterNode) Handle(msg *message.Message) error {
|
||||
scriptEngine := NewScriptEngine(*msg, "Filter", n.Script)
|
||||
isTrue, err := scriptEngine.ScriptOnFilter()
|
||||
if err != nil {
|
||||
n.Debug(msg, message.DEBUGOUT, err.Error())
|
||||
if failureLabelNode != nil {
|
||||
n.Debug(msg, message.DEBUGOUT, err.Error())
|
||||
return failureLabelNode.Handle(msg)
|
||||
}
|
||||
}
|
||||
|
||||
if isTrue == true && trueLabelNode != nil {
|
||||
if isTrue && trueLabelNode != nil {
|
||||
n.Debug(msg, message.DEBUGOUT, "")
|
||||
return trueLabelNode.Handle(msg)
|
||||
} else {
|
||||
n.Debug(msg, message.DEBUGOUT, "Script脚本执行失败")
|
||||
if falseLabelNode != nil {
|
||||
n.Debug(msg, message.DEBUGOUT, "Script脚本执行失败")
|
||||
return falseLabelNode.Handle(msg)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user