Skip to content

Commit 00dbf32

Browse files
committed
SCFF-21 appending only 'msg' field from logs (Klava session)
1 parent b81e76e commit 00dbf32

4 files changed

Lines changed: 27 additions & 34 deletions

File tree

eventRouting/eventrouting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func (e *EventRouting) RouteEvent(msg *events.Envelope) {
8080
if ignored, hasIgnoredField := event.Fields["cf_ignored_app"]; ignored == true && hasIgnoredField {
8181
e.selectedEventsCount["ignored_app_message"]++
8282
} else {
83-
e.sLAppender.AppendLogs(event.Fields, event.Msg) //**
84-
e.log.ShipEvents(event.Fields, event.Msg) // here we have to change the method for the one on sumoLogicAppender
83+
e.sLAppender.AppendLogs(event.Fields) //**
84+
e.log.ShipEvents(event.Fields, event.Msg) // here we have to change the method for the one on sumoLogicAppender
8585
e.selectedEventsCount[eventType.String()]++
8686

8787
}

main.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@ func main() {
4545
kingpin.Version(version)
4646
kingpin.Parse()
4747

48-
//Setup Logging
48+
//Setup Logging <-- this loggingClient has to be removed when sumoLog4go Library is working
4949
loggingClient := logging.NewLogging(syslogServer, syslogProtocol, *logFormatterType, *debug)
50+
//Setup Loggin with sumoLog4go library
5051
loggingClientSumo := sumoLog4go.NewSumoLogicAppender("http://httpbin.org/post", 1000)
51-
//loggingClient, err := syslog.Dial(syslogProtocol, syslogServer, syslog.LOG_ERR, "demotag")
52-
//defer loggingClient.Close()
53-
//if err != nil {
54-
// log.Fatal("error")
55-
//}
56-
logging.LogStd(fmt.Sprintf("Starting firehose-to-syslog %s ", version), true)
52+
53+
logging.LogStd(fmt.Sprintf("Starting firehose-to-sumo %s ", version), true)
5754

5855
if *modeProf != "" {
5956
switch *modeProf {
@@ -80,12 +77,6 @@ func main() {
8077
cfClient.Endpoint.DopplerEndpoint = *dopplerEndpoint
8178
}
8279

83-
logging.LogStd(fmt.Sprintf("Login with '%s' user", *user), true)
84-
logging.LogStd(fmt.Sprintf("using '%s' as user", c.Username), true)
85-
logging.LogStd(fmt.Sprintf("using '%s' as password", *password), true)
86-
87-
logging.LogStd(fmt.Sprintf("Using %s as doppler endpoint", cfClient.Endpoint.DopplerEndpoint), true)
88-
8980
//Creating Caching
9081
var cachingClient caching.Caching
9182
if caching.IsNeeded(*wantedEvents) {
@@ -127,10 +118,8 @@ func main() {
127118
IdleTimeoutSeconds: *keepAlive,
128119
FirehoseSubscriptionID: *subscriptionId,
129120
}
130-
// logging.LogStd(fmt.Sprintf("connect logging '%s'", loggingClient.Connect()), true)
131-
//logging.LogStd(fmt.Sprintf("using '%s' as syslogServer", syslogServer), true)
132-
//logging.LogStd(fmt.Sprintf("using '%s' as syslogServer", *debug), true)
133-
if loggingClient.Connect() || *debug {
121+
122+
if /*loggingClientSumo.Connect() ||*/ *debug {
134123

135124
logging.LogStd("Connected to Server! Connecting to Firehose...", true)
136125
firehoseClient := firehoseclient.NewFirehoseNozzle(cfClient, events, firehoseConfig)

sumoLog4go/sumoLog4go.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ package sumoLog4go
22

33
type SumoLog4go interface {
44
Connect() bool
5-
AppendLogs(map[string]interface{}, string)
5+
AppendLogs(map[string]interface{})
66
}

sumoLog4go/sumoLogicAppender.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sumoLog4go
22

33
import (
44
"bytes"
5-
"encoding/json"
65
"fmt"
76
"net"
87
"net/http"
@@ -27,7 +26,6 @@ func (s *SumoLogicAppender) Connect() bool {
2726
success := false
2827
if s.url != "" {
2928
conn, err := net.Dial("tcp", s.url)
30-
fmt.Printf(fmt.Sprintf("Unable to connect to sumo server [%s]!\n", s.url), err.Error())
3129
if err != nil {
3230
fmt.Printf(fmt.Sprintf("Unable to connect to sumo server [%s]!\n", s.url), err.Error())
3331
} else {
@@ -41,37 +39,43 @@ func (s *SumoLogicAppender) Connect() bool {
4139
return success
4240
}
4341

44-
func (s *SumoLogicAppender) AppendLogs(Event map[string]interface{}, Message string) {
42+
func (s *SumoLogicAppender) AppendLogs(Event map[string]interface{}) {
4543
//adding the message to the map
46-
Event["msg"] = Message
47-
jsonEvent, err := json.Marshal(Event)
48-
if err == nil {
49-
fmt.Println("-----here are the logs to send to sumo-------")
44+
if Event == nil {
45+
return
46+
}
5047

51-
//fmt.Println(string(jsonEvent)) //**
52-
s.SendToSumo(jsonEvent)
53-
//fmt.Println("---------------------------------------------")
48+
if Event["msg"] == nil {
49+
return
5450
}
5551

52+
if Event["msg"] == "" {
53+
return
54+
}
55+
56+
Message := ""
57+
Message = Event["msg"].(string) + "\n"
58+
59+
s.SendToSumo(Message)
60+
5661
}
5762

58-
func (s *SumoLogicAppender) SendToSumo(log []byte) {
59-
request, err := http.NewRequest("POST", s.url, bytes.NewBuffer(log))
63+
func (s *SumoLogicAppender) SendToSumo(log string) {
64+
request, err := http.NewRequest("POST", s.url, bytes.NewBufferString(log))
6065
if err != nil {
6166
fmt.Printf("http.NewRequest() error: %v\n", err)
6267
return
6368
}
6469
request.Header.Add("content-type", "application/json")
6570
//request.SetBasicAuth("admin", "admin")
6671
response, err := s.httpClient.Do(request)
72+
6773
if err != nil {
6874
fmt.Printf("http.Do() error: %v\n", err)
6975
return
70-
//consume the body if you want to re-use the connection
7176
} else {
7277
fmt.Println("Do(Request) successful")
7378
}
74-
fmt.Println(response)
7579
defer response.Body.Close()
7680

7781
}

0 commit comments

Comments
 (0)