incident

package
v0.0.0-...-cd37cee Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSuperfluousStateChange = errors.New("ignoring superfluous state change")

ErrSuperfluousStateChange indicates a superfluous state change being ignored and stopping further processing.

Functions

func GetCurrentIncidents

func GetCurrentIncidents() map[int64]*Incident

GetCurrentIncidents returns a map of all incidents for debugging purposes.

func LoadOpenIncidents

func LoadOpenIncidents(ctx context.Context, db *icingadb.DB, logger *logging.Logger, runtimeConfig *config.RuntimeConfig) error

LoadOpenIncidents loads all active (not yet closed) incidents from the database and restores all their states. Returns error on any database failure.

func ProcessEvent

func ProcessEvent(
	ctx context.Context,
	db *icingadb.DB,
	logs *logging.Logging,
	runtimeConfig *config.RuntimeConfig,
	ev *event.Event,
) error

ProcessEvent from an event.Event.

This function first gets this Event's object.Object and its incident.Incident. Then, after performing some safety checks, it calls the Incident.ProcessEvent method.

The returned error might be wrapped around ErrSuperfluousStateChange.

func RemoveCurrent

func RemoveCurrent(obj *object.Object)

Types

type ContactRole

type ContactRole int
const (
	RoleNone ContactRole = iota
	RoleRecipient
	RoleSubscriber
	RoleManager
)

func (*ContactRole) Scan

func (c *ContactRole) Scan(src any) error

Scan implements the sql.Scanner interface.

func (*ContactRole) String

func (c *ContactRole) String() string

func (ContactRole) Value

func (c ContactRole) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type ContactRow

type ContactRow struct {
	IncidentID    int64 `db:"incident_id"`
	recipient.Key `db:",inline"`
	Role          ContactRole `db:"role"`
}

ContactRow represents a single incident contact database entry.

func (*ContactRow) Constraint

func (c *ContactRow) Constraint() string

Constraint implements the contracts.Constrainter interface.

func (*ContactRow) TableName

func (c *ContactRow) TableName() string

TableName implements the contracts.TableNamer interface.

func (*ContactRow) Upsert

func (c *ContactRow) Upsert() interface{}

Upsert implements the contracts.Upserter interface.

type EscalationState

type EscalationState struct {
	IncidentID       int64           `db:"incident_id"`
	RuleEscalationID int64           `db:"rule_escalation_id"`
	TriggeredAt      types.UnixMilli `db:"triggered_at"`
}

func (*EscalationState) TableName

func (e *EscalationState) TableName() string

TableName implements the contracts.TableNamer interface.

type EventRow

type EventRow struct {
	IncidentID int64 `db:"incident_id"`
	EventID    int64 `db:"event_id"`
}

EventRow represents a single incident event database entry.

func (*EventRow) TableName

func (e *EventRow) TableName() string

TableName implements the contracts.TableNamer interface.

type HistoryEventType

type HistoryEventType int
const (
	HistoryEventTypeNull HistoryEventType = iota

	Opened
	IncidentSeverityChanged
	RuleMatched
	EscalationTriggered
	RecipientRoleChanged
	Closed
	Notified
)

func (*HistoryEventType) Scan

func (h *HistoryEventType) Scan(src any) error

Scan implements the sql.Scanner interface. Supports SQL NULL.

func (*HistoryEventType) String

func (h *HistoryEventType) String() string

func (HistoryEventType) Value

func (h HistoryEventType) Value() (driver.Value, error)

type HistoryRow

type HistoryRow struct {
	ID                int64     `db:"id"`
	IncidentID        int64     `db:"incident_id"`
	RuleEscalationID  types.Int `db:"rule_escalation_id"`
	EventID           types.Int `db:"event_id"`
	recipient.Key     `db:",inline"`
	RuleID            types.Int         `db:"rule_id"`
	Time              types.UnixMilli   `db:"time"`
	Type              HistoryEventType  `db:"type"`
	ChannelID         types.Int         `db:"channel_id"`
	NewSeverity       event.Severity    `db:"new_severity"`
	OldSeverity       event.Severity    `db:"old_severity"`
	NewRecipientRole  ContactRole       `db:"new_recipient_role"`
	OldRecipientRole  ContactRole       `db:"old_recipient_role"`
	Message           types.String      `db:"message"`
	NotificationState NotificationState `db:"notification_state"`
	SentAt            types.UnixMilli   `db:"sent_at"`
}

HistoryRow represents a single incident history database entry.

func (*HistoryRow) TableName

func (h *HistoryRow) TableName() string

TableName implements the contracts.TableNamer interface.

type Incident

type Incident struct {
	Id          int64           `db:"id"`
	ObjectID    types.Binary    `db:"object_id"`
	StartedAt   types.UnixMilli `db:"started_at"`
	RecoveredAt types.UnixMilli `db:"recovered_at"`
	Severity    event.Severity  `db:"severity"`

	Object *object.Object `db:"-"`

	EscalationState map[escalationID]*EscalationState
	Rules           map[ruleID]struct{}
	Recipients      map[recipient.Key]*RecipientState

	sync.Mutex
	// contains filtered or unexported fields
}

func GetCurrent

func GetCurrent(
	ctx context.Context, db *icingadb.DB, obj *object.Object, logger *logging.Logger, runtimeConfig *config.RuntimeConfig,
	create bool,
) (*Incident, bool, error)

func NewIncident

func NewIncident(
	db *icingadb.DB, obj *object.Object, runtimeConfig *config.RuntimeConfig, logger *zap.SugaredLogger,
) *Incident

func (*Incident) AddEscalationTriggered

func (i *Incident) AddEscalationTriggered(ctx context.Context, tx *sqlx.Tx, state *EscalationState) error

func (*Incident) AddEvent

func (i *Incident) AddEvent(ctx context.Context, tx *sqlx.Tx, ev *event.Event) error

AddEvent Inserts incident history record to the database and returns an error on db failure.

func (*Incident) AddHistory

func (i *Incident) AddHistory(ctx context.Context, tx *sqlx.Tx, historyRow *HistoryRow, fetchId bool) (types.Int, error)

func (*Incident) AddRecipient

func (i *Incident) AddRecipient(ctx context.Context, tx *sqlx.Tx, escalation *rule.Escalation, eventId int64) error

AddRecipient adds recipient from the given *rule.Escalation to this incident. Syncs also all the recipients with the database and returns an error on db failure.

func (*Incident) AddRuleMatched

func (i *Incident) AddRuleMatched(ctx context.Context, tx *sqlx.Tx, r *rule.Rule) error

AddRuleMatched syncs the given *rule.Rule to the database. Returns an error on database failure.

func (*Incident) HasManager

func (i *Incident) HasManager() bool

func (*Incident) ID

func (i *Incident) ID() int64

func (*Incident) IncidentObject

func (i *Incident) IncidentObject() *object.Object

func (*Incident) IsNotifiable

func (i *Incident) IsNotifiable(role ContactRole) bool

IsNotifiable returns whether contacts in the given role should be notified about this incident.

For a managed incident, only managers and subscribers should be notified, for unmanaged incidents, regular recipients are notified as well.

func (*Incident) ProcessEvent

func (i *Incident) ProcessEvent(ctx context.Context, ev *event.Event, created bool) error

ProcessEvent processes the given event for the current incident in an own transaction.

func (*Incident) RetriggerEscalations

func (i *Incident) RetriggerEscalations(ev *event.Event)

RetriggerEscalations tries to re-evaluate the escalations and notify contacts.

func (*Incident) SeverityString

func (i *Incident) SeverityString() string

func (*Incident) String

func (i *Incident) String() string

func (*Incident) Sync

func (i *Incident) Sync(ctx context.Context, tx *sqlx.Tx) error

Sync initiates an *incident.IncidentRow from the current incident state and syncs it with the database. Before syncing any incident related database entries, this method should be called at least once. Returns an error on db failure.

func (*Incident) Upsert

func (i *Incident) Upsert() interface{}

Upsert implements the contracts.Upserter interface.

type NotificationEntry

type NotificationEntry struct {
	HistoryRowID int64 `db:"id"`
	ContactID    int64
	ChannelID    int64
	State        NotificationState `db:"notification_state"`
	SentAt       types.UnixMilli   `db:"sent_at"`
}

NotificationEntry is used to cache a set of incident history fields of type Notified.

The event processing workflow is performed in a separate transaction before trying to send the actual notifications. Thus, all resulting notification entries are marked as pending, and it creates a reference to them of this type. The cached entries are then used to actually notify the contacts and mark the pending notification entries as either NotificationStateSent or NotificationStateFailed.

func (*NotificationEntry) TableName

func (h *NotificationEntry) TableName() string

TableName implements the contracts.TableNamer interface.

type NotificationState

type NotificationState int
const (
	NotificationStateNull NotificationState = iota
	NotificationStatePending
	NotificationStateSent
	NotificationStateFailed
)

func (*NotificationState) Scan

func (n *NotificationState) Scan(src any) error

Scan implements the sql.Scanner interface. Supports SQL NULL.

func (*NotificationState) String

func (n *NotificationState) String() string

func (NotificationState) Value

func (n NotificationState) Value() (driver.Value, error)

type RecipientState

type RecipientState struct {
	Role ContactRole
}

type RuleRow

type RuleRow struct {
	IncidentID int64 `db:"incident_id"`
	RuleID     int64 `db:"rule_id"`
}

RuleRow represents a single incident rule database entry.

func (*RuleRow) TableName

func (r *RuleRow) TableName() string

TableName implements the contracts.TableNamer interface.

Jump to

Keyboard shortcuts

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