Documentation ¶
Overview ¶
Package sensu contains types and functions for authoring Go plugins to Sensu.
Index ¶
- Constants
- Variables
- func EventKey(event *corev2.Event) string
- func EventSummary(event *corev2.Event) string
- func EventSummaryWithTrim(event *corev2.Event, trimAt int) string
- func FormattedMessage(event *corev2.Event) string
- type Check
- type ConfigOption
- type ErrValidationFailed
- type GoCheck
- type GoHandler
- type GoMutator
- type Handler
- type MapOptionValue
- type MapPluginConfigOption
- type Mutator
- type OptionValue
- type PluginConfig
- type PluginConfigOption
- type SecurityConfig
- type SetAnnotationResult
- type SliceOptionValue
- type SlicePluginConfigOption
Constants ¶
const ( CheckStateOK = 0 CheckStateWarning = 1 CheckStateCritical = 2 CheckStateUnknown = 3 )
Variables ¶
var NewEnterpriseGoHandler = NewEnterpriseHandler
NewEnterpriseGoHandler is deprecated, use NewEnterpriseHandler
var NewGoCheck = NewCheck
NewGoCheck creates a new check. Deprecated: use NewCheck
var NewGoHandler = NewHandler
NewGoHandler creates a new handler. Deprecated: use NewHandler
var NewGoMutator = NewMutator
NewGoMutator creates a new Mutator. Deprecated: use NewGoMutator
Functions ¶
func EventSummary ¶
EventSummary generates the event summary, without trimming any of the output
func EventSummaryWithTrim ¶
EventSummaryWithTrim generates the event summary, trimming the output at trimAt if necessary
func FormattedMessage ¶
FormattedMessage creates a formatted message, intended for chat rooms etc.
Types ¶
type Check ¶
type Check struct {
// contains filtered or unexported fields
}
Check is a framework for writing sensu checks.
type ConfigOption ¶
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 ¶
type ErrValidationFailed string
ErrValidationFailed should be returned when a configuration validation function fails.
func (ErrValidationFailed) Error ¶
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 ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a framework for writing Sensu handlers.
func NewEnterpriseHandler ¶
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 ¶
func NewHandler(config *PluginConfig, options []ConfigOption, validationFunction func(event *corev2.Event) error, executeFunction func(event *corev2.Event) error) *Handler
NewHandler creates a new handler.
type MapOptionValue ¶
MapOptionValue is like OptionValue but applies to MapPluginConfigOption.
type MapPluginConfigOption ¶
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 ¶
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 ¶
func (p *MapPluginConfigOption[T]) SetValue(valueStr string) (err error)
SetValue sets the configuration value based on a json-encoded string.
type Mutator ¶
type Mutator struct {
// contains filtered or unexported fields
}
Mutator is the framework for writing sensu mutators.
func NewMutator ¶
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.
type OptionValue ¶
type OptionValue interface { ~int | ~int32 | ~int64 | ~uint | ~uint32 | ~uint64 | ~float32 | ~float64 | ~bool | ~string | ~[]string }
OptionValue is a type constraint that creates a compile-time guard against creating a PluginConfigOption with an unsupported data type.
type PluginConfig ¶
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 ¶
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 ¶
func (p *PluginConfigOption[T]) SetValue(valueStr string) (err error)
SetValue sets the configuration value based on either a raw string or json-encoded string.
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 ¶
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 ¶
type SliceOptionValue interface { ~int | ~int32 | ~int64 | ~uint | ~float32 | ~float64 | ~bool | ~string }
SliceOptionValue is like OptionValue but applies to SlicePluginConfigOption.
type SlicePluginConfigOption ¶
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 ¶
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 ¶
func (p *SlicePluginConfigOption[T]) SetValue(valueStr string) (err error)
SetValue sets the configuration value based on either a raw string or json-encoded string.