Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Event-Handler: Add ability to skip Teleport events (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
tigrato authored May 3, 2024
1 parent 380feaa commit 75f122f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions event-handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ You may specify configuration options via command line arguments, environment va
| storage | Storage directory | FDFWD_STORAGE |
| batch | Fetch batch size | FDFWD_BATCH |
| types | Comma-separated list of event types to forward | FDFWD_TYPES |
| skip-event-types | Comma-separated list of event types to skip | FDFWD_SKIP_EVENT_TYPES |
| skip-session-types | Comma-separated list of session event types to skip | FDFWD_SKIP_SESSION_TYPES |
| start-time | Minimum event time (RFC3339 format) | FDFWD_START_TIME |
| timeout | Polling timeout | FDFWD_TIMEOUT |
Expand Down
8 changes: 8 additions & 0 deletions event-handler/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ type IngestConfig struct {
// Types are event types to log
Types []string `help:"Comma-separated list of event types to forward" env:"FDFWD_TYPES"`

// SkipEventTypesRaw are event types to skip
SkipEventTypesRaw []string `name:"skip-event-types" help:"Comma-separated list of event types to skip" env:"FDFWD_SKIP_EVENT_TYPES"`

// SkipEventTypes is a map generated from SkipEventTypesRaw
SkipEventTypes map[string]struct{} `kong:"-"`

// SkipSessionTypes are session event types to skip
SkipSessionTypesRaw []string `name:"skip-session-types" help:"Comma-separated list of session event types to skip" default:"print" env:"FDFWD_SKIP_SESSION_TYPES"`

Expand Down Expand Up @@ -226,6 +232,7 @@ func (c *StartCmdConfig) Validate() error {
return trace.Wrap(err)
}
c.SkipSessionTypes = lib.SliceToAnonymousMap(c.SkipSessionTypesRaw)
c.SkipEventTypes = lib.SliceToAnonymousMap(c.SkipEventTypesRaw)

return nil
}
Expand All @@ -237,6 +244,7 @@ func (c *StartCmdConfig) Dump(ctx context.Context) {
// Log configuration variables
log.WithField("batch", c.BatchSize).Info("Using batch size")
log.WithField("types", c.Types).Info("Using type filter")
log.WithField("skip-event-types", c.SkipEventTypes).Info("Using type exclude filter")
log.WithField("types", c.SkipSessionTypes).Info("Skipping session events of type")
log.WithField("value", c.StartTime).Info("Using start time")
log.WithField("timeout", c.Timeout).Info("Using timeout")
Expand Down
1 change: 1 addition & 0 deletions event-handler/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestStartCmdConfig(t *testing.T) {
IngestConfig: IngestConfig{
StorageDir: "./storage",
BatchSize: 20,
SkipEventTypes: map[string]struct{}{},
SkipSessionTypesRaw: []string{"print"},
SkipSessionTypes: map[string]struct{}{
"print": {},
Expand Down
10 changes: 7 additions & 3 deletions event-handler/teleport_events_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (t *TeleportEventsWatcher) fetch(ctx context.Context) error {
}

// Zero batch
t.batch = make([]*TeleportEvent, len(b))
t.batch = make([]*TeleportEvent, 0, len(b))

// Save next cursor
t.nextCursor = nextCursor
Expand All @@ -193,13 +193,17 @@ func (t *TeleportEventsWatcher) fetch(ctx context.Context) error {
pos := 0

// Convert batch to TeleportEvent
for i, e := range b {
for _, e := range b {
if _, ok := t.config.SkipEventTypes[e.Type]; ok {
log.WithField("event", e).Debug("Skipping event")
continue
}
evt, err := NewTeleportEvent(e, t.cursor)
if err != nil {
return trace.Wrap(err)
}

t.batch[i] = evt
t.batch = append(t.batch, evt)
}

// If last known id is not empty, let's try to find it's pos
Expand Down

0 comments on commit 75f122f

Please sign in to comment.