hec

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2017 License: Apache-2.0 Imports: 9 Imported by: 3

README

Splunk HEC Golang Library

Build Status

Build

You need install glide before build. To install all dependencies,

glide install

go build -o build/example ./example/main.go

Example

client := hec.NewCluster(
	[]string{"https://127.0.0.1:8088", "https://localhost:8088"},
	"00000000-0000-0000-0000-000000000000",
)
client.SetHTTPClient(&http.Client{Transport: &http.Transport{
	TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}})

event1 := hec.NewEvent("event one")
event1.SetTime(time.Now())
event2 := hec.NewEvent("event two")
event2.SetTime(time.Now().Add(time.Minute))

err := client.WriteBatch([]*hec.Event{event1, event2})
if err != nil {
	log.Fatal(err)
}

See hec.go for more usages.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func String

func String(str string) *string

Types

type Client

type Client struct {
	HEC
	// contains filtered or unexported fields
}

func (*Client) SetChannel

func (hec *Client) SetChannel(channel string)

func (*Client) SetHTTPClient

func (hec *Client) SetHTTPClient(client *http.Client)

func (*Client) SetKeepAlive

func (hec *Client) SetKeepAlive(enable bool)

func (*Client) WriteBatch

func (hec *Client) WriteBatch(events []*Event) error

func (*Client) WriteEvent

func (hec *Client) WriteEvent(event *Event) error

func (*Client) WriteRaw

func (hec *Client) WriteRaw(events []byte, metadata *EventMetadata) error

type Cluster

type Cluster struct {
	HEC
	// contains filtered or unexported fields
}

func (*Cluster) SetChannel

func (c *Cluster) SetChannel(channel string)

func (*Cluster) SetHTTPClient

func (c *Cluster) SetHTTPClient(httpClient *http.Client)

func (*Cluster) SetKeepAlive

func (c *Cluster) SetKeepAlive(enable bool)

func (*Cluster) WriteBatch

func (c *Cluster) WriteBatch(events []*Event) error

func (*Cluster) WriteEvent

func (c *Cluster) WriteEvent(event *Event) error

func (*Cluster) WriteRaw

func (c *Cluster) WriteRaw(events []byte, metadata *EventMetadata) error

type Event

type Event struct {
	Host       *string     `json:"host,omitempty"`
	Index      *string     `json:"index,omitempty"`
	Source     *string     `json:"source,omitempty"`
	SourceType *string     `json:"sourcetype,omitempty"`
	Time       *string     `json:"time,omitempty"`
	Event      interface{} `json:"event"`
}

func NewEvent

func NewEvent(data interface{}) *Event

func (*Event) SetHost

func (e *Event) SetHost(host string)

func (*Event) SetIndex

func (e *Event) SetIndex(index string)

func (*Event) SetSource

func (e *Event) SetSource(source string)

func (*Event) SetSourceType

func (e *Event) SetSourceType(sourcetype string)

func (*Event) SetTime

func (e *Event) SetTime(time time.Time)

type EventMetadata

type EventMetadata struct {
	Host       *string
	Index      *string
	Source     *string
	SourceType *string
	Time       *time.Time
}

type HEC

type HEC interface {
	SetHTTPClient(client *http.Client)
	SetKeepAlive(enable bool)
	SetChannel(channel string)

	WriteEvent(event *Event) error
	WriteBatch(events []*Event) error
	WriteRaw(events []byte, metadata *EventMetadata) error
}

func NewClient

func NewClient(serverURL string, token string) HEC

func NewCluster

func NewCluster(serverURLs []string, token string) HEC

type Response

type Response struct {
	Text string `json:"text"`
	Code string `json:"code"`
}

Response is response message from HEC. For example, `{"text":"Success","code":0}`.

func (*Response) Error

func (res *Response) Error() string

func (*Response) String

func (res *Response) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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