Documentation
¶
Index ¶
- Constants
- func AlertID(err error) int
- func IsAlreadyAcknowledged(err error) bool
- func IsAlreadyClosed(err error) bool
- type Alert
- type DedupID
- type DedupType
- type IDFilter
- type LegacySearchOptions
- type Log
- type LogEntryFetcher
- type LogEvent
- type SearchCursor
- type SearchOptions
- type SortBy
- type SortMode
- type Source
- type State
- type Status
- type Store
- func (s *Store) Create(ctx context.Context, a *Alert) (*Alert, error)
- func (s *Store) CreateOrUpdate(ctx context.Context, a *Alert) (*Alert, error)
- func (s *Store) CreateOrUpdateTx(ctx context.Context, tx *sql.Tx, a *Alert) (*Alert, bool, 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) EscalateMany(ctx context.Context, alertIDs []int) ([]int, error)
- func (s *Store) FindAllSummary(ctx context.Context) ([]Summary, error)
- func (s *Store) FindMany(ctx context.Context, alertIDs []int) ([]Alert, error)
- func (s *Store) FindOne(ctx context.Context, id int) (*Alert, error)
- func (s *Store) GetCreationTime(ctx context.Context, id int) (t time.Time, err error)
- func (s *Store) LegacySearch(ctx context.Context, opts *LegacySearchOptions) ([]Alert, int, 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) State(ctx context.Context, alertIDs []int) ([]State, error)
- func (s *Store) UpdateManyAlertStatus(ctx context.Context, status Status, alertIDs []int) ([]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
- 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.
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyAcknowledged ¶
func IsAlreadyClosed ¶
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 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 LogEvent ¶
type LogEvent string
A LogEvent represents a state change of an alert.
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 )
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) EscalateMany ¶
func (*Store) FindAllSummary ¶
func (*Store) GetCreationTime ¶
func (*Store) LegacySearch ¶
LegacySearch will return a list of matching alerts, up to Limit, and the total number of matches available.
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.