receiver

package
v0.5.2-pre1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: LGPL-2.1 Imports: 14 Imported by: 0

Documentation

Overview

Package receiver provides various skogul Receivers that accept data and execute a handler. They are the "inbound" API of Skogul.

Index

Examples

Constants

This section is empty.

Variables

Auto maps names to Receivers to allow auto configuration

Functions

This section is empty.

Types

type File

type File struct {
	File    string            `doc:"Path to the file to read from once."`
	Handler skogul.HandlerRef `doc:"Handler used to parse, transform and send data."`
	// contains filtered or unexported fields
}

File reads from a FILE, a single JSON object per line, and exits at EOF.

func (*File) Start

func (s *File) Start() error

Start reads a file once, then returns.

type HTTP

type HTTP struct {
	Address  string                        `doc:"Address to listen to." example:"[::1]:80 [2001:db8::1]:443"`
	Handlers map[string]*skogul.HandlerRef `doc:"Paths to handlers. Need at least one." example:"{\"/\": \"someHandler\" }"`
	Auth     map[string]*HTTPAuth          `doc:"A map corresponding to Handlers; specifying authentication for the given path, if required."`
	Certfile string                        `doc:"Path to certificate file for TLS. If left blank, un-encrypted HTTP is used."`
	Keyfile  string                        `doc:"Path to key file for TLS."`
}

HTTP accepts HTTP connections on the Address specified, and requires at least one handler to be set up, using Handle. This is done implicitly if the HTTP receiver is created using New()

Example

HTTP can have different skogul.Handler's for different paths, with potentially different behaviors.

package main

import (
	"github.com/telenornms/skogul"
	"github.com/telenornms/skogul/parser"
	"github.com/telenornms/skogul/receiver"
	"github.com/telenornms/skogul/sender"
	"github.com/telenornms/skogul/transformer"
)

func main() {
	h := receiver.HTTP{Address: "localhost:8080"}
	template := skogul.Handler{Parser: parser.JSON{}, Transformers: []skogul.Transformer{transformer.Templater{}}, Sender: &sender.Debug{}}
	noTemplate := skogul.Handler{Parser: parser.JSON{}, Sender: &sender.Debug{}}
	h.Handlers = map[string]*skogul.HandlerRef{
		"/template":   {H: &template},
		"/notemplate": {H: &noTemplate},
	}
	h.Start()
}
Output:

func (*HTTP) Start

func (htt *HTTP) Start() error

Start never returns.

func (*HTTP) Verify

func (htt *HTTP) Verify() error

Verify verifies the configuration for the HTTP receiver

type HTTPAuth added in v0.3.0

type HTTPAuth struct {
	Username string `doc:"Username for basic authentication. No authentication is required if left blank."`
	Password string `doc:"Password for basic authentication."`
}

HTTPAuth contains ways to authenticate a HTTP request, e.g. Username/Password for Basic Auth.

type LineFile

type LineFile struct {
	File    string            `doc:"Path to the fifo or file from which to read from repeatedly."`
	Handler skogul.HandlerRef `doc:"Handler used to parse and transform and send data."`
	Delay   skogul.Duration   `doc:"Delay before re-opening the file, if any."`
}

LineFile will keep reading File over and over again, assuming one collection per line. Best suited for pointing at a FIFO, which will allow you to 'cat' stuff to Skogul.

func (*LineFile) Start

func (lf *LineFile) Start() error

Start never returns.

type LogrusLog added in v0.3.0

type LogrusLog struct {
	Loglevel string
	Handler  skogul.HandlerRef
}

LogrusLog configures the logrus log receiver

func (*LogrusLog) Start added in v0.3.0

func (lg *LogrusLog) Start() error

Start initializes the logger and sets up required facilities

func (*LogrusLog) Write added in v0.3.0

func (lg *LogrusLog) Write(bytes []byte) (int, error)

Write logrus logs as skogul.Containers to a handler

type LogrusSkogulHook added in v0.3.0

type LogrusSkogulHook struct {
	Writer *LogrusLog
	A      string
}

LogrusSkogulHook is a logrus.Hook made for skogul

func (*LogrusSkogulHook) Fire added in v0.3.0

func (hook *LogrusSkogulHook) Fire(entry *logrus.Entry) error

Fire implements the logrus.Hook interface and handles each log entry

func (*LogrusSkogulHook) Levels added in v0.3.0

func (hook *LogrusSkogulHook) Levels() []logrus.Level

Levels returns the log levels the hook should care about

type MQTT

type MQTT struct {
	Broker   string             `doc:"Address of broker to connect to." example:"[::1]:8888"`
	Topics   []string           `doc:"List of topics to subscribe to"`
	Handler  *skogul.HandlerRef `doc:"Handler used to parse, transform and send data."`
	Password string             `doc:"Username for authenticating to the broker."`
	Username string             `doc:"Password for authenticating."`
	ClientID string             `doc:"Custom client id to use (default: random)"`
	// contains filtered or unexported fields
}

MQTT connects to a MQTT broker and listens for messages on a topic.

func (*MQTT) Start

func (handler *MQTT) Start() error

Start MQTT receiver.

func (*MQTT) Verify added in v0.4.0

func (handler *MQTT) Verify() error

Verify makes sure required configuration options are set

type Stdin

type Stdin struct {
	Handler skogul.HandlerRef `doc:"Handler used to parse, transform and send data."`
	// contains filtered or unexported fields
}

Stdin reads from /dev/stdin

func (*Stdin) Start

func (s *Stdin) Start() error

Start reads from stdin until EOF, then returns

type TCPLine

type TCPLine struct {
	Address string            `doc:"Address and port to listen to." example:"[::1]:3306"`
	Handler skogul.HandlerRef `doc:"Handler used to parse, transform and send data."`
}

TCPLine listens on a IP:TCP port specified in the Address string and accepts one container per line to be sent to the parser.

Example usage, assuming JSON parser:

$ cat payloads/simple.json  | jq -c . | nc '::1' '1234'

Since this is not possible to secure, it should be avoided where possible and placed as close to the data source. A good use of this model is to use a TCPLine receiver on the same box that needs to write to it, combined with skogul.senders.HTTP to forward over a more sensible channel.

func (*TCPLine) Start

func (tl *TCPLine) Start() error

Start the TCP line receiver and run forever.

We close the write-side of the connection leaving it to the other side to finish up. We should probably add a read-timeout in the future.

type Tester

type Tester struct {
	Metrics int64             `doc:"Number of metrics in each container"`
	Values  int64             `doc:"Number of unique values for each metric"`
	Threads int               `doc:"Threads to spawn"`
	Delay   skogul.Duration   `doc:"Sleep time between each metric is generated, if any."`
	Handler skogul.HandlerRef `doc:"Reference to a handler where the data is sent"`
}

Tester synthesise dummy data.

func (*Tester) Start

func (tst *Tester) Start() error

Start never returns.

type UDP

type UDP struct {
	Address string            `doc:"Address and port to listen to." example:"[::1]:3306"`
	Handler skogul.HandlerRef `doc:"Handler used to parse, transform and send data."`
}

UDP contains the configuration for the receiver

func (*UDP) Start

func (ud *UDP) Start() error

Start starts listening for incoming UDP messages on the configured address

Jump to

Keyboard shortcuts

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