node.go 18 KB

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