44 "bytes"
55 "compress/gzip"
66 "errors"
7- "fmt"
87 "net/http"
98 "runtime"
109 "time"
@@ -22,6 +21,9 @@ type SumoLogicAppender struct {
2221 eventsBatchSize int
2322 sumoPostMinimumDelay time.Duration
2423 timerBetweenPost time.Time
24+ sumoCategory string
25+ sumoName string
26+ sumoClient string
2527}
2628
2729type SumoBuffer struct {
@@ -30,14 +32,17 @@ type SumoBuffer struct {
3032 timerIdlebuffer time.Time
3133}
3234
33- func NewSumoLogicAppender (urlValue string , connectionTimeoutValue int , nozzleQueue * eventQueue.Queue , eventsBatchSize int , sumoPostMinimumDelay time.Duration ) * SumoLogicAppender {
35+ func NewSumoLogicAppender (urlValue string , connectionTimeoutValue int , nozzleQueue * eventQueue.Queue , eventsBatchSize int , sumoPostMinimumDelay time.Duration , sumoCategory string , sumoName string , sumoClient string ) * SumoLogicAppender {
3436 return & SumoLogicAppender {
3537 url : urlValue ,
3638 connectionTimeout : connectionTimeoutValue ,
3739 httpClient : http.Client {Timeout : time .Duration (connectionTimeoutValue * int (time .Millisecond ))},
3840 nozzleQueue : nozzleQueue ,
3941 eventsBatchSize : eventsBatchSize ,
4042 sumoPostMinimumDelay : sumoPostMinimumDelay ,
43+ sumoCategory : sumoCategory ,
44+ sumoName : sumoName ,
45+ sumoClient : sumoClient ,
4146 }
4247}
4348
@@ -115,7 +120,6 @@ func (s *SumoLogicAppender) AppendLogs(buffer *SumoBuffer) {
115120}
116121
117122func (s * SumoLogicAppender ) SendToSumo (logStringToSend string ) {
118-
119123 var buf bytes.Buffer
120124 g := gzip .NewWriter (& buf )
121125 g .Write ([]byte (logStringToSend ))
@@ -131,8 +135,19 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string) {
131135 logging .Error .Printf ("http.NewRequest() error: %v\n " , err )
132136 return
133137 }
138+
134139 request .Header .Add ("Content-Encoding" , "gzip" )
135- //request.SetBasicAuth("admin", "admin")
140+
141+ if s .sumoName != "" {
142+ request .Header .Add ("X-Sumo-Name" , s .sumoName )
143+ }
144+ if s .sumoClient != "" {
145+ request .Header .Add ("X-Sumo-Client" , s .sumoClient )
146+ }
147+ if s .sumoCategory != "" {
148+ request .Header .Add ("X-Sumo-Category" , s .sumoCategory )
149+ }
150+
136151 response , err := s .httpClient .Do (request )
137152
138153 if (err != nil ) || (response .StatusCode != 200 && response .StatusCode != 302 && response .StatusCode < 500 ) {
@@ -148,17 +163,25 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string) {
148163 logging .Error .Printf ("http.NewRequest() error: %v\n " , err )
149164 }
150165 request .Header .Add ("Content-Encoding" , "gzip" )
166+
167+ if s .sumoName != "" {
168+ request .Header .Add ("X-Sumo-Name" , s .sumoName )
169+ }
170+ if s .sumoClient != "" {
171+ request .Header .Add ("X-Sumo-Client" , s .sumoClient )
172+ }
173+ if s .sumoCategory != "" {
174+ request .Header .Add ("X-Sumo-Category" , s .sumoCategory )
175+ }
151176 response , errRetry = s .httpClient .Do (request )
152177 if errRetry != nil {
153178 logging .Error .Printf ("http.Do() error: %v\n " , errRetry )
154179 logging .Info .Println ("Waiting for 300 ms to retry after error" )
155- fmt .Println (attempt )
156180 time .Sleep (300 * time .Millisecond )
157181 return attempt < 5 , errRetry
158182 } else if response .StatusCode != 200 && response .StatusCode != 302 && response .StatusCode < 500 {
159183 logging .Info .Println ("Endpoint dropped the post send again" )
160184 logging .Info .Println ("Waiting for 300 ms to retry after a retry ..." )
161- fmt .Println (attempt )
162185 statusCode = response .StatusCode
163186 time .Sleep (300 * time .Millisecond )
164187 return attempt < 5 , errRetry
0 commit comments