-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFilterDropEvents.go
56 lines (50 loc) · 1.59 KB
/
FilterDropEvents.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package canarytools
import (
"fmt"
log "github.com/sirupsen/logrus"
)
// FilterDropEvents is a filter that drops "events" from incidents' descritpion
// object, this will reduce incident size keeping only basic information about
// the incident.
type FilterDropEvents struct {
l *log.Logger
}
// NewFilterDropEvents creates a new FilterDropEvents
func NewFilterDropEvents(l *log.Logger) (fde *FilterDropEvents, err error) {
fde = &FilterDropEvents{}
fde.l = l
return
}
// Filter filters the incidents, in this case it drops "description.events"
func (fn FilterDropEvents) Filter(incidnetsChan <-chan Incident, filteredIncidnetsChan chan<- Incident) {
fn.l.WithFields(log.Fields{
"source": "FilterDropEvents",
"stage": "filter",
}).Info("starting FilterDropEvents")
for v := range incidnetsChan {
fn.l.WithFields(log.Fields{
"source": "FilterDropEvents",
"stage": "filter",
"content": fmt.Sprintf("%#v", v),
}).Trace("Orignial incident 'before filtering'")
if _, ok := v.Description["events"]; ok {
delete(v.Description, "events")
} else {
fn.l.WithFields(log.Fields{
"source": "FilterDropEvents",
"stage": "filter",
}).Debug("Orignial incident didn't have 'events' array; FilterDropEvents didn't do anything")
}
fn.l.WithFields(log.Fields{
"source": "FilterDropEvents",
"stage": "filter",
"content": fmt.Sprintf("%#v", v),
}).Trace("Modified incident 'after filtering'")
fn.l.WithFields(log.Fields{
"source": "FilterDropEvents",
"stage": "filter",
"Incidnet": v.Description,
}).Debug("Filter Incident")
filteredIncidnetsChan <- v
}
}