Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fields column in Splunk Hec output plugin is not working . #505 #527

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/plugins/outputs/splunk_hec.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ More info at https://github.com/splunk/fluent-plugin-splunk-hec
| ca_path | string | No | - | The path to a directory containing CA certificates in PEM format.<br> |
| ssl_ciphers | string | No | - | List of SSL ciphers allowed.<br> |
| insecure_ssl | *bool | No | false | Indicates if insecure SSL connection is allowed <br> |
| fields | map[string]string | No | - | In this case, parameters inside <fields> are used as indexed fields and removed from the original input events<br> |
| fields | Fields | No | - | In this case, parameters inside <fields> are used as indexed fields and removed from the original input events<br> |
| format | *Format | No | - | [Format](../format/)<br> |
| buffer | *Buffer | No | - | [Buffer](../buffer/)<br> |
23 changes: 22 additions & 1 deletion pkg/sdk/model/output/splunk_hec.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,26 @@ type SplunkHecOutput struct {
// Indicates if insecure SSL connection is allowed (default:false)
InsecureSSL *bool `json:"insecure_ssl,omitempty"`
// In this case, parameters inside <fields> are used as indexed fields and removed from the original input events
Fields map[string]string `json:"fields,omitempty"`
Fields Fields `json:"fields,omitempty"`
// +docLink:"Format,../format/"
Format *Format `json:"format,omitempty"`
// +docLink:"Buffer,../buffer/"
Buffer *Buffer `json:"buffer,omitempty"`
}

type Fields map[string]string

func (r Fields) ToDirective(secretLoader secret.SecretLoader, id string) (types.Directive, error) {
recordSet := types.PluginMeta{
Directive: "fields",
}
directive := &types.GenericDirective{
PluginMeta: recordSet,
Params: r,
}
return directive, nil
}

func (c *SplunkHecOutput) ToDirective(secretLoader secret.SecretLoader, id string) (types.Directive, error) {
pluginType := "splunk_hec"
splunkHec := &types.OutputPlugin{
Expand Down Expand Up @@ -150,6 +163,14 @@ func (c *SplunkHecOutput) ToDirective(secretLoader secret.SecretLoader, id strin
}
}

if c.Fields != nil {
if meta, err := c.Fields.ToDirective(secretLoader, ""); err != nil {
return nil, err
} else {
splunkHec.SubDirectives = append(splunkHec.SubDirectives, meta)
}
}

return splunkHec, nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/sdk/model/output/splunk_hec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ hec_host: splunk.default.svc.cluster.local
hec_port: 8088
insecure_ssl: true
index: foo
fields:
dummy: " "
host: foo
protocol: http
metrics_from_event: true
Expand Down Expand Up @@ -55,6 +57,9 @@ source: foo
protocol http
source foo
sourcetype foo
<fields>
dummy
</fields>
</match>
`
es := &output.SplunkHecOutput{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/model/output/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.