graylog

package module
v0.0.0-...-c16c35c Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: MIT Imports: 6 Imported by: 6

README

go-graylog

GoDoc

Graylog GELF messages sending using UDP, TCP or TCP/TLS, written in Golang.

Examples

package main

import (
	"time"

	"github.com/Devatoria/go-graylog"
)

func main() {
    // Initialize a new graylog client with TLS
	g, err := graylog.NewGraylogTLS(graylog.Endpoint{
		Transport: graylog.TCP,
		Address:   "localhost",
		Port:      12202,
	}, 3*time.Second, nil)
	if err != nil {
		panic(err)
	}

    // Send a message
	err = g.Send(graylog.Message{
		Version:      "1.1",
		Host:         "localhost",
		ShortMessage: "Sample test",
		FullMessage:  "Stacktrace",
		Timestamp:    time.Now().Unix(),
		Level:        1,
		Extra: map[string]string{
			"MY-EXTRA-FIELD": "extra_value",
		},
	})
    if err != nil {
        panic(err)
    }

    // Close the graylog connection
    if err := g.Close(); err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	Transport Transport
	Address   string
	Port      uint
}

Endpoint represents a graylog endpoint

type Graylog

type Graylog struct {
	Client    *net.Conn
	TLSClient *tls.Conn
}

Graylog represents an established graylog connection

func NewGraylog

func NewGraylog(e Endpoint) (*Graylog, error)

NewGraylog instanciates a new graylog connection using the given endpoint

func NewGraylogTLS

func NewGraylogTLS(e Endpoint, timeout time.Duration, config *tls.Config) (*Graylog, error)

NewGraylogTLS instanciates a new graylog connection with TLS, using the given endpoint

func (*Graylog) Close

func (g *Graylog) Close() error

Close closes the opened connections of the given client

func (*Graylog) Send

func (g *Graylog) Send(m Message) error

Send writes the given message to the given graylog client

type Message

type Message struct {
	Version      string            `json:"version"`
	Host         string            `json:"host"`
	ShortMessage string            `json:"short_message"`
	FullMessage  string            `json:"full_message,omitempty"`
	Timestamp    int64             `json:"timestamp,omitempty"`
	Level        uint              `json:"level,omitempty"`
	Extra        map[string]string `json:"-"`
}

Message represents a GELF formated message

type Transport

type Transport string

Transport represents a transport type enum

const (
	UDP Transport = "udp"
	TCP Transport = "tcp"
)

Jump to

Keyboard shortcuts

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