Documentation ¶
Overview ¶
Package condition contains logical operators that, based on their configuration, return boolean values from messages under certain circumstances.
Index ¶
- Variables
- func Descriptions() string
- func SanitiseConfig(conf Config) (interface{}, error)
- type And
- type AndConfig
- type Config
- type Count
- type CountConfig
- type JMESPath
- type JMESPathConfig
- type Metadata
- type MetadataConfig
- type Not
- type NotConfig
- type Or
- type OrConfig
- type Resource
- type Static
- type Text
- type TextConfig
- type Type
- func New(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewAnd(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewCount(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewJMESPath(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewMetadata(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewNot(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewOr(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewResource(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewStatic(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewText(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- func NewXor(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)
- type TypeSpec
- type Xor
- type XorConfig
Constants ¶
This section is empty.
Variables ¶
var ( TypeAnd = "and" TypeCount = "count" TypeJMESPath = "jmespath" TypeNot = "not" TypeMetadata = "metadata" TypeOr = "or" TypeResource = "resource" TypeStatic = "static" TypeText = "text" TypeXor = "xor" )
String constants representing each condition type.
var Constructors = map[string]TypeSpec{}
Constructors is a map of all condition types with their specs.
var (
ErrInvalidMetadataOperator = errors.New("invalid metadata operator type")
)
Errors for the metadata condition.
var (
ErrInvalidTextOperator = errors.New("invalid text operator type")
)
Errors for the text condition.
Functions ¶
func Descriptions ¶
func Descriptions() string
Descriptions returns a formatted string of collated descriptions of each type.
func SanitiseConfig ¶
SanitiseConfig returns a sanitised version of the Config, meaning sections that aren't relevant to behaviour are removed.
Types ¶
type And ¶
type And struct {
// contains filtered or unexported fields
}
And is a condition that returns the logical AND of all children.
type AndConfig ¶
type AndConfig []Config
AndConfig is a configuration struct containing fields for the And condition.
func NewAndConfig ¶
func NewAndConfig() AndConfig
NewAndConfig returns a AndConfig with default values.
type Config ¶
type Config struct { Type string `json:"type" yaml:"type"` And AndConfig `json:"and" yaml:"and"` Count CountConfig `json:"count" yaml:"count"` JMESPath JMESPathConfig `json:"jmespath" yaml:"jmespath"` Not NotConfig `json:"not" yaml:"not"` Metadata MetadataConfig `json:"metadata" yaml:"metadata"` Or OrConfig `json:"or" yaml:"or"` Resource string `json:"resource" yaml:"resource"` Static bool `json:"static" yaml:"static"` Text TextConfig `json:"text" yaml:"text"` Xor XorConfig `json:"xor" yaml:"xor"` }
Config is the all encompassing configuration struct for all condition types.
func NewConfig ¶
func NewConfig() Config
NewConfig returns a configuration struct fully populated with default values.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON ensures that when parsing configs that are in a slice the default values are still applied.
func (*Config) UnmarshalYAML ¶
UnmarshalYAML ensures that when parsing configs that are in a slice the default values are still applied.
type Count ¶
type Count struct {
// contains filtered or unexported fields
}
Count is a condition that counts each message and returns false once a target count has been reached, at which point it resets the counter and starts again.
type CountConfig ¶
type CountConfig struct {
Arg int `json:"arg" yaml:"arg"`
}
CountConfig is a configuration struct containing fields for the Count condition.
func NewCountConfig ¶
func NewCountConfig() CountConfig
NewCountConfig returns a CountConfig with default values.
type JMESPath ¶
type JMESPath struct {
// contains filtered or unexported fields
}
JMESPath is a condition that checks message against a jmespath query.
type JMESPathConfig ¶
type JMESPathConfig struct { Part int `json:"part" yaml:"part"` Query string `json:"query" yaml:"query"` }
JMESPathConfig is a configuration struct containing fields for the jmespath condition.
func NewJMESPathConfig ¶
func NewJMESPathConfig() JMESPathConfig
NewJMESPathConfig returns a JMESPathConfig with default values.
type Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
Metadata is a condition that checks message text against logical operators.
type MetadataConfig ¶
type MetadataConfig struct { Operator string `json:"operator" yaml:"operator"` Part int `json:"part" yaml:"part"` Key string `json:"key" yaml:"key"` Arg string `json:"arg" yaml:"arg"` }
MetadataConfig is a configuration struct containing fields for the metadata condition.
func NewMetadataConfig ¶
func NewMetadataConfig() MetadataConfig
NewMetadataConfig returns a MetadataConfig with default values.
type Not ¶
type Not struct {
// contains filtered or unexported fields
}
Not is a condition that returns the opposite of a child condition.
type NotConfig ¶
type NotConfig struct {
*Config
}
NotConfig is a configuration struct containing fields for the Not condition.
func NewNotConfig ¶
func NewNotConfig() NotConfig
NewNotConfig returns a NotConfig with default values.
func (NotConfig) MarshalJSON ¶
MarshalJSON prints an empty object instead of nil.
func (NotConfig) MarshalYAML ¶
MarshalYAML prints an empty object instead of nil.
func (*NotConfig) UnmarshalJSON ¶
UnmarshalJSON ensures that when parsing child config it is initialised.
func (*NotConfig) UnmarshalYAML ¶
UnmarshalYAML ensures that when parsing child config it is initialised.
type Or ¶
type Or struct {
// contains filtered or unexported fields
}
Or is a condition that returns the logical or of all children.
type OrConfig ¶
type OrConfig []Config
OrConfig is a configuration struct containing fields for the Or condition.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource is a condition that returns the result of a condition resource.
type Static ¶
type Static struct {
// contains filtered or unexported fields
}
Static is a condition that always returns a static boolean value.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text is a condition that checks message text against logical operators.
type TextConfig ¶
type TextConfig struct { Operator string `json:"operator" yaml:"operator"` Part int `json:"part" yaml:"part"` Arg string `json:"arg" yaml:"arg"` }
TextConfig is a configuration struct containing fields for the text condition.
func NewTextConfig ¶
func NewTextConfig() TextConfig
NewTextConfig returns a TextConfig with default values.
type Type ¶
type Type interface { // Check tests a message against a configured condition. Check(msg types.Message) bool }
Type reads a message, calculates a condition and returns a boolean.
func NewJMESPath ¶
func NewJMESPath( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewJMESPath returns a JMESPath condition.
func NewMetadata ¶
func NewMetadata( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewMetadata returns a Metadata condition.
func NewResource ¶
func NewResource( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewResource returns a resource condition.
func NewStatic ¶
func NewStatic( conf Config, mgr types.Manager, log log.Modular, stats metrics.Type, ) (Type, error)
NewStatic returns a Static condition.
type TypeSpec ¶
type TypeSpec struct {
// contains filtered or unexported fields
}
TypeSpec Constructor and a usage description for each condition type.