Documentation ¶
Index ¶
- Constants
- func AlertID(err error) int
- func IsAlreadyAcknowledged(err error) bool
- func IsAlreadyClosed(err error) bool
- func ValidateMetadata(m map[string]string) error
- type Alert
- type DedupID
- type DedupType
- type Feedback
- type IDFilter
- type Log
- type LogEntryFetcher
- type LogEvent
- type MetadataAlertID
- type SearchCursor
- type SearchOptions
- type SortMode
- type Source
- type State
- type Status
- type Store
- func (s *Store) CreateOrUpdate(ctx context.Context, a *Alert) (*Alert, bool, error)
- func (s *Store) CreateOrUpdateTx(ctx context.Context, tx *sql.Tx, a *Alert) (*Alert, bool, error)
- func (s *Store) CreateOrUpdateWithMeta(ctx context.Context, a *Alert, meta map[string]string) (*Alert, bool, error)
- func (s *Store) CreateTx(ctx context.Context, tx *sql.Tx, a *Alert) (*Alert, error)
- func (s *Store) DisplayInfo(ctx context.Context, args map[string]string) (*nfydest.DisplayInfo, error)
- func (s *Store) EPID(ctx context.Context, alertID int) (string, error)
- func (s *Store) Escalate(ctx context.Context, alertID int, currentLevel int) error
- func (s *Store) EscalateAsOf(ctx context.Context, id int, t time.Time) error
- func (s *Store) EscalateMany(ctx context.Context, alertIDs []int) ([]int, error)
- func (s *Store) Feedback(ctx context.Context, alertIDs []int) ([]Feedback, error)
- func (s *Store) FindMany(ctx context.Context, alertIDs []int) ([]Alert, error)
- func (s Store) FindManyMetadata(ctx context.Context, db gadb.DBTX, alertIDs []int) ([]MetadataAlertID, error)
- func (s *Store) FindOne(ctx context.Context, id int) (*Alert, error)
- func (s *Store) ID() string
- func (s *Store) Metadata(ctx context.Context, db gadb.DBTX, alertID int) (meta map[string]string, err error)
- func (s *Store) Search(ctx context.Context, opts *SearchOptions) ([]Alert, error)
- func (s *Store) ServiceInfo(ctx context.Context, serviceID string) (string, int, error)
- func (s Store) SetMetadataTx(ctx context.Context, db gadb.DBTX, alertID int, meta map[string]string) error
- func (s *Store) State(ctx context.Context, alertIDs []int) ([]State, error)
- func (s *Store) TypeInfo(ctx context.Context) (*nfydest.TypeInfo, error)
- func (s Store) UpdateFeedback(ctx context.Context, feedback *Feedback) error
- func (s Store) UpdateManyAlertFeedback(ctx context.Context, noiseReason string, alertIDs []int) ([]int, error)
- func (s *Store) UpdateManyAlertStatus(ctx context.Context, status Status, alertIDs []int, logMeta interface{}) ([]int, error)
- func (s *Store) UpdateStatus(ctx context.Context, id int, stat Status) error
- func (s *Store) UpdateStatusByService(ctx context.Context, serviceID string, status Status) error
- func (s *Store) UpdateStatusTx(ctx context.Context, tx *sql.Tx, id int, stat Status) error
- func (s *Store) ValidateField(ctx context.Context, fieldID, value string) error
- type Summary
- type Trigger
Constants ¶
const ( MaxSummaryLength = 1024 // 1KiB MaxDetailsLength = 6 * 1024 // 6KiB )
maximum lengths
const ( DedupTypeUser = DedupType("user") DedupTypeAuto = DedupType("auto") DedupTypeHeartbeat = DedupType("heartbeat") )
DedupType can be auto or user-generated.
const ( DestTypeAlert = "builtin-alert" ParamSummary = "summary" ParamDetails = "details" ParamDedup = "dedup" ParamClose = "close" FallbackIconURL = "builtin://alert" )
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyAcknowledged ¶
func IsAlreadyClosed ¶
func ValidateMetadata ¶ added in v0.33.0
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 ¶
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 ¶
type DedupID ¶
DedupID represents a de-duplication ID for alerts.
func NewUserDedup ¶
NewUserDedup will create a new DedupID from a user-provided string.
func ParseDedupString ¶
ParseDedupString will parse a string into a DedupID struct.
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 LogEvent ¶
type LogEvent string
A LogEvent represents a state change of an alert.
type MetadataAlertID ¶ added in v0.33.0
type SearchCursor ¶
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
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.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) CreateOrUpdate ¶
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 ¶
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) DisplayInfo ¶ added in v0.33.0
func (*Store) EscalateAsOf ¶ added in v0.31.0
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 (Store) FindManyMetadata ¶ added in v0.33.0
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) ServiceInfo ¶ added in v0.30.0
ServiceInfo will return the name of the given service ID as well as the current number of unacknowledged alerts.