metaalarm

package
v0.0.0-...-d841f61 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RulesCollectionName = "meta_alarm_rules"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

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

func NewRuleApplicatorContainer

func NewRuleApplicatorContainer() *Container

func (*Container) Get

func (container *Container) Get(ruleType RuleType) (RuleApplicator, bool)

func (*Container) Has

func (container *Container) Has(ruleType RuleType) bool

func (*Container) Set

func (container *Container) Set(ruleType RuleType, service RuleApplicator)

type Rule

type Rule struct {
	// ID is a unique id for the rule.
	ID string `bson:"_id"`

	// RuleType is the rule's type.
	Type RuleType `bson:"type"`

	Patterns RulePatterns `bson:"patterns,omitempty"`

	Config RuleConfig `bson:"config"`

	// Name was added to identify manual grouping
	Name string `bson:"name"`

	AutoResolve bool `bson:"auto_resolve"`

	OutputTemplate string `bson:"output_template"`
}

type RuleApplicator

type RuleApplicator interface {
	Apply(context.Context, *types.Event, Rule) ([]types.Event, error)
}

type RuleApplicatorContainer

type RuleApplicatorContainer interface {
	Get(RuleType) (RuleApplicator, bool)
	Set(RuleType, RuleApplicator)
}

type RuleConfig

type RuleConfig struct {
	TimeInterval int `bson:"time_interval,omitempty" json:"time_interval,omitempty"`
	// AlarmPatterns represents Alarm's attribute pattern list
	AlarmPatterns pattern.AlarmPatternList `bson:"alarm_patterns,omitempty" json:"alarm_patterns,omitempty"`
	// EntityPatterns represents Entity's attribute pattern list
	EntityPatterns pattern.EntityPatternList `bson:"entity_patterns,omitempty" json:"entity_patterns,omitempty"`
	// TotalEntityPatterns represents Entity's attribute pattern list to find total entity count.
	TotalEntityPatterns *pattern.EntityPatternList `bson:"total_entity_patterns,omitempty" json:"total_entity_patterns,omitempty"`
	// EventPatterns represents Events's attribute pattern list
	EventPatterns pattern.EventPatternList `bson:"event_patterns,omitempty" json:"event_patterns,omitempty"`
	// ThresholdRate is malfunctioning entities rate threshold to trigger the rule
	ThresholdRate *float64 `bson:"threshold_rate,omitempty" json:"threshold_rate,omitempty"`
	// ThresholdCount is malfunctioning entities count threshold to trigger the rule
	ThresholdCount *int64 `bson:"threshold_count,omitempty" json:"threshold_count,omitempty"`
	//
	ValuePaths []string `bson:"value_paths,omitempty" json:"value_paths,omitempty"`
}

type RuleEntityCounter

type RuleEntityCounter interface {
	CountTotalEntitiesAmount(context.Context, Rule) error
	GetTotalEntitiesAmount(context.Context, Rule) (int, error)
}

func NewRuleEntityCounter

func NewRuleEntityCounter(entityAdapter entity.Adapter, redisClient *redis.Client, logger zerolog.Logger) RuleEntityCounter

type RulePatterns

type RulePatterns struct {
	EntityPatterns pattern.EntityPatternList `bson:"entity_patterns,omitempty" json:"entity_patterns,omitempty"`
}

func (*RulePatterns) IsMatched

func (rp *RulePatterns) IsMatched(event types.Event) bool

type RuleType

type RuleType string

RuleType is a type representing the type of an meta-alarm's rule.

const (
	// Component-resource matching
	RuleTypeRelation  RuleType = "relation"
	RuleTypeTimeBased RuleType = "timebased"
	// RuleTypeAttribute for Attribute matching
	RuleTypeAttribute RuleType = "attribute"
	// RuleTypeComplex for complex rules
	RuleTypeComplex RuleType = "complex"

	RuleValueGroup RuleType = "valuegroup"

	RuleManualGroup RuleType = "manualgroup"
)

type RulesAdapter

type RulesAdapter interface {
	// Get read meta-alarm rules from db
	Get() ([]Rule, error)

	Save(Rule) error
	GetManualRule() (Rule, error)
	GetRule(id string) (Rule, error)
}

func NewRuleAdapter

func NewRuleAdapter(dbClient mongo.DbClient) RulesAdapter

NewRuleAdapter returns an rulesAdapter to a rules collection.

type RulesService

type RulesService interface {
	// LoadRules loads the meta-alarm rules from the database, and adds them to the ruleService.
	LoadRules(ctx context.Context) error

	ProcessEvent(context.Context, *types.Event) ([]types.Event, error)
}

func NewRulesService

func NewRulesService(ruleAdapter RulesAdapter, ruleEntityCounter RuleEntityCounter, valueGroupEntityCounter ValueGroupEntityCounter, container *Container, logger zerolog.Logger) RulesService

type ValueGroupEntityCounter

type ValueGroupEntityCounter interface {
	CountTotalEntitiesAmount(ctx context.Context, rule Rule) error
	CountTotalEntitiesAmountForValuePaths(ctx context.Context, rule Rule, valuePathsMap map[string]string) error
	GetTotalEntitiesAmount(ctx context.Context, ruleId string, valueGroup string) (int, error)
}

func NewValueGroupEntityCounter

func NewValueGroupEntityCounter(client mongo.DbClient, redisClient *redis.Client, logger zerolog.Logger) ValueGroupEntityCounter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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