grok_pattern.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package types
  2. import (
  3. "time"
  4. "github.com/antonmedv/expr/vm"
  5. "github.com/crowdsecurity/grokky"
  6. )
  7. // Used mostly for statics
  8. type ExtraField struct {
  9. //if the target is indicated by name Struct.Field etc,
  10. TargetByName string `yaml:"target,omitempty"`
  11. //if the target field is in Event map
  12. Parsed string `yaml:"parsed,omitempty"`
  13. //if the target field is in Meta map
  14. Meta string `yaml:"meta,omitempty"`
  15. //if the target field is in Enriched map
  16. Enriched string `yaml:"enriched,omitempty"`
  17. //the source is a static value
  18. Value string `yaml:"value,omitempty"`
  19. //or the result of an Expression
  20. ExpValue string `yaml:"expression,omitempty"`
  21. RunTimeValue *vm.Program `json:"-"` //the actual compiled filter
  22. //or an enrichment method
  23. Method string `yaml:"method,omitempty"`
  24. }
  25. type GrokPattern struct {
  26. //the field to which regexp is going to apply
  27. TargetField string `yaml:"apply_on,omitempty"`
  28. //the grok/regexp by name (loaded from patterns/*)
  29. RegexpName string `yaml:"name,omitempty"`
  30. //a proper grok pattern
  31. RegexpValue string `yaml:"pattern,omitempty"`
  32. //the runtime form of regexpname / regexpvalue
  33. RunTimeRegexp *grokky.Pattern `json:"-"` //the actual regexp
  34. //the output of the expression is going to be the source for regexp
  35. ExpValue string `yaml:"expression,omitempty"`
  36. RunTimeValue *vm.Program `json:"-"` //the actual compiled filter
  37. //a grok can contain statics that apply if pattern is successful
  38. Statics []ExtraField `yaml:"statics,omitempty"`
  39. }
  40. type DataCapture struct {
  41. Name string `yaml:"name,omitempty"`
  42. Key string `yaml:"key,omitempty"`
  43. KeyExpression *vm.Program `yaml:"-"`
  44. Value string `yaml:"value,omitempty"`
  45. ValueExpression *vm.Program `yaml:"-"`
  46. TTL string `yaml:"ttl,omitempty"`
  47. TTLVal time.Duration `yaml:"-"`
  48. MaxMapSize int `yaml:"size,omitempty"`
  49. }