correlation

package
v0.0.0-...-9b5cd94 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMetaAlarmEntityPrefix  = "meta-alarm-entity-"
	DefaultMetaAlarmComponent     = "metaalarm"
	DefaultMetaAlarmConnector     = "engine"
	DefaultMetaAlarmConnectorName = "correlation"

	InfosKeyMetaAlarmMeta = "Meta"

	DefaultConfigTimeInterval = 86400
)
View Source
const (
	RuleTypeRelation    = "relation"
	RuleTypeTimeBased   = "timebased"
	RuleTypeAttribute   = "attribute"
	RuleTypeComplex     = "complex"
	RuleTypeValueGroup  = "valuegroup"
	RuleTypeManualGroup = "manualgroup"
	RuleTypeCorel       = "corel"
)
View Source
const (
	Opened = iota
	Ready
	Created
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventExtraInfosMeta

type EventExtraInfosMeta struct {
	Rule     Rule
	Count    int64
	Children types.AlarmWithEntity
}

type MetaAlarmState

type MetaAlarmState struct {
	ID string `bson:"_id"`

	// MetaAlarmName is meta alarm entity name
	MetaAlarmName string `bson:"meta_alarm_name"`

	Version int64 `bson:"version"`
	State   int   `bson:"state"`

	ChildrenEntityIDs  []string `bson:"children_entity_ids"`
	ChildrenTimestamps []int64  `bson:"children_timestamps"`

	// only for corel rule type
	ParentsEntityIDs  []string `bson:"parents_entity_ids"`
	ParentsTimestamps []int64  `bson:"parents_timestamps"`

	// ExpiredAt is used to remove expired state.
	// Type should be time.Time for ttl index.
	ExpiredAt time.Time `bson:"expired_at,omitempty"`

	ChildInactiveExpireAt *datetime.CpsTime `bson:"child_inactive_expire_at,omitempty"`
}

func (*MetaAlarmState) GetChildrenOpenTime

func (s *MetaAlarmState) GetChildrenOpenTime() int64

func (*MetaAlarmState) GetParentOpenTime

func (s *MetaAlarmState) GetParentOpenTime() int64

func (*MetaAlarmState) IsOutdated

func (s *MetaAlarmState) IsOutdated(alarmLastUpdate, timeInterval int64) bool

func (*MetaAlarmState) PushChild

func (s *MetaAlarmState) PushChild(entityID string, timestamp int64, ruleTimeInterval int64) []string

func (*MetaAlarmState) PushParent

func (s *MetaAlarmState) PushParent(entityID string, timestamp int64, ruleTimeInterval int64)

func (*MetaAlarmState) RemoveChildrenBefore

func (s *MetaAlarmState) RemoveChildrenBefore(timestamp int64)

func (*MetaAlarmState) RemoveParentsBefore

func (s *MetaAlarmState) RemoveParentsBefore(timestamp int64)

func (*MetaAlarmState) Reset

func (s *MetaAlarmState) Reset(id string)

func (*MetaAlarmState) ResetChildInactiveExpireAt

func (s *MetaAlarmState) ResetChildInactiveExpireAt(childInactiveDelay *datetime.DurationWithUnit)

func (*MetaAlarmState) ResetExpireAt

func (s *MetaAlarmState) ResetExpireAt(timeIntervalInSeconds int64)

type MetaAlarmStateService

type MetaAlarmStateService interface {
	// GetMetaAlarmState returns current alarm state.
	GetMetaAlarmState(ctx context.Context, ruleID string) (MetaAlarmState, error)
	// UpdateOpenedState updates opened metaalarm state by increasing its version and replaces alarm groups.
	UpdateOpenedState(ctx context.Context, state MetaAlarmState, previousVersion int64, previousState int, upsert bool) (bool, error)
	// ArchiveState moves state to a separate document, needed for late create metaalarm events to get their state instead of new one.
	ArchiveState(ctx context.Context, state MetaAlarmState) (bool, error)
	// SwitchStateToReady switch state status to ready, should be used only after metaalarm is triggered.
	SwitchStateToReady(ctx context.Context, state MetaAlarmState, previousVersion int64, previousState int, upsert bool) (bool, error)
	// SwitchStateToCreated switch state status to created, should be used only after or during the metaalarm creation.
	SwitchStateToCreated(ctx context.Context, stateID string) (bool, error)
	// PushChild pushes child to the child group in the DB, should be used only when group is gathered and metaalarm is triggered.
	PushChild(ctx context.Context, state MetaAlarmState, previousVersion int64, previousState int, entityID string, alarmLastUpdate int64) (bool, error)
	// RefreshMetaAlarmStateGroup removes resolved alarms and current event entity from the group.
	RefreshMetaAlarmStateGroup(ctx context.Context, state *MetaAlarmState, entityID string, timeInterval int64) error
	RemoveInactiveDelay(ctx context.Context, ruleId string, entityIds []string) error
	AddInactiveDelay(ctx context.Context, entityId, ruleId string, d datetime.CpsTime) error
	UpdateInactiveDelay(ctx context.Context, entityId, ruleId string, d datetime.CpsTime) error
}

func NewMetaAlarmStateService

func NewMetaAlarmStateService(dbClient mongo.DbClient) MetaAlarmStateService

type Rule

type Rule struct {
	ID             string     `bson:"_id" json:"_id"`
	Type           string     `bson:"type" json:"type"`
	Name           string     `bson:"name" json:"name"`
	Author         string     `bson:"author" json:"author"`
	OutputTemplate string     `bson:"output_template" json:"output_template"`
	Config         RuleConfig `bson:"config" json:"config"`
	AutoResolve    bool       `bson:"auto_resolve" json:"auto_resolve"`

	savedpattern.EntityPatternFields `bson:",inline"`
	savedpattern.AlarmPatternFields  `bson:",inline"`
	TotalEntityPatternFields         `bson:",inline"`

	Created *datetime.CpsTime `bson:"created,omitempty" json:"created,omitempty" swaggertype:"integer"`
	Updated *datetime.CpsTime `bson:"updated,omitempty" json:"updated,omitempty" swaggertype:"integer"`
}

func (*Rule) IsManual

func (r *Rule) IsManual() bool

func (*Rule) Matches

func (r *Rule) Matches(alarmWithEntity types.AlarmWithEntity) (bool, error)

type RuleConfig

type RuleConfig struct {
	// TimeInterval defines the length of the time window for alarm groups.
	TimeInterval *datetime.DurationWithUnit `bson:"time_interval,omitempty" json:"time_interval,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 int `bson:"threshold_count,omitempty" json:"threshold_count,omitempty"`
	// ValuePaths defines entity fields by which alarms should be correlated, only for valuegroup type of rules.
	ValuePaths []string `bson:"value_paths,omitempty" json:"value_paths,omitempty"`
	// CorelID is an AlarmWithEntity template to mark that alarms are correlated.
	CorelID string `bson:"corel_id,omitempty" json:"corel_id,omitempty"`
	// CorelStatus is an AlarmWithEntity template to get correlation relation value.
	CorelStatus string `bson:"corel_status,omitempty" json:"corel_status,omitempty"`
	// CorelParent is the correlation relation value, which mark alarm as a parent.
	CorelParent string `bson:"corel_parent,omitempty" json:"corel_parent,omitempty"`
	// CorelChild is the correlation relation value, which mark alarm as a child.
	CorelChild string `bson:"corel_child,omitempty" json:"corel_child,omitempty"`

	ChildInactiveDelay *datetime.DurationWithUnit `bson:"child_inactive_delay,omitempty" json:"child_inactive_delay,omitempty"`
}

func (*RuleConfig) GetTimeIntervalInSeconds

func (c *RuleConfig) GetTimeIntervalInSeconds() int64

type RulesAdapter

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

	Save(ctx context.Context, r Rule) error
	GetManualRule(ctx context.Context, autoResolve bool) (Rule, error)
	GetRule(ctx context.Context, id string) (Rule, error)
}

func NewRuleAdapter

func NewRuleAdapter(dbClient mongo.DbClient) RulesAdapter

NewRuleAdapter returns an rulesAdapter to a rules collection.

type TotalEntityPatternFields

type TotalEntityPatternFields struct {
	TotalEntityPattern pattern.Entity `bson:"total_entity_pattern" json:"total_entity_pattern,omitempty"`

	CorporateTotalEntityPattern      string `bson:"corporate_total_entity_pattern" json:"corporate_total_entity_pattern,omitempty"`
	CorporateTotalEntityPatternTitle string `bson:"corporate_total_entity_pattern_title" json:"corporate_total_entity_pattern_title,omitempty"`
}

Jump to

Keyboard shortcuts

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