Documentation ¶
Index ¶
- func GetCurrentIncidents() map[int64]*Incident
- func LoadOpenIncidents(ctx context.Context, db *database.DB, logger *logging.Logger, ...) error
- func ProcessEvent(ctx context.Context, db *database.DB, logs *logging.Logging, ...) error
- func RemoveCurrent(obj *object.Object)
- type ContactRole
- type ContactRow
- type EscalationState
- type EventRow
- type HistoryEventType
- type HistoryRow
- type Incident
- func (i *Incident) AddEscalationTriggered(ctx context.Context, tx *sqlx.Tx, state *EscalationState) error
- func (i *Incident) AddEvent(ctx context.Context, tx *sqlx.Tx, ev *event.Event) error
- func (i *Incident) AddRecipient(ctx context.Context, tx *sqlx.Tx, escalation *rule.Escalation, eventId int64) error
- func (i *Incident) AddRuleMatched(ctx context.Context, tx *sqlx.Tx, r *rule.Rule) error
- func (i *Incident) HasManager() bool
- func (i *Incident) ID() int64
- func (i *Incident) IncidentObject() *object.Object
- func (i *Incident) IsNotifiable(role ContactRole) bool
- func (i *Incident) ProcessEvent(ctx context.Context, ev *event.Event) error
- func (i *Incident) RetriggerEscalations(ev *event.Event)
- func (i *Incident) SeverityString() string
- func (i *Incident) String() string
- func (i *Incident) Sync(ctx context.Context, tx *sqlx.Tx) error
- func (i *Incident) Upsert() interface{}
- type NotificationEntry
- type NotificationState
- type RecipientState
- type RuleRow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCurrentIncidents ¶
GetCurrentIncidents returns a map of all incidents for debugging purposes.
func LoadOpenIncidents ¶
func LoadOpenIncidents(ctx context.Context, db *database.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 *database.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 event.ErrSuperfluousStateChange.
func RemoveCurrent ¶
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
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) PgsqlOnConflictConstraint ¶
func (c *ContactRow) PgsqlOnConflictConstraint() string
PgsqlOnConflictConstraint implements the database.PgsqlOnConflictConstrainter 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 HistoryEventType ¶
type HistoryEventType int
const ( HistoryEventTypeNull HistoryEventType = iota Opened Muted Unmuted 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
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) Sync ¶
Sync persists the current state of this history to the database and retrieves the just inserted history ID. Returns error when failed to execute the query.
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 `db:"-"` Rules map[ruleID]struct{} `db:"-"` Recipients map[recipient.Key]*RecipientState `db:"-"` sync.Mutex // contains filtered or unexported fields }
func GetCurrent ¶
func NewIncident ¶
func NewIncident( db *database.DB, obj *object.Object, runtimeConfig *config.RuntimeConfig, logger *zap.SugaredLogger, ) *Incident
func (*Incident) AddEscalationTriggered ¶
func (*Incident) AddEvent ¶
AddEvent Inserts incident history record to the database and returns an error on db failure.
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 ¶
AddRuleMatched syncs the given *rule.Rule to the database. Returns an error on database failure.
func (*Incident) HasManager ¶
func (*Incident) IncidentObject ¶
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 ¶
ProcessEvent processes the given event for the current incident in an own transaction.
func (*Incident) RetriggerEscalations ¶
RetriggerEscalations tries to re-evaluate the escalations and notify contacts.
func (*Incident) SeverityString ¶
type NotificationEntry ¶
type NotificationEntry struct { HistoryRowID int64 `db:"id"` ContactID int64 `db:"-"` ChannelID int64 `db:"-"` 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 NotificationStateSuppressed 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
type RecipientState ¶
type RecipientState struct {
Role ContactRole
}