node.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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 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.Debug("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 if !NodeHasOKGrok {
  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. NodeState = false
  290. }
  291. }
  292. }
  293. /*todo : check if a node made the state change ?*/
  294. /* should the childs inherit the on_success behavior */
  295. clog.Tracef("State after nodes : %v", NodeState)
  296. //grok or leafs failed, don't process statics
  297. if !NodeState {
  298. if n.Name != "" {
  299. NodesHitsKo.With(prometheus.Labels{"source": p.Line.Src, "type": p.Line.Module, "name": n.Name}).Inc()
  300. }
  301. clog.Debugf("Event leaving node : ko")
  302. return NodeState, nil
  303. }
  304. if n.Name != "" {
  305. NodesHitsOk.With(prometheus.Labels{"source": p.Line.Src, "type": p.Line.Module, "name": n.Name}).Inc()
  306. }
  307. /*
  308. Please kill me. this is to apply statics when the node *has* whitelists that successfully matched the node.
  309. */
  310. if hasWhitelist && isWhitelisted && len(n.Statics) > 0 || len(n.Statics) > 0 && !hasWhitelist {
  311. clog.Debugf("+ Processing %d statics", len(n.Statics))
  312. // if all else is good in whitelist, process node's statics
  313. err := n.ProcessStatics(n.Statics, p)
  314. if err != nil {
  315. clog.Errorf("Failed to process statics : %v", err)
  316. return false, err
  317. }
  318. } else {
  319. clog.Tracef("! No node statics")
  320. }
  321. if NodeState {
  322. clog.Debugf("Event leaving node : ok")
  323. log.Tracef("node is successful, check strategy")
  324. if n.OnSuccess == "next_stage" {
  325. idx := stageidx(p.Stage, ctx.Stages)
  326. //we're at the last stage
  327. if idx+1 == len(ctx.Stages) {
  328. clog.Debugf("node reached the last stage : %s", p.Stage)
  329. } else {
  330. clog.Debugf("move Event from stage %s to %s", p.Stage, ctx.Stages[idx+1])
  331. p.Stage = ctx.Stages[idx+1]
  332. }
  333. } else {
  334. clog.Tracef("no strategy on success (%s), continue !", n.OnSuccess)
  335. }
  336. } else {
  337. clog.Debugf("Event leaving node : ko")
  338. }
  339. clog.Tracef("Node successful, continue")
  340. return NodeState, nil
  341. }
  342. func (n *Node) compile(pctx *UnixParserCtx, ectx EnricherCtx) error {
  343. var err error
  344. var valid bool
  345. valid = false
  346. dumpr := spew.ConfigState{MaxDepth: 1, DisablePointerAddresses: true}
  347. n.rn = seed.Generate()
  348. n.EnrichFunctions = ectx
  349. log.Tracef("compile, node is %s", n.Stage)
  350. /* if the node has debugging enabled, create a specific logger with debug
  351. that will be used only for processing this node ;) */
  352. if n.Debug {
  353. var clog = logrus.New()
  354. if err := types.ConfigureLogger(clog); err != nil {
  355. log.Fatalf("While creating bucket-specific logger : %s", err)
  356. }
  357. clog.SetLevel(log.DebugLevel)
  358. n.Logger = clog.WithFields(log.Fields{
  359. "id": n.rn,
  360. })
  361. n.Logger.Infof("%s has debug enabled", n.Name)
  362. } else {
  363. /* else bind it to the default one (might find something more elegant here)*/
  364. n.Logger = log.WithFields(log.Fields{
  365. "id": n.rn,
  366. })
  367. }
  368. /* display info about top-level nodes, they should be the only one with explicit stage name ?*/
  369. n.Logger = n.Logger.WithFields(log.Fields{"stage": n.Stage, "name": n.Name})
  370. n.Logger.Tracef("Compiling : %s", dumpr.Sdump(n))
  371. //compile filter if present
  372. if n.Filter != "" {
  373. n.RunTimeFilter, err = expr.Compile(n.Filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  374. if err != nil {
  375. return fmt.Errorf("compilation of '%s' failed: %v", n.Filter, err)
  376. }
  377. if n.Debug {
  378. n.ExprDebugger, err = exprhelpers.NewDebugger(n.Filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  379. if err != nil {
  380. log.Errorf("unable to build debug filter for '%s' : %s", n.Filter, err)
  381. }
  382. }
  383. }
  384. /* handle pattern_syntax and groks */
  385. for _, pattern := range n.SubGroks {
  386. n.Logger.Tracef("Adding subpattern '%s' : '%s'", pattern.Key, pattern.Value)
  387. if err := pctx.Grok.Add(pattern.Key.(string), pattern.Value.(string)); err != nil {
  388. if err == grokky.ErrAlreadyExist {
  389. n.Logger.Warningf("grok '%s' already registred", pattern.Key)
  390. continue
  391. }
  392. n.Logger.Errorf("Unable to compile subpattern %s : %v", pattern.Key, err)
  393. return err
  394. }
  395. }
  396. /* load grok by name or compile in-place */
  397. if n.Grok.RegexpName != "" {
  398. n.Logger.Tracef("+ Regexp Compilation '%s'", n.Grok.RegexpName)
  399. n.Grok.RunTimeRegexp, err = pctx.Grok.Get(n.Grok.RegexpName)
  400. if err != nil {
  401. return fmt.Errorf("Unable to find grok '%s' : %v", n.Grok.RegexpName, err)
  402. }
  403. if n.Grok.RunTimeRegexp == nil {
  404. return fmt.Errorf("Empty grok '%s'", n.Grok.RegexpName)
  405. }
  406. n.Logger.Tracef("%s regexp: %s", n.Grok.RegexpName, n.Grok.RunTimeRegexp.Regexp.String())
  407. valid = true
  408. } else if n.Grok.RegexpValue != "" {
  409. if strings.HasSuffix(n.Grok.RegexpValue, "\n") {
  410. n.Logger.Debugf("Beware, pattern ends with \\n : '%s'", n.Grok.RegexpValue)
  411. }
  412. n.Grok.RunTimeRegexp, err = pctx.Grok.Compile(n.Grok.RegexpValue)
  413. if err != nil {
  414. return fmt.Errorf("Failed to compile grok '%s': %v\n", n.Grok.RegexpValue, err)
  415. }
  416. if n.Grok.RunTimeRegexp == nil {
  417. // We shouldn't be here because compilation succeeded, so regexp shouldn't be nil
  418. return fmt.Errorf("Grok compilation failure: %s", n.Grok.RegexpValue)
  419. }
  420. n.Logger.Tracef("%s regexp : %s", n.Grok.RegexpValue, n.Grok.RunTimeRegexp.Regexp.String())
  421. valid = true
  422. }
  423. /*if grok source is an expression*/
  424. if n.Grok.ExpValue != "" {
  425. n.Grok.RunTimeValue, err = expr.Compile(n.Grok.ExpValue,
  426. expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  427. if err != nil {
  428. return errors.Wrap(err, "while compiling grok's expression")
  429. }
  430. }
  431. /* load grok statics */
  432. if len(n.Grok.Statics) > 0 {
  433. //compile expr statics if present
  434. for idx := range n.Grok.Statics {
  435. if n.Grok.Statics[idx].ExpValue != "" {
  436. n.Grok.Statics[idx].RunTimeValue, err = expr.Compile(n.Grok.Statics[idx].ExpValue,
  437. expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  438. if err != nil {
  439. return err
  440. }
  441. }
  442. }
  443. valid = true
  444. }
  445. /* compile leafs if present */
  446. if len(n.LeavesNodes) > 0 {
  447. for idx := range n.LeavesNodes {
  448. if n.LeavesNodes[idx].Name == "" {
  449. n.LeavesNodes[idx].Name = fmt.Sprintf("child-%s", n.Name)
  450. }
  451. /*propagate debug/stats to child nodes*/
  452. if !n.LeavesNodes[idx].Debug && n.Debug {
  453. n.LeavesNodes[idx].Debug = true
  454. }
  455. if !n.LeavesNodes[idx].Profiling && n.Profiling {
  456. n.LeavesNodes[idx].Profiling = true
  457. }
  458. n.LeavesNodes[idx].Stage = n.Stage
  459. err = n.LeavesNodes[idx].compile(pctx, ectx)
  460. if err != nil {
  461. return err
  462. }
  463. }
  464. valid = true
  465. }
  466. /* load statics if present */
  467. for idx := range n.Statics {
  468. if n.Statics[idx].ExpValue != "" {
  469. n.Statics[idx].RunTimeValue, err = expr.Compile(n.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  470. if err != nil {
  471. n.Logger.Errorf("Statics Compilation failed %v.", err)
  472. return err
  473. }
  474. }
  475. valid = true
  476. }
  477. /* compile whitelists if present */
  478. for _, v := range n.Whitelist.Ips {
  479. n.Whitelist.B_Ips = append(n.Whitelist.B_Ips, net.ParseIP(v))
  480. n.Logger.Debugf("adding ip %s to whitelists", net.ParseIP(v))
  481. valid = true
  482. }
  483. for _, v := range n.Whitelist.Cidrs {
  484. _, tnet, err := net.ParseCIDR(v)
  485. if err != nil {
  486. n.Logger.Fatalf("Unable to parse cidr whitelist '%s' : %v.", v, err)
  487. }
  488. n.Whitelist.B_Cidrs = append(n.Whitelist.B_Cidrs, tnet)
  489. n.Logger.Debugf("adding cidr %s to whitelists", tnet)
  490. valid = true
  491. }
  492. for _, filter := range n.Whitelist.Exprs {
  493. expression := &ExprWhitelist{}
  494. expression.Filter, err = expr.Compile(filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  495. if err != nil {
  496. n.Logger.Fatalf("Unable to compile whitelist expression '%s' : %v.", filter, err)
  497. }
  498. expression.ExprDebugger, err = exprhelpers.NewDebugger(filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  499. if err != nil {
  500. log.Errorf("unable to build debug filter for '%s' : %s", filter, err)
  501. }
  502. n.Whitelist.B_Exprs = append(n.Whitelist.B_Exprs, expression)
  503. n.Logger.Debugf("adding expression %s to whitelists", filter)
  504. valid = true
  505. }
  506. if !valid {
  507. /* node is empty, error force return */
  508. n.Logger.Error("Node is empty or invalid, abort")
  509. n.Stage = ""
  510. return fmt.Errorf("Node is empty")
  511. }
  512. if err := n.validate(pctx, ectx); err != nil {
  513. return err
  514. }
  515. return nil
  516. }