A simple and lightweight HTTP Splunk logging package for Go. Instantiates a logging connection object to your Splunk server and allows you to submit log events as desired. Uses HTTP event collection on a Splunk server.
go get "github.com/ZachtimusPrime/Go-Splunk-HTTP/splunk"
Construct a new Splunk HTTP client, then send log events as desired.
For example:
package main
import "github.com/ZachtimusPrime/Go-Splunk-HTTP/splunk"
func main() {
// Create new Splunk client
splunk := splunk.NewClient(
nil,
"https://{your-splunk-URL}:8088/services/collector",
"{your-token}",
"{your-source}",
"{your-sourcetype}",
"{your-index}"
)
// Use the client to send a log with time auto-generated by go host [ time.Now().Unix() ]
err := splunk.Log(
interface{"msg": "send key/val pairs or json objects here", "msg2": "anything that is useful to you in the log event"}
)
if err != nil {
return err
}
// Use the client to send a log with time passed by source
err = splunk.LogWithTime(
1514764800,
interface{"msg": "send key/val pairs or json objects here", "msg2": "anything that is useful to you in the log event"}
)
if err != nil {
return err
}
// Use the client to send a batch of log events
var events []splunk.Event
events = append(
events,
splunk.NewEvent(
interface{"msg": "event1"},
"{desired-source}",
"{desired-sourcetype}",
"{desired-index}"
)
)
events = append(
events,
splunk.NewEvent(
interface{"msg": "event2"},
"{desired-source}",
"{desired-sourcetype}",
"{desired-index}"
)
)
err = splunk.LogEvents(events)
if err != nil {
return err
}
}