Skip to content

Commit 696cbc7

Browse files
committed
SCFF-21 class that will send the logs to sumo, main methods
1 parent 122b8af commit 696cbc7

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

sumo-log4go/sumoLogicAppender.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package sumoLogicAppender
2+
3+
import(
4+
"net/http"
5+
"net/url"
6+
"bytes"
7+
"log"
8+
"io/ioutil"
9+
"time"
10+
"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/eventRouting"
11+
12+
)
13+
14+
type sumoLogicAppender struct{
15+
string url = nil
16+
int connectionTimeout = 1000
17+
//int socketTimeout = 60000
18+
http.Client httpClient = nil
19+
}
20+
21+
// setUrl receives a pointer to sumoLogicAppender so it can modify it.
22+
func (s *sumoLogicAppender) setUrl(string url) {
23+
s.url = url
24+
}
25+
26+
// connectionTimeout receives a pointer to sumoLogicAppender so it can modify it.
27+
func (s *sumoLogicAppender) connectionTimeout(int connectionTimeout) {
28+
s.connectionTimeout = connectionTimeout
29+
}
30+
31+
// socketTimeout receives a pointer to sumoLogicAppender so it can modify it.
32+
func (s *sumoLogicAppender) socketTimeout(int socketTimeout) {
33+
s.socketTimeout = socketTimeout
34+
}
35+
36+
func (boolean) isInitialized() {
37+
return httpClient != nil;
38+
}
39+
40+
func activateOptions(){
41+
httpClient := {
42+
Timeout: connectionTimeout * time.Millisecod,
43+
}
44+
}
45+
46+
47+
func append(Event event){
48+
if !checkEntryConditions() {
49+
return
50+
}
51+
var buffer bytes.Buffer
52+
buffer.WriteString(event)
53+
reader := bufio.NewReader(resp.Body)
54+
for {
55+
line, err := reader.ReadBytes('\n')
56+
//...
57+
//log.Println(string(line))
58+
}
59+
60+
61+
sendToSumo(buffer.String())
62+
}
63+
64+
func (boolean) checkEntryConditions() {
65+
if httpClient==nil {
66+
return false
67+
}
68+
return true
69+
}
70+
71+
72+
func senToSumo(string log){
73+
if !checkEntryConditions() {
74+
return
75+
}
76+
request, err := http.NewRequest("POST", url, bytes.NewBufferString(log))
77+
//request.SetBasicAuth("admin", "admin")
78+
response, err := httpClient.Do(request)
79+
if !err {
80+
if response.StatusCode !=200 {
81+
//log print "Received HTTP error from Sumo Service:"
82+
}
83+
//consume the body if you want to re-use the connection
84+
}else{
85+
log.Fatal(err)
86+
}
87+
defer response.Body.Close()
88+
89+
}
90+
91+
92+

0 commit comments

Comments
 (0)