diff --git a/examples/config/global_config.yaml b/examples/config/global_config.yaml index c008d251c658..6bc56eb6ba5b 100644 --- a/examples/config/global_config.yaml +++ b/examples/config/global_config.yaml @@ -111,11 +111,15 @@ output: # host: localhost # port: 8000 # timeout: 5s + # gotemplate: /path/to/template/test.tmpl + # content-type: application/json # - webhook2: # protocol: http # host: localhost # port: 9000 # timeout: 3s + # gotemplate: /path/to/template/test.tmpl + # content-type: application/json # options: # none: false diff --git a/pkg/cmd/cobra/config.go b/pkg/cmd/cobra/config.go index 88ac517e6bb8..07fef6620a57 100644 --- a/pkg/cmd/cobra/config.go +++ b/pkg/cmd/cobra/config.go @@ -280,6 +280,7 @@ func (c *LogConfig) flags() []string { if c.Filters.LibBPF { flags = append(flags, "filter:libbpf") } + flags = append(flags, getLogFilterAttrFlags(false, c.Filters.In)...) flags = append(flags, getLogFilterAttrFlags(true, c.Filters.Out)...) @@ -404,6 +405,7 @@ func (c *OutputConfig) flags() []string { if len(c.GoTemplate.Files) > 0 { templateFlag += ":" + strings.Join(c.GoTemplate.Files, ",") } + flags = append(flags, templateFlag) } @@ -432,6 +434,13 @@ func (c *OutputConfig) flags() []string { if webhook.Timeout != "" { url += fmt.Sprintf("?timeout=%s", webhook.Timeout) } + if webhook.GoTemplate != "" { + url += fmt.Sprintf("?gotemplate=%s", webhook.GoTemplate) + } + if webhook.ContentType != "" { + url += fmt.Sprintf("?contentType=%s", webhook.ContentType) + } + flags = append(flags, fmt.Sprintf("webhook:%s", url)) } @@ -468,8 +477,10 @@ type OutputForwardConfig struct { } type OutputWebhookConfig struct { - Protocol string `mapstructure:"protocol"` - Host string `mapstructure:"host"` - Port int `mapstructure:"port"` - Timeout string `mapstructure:"timeout"` + Protocol string `mapstructure:"protocol"` + Host string `mapstructure:"host"` + Port int `mapstructure:"port"` + Timeout string `mapstructure:"timeout"` + GoTemplate string `mapstructure:"gotemplate"` + ContentType string `mapstructure:"content-type"` } diff --git a/pkg/cmd/cobra/config_test.go b/pkg/cmd/cobra/config_test.go index 54f0d166b766..4da289cdbb1f 100644 --- a/pkg/cmd/cobra/config_test.go +++ b/pkg/cmd/cobra/config_test.go @@ -354,11 +354,15 @@ output: host: localhost port: 8000 timeout: 5s + gotemplate: /path/to/template1 + content-type: application/json - webhook2: protocol: http host: localhost port: 9000 timeout: 3s + gotemplate: /path/to/template2 + content-type: application/ld+json `, key: "output", expectedFlags: []string{ @@ -376,8 +380,8 @@ output: "gotemplate=template1:file3,file4", "forward:tcp://user:pass@127.0.0.1:24224?tag=tracee1", "forward:udp://user:pass@127.0.0.1:24225?tag=tracee2", - "webhook:http://localhost:8000?timeout=5s", - "webhook:http://localhost:9000?timeout=3s", + "webhook:http://localhost:8000?timeout=5s?gotemplate=/path/to/template1?contentType=application/json", + "webhook:http://localhost:9000?timeout=3s?gotemplate=/path/to/template2?contentType=application/ld+json", }, }, } @@ -1063,19 +1067,21 @@ func TestOutputConfigFlags(t *testing.T) { }, }, { - name: "test webhook with timeout", + name: "test webhook with all fields", config: OutputConfig{ Webhooks: map[string]OutputWebhookConfig{ "example3": { - Protocol: "http", - Host: "webhook.com", - Port: 9090, - Timeout: "5s", + Protocol: "http", + Host: "webhook.com", + Port: 9090, + Timeout: "5s", + GoTemplate: "/path/to/template1", + ContentType: "application/json", }, }, }, expected: []string{ - "webhook:http://webhook.com:9090?timeout=5s", + "webhook:http://webhook.com:9090?timeout=5s?gotemplate=/path/to/template1?contentType=application/json", }, }, {