Skip to content

Commit 98f1e23

Browse files
authored
Add telemetry data (appname and appversion) to HEC requests (#250)
1 parent bb9465e commit 98f1e23

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

eventwriter/splunk.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,16 @@ func (s *splunkClient) send(postBody *[]byte) error {
8585
req.Header.Set("Content-Type", "application/json")
8686
req.Header.Set("Connection", "keep-alive")
8787
req.Header.Set("Authorization", fmt.Sprintf("Splunk %s", s.config.Token))
88+
//Add app headers for HEC telemetry
89+
//Todo: update static values with appName and appVersion variables
90+
req.Header.Set("__splunk_app_name", "Splunk Firehose Nozzle")
91+
req.Header.Set("__splunk_app_version", "2.0.0")
8892

8993
resp, err := s.httpClient.Do(req)
9094
if err != nil {
9195
return err
9296
}
9397
defer resp.Body.Close()
94-
9598
if resp.StatusCode > 299 {
9699
responseBody, _ := ioutil.ReadAll(resp.Body)
97100
return errors.New(fmt.Sprintf("Non-ok response code [%d] from splunk: %s", resp.StatusCode, responseBody))

eventwriter/splunk_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,36 @@ var _ = Describe("Splunk", func() {
8888
Expect(contentType).To(Equal("application/json"))
8989
})
9090

91+
It("sets app name to appName", func() {
92+
appName := "Splunk Firehose Nozzle"
93+
94+
client := NewSplunk(config)
95+
events := []map[string]interface{}{}
96+
err, _ := client.Write(events)
97+
98+
Expect(err).To(BeNil())
99+
Expect(capturedRequest).NotTo(BeNil())
100+
101+
applicationName := capturedRequest.Header.Get("__splunk_app_name")
102+
Expect(applicationName).To(Equal(appName))
103+
104+
})
105+
106+
It("sets app appVersion", func() {
107+
appVersion := "2.0.0"
108+
109+
client := NewSplunk(config)
110+
events := []map[string]interface{}{}
111+
err, _ := client.Write(events)
112+
113+
Expect(err).To(BeNil())
114+
Expect(capturedRequest).NotTo(BeNil())
115+
116+
applicationVersion := capturedRequest.Header.Get("__splunk_app_version")
117+
Expect(applicationVersion).To(Equal(appVersion))
118+
119+
})
120+
91121
It("Writes batch event json", func() {
92122
client := NewSplunk(config)
93123
event1 := map[string]interface{}{"event": map[string]interface{}{

0 commit comments

Comments
 (0)