rule

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: GPL-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const RetryNever = time.Duration(math.MaxInt64)

RetryNever indicates that an escalation condition should never be retried once it has been evaluated.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelOrigin added in v1.0.0

type ChannelOrigin struct {
	ChannelID      int64
	RuleID         int64 // Zero if the contact subscribed via web-gui
	RuleEntryID    int64 // Zero if the contact subscribed via web-gui
	ContactGroupID int64 // Non-zero if the contact was resolved from a contact group.
	ScheduleID     int64 // Non-zero if the contact was resolved from a schedule.
	Role           recipient.Role

	// IncidentRelated is true if the contact is notified as a recipient of the incident (escalation recipient,
	// subscriber, manager) rather than through a notification rule.
	IncidentRelated bool

	// BypassSuppression marks an origin that may be notified even though the incident is muted.
	//
	// It is set for recipient+channel pairs of a newly triggered escalation that are not yet known to the incident.
	BypassSuppression bool
}

ChannelOrigin identifies the entry recipient through which a contact's channel was selected.

A zero value denotes a contact that was added without any rule involvement, e.g. a recipient that subscribed to or manages an incident via the UI.

func (ChannelOrigin) RecipientKey added in v1.0.0

func (o ChannelOrigin) RecipientKey(contact *recipient.Contact) recipient.Key

RecipientKey returns the key of the recipient based on its origin.

type ContactChannelPair

type ContactChannelPair struct {
	Contact   *recipient.Contact
	ChannelID types.Int
}

type ContactChannels

type ContactChannels map[*recipient.Contact][]ChannelOrigin

ContactChannels stores, per contact and channel ID, the origins that selected this channel.

When multiple entry recipients resolve to the same contact and channel, all their origins are recorded: the first origin is the one the notification is attributed to, any further ones denote duplicates that would have notified the same contact via the same channel.

func (ContactChannels) LoadFromEntryRecipients added in v1.0.0

func (ch ContactChannels) LoadFromEntryRecipients(entry *Entry, t time.Time, isNotifiable IsNotifiableFn, opts ...LoadRecipientOption)

LoadFromEntryRecipients adds the channels of all contacts resolved from entry's recipients at time t.

The isNotifiable callback is used to filter out recipients that should not be notified. Additionally, LoadRecipientOption opts can be provided to customize the ChannelOrigin for each loaded recipient channel.

type Entry added in v1.0.0

type Entry struct {
	baseconf.IncrementalPkDbEntry[int64] `db:",inline"`

	RuleID        int64        `db:"rule_id"`
	Position      types.Int    `db:"position"`
	NameRaw       types.String `db:"name"`
	ConditionExpr types.String `db:"condition"`
	FallbackForID types.Int    `db:"fallback_for"`

	Condition  filter.Filter     `db:"-"`
	Fallbacks  []*Entry          `db:"-"`
	Recipients []*EntryRecipient `db:"-"`
}

Entry represents a single entry in a rule, which can be either an escalation stage or a notification recipient set.

For escalation rules it is an escalation stage whose Entry.Condition is evaluated against an EscalationFilter, and for notification rules it is a recipient set whose Entry.Condition is evaluated against a NotificationFilter.

func (*Entry) DisplayName added in v1.0.0

func (e *Entry) DisplayName() string

func (*Entry) Eval added in v1.0.0

func (e *Entry) Eval(filterable filter.Filterable) (bool, error)

Eval reports whether the entry's Condition matches filterable.

Entries without a condition always match.

func (*Entry) GetContactsAt added in v1.0.0

func (e *Entry) GetContactsAt(t time.Time) []ContactChannelPair

func (*Entry) IncrementalInitAndValidate added in v1.0.0

func (e *Entry) IncrementalInitAndValidate() error

IncrementalInitAndValidate implements the config.IncrementalConfigurableInitAndValidatable interface.

func (*Entry) MarshalLogObject added in v1.0.0

func (e *Entry) MarshalLogObject(encoder zapcore.ObjectEncoder) error

MarshalLogObject implements the zapcore.ObjectMarshaler interface.

This allows us to use `zap.Inline(entry)` or `zap.Object("rule_entry", entry)` wherever fine-grained logging context is needed, without having to add all the individual fields ourselves each time. https://pkg.go.dev/go.uber.org/zap/zapcore#ObjectMarshaler

func (*Entry) TableName added in v1.0.0

func (e *Entry) TableName() string

type EntryRecipient added in v1.0.0

type EntryRecipient struct {
	baseconf.IncrementalPkDbEntry[int64] `db:",inline"`

	EntryID       int64     `db:"rule_entry_id"`
	ChannelID     types.Int `db:"channel_id"`
	recipient.Key `db:",inline"`
	Recipient     recipient.Recipient `db:"-"`
}

func (*EntryRecipient) MarshalLogObject added in v1.0.0

func (r *EntryRecipient) MarshalLogObject(encoder zapcore.ObjectEncoder) error

MarshalLogObject implements the zapcore.ObjectMarshaler interface.

func (*EntryRecipient) TableName added in v1.0.0

func (r *EntryRecipient) TableName() string

type EscalationFilter

type EscalationFilter struct {
	IncidentAge      time.Duration
	IncidentSeverity event.Severity
	IsManaged        bool
}

func (*EscalationFilter) EvalEqual

func (e *EscalationFilter) EvalEqual(key []string, value any) (bool, error)

func (*EscalationFilter) EvalExists

func (e *EscalationFilter) EvalExists(key []string) bool

func (*EscalationFilter) EvalLess

func (e *EscalationFilter) EvalLess(key []string, value any) (bool, error)

func (*EscalationFilter) EvalLessOrEqual

func (e *EscalationFilter) EvalLessOrEqual(key []string, value any) (bool, error)

func (*EscalationFilter) EvalLike

func (e *EscalationFilter) EvalLike(_ []string, _ any) (bool, error)

func (*EscalationFilter) ReevaluateAfter

func (e *EscalationFilter) ReevaluateAfter(escalationCond filter.Filter) time.Duration

ReevaluateAfter returns the duration after which escalationCond should be reevaluated the next time on the incident represented by e.

escalationCond must correspond to an escalation that did not trigger on the incident represented by e before. If nothing in the incident changes apart from time passing by, the escalation is guaranteed to not trigger within the returned duration. After that duration, the escalation should be reevaluated, and it may or may not trigger. If anything else changes, for example due to an external event, the escalation must be reevaluated as well.

type FilterAttrsType added in v1.0.0

type FilterAttrsType [][]string

FilterAttrsType represents a list of filter attributes for a given list of filter conditions.

type IsNotifiableFn added in v1.0.0

type IsNotifiableFn func(recipient.Key) bool

IsNotifiableFn is a callback function type that determines whether a specific recipient should be considered for notification.

type LoadRecipientOption added in v1.0.0

type LoadRecipientOption func(*EntryRecipient, *ChannelOrigin)

LoadRecipientOption is a functional option type that allows customization of the ChannelOrigin when loading recipient channels.

func WithIncidentRelated added in v1.0.0

func WithIncidentRelated() LoadRecipientOption

WithIncidentRelated returns a LoadRecipientOption that sets the IncidentRelated flag on the ChannelOrigin.

type NotificationFilter added in v1.0.0

type NotificationFilter struct {
	EventType string
}

NotificationFilter is the filter.Filterable for notification rule entry conditions.

It only knows the event_type attribute and supports equality and existence checks. Using any other operator returns an error.

func (*NotificationFilter) EvalEqual added in v1.0.0

func (n *NotificationFilter) EvalEqual(key []string, value any) (bool, error)

func (*NotificationFilter) EvalExists added in v1.0.0

func (n *NotificationFilter) EvalExists(key []string) bool

func (*NotificationFilter) EvalLess added in v1.0.0

func (n *NotificationFilter) EvalLess(_ []string, _ any) (bool, error)

func (*NotificationFilter) EvalLessOrEqual added in v1.0.0

func (n *NotificationFilter) EvalLessOrEqual(_ []string, _ any) (bool, error)

func (*NotificationFilter) EvalLike added in v1.0.0

func (n *NotificationFilter) EvalLike(_ []string, _ any) (bool, error)

type Rule

type Rule struct {
	baseconf.IncrementalPkDbEntry[int64] `db:",inline"`

	Name             string                 `db:"name"`
	TimePeriod       *timeperiod.TimePeriod `db:"-"`
	TimePeriodID     types.Int              `db:"timeperiod_id"`
	ObjectFilter     filter.Filter          `db:"-"`
	ObjectFilterExpr types.String           `db:"object_filter"`
	SourceType       string                 `db:"source_type"`
	Type             Type                   `db:"type"`
	Entries          map[int64]*Entry       `db:"-"`

	// FilterColumns is a set of all filter columns used in the rule's ObjectFilter.
	//
	// This is computed from the ObjectFilter once and can be used by sources to determine which
	// columns they need to provide for the events to be able to evaluate the rule.
	FilterColumns FilterAttrsType `db:"-"`
}

func (*Rule) Eval

func (r *Rule) Eval(filterable filter.Filterable) (bool, error)

Eval evaluates the configured object filter for the provided filterable.

Returns always true if the current rule doesn't have a configured object filter.

func (*Rule) IncrementalInitAndValidate

func (r *Rule) IncrementalInitAndValidate() error

IncrementalInitAndValidate implements the config.IncrementalConfigurableInitAndValidatable interface.

func (*Rule) MarshalLogObject

func (r *Rule) MarshalLogObject(encoder zapcore.ObjectEncoder) error

MarshalLogObject implements the zapcore.ObjectMarshaler interface.

type Type added in v1.0.0

type Type string

Type represents the type of rule, either a notification or an escalation.

const (
	// TypeNotification rules are evaluated for events with incident=false and notify their recipients immediately,
	// without opening or escalating an incident.
	TypeNotification Type = "notification"
	// TypeEscalation is used for rules that are triggered when an incident is opened or escalated.
	TypeEscalation Type = "escalation"
)

Every rule must have exactly one type of the following values.

func (Type) String added in v1.0.0

func (t Type) String() string

String returns the string representation of the rule type.

Jump to

Keyboard shortcuts

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