extension

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package extension provides types and functions for creating Sensu extensions in Go. The extensions run as servers and use gRPC as a transport.

Users only need provide a net.Listener, and one or more of the extension methods, to have a fully working Sensu extension. See example for details.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("method not implemented")

ErrNotImplemented is returned by extension methods that haven't been mapped.

Functions

This section is empty.

Types

type Extension

type Extension struct {
	HandlerFunc
	MutatorFunc
	FilterFunc
}

Extension is a convenience type for implementing Interface.

func New

func New() *Extension

New creates a new Extension.

func (*Extension) Filter

func (e *Extension) Filter(fn FilterFunc) *Extension

Filter registers fn as the func to call on FilterEvent.

func (*Extension) Handle

func (e *Extension) Handle(fn HandlerFunc) *Extension

Handle registers fn as the func to call on HandleEvent.

func (*Extension) Mutate

func (e *Extension) Mutate(fn MutatorFunc) *Extension

Mutate registers fn as the func to call on MutateEvent.

type FilterFunc

type FilterFunc func(*types.Event) (bool, error)

func (FilterFunc) FilterEvent

func (f FilterFunc) FilterEvent(e *types.Event) (bool, error)

type HandlerFunc

type HandlerFunc func(*types.Event, []byte) error

func (HandlerFunc) HandleEvent

func (h HandlerFunc) HandleEvent(e *types.Event, m []byte) error

type Interface

type Interface interface {
	// FilterEvent filters an event.
	FilterEvent(*types.Event) (bool, error)

	// MutateEvent mutates an event.
	MutateEvent(*types.Event) ([]byte, error)

	// HandleEvent handles an event. It is passed both the original event
	// and the mutated event, if the event was mutated.
	HandleEvent(*types.Event, []byte) error
}

Interface is the definition of an extension.

type MutatorFunc

type MutatorFunc func(*types.Event) ([]byte, error)

func (MutatorFunc) MutateEvent

func (m MutatorFunc) MutateEvent(e *types.Event) ([]byte, error)

type Server

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

Server is a Sensu extension.

Create new extensions that will run on a local port with NewServer, and then supply any of HandlerFunc, MutatorFunc or FilterFunc via the Handler Mutator

func NewServer

func NewServer(extension Interface, ln net.Listener) *Server

NewServer creates a new server that will run on the provided listener.

func (*Server) FilterEvent

func (s *Server) FilterEvent(ctx context.Context, req *rpc.FilterEventRequest) (*rpc.FilterEventResponse, error)

FilterEvent is called by gRPC.

func (*Server) HandleEvent

func (s *Server) HandleEvent(ctx context.Context, req *rpc.HandleEventRequest) (*rpc.HandleEventResponse, error)

HandleEvent is called by gRPC.

func (*Server) MutateEvent

func (s *Server) MutateEvent(ctx context.Context, req *rpc.MutateEventRequest) (*rpc.MutateEventResponse, error)

MutateEvent is called by gRPC.

func (*Server) Start

func (s *Server) Start() error

Start starts the extension service.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the extension. If the extension's listener was pass in to the extension with NewServerWithListener, then the listener will not be closed by Stop.

Directories

Path Synopsis
This program is a sensu extension.
This program is a sensu extension.

Jump to

Keyboard shortcuts

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