outputgelf

package
v0.0.0-...-c13075e Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 22 Imported by: 0

README

gogstash output GELF

GELF (Graylog Extended Log Format) is a Graylog log format

Synopsis

output:
  - type: "gelf"

    # List of Graylog Gelf Input. Format should be host:port
    hosts:
      - localhost:2022

    # (optional)
    # The maximum size of a chunk.
    # Default: 1420
    chunk_size: 1420

    # (optional)
    # The Level of compression.
    # Between 0 (None) to 9 (Best Compression).
    # Default: 1
    compression_level: 1420

    # (optional)
    # Type of compression.
    #  - Gzip: 0
    #  - Zlib: 1
    #  - None: 2
    # Default: 0 (Gzip)
    compression_type: 0

    # (optional)
    # How often to retry to send messages in case it was not delivered successfully
    # Default: 30 seconds
    retry_interval: 30

    # (optional)
    # The maximum size of messages that can be queued (in case of delivery issues) before messages are dropped.
    # Default is one message, use -1 to not limit the queue.
    max_queue_size: 1

Documentation

Index

Constants

View Source
const (
	DefaultChunkSize = 1420
)

Used to control GELF chunking. Should be less than (MTU - len(UDP header)).

TODO: generate dynamically using Path MTU Discovery?

View Source
const ModuleName = "gelf"

ModuleName is the name used in config file

Variables

View Source
var (
	ErrNoValidHosts          = errutil.NewFactory("no valid Hosts found")
	ErrInvalidHost           = errutil.NewFactory("Some host are invalid. Should respect the format: hostname:port")
	ErrorCreateClientFailed1 = errutil.NewFactory("create gelf client failed: %q")
)

errors

Functions

func InitHandler

func InitHandler(
	ctx context.Context,
	raw config.ConfigRaw,
	control config.Control,
) (config.TypeOutputConfig, error)

InitHandler initialize the output plugin

Types

type CompressType

type CompressType int

What compression type the writer should use when sending messages to the graylog2 server

const (
	CompressGzip CompressType = iota
	CompressZlib
	NoCompress
)

type GELFConfig

type GELFConfig struct {
	Host             string
	ChunkSize        int          // Default Value: 1420
	CompressionLevel int          // Default: 1
	CompressionType  CompressType // Default: Gzip
}

type GELFWriter

type GELFWriter interface {
	WriteCustomMessage(ctx context.Context, m *Message) error
	WriteMessage(ctx context.Context, sm *SimpleMessage) error
}

func NewWriter

func NewWriter(config GELFConfig) (GELFWriter, error)

NewWriter returns a new GELFWriter. This writer can be used to send the output of the standard Go log functions to a central GELF server by passing it to log.SetOutput()

type HTTPWriter

type HTTPWriter struct {
	// contains filtered or unexported fields
}

HTTPWriter implements the GELFWriter interface, and cannot be used as an io.Writer

func (HTTPWriter) WriteCustomMessage

func (h HTTPWriter) WriteCustomMessage(ctx context.Context, m *Message) error

func (HTTPWriter) WriteMessage

func (h HTTPWriter) WriteMessage(ctx context.Context, sm *SimpleMessage) error

WriteMessage allow to send messsage to gelf Server It only request basic fields and will handle conversion & co

type Message

type Message struct {
	Extra     map[string]any `json:"-"`
	Full      string         `json:"full_message"`
	Host      string         `json:"host"`
	Level     int32          `json:"level"`
	Short     string         `json:"short_message"`
	Timestamp int64          `json:"timestamp"`
	Version   string         `json:"version"`
}

Message represents the contents of the GELF message. It is gzipped before sending. https://docs.graylog.org/docs/gelf

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

type OutputConfig

type OutputConfig struct {
	config.OutputConfig
	ChunkSize        int      `json:"chunk_size" yaml:"chunk_size"`
	CompressionLevel int      `json:"compression_level" yaml:"compression_level"`
	CompressionType  int      `json:"compression_type" yaml:"compression_type"`
	Hosts            []string `json:"hosts" yaml:"hosts"` // List of Gelf Host servers, format: ip:port

	RetryInterval uint `json:"retry_interval" yaml:"retry_interval"` // seconds before a new retry in case on error
	MaxQueueSize  int  `json:"max_queue_size" yaml:"max_queue_size"` // max size of queue before deleting events (-1=no limit, 0=disable)
	// contains filtered or unexported fields
}

OutputConfig holds the configuration json fields and internal objects

func DefaultOutputConfig

func DefaultOutputConfig() OutputConfig

DefaultOutputConfig returns an OutputConfig struct with default values

func (*OutputConfig) OutputEvent

func (t *OutputConfig) OutputEvent(ctx context.Context, event logevent.LogEvent) (err error)

OutputEvent handle message from the queue

type SimpleMessage

type SimpleMessage struct {
	Extra     map[string]any
	Host      string
	Level     int32
	Message   string
	Timestamp time.Time
}

type UDPWriter

type UDPWriter struct {
	// contains filtered or unexported fields
}

UDPWriter implements io.Writer and is used to send both discrete messages to a graylog2 server, or data from a stream-oriented interface (like the functions in log).

func (*UDPWriter) WriteCustomMessage

func (w *UDPWriter) WriteCustomMessage(ctx context.Context, m *Message) error

WriteCustomMessage sends the specified message to the GELF server specified in the call to NewWriter(). It assumes all the fields are filled out appropriately. In general, clients will want to use Write, rather than WriteMessage.

func (*UDPWriter) WriteMessage

func (w *UDPWriter) WriteMessage(ctx context.Context, sm *SimpleMessage) error

WriteMessage allow to send messsage to gelf Server It only request basic fields and will handle conversion & co

Jump to

Keyboard shortcuts

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