rpc

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 Imports: 10 Imported by: 0

README

Sensu RPC Facilities

Extensions

+---------------+       +-------------+
|               +------->             |
| sensu-backend |       | sensu-agent |
|               <-------+             |
+-----+---^-----+  wss  +-------------+
      |   |
      |   | grpc
      |   |
  +---v---+---+
  |           |
  | extension |
  |           |
  +-----------+

Sensu enables user-defined filters, mutators and handlers via a gRPC interface. Developers can implement a gRPC service, and connect it to Sensu. Sensu will call the methods of the gRPC service during pipeline evaluation.

Because extensions use gRPC, developers can write extensions for Sensu in any language that gRPC supports.

To write a Sensu extension, compile the extension.proto file in this package with protoc and a language plugin. For instance,

protoc -I ../../../../ -I . -I ../types/ -I ../vendor/ --go_out=plugins=grpc:. extension.proto

Is the command for building the extension.proto file for Go. However, users can compile the extension.proto file with any language that gRPC supports.

See https://grpc.io/docs/quickstart/ for more information on which languages are supported.

Once the proto has been compiled, use the generated server interface to write an extension definition. This means writing the HandleEvent, MutateEvent and FilterEvent methods, and setting up the service to listen on a port.

If you're working in Go, you can make use of Sensu's extension framework simply by importing it into your code. See the example for details.

Once you have successfully authored an extension, it can be called by Sensu. Extensions will need to be managed as their own service, external to Sensu. While it is technically possible for Sensu to access these extensions over remote links, it is far more reliable to operate them on the same node the backend is running on.

See the sensuctl extension command for more information.

Documentation

Overview

Package rpc defines extension points for Sensu that can be used by third parties to extend Sensu.

More information can be found in the Extensions proposal and design document.

https://github.com/sensu/proposal/blob/master/design/1043-extensions.md

Index

Constants

View Source
const ExtensionTimeout = 5 * time.Second

Variables

This section is empty.

Functions

func RegisterExtensionServer

func RegisterExtensionServer(s *grpc.Server, srv ExtensionServer)

Types

type ExtensionClient

type ExtensionClient interface {
	HandleEvent(ctx context.Context, in *HandleEventRequest, opts ...grpc.CallOption) (*HandleEventResponse, error)
	MutateEvent(ctx context.Context, in *MutateEventRequest, opts ...grpc.CallOption) (*MutateEventResponse, error)
	FilterEvent(ctx context.Context, in *FilterEventRequest, opts ...grpc.CallOption) (*FilterEventResponse, error)
}

func NewExtensionClient

func NewExtensionClient(cc *grpc.ClientConn) ExtensionClient

type ExtensionExecutor

type ExtensionExecutor 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) (HandleEventResponse, error)

	// Close closes the underlying TCP connection of the executor
	Close() error
}

ExtensionExecutor executes extensions.

func NewGRPCExtensionExecutor

func NewGRPCExtensionExecutor(ext *types.Extension) (ExtensionExecutor, error)

NewGRPCExtensionExecutor creates a new GRPCExtensionExecutor.

type FilterEventRequest

type FilterEventRequest struct {
	Event                *types.Event `protobuf:"bytes,1,opt,name=event" json:"event,omitempty"`
	XXX_NoUnkeyedLiteral struct{}     `json:"-"`
	XXX_unrecognized     []byte       `json:"-"`
	XXX_sizecache        int32        `json:"-"`
}

func (*FilterEventRequest) Descriptor

func (*FilterEventRequest) Descriptor() ([]byte, []int)

func (*FilterEventRequest) GetEvent

func (m *FilterEventRequest) GetEvent() *types.Event

func (*FilterEventRequest) ProtoMessage

func (*FilterEventRequest) ProtoMessage()

func (*FilterEventRequest) Reset

func (m *FilterEventRequest) Reset()

func (*FilterEventRequest) String

func (m *FilterEventRequest) String() string

func (*FilterEventRequest) XXX_DiscardUnknown

func (m *FilterEventRequest) XXX_DiscardUnknown()

func (*FilterEventRequest) XXX_Marshal

func (m *FilterEventRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*FilterEventRequest) XXX_Merge

func (dst *FilterEventRequest) XXX_Merge(src proto.Message)

func (*FilterEventRequest) XXX_Size

func (m *FilterEventRequest) XXX_Size() int

func (*FilterEventRequest) XXX_Unmarshal

func (m *FilterEventRequest) XXX_Unmarshal(b []byte) error

type FilterEventResponse

type FilterEventResponse struct {
	Filtered             bool     `protobuf:"varint,1,opt,name=filtered" json:"filtered,omitempty"`
	Error                string   `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*FilterEventResponse) Descriptor

func (*FilterEventResponse) Descriptor() ([]byte, []int)

func (*FilterEventResponse) GetError

func (m *FilterEventResponse) GetError() string

func (*FilterEventResponse) GetFiltered

func (m *FilterEventResponse) GetFiltered() bool

func (*FilterEventResponse) ProtoMessage

func (*FilterEventResponse) ProtoMessage()

func (*FilterEventResponse) Reset

func (m *FilterEventResponse) Reset()

func (*FilterEventResponse) String

func (m *FilterEventResponse) String() string

func (*FilterEventResponse) XXX_DiscardUnknown

func (m *FilterEventResponse) XXX_DiscardUnknown()

func (*FilterEventResponse) XXX_Marshal

func (m *FilterEventResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*FilterEventResponse) XXX_Merge

func (dst *FilterEventResponse) XXX_Merge(src proto.Message)

func (*FilterEventResponse) XXX_Size

func (m *FilterEventResponse) XXX_Size() int

func (*FilterEventResponse) XXX_Unmarshal

func (m *FilterEventResponse) XXX_Unmarshal(b []byte) error

type GRPCExtensionExecutor

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

GRPCExtensionExecutor executes extension rpc methods.

func (*GRPCExtensionExecutor) Close

func (e *GRPCExtensionExecutor) Close() error

Close closes the extension executor. It will not be usable after Close is called.

func (*GRPCExtensionExecutor) FilterEvent

func (e *GRPCExtensionExecutor) FilterEvent(evt *types.Event) (bool, error)

FilterEvent filters an event.

func (*GRPCExtensionExecutor) HandleEvent

func (e *GRPCExtensionExecutor) HandleEvent(evt *types.Event, mutatedEvt []byte) (HandleEventResponse, error)

HandleEvent handles an event.

func (*GRPCExtensionExecutor) MutateEvent

func (e *GRPCExtensionExecutor) MutateEvent(evt *types.Event) ([]byte, error)

MutateEvent mutates an event.

type HandleEventRequest

type HandleEventRequest struct {
	Event                *types.Event `protobuf:"bytes,1,opt,name=event" json:"event,omitempty"`
	MutatedEvent         []byte       `protobuf:"bytes,2,opt,name=mutated_event,json=mutatedEvent,proto3" json:"mutated_event,omitempty"`
	XXX_NoUnkeyedLiteral struct{}     `json:"-"`
	XXX_unrecognized     []byte       `json:"-"`
	XXX_sizecache        int32        `json:"-"`
}

func (*HandleEventRequest) Descriptor

func (*HandleEventRequest) Descriptor() ([]byte, []int)

func (*HandleEventRequest) GetEvent

func (m *HandleEventRequest) GetEvent() *types.Event

func (*HandleEventRequest) GetMutatedEvent

func (m *HandleEventRequest) GetMutatedEvent() []byte

func (*HandleEventRequest) ProtoMessage

func (*HandleEventRequest) ProtoMessage()

func (*HandleEventRequest) Reset

func (m *HandleEventRequest) Reset()

func (*HandleEventRequest) String

func (m *HandleEventRequest) String() string

func (*HandleEventRequest) XXX_DiscardUnknown

func (m *HandleEventRequest) XXX_DiscardUnknown()

func (*HandleEventRequest) XXX_Marshal

func (m *HandleEventRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HandleEventRequest) XXX_Merge

func (dst *HandleEventRequest) XXX_Merge(src proto.Message)

func (*HandleEventRequest) XXX_Size

func (m *HandleEventRequest) XXX_Size() int

func (*HandleEventRequest) XXX_Unmarshal

func (m *HandleEventRequest) XXX_Unmarshal(b []byte) error

type HandleEventResponse

type HandleEventResponse struct {
	Error                string   `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"`
	Output               string   `protobuf:"bytes,2,opt,name=output" json:"output,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*HandleEventResponse) Descriptor

func (*HandleEventResponse) Descriptor() ([]byte, []int)

func (*HandleEventResponse) GetError

func (m *HandleEventResponse) GetError() string

func (*HandleEventResponse) GetOutput

func (m *HandleEventResponse) GetOutput() string

func (*HandleEventResponse) ProtoMessage

func (*HandleEventResponse) ProtoMessage()

func (*HandleEventResponse) Reset

func (m *HandleEventResponse) Reset()

func (*HandleEventResponse) String

func (m *HandleEventResponse) String() string

func (*HandleEventResponse) XXX_DiscardUnknown

func (m *HandleEventResponse) XXX_DiscardUnknown()

func (*HandleEventResponse) XXX_Marshal

func (m *HandleEventResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HandleEventResponse) XXX_Merge

func (dst *HandleEventResponse) XXX_Merge(src proto.Message)

func (*HandleEventResponse) XXX_Size

func (m *HandleEventResponse) XXX_Size() int

func (*HandleEventResponse) XXX_Unmarshal

func (m *HandleEventResponse) XXX_Unmarshal(b []byte) error

type MutateEventRequest

type MutateEventRequest struct {
	Event                *types.Event `protobuf:"bytes,1,opt,name=event" json:"event,omitempty"`
	XXX_NoUnkeyedLiteral struct{}     `json:"-"`
	XXX_unrecognized     []byte       `json:"-"`
	XXX_sizecache        int32        `json:"-"`
}

func (*MutateEventRequest) Descriptor

func (*MutateEventRequest) Descriptor() ([]byte, []int)

func (*MutateEventRequest) GetEvent

func (m *MutateEventRequest) GetEvent() *types.Event

func (*MutateEventRequest) ProtoMessage

func (*MutateEventRequest) ProtoMessage()

func (*MutateEventRequest) Reset

func (m *MutateEventRequest) Reset()

func (*MutateEventRequest) String

func (m *MutateEventRequest) String() string

func (*MutateEventRequest) XXX_DiscardUnknown

func (m *MutateEventRequest) XXX_DiscardUnknown()

func (*MutateEventRequest) XXX_Marshal

func (m *MutateEventRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MutateEventRequest) XXX_Merge

func (dst *MutateEventRequest) XXX_Merge(src proto.Message)

func (*MutateEventRequest) XXX_Size

func (m *MutateEventRequest) XXX_Size() int

func (*MutateEventRequest) XXX_Unmarshal

func (m *MutateEventRequest) XXX_Unmarshal(b []byte) error

type MutateEventResponse

type MutateEventResponse struct {
	MutatedEvent         []byte   `protobuf:"bytes,1,opt,name=mutated_event,json=mutatedEvent,proto3" json:"mutated_event,omitempty"`
	Error                string   `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*MutateEventResponse) Descriptor

func (*MutateEventResponse) Descriptor() ([]byte, []int)

func (*MutateEventResponse) GetError

func (m *MutateEventResponse) GetError() string

func (*MutateEventResponse) GetMutatedEvent

func (m *MutateEventResponse) GetMutatedEvent() []byte

func (*MutateEventResponse) ProtoMessage

func (*MutateEventResponse) ProtoMessage()

func (*MutateEventResponse) Reset

func (m *MutateEventResponse) Reset()

func (*MutateEventResponse) String

func (m *MutateEventResponse) String() string

func (*MutateEventResponse) XXX_DiscardUnknown

func (m *MutateEventResponse) XXX_DiscardUnknown()

func (*MutateEventResponse) XXX_Marshal

func (m *MutateEventResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MutateEventResponse) XXX_Merge

func (dst *MutateEventResponse) XXX_Merge(src proto.Message)

func (*MutateEventResponse) XXX_Size

func (m *MutateEventResponse) XXX_Size() int

func (*MutateEventResponse) XXX_Unmarshal

func (m *MutateEventResponse) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis
Package extension provides types and functions for creating Sensu extensions in Go.
Package extension provides types and functions for creating Sensu extensions in Go.
example
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