11package sumoLogicAppender
22
33import (
4- "bufio"
54 "bytes"
5+ "encoding/json"
66 "net/http"
77 "time"
88)
@@ -21,43 +21,17 @@ func newSumoLogicAppender(urlValue string, connectionTimeoutValue int) *SumoLogi
2121 }
2222}
2323
24- func (s * SumoLogicAppender ) append (Event map [string ]interface {}, Message string ) {
24+ func (s * SumoLogicAppender ) appendToSumo (Event map [string ]interface {}, Message string ) {
25+ //adding the message to the map
2526 Event ["msg" ] = Message
26- var buffer bytes.Buffer
27- buffer .WriteString (event )
28- reader := bufio .NewReader (resp .Body )
29- for {
30- line , err := reader .ReadBytes ('\n' )
31- //...
32- //log.Println(string(line))
33- }
34-
35- sendToSumo (buffer .String ())
36- }
37-
38- func (boolean ) checkEntryConditions () {
39- if httpClient == nil {
40- return false
41- }
42- return true
43- }
44-
45- func senToSumo (log string ) {
46- if ! checkEntryConditions () {
47- return
48- }
49- request , err := http .NewRequest ("POST" , url , bytes .NewBufferString (log ))
50- //request.SetBasicAuth("admin", "admin")
51- response , err := httpClient .Do (request )
52- if ! err {
53- jghjk
27+ jsonEvent , err := json .Marshal (Event )
28+ request , err := http .NewRequest ("POST" , s .url , bytes .NewBuffer (jsonEvent ))
29+ response , err := s .httpClient .Do (request )
30+ if err != nil {
5431 if response .StatusCode != 200 {
5532 //log print "Received HTTP error from Sumo Service:"
5633 }
5734 //consume the body if you want to re-use the connection
58- } else {
59- log .Fatal (err )
6035 }
6136 defer response .Body .Close ()
62-
6337}
0 commit comments