@@ -3,13 +3,13 @@ package sumoCFFirehose
33import (
44 "bytes"
55 "compress/gzip"
6+ "encoding/json"
67 "errors"
78 "net/http"
89 "runtime"
10+ "strings"
911 "time"
1012
11- "encoding/json"
12-
1313 "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/eventQueue"
1414 "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/events"
1515 "bitbucket.org/mcplusa-ondemand/firehose-to-sumologic/logging"
@@ -27,6 +27,7 @@ type SumoLogicAppender struct {
2727 sumoName string
2828 sumoHost string
2929 verboseLogMessages bool
30+ customMetadata string
3031}
3132
3233type SumoBuffer struct {
@@ -35,7 +36,7 @@ type SumoBuffer struct {
3536 timerIdlebuffer time.Time
3637}
3738
38- func NewSumoLogicAppender (urlValue string , connectionTimeoutValue int , nozzleQueue * eventQueue.Queue , eventsBatchSize int , sumoPostMinimumDelay time.Duration , sumoCategory string , sumoName string , sumoHost string , verboseLogMessages bool ) * SumoLogicAppender {
39+ func NewSumoLogicAppender (urlValue string , connectionTimeoutValue int , nozzleQueue * eventQueue.Queue , eventsBatchSize int , sumoPostMinimumDelay time.Duration , sumoCategory string , sumoName string , sumoHost string , verboseLogMessages bool , customMetadata string ) * SumoLogicAppender {
3940 return & SumoLogicAppender {
4041 url : urlValue ,
4142 connectionTimeout : connectionTimeoutValue ,
@@ -47,6 +48,7 @@ func NewSumoLogicAppender(urlValue string, connectionTimeoutValue int, nozzleQue
4748 sumoName : sumoName ,
4849 sumoHost : sumoHost ,
4950 verboseLogMessages : verboseLogMessages ,
51+ customMetadata : customMetadata ,
5052 }
5153}
5254
@@ -186,6 +188,14 @@ func (s *SumoLogicAppender) AppendLogs(buffer *SumoBuffer) {
186188 buffer .logEventsInCurrentBuffer ++
187189
188190}
191+ func ParseCustomMetadata (customMetadata string ) map [string ]string {
192+ cMetadataArray := strings .Split (customMetadata , "," )
193+ customMetadataMap := make (map [string ]string )
194+ for i := 0 ; i < len (cMetadataArray ); i ++ {
195+ customMetadataMap [strings .Split (cMetadataArray [i ], ":" )[0 ]] = strings .Split (cMetadataArray [i ], ":" )[1 ]
196+ }
197+ return customMetadataMap
198+ }
189199
190200func (s * SumoLogicAppender ) SendToSumo (logStringToSend string ) {
191201 if logStringToSend != "" {
@@ -198,7 +208,6 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string) {
198208 logging .Error .Printf ("http.NewRequest() error: %v\n " , err )
199209 return
200210 }
201-
202211 request .Header .Add ("Content-Encoding" , "gzip" )
203212
204213 if s .sumoName != "" {
@@ -210,6 +219,13 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string) {
210219 if s .sumoCategory != "" {
211220 request .Header .Add ("X-Sumo-Category" , s .sumoCategory )
212221 }
222+
223+ if s .customMetadata != "" {
224+ customMetadataMap := ParseCustomMetadata (s .customMetadata )
225+ for key , value := range customMetadataMap {
226+ request .Header .Add (key , value )
227+ }
228+ }
213229 //checking the timer before first POST intent
214230 for time .Since (s .timerBetweenPost ) < s .sumoPostMinimumDelay {
215231 logging .Trace .Println ("Delaying Post because minimum post timer not expired" )
0 commit comments