alert

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxSummaryLength = 1024     // 1KiB
	MaxDetailsLength = 6 * 1024 // 6KiB
)

maximum lengths

View Source
const (
	DedupTypeUser      = DedupType("user")
	DedupTypeAuto      = DedupType("auto")
	DedupTypeHeartbeat = DedupType("heartbeat")
)

DedupType can be auto or user-generated.

View Source
const (
	DestTypeAlert = "builtin-alert"

	ParamSummary = "summary"
	ParamDetails = "details"
	ParamDedup   = "dedup"
	ParamClose   = "close"

	FallbackIconURL = "builtin://alert"
)

Variables

This section is empty.

Functions

func AlertID added in v0.24.0

func AlertID(err error) int

func IsAlreadyAcknowledged

func IsAlreadyAcknowledged(err error) bool

func IsAlreadyClosed

func IsAlreadyClosed(err error) bool

func ValidateMetadata added in v0.33.0

func ValidateMetadata(m map[string]string) error

Types

type Alert

type Alert struct {
	ID        int       `json:"_id"`
	Status    Status    `json:"status"`
	Summary   string    `json:"summary"`
	Details   string    `json:"details"`
	Source    Source    `json:"source"`
	ServiceID string    `json:"service_id"`
	CreatedAt time.Time `json:"created_at"`
	Dedup     *DedupID  `json:"dedup"`
}

An Alert represents an ongoing situation.

func (*Alert) DedupKey

func (a *Alert) DedupKey() *DedupID

DedupKey will return the de-duplication key for the alert. The Dedup prop is used if non-nil, otherwise one is generated using the Description of the Alert.

func (Alert) Description

func (a Alert) Description() string

func (Alert) Normalize

func (a Alert) Normalize() (*Alert, error)

type DedupID

type DedupID struct {
	Type    DedupType
	Version int
	Payload string
}

DedupID represents a de-duplication ID for alerts.

func NewUserDedup

func NewUserDedup(str string) *DedupID

NewUserDedup will create a new DedupID from a user-provided string.

func ParseDedupString

func ParseDedupString(s string) (*DedupID, error)

ParseDedupString will parse a string into a DedupID struct.

func (*DedupID) Scan

func (d *DedupID) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (DedupID) Value

func (d DedupID) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type DedupType

type DedupType string

DedupType represents a type of dedup identifier.

type Feedback added in v0.31.0

type Feedback struct {
	ID          int
	NoiseReason string
}

Feedback represents user provided information about a given alert

type IDFilter added in v0.25.0

type IDFilter struct {
	Valid bool     `json:"v,omitempty"`
	IDs   []string `json:"i,omitempty"`
}

type Log

type Log struct {
	Timestamp time.Time `json:"timestamp"`
	Event     LogEvent  `json:"event"`
	Message   string    `json:"message"`
}

A Log is a recording of an Alert event.

type LogEntryFetcher

type LogEntryFetcher interface {
	// LogEntry fetches the latest log entry for a given alertID and type.
	LogEntry(ctx context.Context) (*alertlog.Entry, error)
}

type LogEvent

type LogEvent string

A LogEvent represents a state change of an alert.

const (
	LogEventCreated           LogEvent = "created"
	LogEventReopened          LogEvent = "reopened"
	LogEventClosed            LogEvent = "closed"
	LogEventStatusChanged     LogEvent = "status_changed"
	LogEventAssignmentChanged LogEvent = "assignment_changed"
	LogEventEscalated         LogEvent = "escalated"
)

Types of LogEvents

func (*LogEvent) Scan

func (r *LogEvent) Scan(value interface{}) error

Scan handles reading a Role from the DB format

type MetadataAlertID added in v0.33.0

type MetadataAlertID struct {
	// AlertID is the ID of the alert.
	ID   int64
	Meta map[string]string
}

type SearchCursor

type SearchCursor struct {
	ID      int       `json:"i,omitempty"`
	Status  Status    `json:"s,omitempty"`
	Created time.Time `json:"c,omitempty"`
}

type SearchOptions

type SearchOptions struct {
	// Search is matched case-insensitive against the alert summary, id and service name.
	Search string `json:"s,omitempty"`

	// Status, if specified, will restrict alerts to those with a matching status.
	Status []Status `json:"t,omitempty"`

	// ServiceFilter, if specified, will restrict alerts to those with a matching ServiceID on IDs, if valid.
	ServiceFilter IDFilter `json:"v,omitempty"`

	After SearchCursor `json:"a,omitempty"`

	// Omit specifies a list of alert IDs to exclude from the results.
	Omit []int `json:"o,omitempty"`

	// NotifiedUserID will include all alerts the specified user has been
	// notified for to the results.
	NotifiedUserID string `json:"e,omitempty"`

	// Limit restricts the maximum number of rows returned. Default is 50.
	// Note: Limit is applied AFTER AfterID is taken into account.
	Limit int `json:"-"`

	// Sort allows customizing the sort method.
	Sort SortMode `json:"z,omitempty"`

	// NotBefore will omit any alerts created any time before the provided time.
	NotBefore time.Time `json:"n,omitempty"`

	// Before will only include alerts that were created before the provided time.
	Before time.Time `json:"b,omitempty"`

	// ClosedBefore will only include alerts that were closed before the provided time.
	ClosedBefore time.Time `json:"c,omitempty"`

	// NotClosedBefore will omit any alerts closed any time before the provided time.
	NotClosedBefore time.Time `json:"nc,omitempty"`
	// contains filtered or unexported fields
}

SearchOptions contains criteria for filtering and sorting alerts.

type SortMode added in v0.26.0

type SortMode int

SortMode indicates the mode of sorting for alerts.

const (
	// SortModeStatusID will sort by status priority (unacked, then acked, then closed) followed by ID (newest/highest first)
	SortModeStatusID SortMode = iota

	// SortModeDateID will sort alerts by date newest first, falling back to ID (newest/highest first)
	SortModeDateID

	// SortModeDateIDReverse will sort alerts by date oldest first, falling back to ID (oldest/lowest first)
	SortModeDateIDReverse
)

type Source

type Source string

Source is the entity that triggered an alert.

const (
	SourceEmail                  Source = "email"                  // email alert
	SourceGrafana                Source = "grafana"                // grafana alert
	SourceSite24x7               Source = "site24x7"               // site24x7 alert
	SourcePrometheusAlertmanager Source = "prometheusAlertmanager" // prometheus alertmanager alert
	SourceManual                 Source = "manual"                 // manually triggered
	SourceGeneric                Source = "generic"                // generic API
	SourceUniversal              Source = "universal"              // universal integration
)

Source types

func (*Source) Scan

func (s *Source) Scan(value interface{}) error

func (Source) Value

func (s Source) Value() (driver.Value, error)

type State

type State struct {
	// ID is the ID of the alert.
	ID             int
	StepNumber     int
	RepeatCount    int
	LastEscalation time.Time
}

State represents the current escalation state of an alert.

type Status

type Status string

Status is the current state of an Alert.

const (
	StatusTriggered Status = "triggered"
	StatusActive    Status = "active"
	StatusClosed    Status = "closed"
)

Alert status types

func (*Status) Scan

func (s *Status) Scan(value interface{}) error

func (Status) Value

func (s Status) Value() (driver.Value, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore added in v0.30.0

func NewStore(ctx context.Context, db *sql.DB, logDB *alertlog.Store) (*Store, error)

func (*Store) CreateOrUpdate

func (s *Store) CreateOrUpdate(ctx context.Context, a *Alert) (*Alert, bool, error)

CreateOrUpdate will create an alert or log a "duplicate suppressed message" if Status is Triggered. If Status is Closed, it will close and return the result.

In the case that Status is closed but a matching alert is not present, nil is returned. Otherwise the current alert is returned.

func (*Store) CreateOrUpdateTx

func (s *Store) CreateOrUpdateTx(ctx context.Context, tx *sql.Tx, a *Alert) (*Alert, bool, error)

CreateOrUpdateTx returns `isNew` to indicate if the returned alert was a new one. It is the caller's responsibility to log alert creation if the transaction is committed (and isNew is true).

func (*Store) CreateOrUpdateWithMeta added in v0.33.0

func (s *Store) CreateOrUpdateWithMeta(ctx context.Context, a *Alert, meta map[string]string) (*Alert, bool, error)

CreateOrUpdateWithMeta behaves the same as CreateOrUpdate, but also sets metadata on the alert if it is new.

func (*Store) CreateTx added in v0.33.0

func (s *Store) CreateTx(ctx context.Context, tx *sql.Tx, a *Alert) (*Alert, error)

func (*Store) DisplayInfo added in v0.33.0

func (s *Store) DisplayInfo(ctx context.Context, args map[string]string) (*nfydest.DisplayInfo, error)

func (*Store) EPID added in v0.30.0

func (s *Store) EPID(ctx context.Context, alertID int) (string, error)

func (*Store) Escalate

func (s *Store) Escalate(ctx context.Context, alertID int, currentLevel int) error

func (*Store) EscalateAsOf added in v0.31.0

func (s *Store) EscalateAsOf(ctx context.Context, id int, t time.Time) error

EscalateAsOf will request escalation for the given alert ID as-of the given time.

An error will be returned if the alert is already closed, if the service is in maintenance mode, there are no steps on the escalation policy, or if the alert has already been escalated since the given time.

func (*Store) EscalateMany

func (s *Store) EscalateMany(ctx context.Context, alertIDs []int) ([]int, error)

func (*Store) Feedback added in v0.31.0

func (s *Store) Feedback(ctx context.Context, alertIDs []int) ([]Feedback, error)

func (*Store) FindMany added in v0.30.0

func (s *Store) FindMany(ctx context.Context, alertIDs []int) ([]Alert, error)

func (Store) FindManyMetadata added in v0.33.0

func (s Store) FindManyMetadata(ctx context.Context, db gadb.DBTX, alertIDs []int) ([]MetadataAlertID, error)

func (*Store) FindOne added in v0.30.0

func (s *Store) FindOne(ctx context.Context, id int) (*Alert, error)

func (*Store) ID added in v0.33.0

func (s *Store) ID() string

func (*Store) Metadata added in v0.33.0

func (s *Store) Metadata(ctx context.Context, db gadb.DBTX, alertID int) (meta map[string]string, err error)

Metadata returns the metadata for a single alert. If err == nil, meta is guaranteed to be non-nil. If the alert has no metadata, an empty map is returned.

func (*Store) Search

func (s *Store) Search(ctx context.Context, opts *SearchOptions) ([]Alert, error)

func (*Store) ServiceInfo added in v0.30.0

func (s *Store) ServiceInfo(ctx context.Context, serviceID string) (string, int, error)

ServiceInfo will return the name of the given service ID as well as the current number of unacknowledged alerts.

func (Store) SetMetadataTx added in v0.33.0

func (s Store) SetMetadataTx(ctx context.Context, db gadb.DBTX, alertID int, meta map[string]string) error

func (*Store) State

func (s *Store) State(ctx context.Context, alertIDs []int) ([]State, error)

func (*Store) TypeInfo added in v0.33.0

func (s *Store) TypeInfo(ctx context.Context) (*nfydest.TypeInfo, error)

func (Store) UpdateFeedback added in v0.31.0

func (s Store) UpdateFeedback(ctx context.Context, feedback *Feedback) error

func (Store) UpdateManyAlertFeedback added in v0.32.0

func (s Store) UpdateManyAlertFeedback(ctx context.Context, noiseReason string, alertIDs []int) ([]int, error)

func (*Store) UpdateManyAlertStatus added in v0.30.0

func (s *Store) UpdateManyAlertStatus(ctx context.Context, status Status, alertIDs []int, logMeta interface{}) ([]int, error)

func (*Store) UpdateStatus added in v0.30.0

func (s *Store) UpdateStatus(ctx context.Context, id int, stat Status) error

func (*Store) UpdateStatusByService added in v0.30.0

func (s *Store) UpdateStatusByService(ctx context.Context, serviceID string, status Status) error

func (*Store) UpdateStatusTx added in v0.30.0

func (s *Store) UpdateStatusTx(ctx context.Context, tx *sql.Tx, id int, stat Status) error

func (*Store) ValidateField added in v0.33.0

func (s *Store) ValidateField(ctx context.Context, fieldID, value string) error

type Summary

type Summary struct {
	ServiceID   string `json:"service_id"`
	ServiceName string `json:"service_name"`
	Totals      struct {
		Unack  int `json:"unacknowledged"`
		Ack    int `json:"acknowledged"`
		Closed int `json:"closed"`
	} `json:"totals"`
}

type Trigger

type Trigger interface {
	TriggerAlert(int)
}

A Trigger signals that an alert needs to be processed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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