Skip to content

Commit

Permalink
filebeat: fix netflow template sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
simioa committed Dec 17, 2024
1 parent 534ed1e commit ec2b664
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions x-pack/filebeat/input/netflow/decoder/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (c *Config) SequenceResetEnabled() bool {
return c.detectReset
}

// ShareTemplatesEnabled returns if template sharing is enabled.
func (c *Config) ShareTemplatesEnabled() bool {
return c.sharedTemplates
}

// Fields returns the configured fields.
func (c *Config) Fields() fields.FieldDict {
if c.fields == nil {
Expand Down
15 changes: 8 additions & 7 deletions x-pack/filebeat/input/netflow/decoder/v9/v9.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ func New(config config.Config) protocol.Protocol {
func NewProtocolWithDecoder(decoder Decoder, config config.Config, logger *log.Logger) *NetflowV9Protocol {
ctx, cancel := context.WithCancel(context.Background())
pd := &NetflowV9Protocol{
ctx: ctx,
cancel: cancel,
decoder: decoder,
logger: logger,
Session: NewSessionMap(logger, config.ActiveSessionsMetric()),
timeout: config.ExpirationTimeout(),
detectReset: config.SequenceResetEnabled(),
ctx: ctx,
cancel: cancel,
decoder: decoder,
logger: logger,
Session: NewSessionMap(logger, config.ActiveSessionsMetric()),
timeout: config.ExpirationTimeout(),
detectReset: config.SequenceResetEnabled(),
shareTemplates: config.ShareTemplatesEnabled(),
}

if config.Cache() {
Expand Down
10 changes: 10 additions & 0 deletions x-pack/filebeat/input/netflow/decoder/v9/v9_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestOptionTemplates(t *testing.T) {
opt := s.GetTemplate(999)
assert.NotNil(t, opt)
assert.True(t, opt.ScopeFields > 0)
assert.False(t, v9proto.shareTemplates)
})

t.Run("Multiple options template", func(t *testing.T) {
Expand Down Expand Up @@ -96,6 +97,15 @@ func TestOptionTemplates(t *testing.T) {
assert.NotNil(t, opt)
assert.True(t, opt.ScopeFields > 0)
}

t.Run("with template sharing enabled", func(t *testing.T) {
cfg := config.Defaults()
cfg.WithSharedTemplates(true)
proto := New(cfg)
v9proto, ok := proto.(*NetflowV9Protocol)
assert.True(t, ok)
assert.True(t, v9proto.shareTemplates)
})
})

t.Run("records discarded", func(t *testing.T) {
Expand Down

0 comments on commit ec2b664

Please sign in to comment.