Skip to content

Commit e274f65

Browse files
updated docs
1 parent 9936fa8 commit e274f65

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

splunk/splunk.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"errors"
1111
)
1212

13-
// Event represents the log event object that is sent to Splunk when *HTTPCollector.Log is called.
13+
// Event represents the log event object that is sent to Splunk when Client.Log is called.
1414
type Event struct {
1515
Time int64 `json:"time" binding:"required"` // epoch time in seconds
1616
Host string `json:"host" binding:"required"` // hostname
@@ -20,6 +20,13 @@ type Event struct {
2020
Event map[string]string `json:"event" binding:"required"` // throw any useful key/val pairs here
2121
}
2222

23+
24+
// Client manages communication with Splunk's HTTP Event Collector.
25+
// New client objects should be created using the NewClient function.
26+
//
27+
// The URL field must be defined and pointed at a Splunk servers Event Collector port (i.e. https://{your-splunk-URL}:8088/services/collector).
28+
// The Token field must be defined with your access token to the Event Collector.
29+
// The Source, SourceType, and Index fields must be defined.
2330
type Client struct {
2431
HTTPClient *http.Client // HTTP client used to communicate with the API
2532
URL string
@@ -29,6 +36,11 @@ type Client struct {
2936
Index string
3037
}
3138

39+
// NewClient creates a new client to Splunk.
40+
// This should be the primary way a Splunk client object is constructed.
41+
//
42+
// If an httpClient object is specified it will be used instead of the
43+
// default http.DefaultClient.
3244
func NewClient(httpClient *http.Client, URL string, Token string, Source string, SourceType string, Index string) (*Client) {
3345
// Create a new client
3446
if httpClient == nil {
@@ -41,13 +53,20 @@ func NewClient(httpClient *http.Client, URL string, Token string, Source string,
4153
return c
4254
}
4355

56+
// NewEvent creates a new log event to send to Splunk.
57+
// This should be the primary way a Splunk log object is constructed, and is automatically called by the Log function attached to the client.
4458
func NewEvent(event map[string]string, source string, sourcetype string, index string) (Event) {
4559
hostname, _ := os.Hostname()
4660
e := Event{Time: time.Now().Unix(), Host: hostname, Source: source, SourceType: sourcetype, Index: index, Event: event}
4761

4862
return e
4963
}
5064

65+
// Client.Log is used to construct a new log event and POST it to the Splunk server.
66+
//
67+
// All that must be provided for a log event are the desired map[string]string key/val pairs. These can be anything
68+
// that provide context or information for the situation you are trying to log (i.e. err messages, status codes, etc).
69+
// The function auto-generates the event timestamp and hostname for you.
5170
func (c *Client) Log(event map[string]string) (error) {
5271
// create Splunk log
5372
log := NewEvent(event, c.Source, c.SourceType, c.Index)

0 commit comments

Comments
 (0)