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

fix: re-add event to splunk serializer #11237

Merged
merged 1 commit into from
Jun 2, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/serializers/splunkmetric/splunkmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type CommonTags struct {

type HECTimeSeries struct {
Time float64 `json:"time"`
Event string `json:"event"`
Host string `json:"host,omitempty"`
Index string `json:"index,omitempty"`
Source string `json:"source,omitempty"`
Expand Down Expand Up @@ -65,6 +66,7 @@ func (s *serializer) createMulti(metric telegraf.Metric, dataGroup HECTimeSeries
var metricJSON []byte

// Set the event data from the commonTags above.
dataGroup.Event = "metric"
dataGroup.Time = commonTags.Time
dataGroup.Host = commonTags.Host
dataGroup.Index = commonTags.Index
Expand Down Expand Up @@ -121,6 +123,7 @@ func (s *serializer) createSingle(metric telegraf.Metric, dataGroup HECTimeSerie
dataGroup.Time = commonTags.Time

// Apply the common tags from above to every record.
dataGroup.Event = "metric"
dataGroup.Host = commonTags.Host
dataGroup.Index = commonTags.Index
dataGroup.Source = commonTags.Source
Expand Down
10 changes: 5 additions & 5 deletions plugins/serializers/splunkmetric/splunkmetric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestSerializeMetricFloatHec(t *testing.T) {
var buf []byte
buf, err := s.Serialize(m)
require.NoError(t, err)
expS := `{"time":1529875740.819,"fields":{"_value":91.5,"cpu":"cpu0","metric_name":"cpu.usage_idle"}}`
expS := `{"time":1529875740.819,"event":"metric","fields":{"_value":91.5,"cpu":"cpu0","metric_name":"cpu.usage_idle"}}`
require.Equal(t, expS, string(buf))
}

Expand Down Expand Up @@ -82,7 +82,7 @@ func TestSerializeMetricIntHec(t *testing.T) {
buf, err := s.Serialize(m)
require.NoError(t, err)

expS := `{"time":0,"fields":{"_value":90,"cpu":"cpu0","metric_name":"cpu.usage_idle"}}`
expS := `{"time":0,"event":"metric","fields":{"_value":90,"cpu":"cpu0","metric_name":"cpu.usage_idle"}}`
require.Equal(t, expS, string(buf))
}

Expand Down Expand Up @@ -120,7 +120,7 @@ func TestSerializeMetricBoolHec(t *testing.T) {
buf, err := s.Serialize(m)
require.NoError(t, err)

expS := `{"time":0,"fields":{"_value":0,"container-name":"telegraf-test","metric_name":"docker.oomkiller"}}`
expS := `{"time":0,"event":"metric","fields":{"_value":0,"container-name":"telegraf-test","metric_name":"docker.oomkiller"}}`
require.Equal(t, expS, string(buf))
}

Expand Down Expand Up @@ -215,7 +215,7 @@ func TestSerializeBatchHec(t *testing.T) {
buf, err := s.SerializeBatch(metrics)
require.NoError(t, err)

expS := `{"time":0,"fields":{"_value":42,"metric_name":"cpu.value"}}{"time":0,"fields":{"_value":92,"metric_name":"cpu.value"}}`
expS := `{"time":0,"event":"metric","fields":{"_value":42,"metric_name":"cpu.value"}}{"time":0,"event":"metric","fields":{"_value":92,"metric_name":"cpu.value"}}`
require.Equal(t, expS, string(buf))
}

Expand All @@ -235,6 +235,6 @@ func TestSerializeMultiHec(t *testing.T) {
buf, err := s.SerializeBatch(metrics)
require.NoError(t, err)

expS := `{"time":0,"fields":{"metric_name:cpu.system":8,"metric_name:cpu.usage":42}}`
expS := `{"time":0,"event":"metric","fields":{"metric_name:cpu.system":8,"metric_name:cpu.usage":42}}`
require.Equal(t, expS, string(buf))
}