Skip to content

Commit e9c5f36

Browse files
committed
Remove event exclusion code
Signed-off-by: Christian König <ckoenig@posteo.de>
1 parent c7a12fb commit e9c5f36

File tree

4 files changed

+0
-108
lines changed

4 files changed

+0
-108
lines changed

src/events.go

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"encoding/json"
54
"strings"
65
"time"
76

@@ -135,94 +134,3 @@ func getActorName(event events.Message) string {
135134
return ActorName
136135

137136
}
138-
139-
func excludeEvent(event events.Message) bool {
140-
// Checks if any of the exclusion criteria matches the event
141-
142-
ActorID := getActorID(event)
143-
144-
// Convert the event (struct of type event.Message) to a flattend map
145-
eventMap := structToFlatMap(event)
146-
147-
// Check for all exclude key -> value combinations if they match the event
148-
for key, values := range config.Exclude {
149-
eventValue, keyExist := eventMap[key]
150-
151-
// Check if the exclusion key exists in the eventMap
152-
if !keyExist {
153-
log.Debug().
154-
Str("ActorID", ActorID).
155-
Msgf("Exclusion key \"%s\" did not match", key)
156-
return false
157-
}
158-
159-
log.Debug().
160-
Str("ActorID", ActorID).
161-
Msgf("Exclusion key \"%s\" matched, checking values", key)
162-
163-
log.Debug().
164-
Str("ActorID", ActorID).
165-
Msgf("Event's value for key \"%s\" is \"%s\"", key, eventValue)
166-
167-
for _, value := range values {
168-
// comparing the prefix to be able to filter actions like "exec_XXX: YYYY" which use a
169-
// special, dynamic, syntax
170-
// see https://github.com/moby/moby/blob/bf053be997f87af233919a76e6ecbd7d17390e62/api/types/events/events.go#L74-L81
171-
172-
if strings.HasPrefix(eventValue, value) {
173-
log.Debug().
174-
Str("ActorID", ActorID).
175-
Msgf("Event excluded based on exclusion setting \"%s=%s\"", key, value)
176-
return true
177-
}
178-
}
179-
log.Debug().
180-
Str("ActorID", ActorID).
181-
Msgf("Exclusion key \"%s\" matched, but values did not match", key)
182-
}
183-
184-
return false
185-
}
186-
187-
// flatten a nested map, separating nested keys by dots
188-
func flattenMap(prefix string, m map[string]interface{}) map[string]string {
189-
flatMap := make(map[string]string)
190-
for k, v := range m {
191-
newKey := k
192-
// separate nested keys by dot
193-
if prefix != "" {
194-
newKey = prefix + "." + k
195-
}
196-
// if the value is a map/struct itself, transverse it recursivly
197-
switch k {
198-
case "Actor", "Attributes":
199-
nestedMap := v.(map[string]interface{})
200-
for nk, nv := range flattenMap(newKey, nestedMap) {
201-
flatMap[nk] = nv
202-
}
203-
case "time", "timeNano":
204-
flatMap[newKey] = string(v.(json.Number))
205-
default:
206-
flatMap[newKey] = v.(string)
207-
}
208-
}
209-
return flatMap
210-
}
211-
212-
// Convert struct to flat map by first converting it to a map (via JSON) and flatten it afterwards
213-
func structToFlatMap(s interface{}) map[string]string {
214-
m := make(map[string]interface{})
215-
b, err := json.Marshal(s)
216-
if err != nil {
217-
log.Fatal().Err(err).Msg("Marshaling JSON failed")
218-
}
219-
220-
// Using a custom decoder to set 'UseNumber' which will preserver a string representation of
221-
// time and timeNano instead of converting it to float64
222-
decoder := json.NewDecoder(strings.NewReader(string(b)))
223-
decoder.UseNumber()
224-
if err := decoder.Decode(&m); err != nil {
225-
log.Fatal().Err(err).Msg("Unmarshaling JSON failed")
226-
}
227-
return flattenMap("", m)
228-
}

src/main.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,6 @@ func main() {
180180
// if logging level is debug, log the event
181181
log.Debug().
182182
Interface("event", event).Msg("")
183-
184-
// Check if event should be exlcuded from reporting
185-
if len(config.Exclude) > 0 {
186-
log.Debug().Msg("Performing check for event exclusion")
187-
if excludeEvent(event) {
188-
break //breaks out of the select and waits for the next event to arrive
189-
}
190-
}
191183
processEvent(event)
192184
}
193185
}

src/startup.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ func buildStartupMessage(timestamp time.Time) string {
5959
startup_message_builder.WriteString("\nGlobal filter: none")
6060
}
6161

62-
if len(config.Options.ExcludeStrings) > 0 {
63-
startup_message_builder.WriteString("\nExcludeStrings: " + strings.Join(config.Options.ExcludeStrings, " "))
64-
} else {
65-
startup_message_builder.WriteString("\nExcludeStrings: none")
66-
}
67-
6862
return startup_message_builder.String()
6963
}
7064

src/types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ type reporter struct {
3535

3636
type options struct {
3737
Filter map[string][]string `yaml:"filter"`
38-
ExcludeStrings []string `yaml:"exclude_strings,flow"`
3938
LogLevel string `yaml:"log_level"`
4039
ServerTag string `yaml:"server_tag"`
4140
}
@@ -50,6 +49,5 @@ type Config struct {
5049
Reporter reporter
5150
Options options
5251
EnabledReporter []string `yaml:"-"`
53-
Exclude map[string][]string `yaml:"-"`
5452
Notifications []notification `yaml:"notifications"`
5553
}

0 commit comments

Comments
 (0)