sensu

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT, MIT Imports: 17 Imported by: 56

Documentation

Overview

Package sensu contains types and functions for authoring Go plugins to Sensu.

Index

Constants

View Source
const (
	CheckStateOK       = 0
	CheckStateWarning  = 1
	CheckStateCritical = 2
	CheckStateUnknown  = 3
)

Variables

View Source
var NewEnterpriseGoHandler = NewEnterpriseHandler

NewEnterpriseGoHandler is deprecated, use NewEnterpriseHandler

View Source
var NewGoCheck = NewCheck

NewGoCheck creates a new check. Deprecated: use NewCheck

View Source
var NewGoHandler = NewHandler

NewGoHandler creates a new handler. Deprecated: use NewHandler

View Source
var NewGoMutator = NewMutator

NewGoMutator creates a new Mutator. Deprecated: use NewGoMutator

Functions

func EventKey

func EventKey(event *corev2.Event) string

EventKey returns the event key using the event's entity name and check name

func EventSummary

func EventSummary(event *corev2.Event) string

EventSummary generates the event summary, without trimming any of the output

func EventSummaryWithTrim

func EventSummaryWithTrim(event *corev2.Event, trimAt int) string

EventSummaryWithTrim generates the event summary, trimming the output at trimAt if necessary

func FormattedMessage

func FormattedMessage(event *corev2.Event) string

FormattedMessage creates a formatted message, intended for chat rooms etc.

Types

type Check added in v0.16.0

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

Check is a framework for writing sensu checks.

func NewCheck added in v0.16.0

func NewCheck(config *PluginConfig, options []ConfigOption,
	validationFunction func(*corev2.Event) (int, error),
	executeFunction func(*corev2.Event) (int, error), readEvent bool) *Check

NewCheck creates a new check.

func (*Check) Execute added in v0.16.0

func (c *Check) Execute()

Execute is the check's entry point.

type ConfigOption added in v0.16.0

type ConfigOption interface {
	SetupFlag(*cobra.Command) error
	SetValue(string) error
	SetAnnotationValue(keySpace string, e *corev2.Event) (SetAnnotationResult, error)
}

ConfigOption is an interface. It exists so that users can create slices of configuration options with different types. For instance, []ConfigOption{&PluginConfigOption[int]{}, &PluginConfigOption[string]{}}

func SensuSecurityOptions

func SensuSecurityOptions(config *SecurityConfig) []ConfigOption

SensuSecurityOptions adds the following flags to a plugin:

--sensu-ca-cert
--sensu-insecure-skip-verify

type ErrValidationFailed added in v0.15.0

type ErrValidationFailed string

ErrValidationFailed should be returned when a configuration validation function fails.

func (ErrValidationFailed) Error added in v0.15.0

func (e ErrValidationFailed) Error() string

type GoCheck

type GoCheck = Check

GoCheck is a framework for writing sensu checks. Deprecated: use Check

type GoHandler

type GoHandler = Handler

GoHandler is a framework for writing Sensu handlers. Deprecated: use Handler instead.

type GoMutator

type GoMutator = Mutator

GoMutator is the framework for writing sensu mutators. Deprecated: use Mutator

type Handler added in v0.16.0

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

Handler is a framework for writing Sensu handlers.

func NewEnterpriseHandler added in v0.16.0

func NewEnterpriseHandler(config *PluginConfig, options []ConfigOption,
	validationFunction func(event *corev2.Event) error, executeFunction func(event *corev2.Event) error) *Handler

NewEnterpriseHandler is like NewHandler, but requires a valid license.

func NewHandler added in v0.16.0

func NewHandler(config *PluginConfig, options []ConfigOption,
	validationFunction func(event *corev2.Event) error, executeFunction func(event *corev2.Event) error) *Handler

NewHandler creates a new handler.

func (*Handler) Execute added in v0.16.0

func (h *Handler) Execute()

Execute is the handler's entry point.

type MapOptionValue added in v0.16.0

type MapOptionValue interface {
	~int | ~int64 | ~string
}

MapOptionValue is like OptionValue but applies to MapPluginConfigOption.

type MapPluginConfigOption added in v0.16.0

type MapPluginConfigOption[T MapOptionValue] struct {
	// Value is the value to read the configured flag or environment variable into.
	// It's expected that Value is non-nil
	Value *map[string]T

	// Path is the path to the Sensu annotation to consult when parsing config.
	Path string

	// Env is the environment variable to consult when parsing config.
	Env string

	// Argument is the command line argument to consult when parsing config.
	Argument string

	// Shorthand is the shorthand command line argument to consult when parsing config.
	Shorthand string

	// Default is the default value of the config option.
	Default map[string]T

	// Usage adds help context to the command-line flag.
	Usage string

	// If secret option do not copy Argument value into Default
	Secret bool

	// Restrict prevents the values listed here from being used. If Restrict
	// and Allow are both set, the value set of Restrict is ignored. If the
	// Default value is in the Restrict set, then setting the option value is
	// required.
	Restrict map[string]T

	// Allow prevents using values other than the ones listed here. The Default
	// value is always implicitly part of the allowed set, regardless of what
	// the value of Allow is. If Allow is set, then the values listed in
	// Restrict are ignored. If Allow is not set, or is set to an empty map,
	// then Restrict is consulted.
	Allow map[string]T
}

MapPluginConfigOption is like PluginConfigOption, but permits using maps. The map keys are strings.

func (*MapPluginConfigOption[T]) SetAnnotationValue added in v0.16.0

func (p *MapPluginConfigOption[T]) SetAnnotationValue(keySpace string, event *corev2.Event) (SetAnnotationResult, error)

SetAnnotationValue sets the option value based on a prefix indicated by keyspace, and an event object. The check annotation will be resolved first, followed by the entity annotation.

func (*MapPluginConfigOption[T]) SetValue added in v0.16.0

func (p *MapPluginConfigOption[T]) SetValue(valueStr string) (err error)

SetValue sets the configuration value based on a json-encoded string.

func (*MapPluginConfigOption[T]) SetupFlag added in v0.16.0

func (p *MapPluginConfigOption[T]) SetupFlag(cmd *cobra.Command) error

SetupFlag sets up the option's command line flag, and also binds the associated environment variable, and default value.

type Mutator added in v0.16.0

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

Mutator is the framework for writing sensu mutators.

func NewMutator added in v0.16.0

func NewMutator(config *PluginConfig, options []ConfigOption,
	validationFunction func(event *corev2.Event) error,
	executeFunction func(event *corev2.Event) (*corev2.Event, error)) *Mutator

NewMutator creates a new mutator.

func (*Mutator) Execute added in v0.16.0

func (m *Mutator) Execute()

Execute is the mutator's entry point.

type OptionValue added in v0.16.0

type OptionValue interface {
	~int | ~int32 | ~int64 | ~uint | ~uint32 | ~uint64 | ~float32 | ~float64 | ~bool | ~string
}

OptionValue is a type constraint that creates a compile-time guard against creating a PluginConfigOption with an unsupported data type.

type PluginConfig

type PluginConfig struct {
	Name     string
	Short    string
	Timeout  uint64
	Keyspace string
}

PluginConfig defines the base plugin configuration.

type PluginConfigOption

type PluginConfigOption[T OptionValue] struct {
	// Value is the value to read the configured flag or environment variable into.
	// Pass a pointer to any value in your plugin in order to fill it in with the
	// data from a flag or environment variable. The parsing will be done with
	// a function supplied by viper. See the viper documentation for details on
	// how various data types are parsed.
	Value *T

	// Path is the path to the Sensu annotation to consult when parsing config.
	Path string

	// Env is the environment variable to consult when parsing config.
	Env string

	// Argument is the command line argument to consult when parsing config.
	Argument string

	// Shorthand is the shorthand command line argument to consult when parsing config.
	Shorthand string

	// Default is the default value of the config option.
	Default T

	// Usage adds help context to the command-line flag.
	Usage string

	// If secret option do not copy Argument value into Default
	Secret bool

	// Restrict prevents the values listed here from being used. If Restrict
	// and Allow are both set, the value set of Restrict is ignored. If the
	// Default value is in the Restrict set, then setting the option value is
	// required.
	Restrict []T

	// Allow prevents using values other than the ones listed here. The Default
	// value is always implicitly part of the allowed set, regardless of what
	// the value of Allow is. If Allow is set, then the values listed in
	// Restrict are ignored. If Allow is not set, or is set to an empty slice,
	// then Restrict is consulted.
	Allow []T
}

PluginConfigOption defines an option to be read by the plugin on startup. An option can be passed using a command line argument, an environment variable or at for some plugin types using a configuration override from the Sensu event.

func (*PluginConfigOption[T]) SetAnnotationValue added in v0.16.0

func (p *PluginConfigOption[T]) SetAnnotationValue(keySpace string, event *corev2.Event) (SetAnnotationResult, error)

SetAnnotationValue sets the option value based on a prefix indicated by keyspace, and an event object. The check annotation will be resolved first, followed by the entity annotation.

func (*PluginConfigOption[T]) SetValue added in v0.16.0

func (p *PluginConfigOption[T]) SetValue(valueStr string) (err error)

SetValue sets the configuration value based on either a raw string or json-encoded string.

func (*PluginConfigOption[T]) SetupFlag added in v0.16.0

func (p *PluginConfigOption[T]) SetupFlag(cmd *cobra.Command) error

SetupFlag sets up the option's command line flag, and also binds the associated environment variable, and default value.

type SecurityConfig

type SecurityConfig struct {
	// CACertificate provide a means to use a self-signed certificate with
	// an HTTP client.
	CACertificate string

	// InsecureSkipVerify skips hostname verification for certificates. It is
	// not recommended to use this outside of testing.
	InsecureSkipVerify bool
}

SecurityConfig holds configuration for securely communicating with a Sensu backend.

func (*SecurityConfig) GetCACertificate

func (s *SecurityConfig) GetCACertificate() (*x509.Certificate, error)

GetCACertificate gets the CA certificate associated with the path stored at CACertificate. It returns an error if the file is not found, or if the certificate is not a valid x509 certificate. The certificate can be provided to the CoreClient in the httpclient package.

type SetAnnotationResult added in v0.16.0

type SetAnnotationResult struct {
	AnnotationKey    string
	AnnotationValue  string
	CheckAnnotation  bool
	EntityAnnotation bool
}

SetAnnotationResult is returned by SetAnnotation, and indicates what kind of setter action was taken, if any.

type SliceOptionValue added in v0.16.0

type SliceOptionValue interface {
	~int | ~int32 | ~int64 | ~uint | ~float32 | ~float64 | ~bool | ~string
}

SliceOptionValue is like OptionValue but applies to SlicePluginConfigOption.

type SlicePluginConfigOption added in v0.16.0

type SlicePluginConfigOption[T SliceOptionValue] struct {
	// Value is the value to read the configured flag or environment variable into.
	// It's expected that Value is non-nil.
	Value *[]T

	// Path is the path to the Sensu annotation to consult when parsing config.
	Path string

	// Env is the environment variable to consult when parsing config.
	Env string

	// Argument is the command line argument to consult when parsing config.
	Argument string

	// Shorthand is the shorthand command line argument to consult when parsing config.
	Shorthand string

	// Default is the default value of the config option.
	Default []T

	// Usage adds help context to the command-line flag.
	Usage string

	// If secret option do not copy Argument value into Default
	Secret bool

	// Restrict prevents the values listed here from being used. If Restrict
	// and Allow are both set, the value set of Restrict is ignored. If the
	// Default value is in the Restrict set, then setting the option value is
	// required.
	Restrict []T

	// Allow prevents using values other than the ones listed here. The Default
	// value is always implicitly part of the allowed set, regardless of what
	// the value of Allow is. If Allow is set, then the values listed in
	// Restrict are ignored. If Allow is not set, or is set to an empty map,
	// then Restrict is consulted.
	Allow []T

	// UseCobraStringArray instructs cobra to use the StringArrayVarP call
	// instead of the StringSliceVarP call. This enables slightly different
	// behaviour: space and comma separated values are considered single values,
	// not lists to be split by cobra.
	//
	// Cobra only supports this mode of operation for lists of strings. If
	// the SlicePluginConfigOption is instantiated with a non-string type, then
	// this option will have no effect.
	UseCobraStringArray bool
}

SlicePluginConfigOption is like PluginConfigOption but works with slices of T.

func (*SlicePluginConfigOption[T]) SetAnnotationValue added in v0.16.0

func (p *SlicePluginConfigOption[T]) SetAnnotationValue(keySpace string, event *corev2.Event) (SetAnnotationResult, error)

SetAnnotationValue sets the option value based on a prefix indicated by keyspace, and an event object. The check annotation will be resolved first, followed by the entity annotation.

func (*SlicePluginConfigOption[T]) SetValue added in v0.16.0

func (p *SlicePluginConfigOption[T]) SetValue(valueStr string) (err error)

SetValue sets the configuration value based on either a raw string or json-encoded string.

func (*SlicePluginConfigOption[T]) SetupFlag added in v0.16.0

func (p *SlicePluginConfigOption[T]) SetupFlag(cmd *cobra.Command) error

SetupFlag sets up the option's command line flag, and also binds the associated environment variable, and default value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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