node.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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-utilised 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) (bool, error) {
  98. var NodeState bool
  99. var NodeHasOKGrok bool
  100. clog := n.Logger
  101. clog.Tracef("Event entering node")
  102. if n.RunTimeFilter != nil {
  103. //Evaluate node's filter
  104. output, err := expr.Run(n.RunTimeFilter, exprhelpers.GetExprEnv(map[string]interface{}{"evt": p}))
  105. if err != nil {
  106. clog.Warningf("failed to run filter : %v", err)
  107. clog.Debugf("Event leaving node : ko")
  108. return false, nil
  109. }
  110. switch out := output.(type) {
  111. case bool:
  112. if n.Debug {
  113. n.ExprDebugger.Run(clog, out, exprhelpers.GetExprEnv(map[string]interface{}{"evt": p}))
  114. }
  115. if !out {
  116. clog.Debugf("Event leaving node : ko (failed filter)")
  117. return false, nil
  118. }
  119. default:
  120. clog.Warningf("Expr '%s' returned non-bool, abort : %T", n.Filter, output)
  121. clog.Debugf("Event leaving node : ko")
  122. return false, nil
  123. }
  124. NodeState = true
  125. } else {
  126. clog.Tracef("Node has not filter, enter")
  127. NodeState = true
  128. }
  129. if n.Name != "" {
  130. NodesHits.With(prometheus.Labels{"source": p.Line.Src, "type": p.Line.Module, "name": n.Name}).Inc()
  131. }
  132. isWhitelisted := false
  133. hasWhitelist := false
  134. var srcs []net.IP
  135. /*overflow and log don't hold the source ip in the same field, should be changed */
  136. /* perform whitelist checks for ips, cidr accordingly */
  137. /* TODO move whitelist elsewhere */
  138. if p.Type == types.LOG {
  139. if _, ok := p.Meta["source_ip"]; ok {
  140. srcs = append(srcs, net.ParseIP(p.Meta["source_ip"]))
  141. }
  142. } else if p.Type == types.OVFLW {
  143. for k := range p.Overflow.Sources {
  144. srcs = append(srcs, net.ParseIP(k))
  145. }
  146. }
  147. for _, src := range srcs {
  148. if isWhitelisted {
  149. break
  150. }
  151. for _, v := range n.Whitelist.B_Ips {
  152. if v.Equal(src) {
  153. clog.Debugf("Event from [%s] is whitelisted by IP (%s), reason [%s]", src, v, n.Whitelist.Reason)
  154. isWhitelisted = true
  155. } else {
  156. clog.Tracef("whitelist: %s is not eq [%s]", src, v)
  157. }
  158. hasWhitelist = true
  159. }
  160. for _, v := range n.Whitelist.B_Cidrs {
  161. if v.Contains(src) {
  162. clog.Debugf("Event from [%s] is whitelisted by CIDR (%s), reason [%s]", src, v, n.Whitelist.Reason)
  163. isWhitelisted = true
  164. } else {
  165. clog.Tracef("whitelist: %s not in [%s]", src, v)
  166. }
  167. hasWhitelist = true
  168. }
  169. }
  170. if isWhitelisted {
  171. p.Whitelisted = true
  172. }
  173. /* run whitelist expression tests anyway */
  174. for eidx, e := range n.Whitelist.B_Exprs {
  175. output, err := expr.Run(e.Filter, exprhelpers.GetExprEnv(map[string]interface{}{"evt": p}))
  176. if err != nil {
  177. clog.Warningf("failed to run whitelist expr : %v", err)
  178. clog.Debugf("Event leaving node : ko")
  179. return false, nil
  180. }
  181. switch out := output.(type) {
  182. case bool:
  183. if n.Debug {
  184. e.ExprDebugger.Run(clog, out, exprhelpers.GetExprEnv(map[string]interface{}{"evt": p}))
  185. }
  186. if out {
  187. clog.Debugf("Event is whitelisted by expr, reason [%s]", n.Whitelist.Reason)
  188. p.Whitelisted = true
  189. isWhitelisted = true
  190. }
  191. hasWhitelist = true
  192. default:
  193. log.Errorf("unexpected type %t (%v) while running '%s'", output, output, n.Whitelist.Exprs[eidx])
  194. }
  195. }
  196. if isWhitelisted {
  197. p.WhitelistReason = n.Whitelist.Reason
  198. /*huglily wipe the ban order if the event is whitelisted and it's an overflow */
  199. if p.Type == types.OVFLW { /*don't do this at home kids */
  200. ips := []string{}
  201. for _, src := range srcs {
  202. ips = append(ips, src.String())
  203. }
  204. clog.Infof("Ban for %s whitelisted, reason [%s]", strings.Join(ips, ","), n.Whitelist.Reason)
  205. p.Overflow.Whitelisted = true
  206. }
  207. }
  208. //Process grok if present, should be exclusive with nodes :)
  209. gstr := ""
  210. if n.Grok.RunTimeRegexp != nil {
  211. clog.Tracef("Processing grok pattern : %s : %p", n.Grok.RegexpName, n.Grok.RunTimeRegexp)
  212. //for unparsed, parsed etc. set sensible defaults to reduce user hassle
  213. if n.Grok.TargetField != "" {
  214. //it's a hack to avoid using real reflect
  215. if n.Grok.TargetField == "Line.Raw" {
  216. gstr = p.Line.Raw
  217. } else if val, ok := p.Parsed[n.Grok.TargetField]; ok {
  218. gstr = val
  219. } else {
  220. clog.Debugf("(%s) target field '%s' doesn't exist in %v", n.rn, n.Grok.TargetField, p.Parsed)
  221. NodeState = false
  222. }
  223. } else if n.Grok.RunTimeValue != nil {
  224. output, err := expr.Run(n.Grok.RunTimeValue, exprhelpers.GetExprEnv(map[string]interface{}{"evt": p}))
  225. if err != nil {
  226. clog.Warningf("failed to run RunTimeValue : %v", err)
  227. NodeState = false
  228. }
  229. switch out := output.(type) {
  230. case string:
  231. gstr = out
  232. default:
  233. clog.Errorf("unexpected return type for RunTimeValue : %T", output)
  234. }
  235. }
  236. var groklabel string
  237. if n.Grok.RegexpName == "" {
  238. groklabel = fmt.Sprintf("%5.5s...", n.Grok.RegexpValue)
  239. } else {
  240. groklabel = n.Grok.RegexpName
  241. }
  242. grok := n.Grok.RunTimeRegexp.Parse(gstr)
  243. if len(grok) > 0 {
  244. /*tag explicitly that the *current* node had a successful grok pattern. it's important to know success state*/
  245. NodeHasOKGrok = true
  246. clog.Debugf("+ Grok '%s' returned %d entries to merge in Parsed", groklabel, len(grok))
  247. //We managed to grok stuff, merged into parse
  248. for k, v := range grok {
  249. clog.Debugf("\t.Parsed['%s'] = '%s'", k, v)
  250. p.Parsed[k] = v
  251. }
  252. // if the grok succeed, process associated statics
  253. err := n.ProcessStatics(n.Grok.Statics, p)
  254. if err != nil {
  255. clog.Fatalf("(%s) Failed to process statics : %v", n.rn, err)
  256. }
  257. } else {
  258. //grok failed, node failed
  259. clog.Debugf("+ Grok '%s' didn't return data on '%s'", groklabel, gstr)
  260. NodeState = false
  261. }
  262. } else {
  263. clog.Tracef("! No grok pattern : %p", n.Grok.RunTimeRegexp)
  264. }
  265. //Iterate on leafs
  266. if len(n.LeavesNodes) > 0 {
  267. for _, leaf := range n.LeavesNodes {
  268. ret, err := leaf.process(p, ctx)
  269. if err != nil {
  270. clog.Tracef("\tNode (%s) failed : %v", leaf.rn, err)
  271. clog.Debugf("Event leaving node : ko")
  272. return false, err
  273. }
  274. clog.Tracef("\tsub-node (%s) ret : %v (strategy:%s)", leaf.rn, ret, n.OnSuccess)
  275. if ret {
  276. NodeState = true
  277. /* if child is successful, stop processing */
  278. if n.OnSuccess == "next_stage" {
  279. clog.Debugf("child is success, OnSuccess=next_stage, skip")
  280. break
  281. }
  282. } else {
  283. /*
  284. If the parent node has a successful grok pattern, it's state will stay successful even if one or more chil fails.
  285. 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.
  286. */
  287. if !NodeHasOKGrok {
  288. NodeState = false
  289. }
  290. }
  291. }
  292. }
  293. /*todo : check if a node made the state change ?*/
  294. /* should the childs inherit the on_success behaviour */
  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.Fatalf("Failed to process statics : %v", err)
  316. }
  317. } else {
  318. clog.Tracef("! No node statics")
  319. }
  320. if NodeState {
  321. clog.Debugf("Event leaving node : ok")
  322. log.Tracef("node is successful, check strategy")
  323. if n.OnSuccess == "next_stage" {
  324. idx := stageidx(p.Stage, ctx.Stages)
  325. //we're at the last stage
  326. if idx+1 == len(ctx.Stages) {
  327. clog.Debugf("node reached the last stage : %s", p.Stage)
  328. } else {
  329. clog.Debugf("move Event from stage %s to %s", p.Stage, ctx.Stages[idx+1])
  330. p.Stage = ctx.Stages[idx+1]
  331. }
  332. } else {
  333. clog.Tracef("no strategy on success (%s), continue !", n.OnSuccess)
  334. }
  335. } else {
  336. clog.Debugf("Event leaving node : ko")
  337. }
  338. clog.Tracef("Node successful, continue")
  339. return NodeState, nil
  340. }
  341. func (n *Node) compile(pctx *UnixParserCtx, ectx EnricherCtx) error {
  342. var err error
  343. var valid bool
  344. valid = false
  345. dumpr := spew.ConfigState{MaxDepth: 1, DisablePointerAddresses: true}
  346. n.rn = seed.Generate()
  347. n.EnrichFunctions = ectx
  348. log.Tracef("compile, node is %s", n.Stage)
  349. /* if the node has debugging enabled, create a specific logger with debug
  350. that will be used only for processing this node ;) */
  351. if n.Debug {
  352. var clog = logrus.New()
  353. if err := types.ConfigureLogger(clog); err != nil {
  354. log.Fatalf("While creating bucket-specific logger : %s", err)
  355. }
  356. clog.SetLevel(log.DebugLevel)
  357. n.Logger = clog.WithFields(log.Fields{
  358. "id": n.rn,
  359. })
  360. n.Logger.Infof("%s has debug enabled", n.Name)
  361. } else {
  362. /* else bind it to the default one (might find something more elegant here)*/
  363. n.Logger = log.WithFields(log.Fields{
  364. "id": n.rn,
  365. })
  366. }
  367. /* display info about top-level nodes, they should be the only one with explicit stage name ?*/
  368. n.Logger = n.Logger.WithFields(log.Fields{"stage": n.Stage, "name": n.Name})
  369. n.Logger.Tracef("Compiling : %s", dumpr.Sdump(n))
  370. //compile filter if present
  371. if n.Filter != "" {
  372. n.RunTimeFilter, err = expr.Compile(n.Filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  373. if err != nil {
  374. return fmt.Errorf("compilation of '%s' failed: %v", n.Filter, err)
  375. }
  376. if n.Debug {
  377. n.ExprDebugger, err = exprhelpers.NewDebugger(n.Filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  378. if err != nil {
  379. log.Errorf("unable to build debug filter for '%s' : %s", n.Filter, err)
  380. }
  381. }
  382. }
  383. /* handle pattern_syntax and groks */
  384. for _, pattern := range n.SubGroks {
  385. n.Logger.Tracef("Adding subpattern '%s' : '%s'", pattern.Key, pattern.Value)
  386. if err := pctx.Grok.Add(pattern.Key.(string), pattern.Value.(string)); err != nil {
  387. if err == grokky.ErrAlreadyExist {
  388. n.Logger.Warningf("grok '%s' already registred", pattern.Key)
  389. continue
  390. }
  391. n.Logger.Errorf("Unable to compile subpattern %s : %v", pattern.Key, err)
  392. return err
  393. }
  394. }
  395. /* load grok by name or compile in-place */
  396. if n.Grok.RegexpName != "" {
  397. n.Logger.Tracef("+ Regexp Compilation '%s'", n.Grok.RegexpName)
  398. n.Grok.RunTimeRegexp, err = pctx.Grok.Get(n.Grok.RegexpName)
  399. if err != nil {
  400. return fmt.Errorf("Unable to find grok '%s' : %v", n.Grok.RegexpName, err)
  401. }
  402. if n.Grok.RunTimeRegexp == nil {
  403. return fmt.Errorf("Empty grok '%s'", n.Grok.RegexpName)
  404. }
  405. n.Logger.Tracef("%s regexp: %s", n.Grok.RegexpName, n.Grok.RunTimeRegexp.Regexp.String())
  406. valid = true
  407. } else if n.Grok.RegexpValue != "" {
  408. if strings.HasSuffix(n.Grok.RegexpValue, "\n") {
  409. n.Logger.Debugf("Beware, pattern ends with \\n : '%s'", n.Grok.RegexpValue)
  410. }
  411. n.Grok.RunTimeRegexp, err = pctx.Grok.Compile(n.Grok.RegexpValue)
  412. if err != nil {
  413. return fmt.Errorf("Failed to compile grok '%s': %v\n", n.Grok.RegexpValue, err)
  414. }
  415. if n.Grok.RunTimeRegexp == nil {
  416. // We shouldn't be here because compilation succeeded, so regexp shouldn't be nil
  417. return fmt.Errorf("Grok compilation failure: %s", n.Grok.RegexpValue)
  418. }
  419. n.Logger.Tracef("%s regexp : %s", n.Grok.RegexpValue, n.Grok.RunTimeRegexp.Regexp.String())
  420. valid = true
  421. }
  422. /*if grok source is an expression*/
  423. if n.Grok.ExpValue != "" {
  424. n.Grok.RunTimeValue, err = expr.Compile(n.Grok.ExpValue,
  425. expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  426. if err != nil {
  427. return errors.Wrap(err, "while compiling grok's expression")
  428. }
  429. }
  430. /* load grok statics */
  431. if len(n.Grok.Statics) > 0 {
  432. //compile expr statics if present
  433. for idx := range n.Grok.Statics {
  434. if n.Grok.Statics[idx].ExpValue != "" {
  435. n.Grok.Statics[idx].RunTimeValue, err = expr.Compile(n.Grok.Statics[idx].ExpValue,
  436. expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  437. if err != nil {
  438. return err
  439. }
  440. }
  441. }
  442. valid = true
  443. }
  444. /* compile leafs if present */
  445. if len(n.LeavesNodes) > 0 {
  446. for idx := range n.LeavesNodes {
  447. if n.LeavesNodes[idx].Name == "" {
  448. n.LeavesNodes[idx].Name = fmt.Sprintf("child-%s", n.Name)
  449. }
  450. /*propagate debug/stats to child nodes*/
  451. if !n.LeavesNodes[idx].Debug && n.Debug {
  452. n.LeavesNodes[idx].Debug = true
  453. }
  454. if !n.LeavesNodes[idx].Profiling && n.Profiling {
  455. n.LeavesNodes[idx].Profiling = true
  456. }
  457. n.LeavesNodes[idx].Stage = n.Stage
  458. err = n.LeavesNodes[idx].compile(pctx, ectx)
  459. if err != nil {
  460. return err
  461. }
  462. }
  463. valid = true
  464. }
  465. /* load statics if present */
  466. for idx := range n.Statics {
  467. if n.Statics[idx].ExpValue != "" {
  468. n.Statics[idx].RunTimeValue, err = expr.Compile(n.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  469. if err != nil {
  470. n.Logger.Errorf("Statics Compilation failed %v.", err)
  471. return err
  472. }
  473. }
  474. valid = true
  475. }
  476. /* compile whitelists if present */
  477. for _, v := range n.Whitelist.Ips {
  478. n.Whitelist.B_Ips = append(n.Whitelist.B_Ips, net.ParseIP(v))
  479. n.Logger.Debugf("adding ip %s to whitelists", net.ParseIP(v))
  480. valid = true
  481. }
  482. for _, v := range n.Whitelist.Cidrs {
  483. _, tnet, err := net.ParseCIDR(v)
  484. if err != nil {
  485. n.Logger.Fatalf("Unable to parse cidr whitelist '%s' : %v.", v, err)
  486. }
  487. n.Whitelist.B_Cidrs = append(n.Whitelist.B_Cidrs, tnet)
  488. n.Logger.Debugf("adding cidr %s to whitelists", tnet)
  489. valid = true
  490. }
  491. for _, filter := range n.Whitelist.Exprs {
  492. expression := &types.ExprWhitelist{}
  493. expression.Filter, err = expr.Compile(filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  494. if err != nil {
  495. n.Logger.Fatalf("Unable to compile whitelist expression '%s' : %v.", filter, err)
  496. }
  497. expression.ExprDebugger, err = exprhelpers.NewDebugger(filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))
  498. if err != nil {
  499. log.Errorf("unable to build debug filter for '%s' : %s", filter, err)
  500. }
  501. n.Whitelist.B_Exprs = append(n.Whitelist.B_Exprs, expression)
  502. n.Logger.Debugf("adding expression %s to whitelists", filter)
  503. valid = true
  504. }
  505. if !valid {
  506. /* node is empty, error force return */
  507. n.Logger.Infof("Node is empty: %s", spew.Sdump(n))
  508. n.Stage = ""
  509. }
  510. if err := n.validate(pctx, ectx); err != nil {
  511. return err
  512. //n.logger.Fatalf("Node is invalid : %s", err)
  513. }
  514. return nil
  515. }