diff --git a/constant/rule.go b/constant/rule.go index 535f0264..7b27649f 100644 --- a/constant/rule.go +++ b/constant/rule.go @@ -89,3 +89,16 @@ type Rule interface { RuleExtra() *RuleExtra SetRuleExtra(re *RuleExtra) } + +type JSMetadata struct { + Type string `json:"type"` + Network string `json:"network"` + Host string `json:"host"` + SrcIP string `json:"srcIP"` + DstIP string `json:"dstIP"` + SrcPort string `json:"srcPort"` + DstPort string `json:"dstPort"` + Uid *int32 `json:"uid"` + Process string `json:"process"` + ProcessPath string `json:"processPath"` +} diff --git a/rule/common/script.go b/rule/common/script.go index 7b19569f..ccc0e7e9 100644 --- a/rule/common/script.go +++ b/rule/common/script.go @@ -19,7 +19,17 @@ func (s *Script) RuleType() C.RuleType { func (s *Script) Match(metadata *C.Metadata) bool { res := false js.Run(s.name, map[string]any{ - "metadata": metadata, + "metadata": C.JSMetadata{ + Host: metadata.Host, + Network: metadata.NetWork.String(), + Type: metadata.Type.String(), + SrcIP: metadata.SrcIP.String(), + SrcPort: metadata.SrcPort, + DstPort: metadata.DstPort, + Uid: metadata.Uid, + Process: metadata.Process, + ProcessPath: metadata.ProcessPath, + }, }, func(a any, err error) { if err != nil { res = false @@ -29,7 +39,6 @@ func (s *Script) Match(metadata *C.Metadata) bool { if !ok { res = false } - res = r })