idlerule

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

Documentation

Overview

Package idlerule contains idle rule model and adapter.

Index

Constants

View Source
const (
	RuleTypeAlarm                = "alarm"
	RuleTypeEntity               = "entity"
	RuleAlarmConditionLastEvent  = "last_event"  // alarms which don't receive events after "now - duration"
	RuleAlarmConditionLastUpdate = "last_update" // alarms which don't change after "now - duration"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Operation

type Operation struct {
	Type       string      `bson:"type" json:"type"`
	Parameters interface{} `bson:"parameters,omitempty" json:"parameters"`
}

func (*Operation) UnmarshalBSONValue

func (o *Operation) UnmarshalBSONValue(_ bsontype.Type, b []byte) error

type Rule

type Rule struct {
	ID             string                    `bson:"_id,omitempty" json:"_id"`
	Name           string                    `bson:"name" json:"name"`
	Description    string                    `bson:"description" json:"description"`
	Author         string                    `bson:"author" json:"author"`
	Enabled        bool                      `bson:"enabled" json:"enabled"`
	Type           string                    `bson:"type" json:"type"`
	Priority       int64                     `bson:"priority" json:"priority"`
	Duration       types.DurationWithUnit    `bson:"duration" json:"duration"`
	EntityPatterns pattern.EntityPatternList `bson:"entity_patterns" json:"entity_patterns"`
	// DisableDuringPeriods is an option that allows to disable the rule
	// when entity is in listed periods due pbehavior schedule.
	DisableDuringPeriods []string      `bson:"disable_during_periods" json:"disable_during_periods"`
	Created              types.CpsTime `bson:"created" json:"created"`
	Updated              types.CpsTime `bson:"updated" json:"updated"`
	// Only for Alarm rules
	AlarmPatterns  pattern.AlarmPatternList `bson:"alarm_patterns,omitempty" json:"alarm_patterns,omitempty"`
	AlarmCondition string                   `bson:"alarm_condition,omitempty" json:"alarm_condition,omitempty"`
	Operation      *Operation               `bson:"operation,omitempty" json:"operation,omitempty"`
}

Rule represents alarm modification condition and operation.

func (*Rule) Matches

func (r *Rule) Matches(alarm *types.Alarm, entity *types.Entity) bool

Matches returns true if alarm and entity match time condition and field patterns.

type RuleAdapter

type RuleAdapter interface {
	// GetEnabled returns all enabled rules.
	GetEnabled(ctx context.Context) ([]Rule, error)
}

RuleAdapter interface is used to implement an storage adapter.

func NewRuleAdapter

func NewRuleAdapter(client mongo.DbClient) RuleAdapter

NewRuleAdapter creates new rule adapter.

Jump to

Keyboard shortcuts

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