alert

package
v0.0.0-...-9f34937 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	// Label value pairs for purpose of aggregation, matching, and disposition
	// dispatching. This must minimally include an "alertname" label.
	Labels label.LabelSet `json:"labels"`

	// Extra key/value information which does not define alert identity.
	Annotations label.LabelSet `json:"annotations"`

	// The known time range for this alert. Both ends are optional.
	StartsAt     time.Time `json:"startsAt,omitempty"`
	EndsAt       time.Time `json:"endsAt,omitempty"`
	GeneratorURL string    `json:"generatorURL"`

	// The authoritative timestamp.
	UpdatedAt time.Time
	Timeout   bool
}

Alert is a single alert. it is a copy of the Alert struct from the Alertmanager

func (*Alert) Clone

func (a *Alert) Clone() *Alert

Clone returns a deep copy of the alert.

func (*Alert) Fingerprint

func (a *Alert) Fingerprint() label.Fingerprint

func (*Alert) Merge

func (a *Alert) Merge(o *Alert) *Alert

Merge merges the timespan of two alerts based and overwrites annotations based on the authoritative timestamp. A new alert is returned, the labels are assumed to be equal.

func (*Alert) Name

func (a *Alert) Name() string

Name returns the name of the alert. It is equivalent to the "alertname" label.

func (*Alert) Resolved

func (a *Alert) Resolved() bool

Resolved returns true if the activity interval ended in the past.

func (*Alert) ResolvedAt

func (a *Alert) ResolvedAt(ts time.Time) bool

ResolvedAt returns true if the activity interval ended before the given timestamp.

func (*Alert) Status

func (a *Alert) Status() AlertStatus

Status returns the status of the alert.

func (*Alert) String

func (a *Alert) String() string

func (*Alert) Validate

func (a *Alert) Validate() error

Validate checks whether the alert data is inconsistent.

type AlertState

type AlertState string

AlertState is used as part of AlertStatus.

const (
	AlertStateUnprocessed AlertState = "unprocessed"
	AlertStateActive      AlertState = "active"
	AlertStateSuppressed  AlertState = "suppressed"
)

Possible values for AlertState.

type AlertStatus

type AlertStatus string
const (
	AlertNone     AlertStatus = "none"
	AlertFiring   AlertStatus = "firing"
	AlertResolved AlertStatus = "resolved"
)

func (AlertStatus) MarshalGQL

func (a AlertStatus) MarshalGQL(w io.Writer)

func (*AlertStatus) UnmarshalGQL

func (a *AlertStatus) UnmarshalGQL(v interface{}) error

func (AlertStatus) Values

func (a AlertStatus) Values() []string

type Alerts

type Alerts []*Alert

Alerts is a slice of alerts that implements sort.Interface.

func (Alerts) HasFiring

func (as Alerts) HasFiring() bool

HasFiring returns true iff one of the alerts is not resolved.

func (Alerts) Len

func (as Alerts) Len() int

func (Alerts) Less

func (as Alerts) Less(i, j int) bool

func (Alerts) Status

func (as Alerts) Status() AlertStatus

Status returns StatusFiring iff at least one of the alerts is firing.

func (Alerts) Swap

func (as Alerts) Swap(i, j int)

type Marker

type Marker interface {
	// SetActiveOrSilenced replaces the previous SilencedBy by the provided IDs of
	// active and pending silences, including the version number of the
	// silences state. The set of provided IDs is supposed to represent the
	// complete set of relevant silences. If no active silence IDs are provided and
	// InhibitedBy is already empty, it sets the provided alert to AlertStateActive.
	// Otherwise, it sets the provided alert to AlertStateSuppressed.
	SetActiveOrSilenced(alert label.Fingerprint, version int, activeSilenceIDs, pendingSilenceIDs []int)
	// SetInhibited replaces the previous InhibitedBy by the provided IDs of
	// alerts. In contrast to SetActiveOrSilenced, the set of provided IDs is not
	// expected to represent the complete set of inhibiting alerts. (In
	// practice, this method is only called with one or zero IDs. However,
	// this expectation might change in the future. If no IDs are provided
	// and InhibitedBy is already empty, it sets the provided alert to
	// AlertStateActive. Otherwise, it sets the provided alert to
	// AlertStateSuppressed.
	SetInhibited(alert label.Fingerprint, alertIDs ...string)

	// Count alerts of the given state(s). With no state provided, count all
	// alerts.
	Count(...AlertState) int

	// Status of the given alert.
	Status(label.Fingerprint) MarkerStatus
	// Delete the given alert.
	Delete(label.Fingerprint)

	// Various methods to inquire if the given alert is in a certain
	// AlertState. Silenced also returns all the active and pending
	// silences, while Inhibited may return only a subset of inhibiting
	// alerts. Silenced also returns the version of the silences state the
	// result is based on.
	Unprocessed(label.Fingerprint) bool
	Active(label.Fingerprint) bool
	Silenced(label.Fingerprint) (activeIDs, pendingIDs []int, version int, silenced bool)
	Inhibited(label.Fingerprint) ([]string, bool)
}

Marker helps to mark alerts as silenced and/or inhibited. All methods are goroutine-safe.

func NewMarker

func NewMarker(r prometheus.Registerer) Marker

NewMarker returns an instance of a Marker implementation.

type MarkerStatus

type MarkerStatus struct {
	State       AlertState `json:"state"`
	SilencedBy  []int      `json:"silencedBy"`
	InhibitedBy []string   `json:"inhibitedBy"`
	// contains filtered or unexported fields
}

MarkerStatus stores the state of an alert and, as applicable, the IDs of silences silencing the alert and of other alerts inhibiting the alert. Note that currently, SilencedBy is supposed to be the complete set of the relevant silences while InhibitedBy may contain only a subset of the inhibiting alerts – in practice exactly one ID. (This somewhat confusing semantics might change in the future.)

type MuteFunc

type MuteFunc func(label.LabelSet) bool

A MuteFunc is a function that implements the Muter interface.

func (MuteFunc) Mutes

func (f MuteFunc) Mutes(lset label.LabelSet) bool

Mutes implements the Muter interface.

type Muter

type Muter interface {
	Mutes(label.LabelSet) bool
}

A Muter determines whether a given label set is muted. Implementers that maintain an underlying Marker are expected to update it during a call of Mutes.

type SilenceState

type SilenceState string

SilenceState is used as part of SilenceStatus.

const (
	SilenceStateExpired SilenceState = "expired"
	SilenceStateActive  SilenceState = "active"
	SilenceStatePending SilenceState = "pending"
)

Possible values for SilenceState.

func CalcSilenceState

func CalcSilenceState(start, end time.Time) SilenceState

CalcSilenceState returns the SilenceState that a silence with the given start and end time would have right now.

func (SilenceState) IsValid

func (s SilenceState) IsValid() bool

func (SilenceState) MarshalGQL

func (s SilenceState) MarshalGQL(w io.Writer)

func (SilenceState) String

func (s SilenceState) String() string

String implements fmt.Stringer.

func (*SilenceState) UnmarshalGQL

func (s *SilenceState) UnmarshalGQL(v interface{}) error

func (SilenceState) Values

func (s SilenceState) Values() []string

type SilenceStatus

type SilenceStatus struct {
	State SilenceState `json:"state"`
}

SilenceStatus stores the state of a silence.

Jump to

Keyboard shortcuts

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