Skip to content

Commit 094ff9e

Browse files
Merge pull request #12 from atoulme/master
Merge community changes
2 parents f5369e7 + 06d7185 commit 094ff9e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

splunk/splunk.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ import (
66
"encoding/json"
77
"errors"
88
"io"
9+
"io/ioutil"
910
"net/http"
1011
"os"
1112
"time"
1213
)
1314

1415
// Event represents the log event object that is sent to Splunk when Client.Log is called.
1516
type Event struct {
16-
Time int64 `json:"time" binding:"required"` // epoch time in seconds
17-
Host string `json:"host" binding:"required"` // hostname
18-
Source string `json:"source" binding:"required"` // app name
19-
SourceType string `json:"sourcetype" binding:"required"` // Splunk bucket to group logs in
20-
Index string `json:"index" binding:"required"` // idk what it does..
21-
Event interface{} `json:"event" binding:"required"` // throw any useful key/val pairs here
17+
Time int64 `json:"time"` // epoch time in seconds
18+
Host string `json:"host"` // hostname
19+
Source string `json:"source,omitempty"` // optional description of the source of the event; typically the app's name
20+
SourceType string `json:"sourcetype,omitempty"` // optional name of a Splunk parsing configuration; this is usually inferred by Splunk
21+
Index string `json:"index,omitempty"` // optional name of the Splunk index to store the event in; not required if the token has a default index set in Splunk
22+
Event interface{} `json:"event"` // throw any useful key/val pairs here
2223
}
2324

2425
// Client manages communication with Splunk's HTTP Event Collector.
2526
// New client objects should be created using the NewClient function.
2627
//
2728
// The URL field must be defined and pointed at a Splunk servers Event Collector port (i.e. https://{your-splunk-URL}:8088/services/collector).
2829
// The Token field must be defined with your access token to the Event Collector.
29-
// The Source, SourceType, and Index fields must be defined.
3030
type Client struct {
3131
HTTPClient *http.Client // HTTP client used to communicate with the API
3232
URL string
@@ -164,6 +164,8 @@ func (c *Client) doRequest(b *bytes.Buffer) error {
164164
// If statusCode is not good, return error string
165165
switch res.StatusCode {
166166
case 200:
167+
// need to read the reply otherwise the connection hangs
168+
io.Copy(ioutil.Discard, res.Body)
167169
return nil
168170
default:
169171
// Turn response into string and return it

splunk/writer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package splunk
22

33
import (
4+
"encoding/json"
45
"sync"
56
"time"
67
)
@@ -35,7 +36,7 @@ type Writer struct {
3536
// Helpful if we have long flush intervals to more precisely record the time at which
3637
// a message was written
3738
type message struct {
38-
data []byte
39+
data json.RawMessage
3940
writtenAt time.Time
4041
}
4142

0 commit comments

Comments
 (0)