node.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. package parser
  2. import (
  3. "fmt"
  4. "net"
  5. "strings"
  6. "github.com/antonmedv/expr"
  7. "github.com/crowdsecurity/grokky"
  8. "github.com/pkg/errors"
  9. yaml "gopkg.in/yaml.v2"
  10. "github.com/antonmedv/expr/vm"
  11. "github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
  12. "github.com/crowdsecurity/crowdsec/pkg/types"
  13. "github.com/davecgh/go-spew/spew"
  14. "github.com/prometheus/client_golang/prometheus"
  15. "github.com/sirupsen/logrus"
  16. log "github.com/sirupsen/logrus"
  17. )
  18. type Node struct {
  19. FormatVersion string `yaml:"format"`
  20. //Enable config + runtime debug of node via config o/
  21. Debug bool `yaml:"debug,omitempty"`
  22. //If enabled, the node (and its child) will report their own statistics
  23. Profiling bool `yaml:"profiling,omitempty"`
  24. //Name, author, description and reference(s) for parser pattern
  25. Name string `yaml:"name,omitempty"`
  26. Author string `yaml:"author,omitempty"`
  27. Description string `yaml:"description,omitempty"`
  28. References []string `yaml:"references,omitempty"`
  29. //if debug is present in the node, keep its specific Logger in runtime structure
  30. Logger *log.Entry `yaml:"-"`
  31. //This is mostly a hack to make writing less repetitive.
  32. //relying on stage, we know which field to parse, and we
  33. //can also promote log to next stage on success
  34. Stage string `yaml:"stage,omitempty"`
  35. //OnSuccess allows to tag a node to be able to move log to next stage on success
  36. OnSuccess string `yaml:"onsuccess,omitempty"`
  37. rn string //this is only for us in debug, a random generated name for each node
  38. //Filter is executed at runtime (with current log line as context)
  39. //and must succeed or node is exited
  40. Filter string `yaml:"filter,omitempty"`
  41. RunTimeFilter *vm.Program `yaml:"-" json:"-"` //the actual compiled filter
  42. ExprDebugger *exprhelpers.ExprDebugger `yaml:"-" json:"-"` //used to debug expression by printing the content of each variable of the expression
  43. //If node has leafs, execute all of them until one asks for a 'break'
  44. LeavesNodes []Node `yaml:"nodes,omitempty"`
  45. //Flag used to describe when to 'break' or return an 'error'
  46. EnrichFunctions EnricherCtx
  47. /* If the node is actually a leaf, it can have : grok, enrich, statics */
  48. //pattern_syntax are named grok patterns that are re-utilized over several grok patterns
  49. SubGroks yaml.MapSlice `yaml:"pattern_syntax,omitempty"`
  50. //Holds a grok pattern
  51. Grok types.GrokPattern `yaml:"grok,omitempty"`
  52. //Statics can be present in any type of node and is executed last
  53. Statics []types.ExtraField `yaml:"statics,omitempty"`
  54. //Whitelists
  55. Whitelist types.Whitelist `yaml:"whitelist,omitempty"`
  56. Data []*types.DataSource `yaml:"data,omitempty"`
  57. }
  58. func (n *Node) validate(pctx *UnixParserCtx, ectx EnricherCtx) error {
  59. //stage is being set automagically
  60. if n.Stage == "" {
  61. return fmt.Errorf("stage needs to be an existing stage")
  62. }
  63. /* "" behaves like continue */
  64. if n.OnSuccess != "continue" && n.OnSuccess != "next_stage" && n.OnSuccess != "" {
  65. return fmt.Errorf("onsuccess '%s' not continue,next_stage", n.OnSuccess)
  66. }
  67. if n.Filter != "" && n.RunTimeFilter == nil {
  68. return fmt.Errorf("non-empty filter '%s' was not compiled", n.Filter)
  69. }
  70. if n.Grok.RunTimeRegexp != nil || n.Grok.TargetField != "" {
  71. if n.Grok.TargetField == "" && n.Grok.ExpValue == "" {
  72. return fmt.Errorf("grok requires 'expression' or 'apply_on'")
  73. }
  74. if n.Grok.RegexpName == "" && n.Grok.RegexpValue == "" {
  75. return fmt.Errorf("grok needs 'pattern' or 'name'")
  76. }
  77. }
  78. for idx, static := range n.Statics {
  79. if static.Method != "" {
  80. if static.ExpValue == "" {
  81. return fmt.Errorf("static %d : when method is set, expression must be present", idx)
  82. }
  83. if _, ok := ectx.Registered[static.Method]; !ok {
  84. log.Warningf("the method '%s' doesn't exist or the plugin has not been initialized", static.Method)
  85. }
  86. } else {
  87. if static.Meta == "" && static.Parsed == "" && static.TargetByName == "" {
  88. return fmt.Errorf("static %d : at least one of meta/event/target must be set", idx)
  89. }
  90. if static.Value == "" && static.RunTimeValue == nil {
  91. return fmt.Errorf("static %d value or expression must be set", idx)
  92. }
  93. }
  94. }
  95. return nil
  96. }
  97. func (n *Node) process(p *types.Event, ctx UnixParserCtx, expressionEnv map[string]interface{}) (bool, error) {
  98. var NodeState bool
  99. var NodeHasOKGrok bool
  100. clog := n.Logger
  101. cachedExprEnv := expressionEnv
  102. clog.Tracef("Event entering node")
  103. if n.RunTimeFilter != nil {
  104. //Evaluate node's filter
  105. output, err := expr.Run(n.RunTimeFilter, cachedExprEnv)
  106. if err != nil {
  107. clog.Warningf("failed to run filter : %v", err)
  108. clog.Debugf("Event leaving node : ko")
  109. return false, nil
  110. }
  111. switch out := output.(type) {
  112. case bool:
  113. if n.Debug {
  114. n.ExprDebugger.Run(clog, out, cachedExprEnv)
  115. }
  116. if !out {
  117. clog.Debugf("Event leaving node : ko (failed filter)")
  118. return false, nil
  119. }
  120. default:
  121. clog.Warningf("Expr '%s' returned non-bool, abort : %T", n.Filter, output)
  122. clog.Debugf("Event leaving node : ko")
  123. return false, nil
  124. }
  125. NodeState = true
  126. } else {
  127. clog.Tracef("Node has not filter, enter")
  128. NodeState = true
  129. }
  130. if n.Name != "" {
  131. NodesHits.With(prometheus.Labels{"source": p.Line.Src, "type": p.Line.Module, "name": n.Name}).Inc()
  132. }
  133. isWhitelisted := false
  134. hasWhitelist := false
  135. var srcs []net.IP
  136. /*overflow and log don't hold the source ip in the same field, should be changed */
  137. /* perform whitelist checks for ips, cidr accordingly */
  138. /* TODO move whitelist elsewhere */
  139. if p.Type == types.LOG {
  140. if _, ok := p.Meta["source_ip"]; ok {
  141. srcs = append(srcs, net.ParseIP(p.Meta["source_ip"]))
  142. }
  143. } else if p.Type == types.OVFLW {
  144. for k := range p.Overflow.Sources {
  145. srcs = append(srcs, net.ParseIP(k))
  146. }
  147. }
  148. for _, src := range srcs {
  149. if isWhitelisted {
  150. break
  151. }
  152. for _, v := range n.Whitelist.B_Ips {
  153. if v.Equal(src) {
  154. clog.Debugf("Event from [%s] is whitelisted by IP (%s), reason [%s]", src, v, n.Whitelist.Reason)
  155. isWhitelisted = true
  156. } else {
  157. clog.Tracef("whitelist: %s is not eq [%s]", src, v)
  158. }
  159. hasWhitelist = true
  160. }
  161. for _, v := range n.Whitelist.B_Cidrs {
  162. if v.Contains(src) {
  163. clog.Debugf("Event from [%s] is whitelisted by CIDR (%s), reason [%s]", src, v, n.Whitelist.Reason)
  164. isWhitelisted = true
  165. } else {
  166. clog.Tracef("whitelist: %s not in [%s]", src, v)
  167. }
  168. hasWhitelist = true
  169. }
  170. }
  171. if isWhitelisted {
  172. p.Whitelisted = true
  173. }
  174. /* run whitelist expression tests anyway */
  175. for eidx, e := range n.Whitelist.B_Exprs {
  176. output, err := expr.Run(e.Filter, cachedExprEnv)
  177. if err != nil {
  178. clog.Warningf("failed to run whitelist expr : %v", err)
  179. clog.Debugf("Event leaving node : ko")
  180. return false, nil
  181. }
  182. switch out := output.(type) {
  183. case bool:
  184. if n.Debug {
  185. e.ExprDebugger.Run(clog, out, cachedExprEnv)
  186. }
  187. if out {
  188. clog.Debugf("Event is whitelisted by expr, reason [%s]", n.Whitelist.Reason)
  189. p.Whitelisted = true
  190. isWhitelisted = true
  191. }
  192. hasWhitelist = true
  193. default:
  194. log.Errorf("unexpected type %t (%v) while running '%s'", output, output, n.Whitelist.Exprs[eidx])
  195. }
  196. }
  197. if isWhitelisted {
  198. p.WhitelistReason = n.Whitelist.Reason
  199. /*huglily wipe the ban order if the event is whitelisted and it's an overflow */
  200. if p.Type == types.OVFLW { /*don't do this at home kids */
  201. ips := []string{}
  202. for _, src := range srcs {
  203. ips = append(ips, src.String())
  204. }
  205. clog.Infof("Ban for %s whitelisted, reason [%s]", strings.Join(ips, ","), n.Whitelist.Reason)
  206. p.Overflow.Whitelisted = true
  207. }
  208. }
  209. //Process grok if present, should be exclusive with nodes :)
  210. gstr := ""
  211. if n.Grok.RunTimeRegexp != nil {
  212. clog.Tracef("Processing grok pattern : %s : %p", n.Grok.RegexpName, n.Grok.RunTimeRegexp)
  213. //for unparsed, parsed etc. set sensible defaults to reduce user hassle
  214. if n.Grok.TargetField != "" {
  215. //it's a hack to avoid using real reflect
  216. if n.Grok.TargetField == "Line.Raw" {
  217. gstr = p.Line.Raw
  218. } else if val, ok := p.Parsed[n.Grok.TargetField]; ok {
  219. gstr = val
  220. } else {
  221. clog.Debugf("(%s) target field '%s' doesn't exist in %v", n.rn, n.Grok.TargetField, p.Parsed)
  222. NodeState = false
  223. }
  224. } else if n.Grok.RunTimeValue != nil {
  225. output, err := expr.Run(n.Grok.RunTimeValue, cachedExprEnv)
  226. if err != nil {
  227. clog.Warningf("failed to run RunTimeValue : %v", err)
  228. NodeState = false
  229. }
  230. switch out := output.(type) {
  231. case string:
  232. gstr = out
  233. default:
  234. clog.Errorf("unexpected return type for RunTimeValue : %T", output)
  235. }
  236. }
  237. var groklabel string
  238. if n.Grok.RegexpName == "" {
  239. groklabel = fmt.Sprintf("%5.5s...", n.Grok.RegexpValue)
  240. } else {
  241. groklabel = n.Grok.RegexpName
  242. }
  243. grok := n.Grok.RunTimeRegexp.Parse(gstr)
  244. if len(grok) > 0 {
  245. /*tag explicitly that the *current* node had a successful grok pattern. it's important to know success state*/
  246. NodeHasOKGrok = true
  247. clog.Debugf("+ Grok '%s' returned %d entries to merge in Parsed", groklabel, len(grok))
  248. //We managed to grok stuff, merged into parse
  249. for k, v := range grok {
  250. clog.Debugf("\t.Parsed['%s'] = '%s'", k, v)
  251. p.Parsed[k] = v
  252. }
  253. // if the grok succeed, process associated statics
  254. err := n.ProcessStatics(n.Grok.Statics, p)
  255. if err != nil {
  256. clog.Errorf("(%s) Failed to process statics : %v", n.rn, err)
  257. return false, err
  258. }
  259. } else {
  260. //grok failed, node failed
  261. clog.Debugf("+ Grok '%s' didn't return data on '%s'", groklabel, gstr)
  262. NodeState = false
  263. }
  264. } else {
  265. clog.Tracef("! No grok pattern : %p", n.Grok.RunTimeRegexp)
  266. }
  267. //Iterate on leafs
  268. if len(n.LeavesNodes) > 0 {
  269. for _, leaf := range n.LeavesNodes {
  270. ret, err := leaf.process(p, ctx, cachedExprEnv)
  271. if err != nil {
  272. clog.Tracef("\tNode (%s) failed : %v", leaf.rn, err)
  273. clog.Debugf("Event leaving node : ko")
  274. return false, err
  275. }
  276. clog.Tracef("\tsub-node (%s) ret : %v (strategy:%s)", leaf.rn, ret, n.OnSuccess)
  277. if ret {
  278. NodeState = true
  279. /* if child is successful, stop processing */
  280. if n.OnSuccess == "next_stage" {
  281. clog.Debugf("child is success, OnSuccess=next_stage, skip")
  282. break
  283. }
  284. } else {
  285. /*
  286. If the parent node has a successful grok pattern, it's state will stay successful even if one or more chil fails.
  287. If the parent node is a skeleton node (no grok pattern), then at least one child must be successful for it to be a success.
  288. */
  289. if !NodeHasOKGrok {
  290. NodeState = false
  291. }
  292. }
  293. }
  294. }
  295. /*todo : check if a node made the state change ?*/
  296. /* should the childs inherit the on_success behavior */
  297. clog.Tracef("State after nodes : %v", NodeState)
  298. //grok or leafs failed, don't process statics
  299. if !NodeState {
  300. if n.Name != "" {
  301. NodesHitsKo.With(prometheus.Labels{"source": p.Line.Src, "type": p.Line.Module, "name": n.Name}).Inc()
  302. }
  303. clog.Debugf("Event leaving node : ko")
  304. return NodeState, nil
  305. }
  306. if n.Name != "" {
  307. NodesHitsOk.With(prometheus.Labels{"source": p.Line.Src, "type": p.Line.Module, "name": n.Name}).Inc()
  308. }
  309. /*
  310. Please kill me. this is to apply statics when the node *has* whitelists that successfully matched the node.
  311. */
  312. if hasWhitelist && isWhitelisted && len(n.Statics) > 0 || len(n.Statics) > 0 && !hasWhitelist {
  313. clog.Debugf("+ Processing %d statics", len(n.Statics))
  314. // if all else is good in whitelist, process node's statics
  315. err := n.ProcessStatics(n.Statics, p)
  316. if err != nil {
  317. clog.Errorf("Failed to process statics : %v", err)
  318. return false, err
  319. }
  320. } else {
  321. clog.Tracef("! No node statics")
  322. }
  323. if NodeState {
  324. clog.Debugf("Event leaving node : ok")
  325. log.Tracef("node is successful, check strategy")
  326. if n.OnSuccess == "next_stage" {
  327. idx := stageidx(p.Stage, ctx.Stages)
  328. //we're at the last stage
  329. if idx+1 == len(ctx.Stages) {
  330. clog.Debugf("node reached the last stage : %s", p.Stage)
  331. } else {
  332. clog.Debugf("move Event from stage %s to %s", p.Stage, ctx.Stages[idx+1])
  333. p.Stage = ctx.Stages[idx+1]
  334. }
  335. } else {
  336. clog.Tracef("no strategy on success (%s), continue !", n.OnSuccess)
  337. }
  338. } else {
  339. clog.Debugf("Event leaving node : ko")
  340. }
  341. clog.Tracef("Node successful, continue")
  342. return NodeState, nil
  343. }
  344. func (n *Node) compile(pctx *UnixParserCtx, ectx EnricherCtx) error {
  345. var err error
  346. var valid bool
  347. valid = false
  348. dumpr := spew.ConfigState{MaxDepth: 1, DisablePointerAddresses: true}
  349. n.rn = seed.Generate()
  350. n.EnrichFunctions = ectx
  351. log.Tracef("compile, node is %s", n.Stage)
  352. /* if the node has debugging enabled, create a specific logger with debug
  353. that will be used only for processing this node ;) */
  354. if n.Debug {
  355. var clog = logrus.New()
  356. if err := types.ConfigureLogger(clog); err != nil {
  357. log.Fatalf("While creating bucket-specific logger : %s", err)
  358. }
  359. clog.SetLevel(log.DebugLevel)
  360. n.Logger = clog.WithFields(log.Fields{
  361. "id": n.rn,
  362. })
  363. n.Logger.Infof("%s has debug enabled", n.Name)
  364. } else {
  365. /* else bind it to the default one (might find something more elegant here)*/
  366. n.Logger = log.WithFields(log.Fields{
  367. "id": n.rn,
  368. })
  369. }
  370. /* display info about top-level nodes, they should be the only one with explicit stage name ?*/
  371. n.Logger = n.Logger.WithFields(log.Fields{"stage": n.Stage, "name": n.Name})
  372. n.Logger.Tracef("Compiling : %s", dumpr.Sdump(n))
  373. //compile filter if present
  374. if n.Filter != "" {
  375. n.RunTimeFilter, err = expr.Compile(n.Filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  376. if err != nil {
  377. return fmt.Errorf("compilation of '%s' failed: %v", n.Filter, err)
  378. }
  379. if n.Debug {
  380. n.ExprDebugger, err = exprhelpers.NewDebugger(n.Filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  381. if err != nil {
  382. log.Errorf("unable to build debug filter for '%s' : %s", n.Filter, err)
  383. }
  384. }
  385. }
  386. /* handle pattern_syntax and groks */
  387. for _, pattern := range n.SubGroks {
  388. n.Logger.Tracef("Adding subpattern '%s' : '%s'", pattern.Key, pattern.Value)
  389. if err := pctx.Grok.Add(pattern.Key.(string), pattern.Value.(string)); err != nil {
  390. if err == grokky.ErrAlreadyExist {
  391. n.Logger.Warningf("grok '%s' already registred", pattern.Key)
  392. continue
  393. }
  394. n.Logger.Errorf("Unable to compile subpattern %s : %v", pattern.Key, err)
  395. return err
  396. }
  397. }
  398. /* load grok by name or compile in-place */
  399. if n.Grok.RegexpName != "" {
  400. n.Logger.Tracef("+ Regexp Compilation '%s'", n.Grok.RegexpName)
  401. n.Grok.RunTimeRegexp, err = pctx.Grok.Get(n.Grok.RegexpName)
  402. if err != nil {
  403. return fmt.Errorf("Unable to find grok '%s' : %v", n.Grok.RegexpName, err)
  404. }
  405. if n.Grok.RunTimeRegexp == nil {
  406. return fmt.Errorf("Empty grok '%s'", n.Grok.RegexpName)
  407. }
  408. n.Logger.Tracef("%s regexp: %s", n.Grok.RegexpName, n.Grok.RunTimeRegexp.Regexp.String())
  409. valid = true
  410. } else if n.Grok.RegexpValue != "" {
  411. if strings.HasSuffix(n.Grok.RegexpValue, "\n") {
  412. n.Logger.Debugf("Beware, pattern ends with \\n : '%s'", n.Grok.RegexpValue)
  413. }
  414. n.Grok.RunTimeRegexp, err = pctx.Grok.Compile(n.Grok.RegexpValue)
  415. if err != nil {
  416. return fmt.Errorf("Failed to compile grok '%s': %v\n", n.Grok.RegexpValue, err)
  417. }
  418. if n.Grok.RunTimeRegexp == nil {
  419. // We shouldn't be here because compilation succeeded, so regexp shouldn't be nil
  420. return fmt.Errorf("Grok compilation failure: %s", n.Grok.RegexpValue)
  421. }
  422. n.Logger.Tracef("%s regexp : %s", n.Grok.RegexpValue, n.Grok.RunTimeRegexp.Regexp.String())
  423. valid = true
  424. }
  425. /*if grok source is an expression*/
  426. if n.Grok.ExpValue != "" {
  427. n.Grok.RunTimeValue, err = expr.Compile(n.Grok.ExpValue,
  428. expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  429. if err != nil {
  430. return errors.Wrap(err, "while compiling grok's expression")
  431. }
  432. }
  433. /* load grok statics */
  434. if len(n.Grok.Statics) > 0 {
  435. //compile expr statics if present
  436. for idx := range n.Grok.Statics {
  437. if n.Grok.Statics[idx].ExpValue != "" {
  438. n.Grok.Statics[idx].RunTimeValue, err = expr.Compile(n.Grok.Statics[idx].ExpValue,
  439. expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  440. if err != nil {
  441. return err
  442. }
  443. }
  444. }
  445. valid = true
  446. }
  447. /* compile leafs if present */
  448. if len(n.LeavesNodes) > 0 {
  449. for idx := range n.LeavesNodes {
  450. if n.LeavesNodes[idx].Name == "" {
  451. n.LeavesNodes[idx].Name = fmt.Sprintf("child-%s", n.Name)
  452. }
  453. /*propagate debug/stats to child nodes*/
  454. if !n.LeavesNodes[idx].Debug && n.Debug {
  455. n.LeavesNodes[idx].Debug = true
  456. }
  457. if !n.LeavesNodes[idx].Profiling && n.Profiling {
  458. n.LeavesNodes[idx].Profiling = true
  459. }
  460. n.LeavesNodes[idx].Stage = n.Stage
  461. err = n.LeavesNodes[idx].compile(pctx, ectx)
  462. if err != nil {
  463. return err
  464. }
  465. }
  466. valid = true
  467. }
  468. /* load statics if present */
  469. for idx := range n.Statics {
  470. if n.Statics[idx].ExpValue != "" {
  471. n.Statics[idx].RunTimeValue, err = expr.Compile(n.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  472. if err != nil {
  473. n.Logger.Errorf("Statics Compilation failed %v.", err)
  474. return err
  475. }
  476. }
  477. valid = true
  478. }
  479. /* compile whitelists if present */
  480. for _, v := range n.Whitelist.Ips {
  481. n.Whitelist.B_Ips = append(n.Whitelist.B_Ips, net.ParseIP(v))
  482. n.Logger.Debugf("adding ip %s to whitelists", net.ParseIP(v))
  483. valid = true
  484. }
  485. for _, v := range n.Whitelist.Cidrs {
  486. _, tnet, err := net.ParseCIDR(v)
  487. if err != nil {
  488. n.Logger.Fatalf("Unable to parse cidr whitelist '%s' : %v.", v, err)
  489. }
  490. n.Whitelist.B_Cidrs = append(n.Whitelist.B_Cidrs, tnet)
  491. n.Logger.Debugf("adding cidr %s to whitelists", tnet)
  492. valid = true
  493. }
  494. for _, filter := range n.Whitelist.Exprs {
  495. expression := &types.ExprWhitelist{}
  496. expression.Filter, err = expr.Compile(filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  497. if err != nil {
  498. n.Logger.Fatalf("Unable to compile whitelist expression '%s' : %v.", filter, err)
  499. }
  500. expression.ExprDebugger, err = exprhelpers.NewDebugger(filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  501. if err != nil {
  502. log.Errorf("unable to build debug filter for '%s' : %s", filter, err)
  503. }
  504. n.Whitelist.B_Exprs = append(n.Whitelist.B_Exprs, expression)
  505. n.Logger.Debugf("adding expression %s to whitelists", filter)
  506. valid = true
  507. }
  508. if !valid {
  509. /* node is empty, error force return */
  510. n.Logger.Error("Node is empty or invalid, abort")
  511. n.Stage = ""
  512. return fmt.Errorf("Node is empty")
  513. }
  514. if err := n.validate(pctx, ectx); err != nil {
  515. return err
  516. }
  517. return nil
  518. }