Skip to content

Commit f184466

Browse files
committed
SCFF-23 HTTP post part of the message logs to sumo
1 parent a1eb015 commit f184466

7 files changed

Lines changed: 29 additions & 25 deletions

File tree

caching/caching_boltdb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (c *CachingBolt) GetAllApp() []App {
119119
}
120120

121121
for _, app := range cfApps {
122-
fmt.Printf("App [%s] Found... \n", app.Name)
122+
//fmt.Printf("App [%s] Found... \n", app.Name)
123123
apps = append(apps, App{
124124
app.Name,
125125
app.Guid,
@@ -132,7 +132,7 @@ func (c *CachingBolt) GetAllApp() []App {
132132
}
133133

134134
c.fillDatabase(apps)
135-
fmt.Printf("Found [%d] Apps!", len(apps))
135+
//fmt.Printf("Found [%d] Apps!", len(apps))
136136

137137
return apps
138138
}

eventRouting/eventrouting.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ func (e *EventRouting) RouteEvent(msg *events.Envelope) {
7474
if ignored, hasIgnoredField := event.Fields["cf_ignored_app"]; ignored == true && hasIgnoredField {
7575
e.selectedEventsCount["ignored_app_message"]++
7676
} else {
77-
/*fmt.Printf("I'm in eventRpouting method .. -------")
78-
fmt.Println(event.Fields)
77+
/*fmt.Println("This is the message field")
7978
fmt.Println(event.Msg)*/
80-
e.sLAppender.AppendLogs(event.Fields) //**/here we have to change the method for the one on sumoLogicAppender
79+
e.sLAppender.AppendLogs(event.Fields, event.Msg) //**/here we have to change the method for the one on sumoLogicAppender
8180
e.selectedEventsCount[eventType.String()]++
8281

8382
}
@@ -146,7 +145,7 @@ func (e *EventRouting) LogEventTotals(logTotalsTime time.Duration) {
146145
event, lastCount := e.getEventTotals(totalElapsedTime, elapsedTime, count)
147146
count = lastCount
148147
//*e.log.ShipEvents(event.Fields, event.Msg)
149-
e.sLAppender.AppendLogs(event.Fields)
148+
e.sLAppender.AppendLogs(event.Fields, event.Msg)
150149
}
151150
}()
152151
}

firehoseclient/firehoseclient.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package firehoseclient
22

33
import (
44
"crypto/tls"
5+
"fmt"
56
"time"
67

78
"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/eventRouting"
8-
//*"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/logging"
9-
109
"github.com/cloudfoundry-community/go-cfclient"
1110
"github.com/cloudfoundry/noaa/consumer"
1211
"github.com/cloudfoundry/sonde-go/events"
@@ -44,8 +43,11 @@ func NewFirehoseNozzle(cfClient *cfclient.Client, eventRouting *eventRouting.Eve
4443
}
4544

4645
func (f *FirehoseNozzle) Start() error {
46+
fmt.Printf("Started the Nozzle... \n")
4747
f.consumeFirehose()
48+
fmt.Printf("consume the firehose... \n")
4849
err := f.routeEvent()
50+
fmt.Printf("route event... \n")
4951
return err
5052
}
5153

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/caching"
1010
"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/eventRouting"
1111
"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/firehoseclient"
12-
//*"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/logging"
1312
"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/sumoCFFirehose"
1413
"github.com/cloudfoundry-community/go-cfclient"
1514
"gopkg.in/alecthomas/kingpin.v2"
@@ -18,6 +17,7 @@ import (
1817
var (
1918
debug = true //debug", "Enable debug mode, print in console
2019
apiEndpoint = "https://api.bosh-lite.com"
20+
sumoEndpoint = kingpin.Flag("sumo-endpoint", "Sumo Endpoint").String()
2121
dopplerEndpoint = kingpin.Flag("doppler-endpoint", "Overwrite default doppler endpoint return by /v2/info").OverrideDefaultFromEnvar("DOPPLER_ENDPOINT").String()
2222
subscriptionId = kingpin.Flag("subscription-id", "Id for the subscription.").Default("firehose").OverrideDefaultFromEnvar("FIREHOSE_SUBSCRIPTION_ID").String()
2323
user = "firehose_user" //user created in CF, authorized to connect the firehose
@@ -37,7 +37,9 @@ func main() {
3737
kingpin.Version(version)
3838
kingpin.Parse()
3939

40-
loggingClientSumo := sumoCFFirehose.NewSumoLogicAppender("http://httpbin.org/post", 1000)
40+
fmt.Println("this is the sumo endpoint")
41+
fmt.Println(sumoEndpoint)
42+
loggingClientSumo := sumoCFFirehose.NewSumoLogicAppender(*sumoEndpoint, 1000)
4143

4244
fmt.Printf("Starting firehose-to-sumo %s \n", version)
4345

@@ -91,6 +93,7 @@ func main() {
9193
fmt.Printf("Connected to Server! Connecting to Firehose... \n")
9294
firehoseClient := firehoseclient.NewFirehoseNozzle(cfClient, events, firehoseConfig)
9395
err = firehoseClient.Start()
96+
fmt.Printf("I created the Firehose... \n")
9497
if err != nil {
9598
fmt.Printf("Failed connecting to Firehose...Please check settings and try again! \n") //Log error
9699

sumoCFFirehose/sumoCFFirehose.go

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

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

sumoCFFirehose/sumoLog4gofakes/fake_SumoLog4go.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// This file was generated by counterfeiter
22
package sumoLog4gofakes
33

4-
import (
5-
"sync"
6-
7-
"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/sumoCFFirehose"
8-
)
4+
import "sync"
95

106
type FakeSumoLog4go struct {
117
ConnectStub func() bool
@@ -95,4 +91,4 @@ func (fake *FakeSumoLog4go) recordInvocation(key string, args []interface{}) {
9591
fake.invocations[key] = append(fake.invocations[key], args)
9692
}
9793

98-
var _ sumoCFFirehose.SumoCFFirehose = new(FakeSumoLog4go)
94+
//var _ sumoCFFirehose.SumoCFFirehose = new(FakeSumoLog4go)

sumoCFFirehose/sumoLogicAppender.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func (s *SumoLogicAppender) Connect() bool {
3939
return success
4040
}
4141

42-
func (s *SumoLogicAppender) AppendLogs(Event map[string]interface{}) {
42+
func (s *SumoLogicAppender) AppendLogs(fields map[string]interface{}, message string) {
4343
//adding the message to the map
4444
//fmt.Printf("I'm in AppendLogs method")
45-
if Event == nil {
45+
/*if Event == nil {
4646
return
4747
}
4848
@@ -52,12 +52,16 @@ func (s *SumoLogicAppender) AppendLogs(Event map[string]interface{}) {
5252
5353
if Event["msg"] == "" {
5454
return
55-
}
56-
57-
Message := ""
58-
Message = Event["msg"].(string) + "\n"
59-
55+
}*/
56+
//timestampToInt, err := strconv.ParseInt(fields["timestamp"].(string), 10, 64)
57+
//if err == nil {
58+
//date := time.Unix(timestampToInt, 0)
59+
Message := /*strconv.Itoa(fields["timestamp"]) + */ "\t" + fields["message_type"].(string) + "\t" + message
60+
/*fmt.Println("---------------------I'm about to do an HTTP Post with this message-------------------")
61+
fmt.Println(Message)
62+
fmt.Println("---------------------------------------------------------------------------------------")*/
6063
s.SendToSumo(Message)
64+
//}
6165

6266
}
6367

@@ -67,7 +71,7 @@ func (s *SumoLogicAppender) SendToSumo(log string) {
6771
fmt.Printf("http.NewRequest() error: %v\n", err)
6872
return
6973
}
70-
request.Header.Add("content-type", "application/json")
74+
//request.Header.Add("content-type", "application/json")
7175
//request.SetBasicAuth("admin", "admin")
7276
response, err := s.httpClient.Do(request)
7377

0 commit comments

Comments
 (0)