splunk

package module
v0.0.0-...-8b873cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2021 License: MIT Imports: 8 Imported by: 0

README

Build Status

Splunk Hook for Logrus

Splunk hook for logrus

Install

go get github.com/Franco-Poveda/logrus-splunk-hook

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPClient *http.Client // HTTP client used to communicate with the API
	URL        string
	Hostname   string
	Token      string
	Source     string //Default source
	SourceType string //Default source type
	Index      string //Default index
}

Client manages communication with Splunk's HTTP Event Collector. New client objects should be created using the NewClient function.

The URL field must be defined and pointed at a Splunk servers Event Collector port (i.e. https://{your-splunk-URL}:8088/services/collector). The Token field must be defined with your access token to the Event Collector. The Source, SourceType, and Index fields must be defined.

func NewClient

func NewClient(httpClient *http.Client, URL string, Token string, Source string, SourceType string, Index string) *Client

NewClient creates a new client to Splunk. This should be the primary way a Splunk client object is constructed.

If an httpClient object is specified it will be used instead of the default http.DefaultClient.

func (*Client) Log

func (c *Client) Log(event interface{}) error

Client.Log is used to construct a new log event and POST it to the Splunk server.

All that must be provided for a log event are the desired map[string]string key/val pairs. These can be anything that provide context or information for the situation you are trying to log (i.e. err messages, status codes, etc). The function auto-generates the event timestamp and hostname for you.

func (*Client) LogEvent

func (c *Client) LogEvent(e *Event) error

Client.LogEvent is used to POST a single event to the Splunk server.

func (*Client) LogEvents

func (c *Client) LogEvents(events []*Event) error

Client.LogEvents is used to POST multiple events with a single request to the Splunk server.

func (*Client) LogWithTime

func (c *Client) LogWithTime(t int64, event interface{}) error

Client.LogWithTime is used to construct a new log event with a scpecified timestamp and POST it to the Splunk server.

This is similar to Client.Log, just with the t parameter.

func (*Client) NewEvent

func (c *Client) NewEvent(event interface{}, source string, sourcetype string, index string) *Event

NewEvent creates a new log event to send to Splunk. This should be the primary way a Splunk log object is constructed, and is automatically called by the Log function attached to the client. This method takes the current timestamp for the event, meaning that the event is generated at runtime.

func (*Client) NewEventWithTime

func (c *Client) NewEventWithTime(t int64, event interface{}, source string, sourcetype string, index string) *Event

NewEventWithTime creates a new log event with a specified timetamp to send to Splunk. This is similar to NewEvent but if you want to log in a different time rather than time.Now this becomes handy. If that's the case, use this function to create the Event object and the the LogEvent function.

type Event

type Event struct {
	Time       int64       `json:"time" binding:"required"`                 // epoch time in seconds
	Host       string      `json:"host,omitempty" binding:"required"`       // hostname
	Source     string      `json:"source,omitempty" binding:"required"`     // app name
	SourceType string      `json:"sourcetype,omitempty" binding:"required"` // Splunk bucket to group logs in
	Index      string      `json:"index,omitempty" binding:"required"`      // idk what it does..
	Event      interface{} `json:"event" binding:"required"`                // throw any useful key/val pairs here
}

Event represents the log event object that is sent to Splunk when Client.Log is called.

type Hook

type Hook struct {
	Client *Client
	// contains filtered or unexported fields
}

Hook is a logrus hook for splunk

func NewHook

func NewHook(client *Client, levels []logrus.Level) *Hook

NewHook creates new hook client - splunk client instance (use NewClient) level - log level

func (*Hook) Fire

func (h *Hook) Fire(entry *logrus.Entry) error

Fire triggers a splunk event

func (*Hook) Levels

func (h *Hook) Levels() []logrus.Level

Levels Required for logrus hook implementation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL