event.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package types
  2. import (
  3. "time"
  4. log "github.com/sirupsen/logrus"
  5. "github.com/antonmedv/expr/vm"
  6. "github.com/crowdsecurity/crowdsec/pkg/models"
  7. )
  8. const (
  9. LOG = iota
  10. OVFLW
  11. )
  12. //Event is the structure representing a runtime event (log or overflow)
  13. type Event struct {
  14. /* is it a log or an overflow */
  15. Type int `yaml:"Type,omitempty" json:"Type,omitempty"` //Can be types.LOG (0) or types.OVFLOW (1)
  16. ExpectMode int `yaml:"ExpectMode,omitempty" json:"ExpectMode,omitempty"` //how to buckets should handle event : leaky.TIMEMACHINE or leaky.LIVE
  17. Whitelisted bool `yaml:"Whitelisted,omitempty" json:"Whitelisted,omitempty"`
  18. WhiteListReason string `yaml:"whitelist_reason,omitempty" json:"whitelist_reason,omitempty"`
  19. //should add whitelist reason ?
  20. /* the current stage of the line being parsed */
  21. Stage string `yaml:"Stage,omitempty" json:"Stage,omitempty"`
  22. /* original line (produced by acquisition) */
  23. Line Line `yaml:"Line,omitempty" json:"Line,omitempty"`
  24. /* output of groks */
  25. Parsed map[string]string `yaml:"Parsed,omitempty" json:"Parsed,omitempty"`
  26. /* output of enrichment */
  27. Enriched map[string]string `yaml:"Enriched,omitempty" json:"Enriched,omitempty"`
  28. /* Overflow */
  29. Overflow RuntimeAlert `yaml:"Alert,omitempty" json:"Alert,omitempty"`
  30. Time time.Time `yaml:"Time,omitempty" json:"Time,omitempty"` //parsed time `json:"-"` ``
  31. StrTime string `yaml:"StrTime,omitempty" json:"StrTime,omitempty"`
  32. MarshaledTime string `yaml:"MarshaledTime,omitempty" json:"MarshaledTime,omitempty"`
  33. Process bool `yaml:"Process,omitempty" json:"Process,omitempty"` //can be set to false to avoid processing line
  34. /* Meta is the only part that will make it to the API - it should be normalized */
  35. Meta map[string]string `yaml:"Meta,omitempty" json:"Meta,omitempty"`
  36. }
  37. func (e *Event) GetType() string {
  38. if e.Type == OVFLW {
  39. return "overflow"
  40. } else if e.Type == LOG {
  41. return "log"
  42. } else {
  43. log.Warningf("unknown event type for %+v", e)
  44. return "unknown"
  45. }
  46. }
  47. //Move in leakybuckets
  48. const (
  49. Undefined = ""
  50. Ip = "Ip"
  51. Range = "Range"
  52. Filter = "Filter"
  53. Country = "Country"
  54. AS = "AS"
  55. )
  56. //Move in leakybuckets
  57. type ScopeType struct {
  58. Scope string `yaml:"type"`
  59. Filter string `yaml:"expression"`
  60. RunTimeFilter *vm.Program
  61. }
  62. type RuntimeAlert struct {
  63. Mapkey string `yaml:"MapKey,omitempty" json:"MapKey,omitempty"`
  64. BucketId string `yaml:"BucketId,omitempty" json:"BucketId,omitempty"`
  65. Whitelisted bool `yaml:"Whitelisted,omitempty" json:"Whitelisted,omitempty"`
  66. Reprocess bool `yaml:"Reprocess,omitempty" json:"Reprocess,omitempty"`
  67. Sources map[string]models.Source `yaml:"Sources,omitempty" json:"Sources,omitempty"`
  68. Alert *models.Alert `yaml:"Alert,omitempty" json:"Alert,omitempty"` //this one is a pointer to APIAlerts[0] for convenience.
  69. //APIAlerts will be populated at the end when there is more than one source
  70. APIAlerts []models.Alert `yaml:"APIAlerts,omitempty" json:"APIAlerts,omitempty"`
  71. }