alert

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxSummaryLength = 118
	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.

Variables

This section is empty.

Functions

func IsAlreadyAcknowledged

func IsAlreadyAcknowledged(err error) bool

func IsAlreadyClosed

func IsAlreadyClosed(err error) bool

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 DB

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

func NewDB

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

func (*DB) Create

func (db *DB) Create(ctx context.Context, a *Alert) (*Alert, error)

func (*DB) CreateOrUpdate

func (db *DB) CreateOrUpdate(ctx context.Context, a *Alert) (*Alert, error)

func (*DB) CreateOrUpdateTx

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

func (*DB) EPID

func (db *DB) EPID(ctx context.Context, alertID int) (string, error)

func (*DB) Escalate

func (db *DB) Escalate(ctx context.Context, alertID int, currentLevel int) error

func (*DB) EscalateMany

func (db *DB) EscalateMany(ctx context.Context, alertIDs []int) ([]int, error)

func (*DB) FindAllSummary

func (db *DB) FindAllSummary(ctx context.Context) ([]Summary, error)

func (*DB) FindMany

func (db *DB) FindMany(ctx context.Context, ids []int) ([]Alert, error)

func (*DB) FindOne

func (db *DB) FindOne(ctx context.Context, id int) (*Alert, error)

func (*DB) GetCreationTime

func (db *DB) GetCreationTime(ctx context.Context, id int) (t time.Time, err error)

func (*DB) LegacySearch

func (db *DB) LegacySearch(ctx context.Context, opts *LegacySearchOptions) ([]Alert, int, error)

LegacySearch will return a list of matching alerts, up to Limit, and the total number of matches available.

func (*DB) Search

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

func (*DB) State

func (db *DB) State(ctx context.Context, alertIDs []int) ([]State, error)

func (*DB) UpdateManyAlertStatus

func (db *DB) UpdateManyAlertStatus(ctx context.Context, status Status, alertIDs []int) ([]int, error)

func (*DB) UpdateStatus

func (db *DB) UpdateStatus(ctx context.Context, id int, s Status) error

func (*DB) UpdateStatusByService

func (db *DB) UpdateStatusByService(ctx context.Context, serviceID string, status Status) error

func (*DB) UpdateStatusTx

func (db *DB) UpdateStatusTx(ctx context.Context, tx *sql.Tx, id int, s Status) 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 LegacySearchOptions

type LegacySearchOptions struct {
	// Search is matched case-insensitive against the alert summary, id and service name.
	Search string

	// ServiceID, if specified, will restrict alerts to those with a matching ServiceID.
	ServiceID string

	OmitTriggered bool
	OmitActive    bool
	OmitClosed    bool

	// Limit restricts the maximum number of rows returned. Default is 50.
	// Note: Limit is applied AFTER offset is taken into account.
	Limit int

	// Offset indicates the starting row of the returned results.
	Offset int

	// SortBy specifies the column to sort by. If anything other than ID,
	// ID is used as a secondary sort in descending (newest first) order.
	SortBy SortBy

	// SortDesc controls ascending or descending results of the primary sort (SortBy field).
	SortDesc bool

	//FavoriteServicesOnlyUserID, if populated, filters all those alerts which belong to this user's favorite services, if empty, it is ignored.
	FavoriteServicesOnlyUserID string
}

LegacySearchOptions contains criteria for filtering and sorting alerts.

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 fetchs 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 Manager

type Manager interface {
	FindOne(context.Context, int) (*Alert, error)
	FindMany(context.Context, []int) ([]Alert, error)
	UpdateStatus(context.Context, int, Status) error
	UpdateStatusByService(ctx context.Context, serviceID string, status Status) error
	UpdateManyAlertStatus(ctx context.Context, status Status, alertIDs []int) (updatedAlertIDs []int, err error)
	UpdateStatusTx(context.Context, *sql.Tx, int, Status) error
	EPID(ctx context.Context, alertID int) (string, error)
}

type SearchCursor

type SearchCursor struct {
	ID     int    `json:"i,omitempty"`
	Status Status `json:"s,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"`

	// Services, if specified, will restrict alerts to those with a matching ServiceID.
	Services []string `json:"v,omitempty"`

	After SearchCursor `json:"a,omitempty"`

	// Omit specifies a list of alert IDs to exclude from the results.
	Omit []int

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

SearchOptions contains criteria for filtering and sorting alerts.

type SortBy

type SortBy int

SortBy describes the possible primary sort options for alerts.

const (
	SortByStatus SortBy = iota
	SortByID
	SortByCreatedTime
	SortBySummary
	SortByServiceName
)

Configurable sort columns.

type Source

type Source string

Source is the entity that triggered an alert.

const (
	SourceEmail   Source = "email"   // email alert
	SourceGrafana Source = "grafana" // grafana alert
	SourceManual  Source = "manual"  // manually triggered
	SourceGeneric Source = "generic" // generic API
)

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 {
	AlertID        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 interface {
	Manager
	Create(context.Context, *Alert) (*Alert, 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.
	CreateOrUpdate(context.Context, *Alert) (*Alert, 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).
	CreateOrUpdateTx(context.Context, *sql.Tx, *Alert) (a *Alert, isNew bool, err error)

	FindAllSummary(ctx context.Context) ([]Summary, error)
	Escalate(ctx context.Context, alertID int, currentLevel int) error
	EscalateMany(ctx context.Context, alertIDs []int) ([]int, error)
	GetCreationTime(ctx context.Context, alertID int) (time.Time, error)

	LegacySearch(ctx context.Context, opt *LegacySearchOptions) ([]Alert, int, error)
	Search(ctx context.Context, opts *SearchOptions) ([]Alert, error)
	State(ctx context.Context, alertIDs []int) ([]State, 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