Skip to content

Commit

Permalink
fix: re-add event to splunk serializer (#11237)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored Jun 2, 2022
1 parent 7fa2797 commit 9c47c9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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))
}

0 comments on commit 9c47c9c

Please sign in to comment.