Documentation
¶
Overview ¶
Package alert opens an incident when a check keeps failing or an edge goes quiet, resolves it when it stops, and tells the channels of each event.
Index ¶
Constants ¶
const ( DefaultFailures = 3 DefaultSilence = 5 * time.Minute DefaultInterval = 30 * time.Second )
Defaults of the settings.
const EventTest = "test"
Events a webhook is called for, besides the two of an incident.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Failures is how many failures in a row open an incident; zero means 3.
Failures int
// Silence is how long an edge may go without a result before it is
// reported; zero means 5 minutes.
Silence time.Duration
// Interval is how often the results are looked at; zero means 30 seconds.
Interval time.Duration
// Sender delivers the notifications; nil posts to the channels' webhooks.
Sender Sender
// Policy is where those webhooks may not connect; nil means the default
// ranges, a pointer to the zero value nowhere.
Policy *probe.Policy
// Now is the clock; nil means time.Now.
Now func() time.Time
}
Config sets when an incident opens.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine evaluates the results and notifies the channels.
type IncidentJSON ¶
type IncidentJSON struct {
ID int64 `json:"id"`
Kind string `json:"kind"`
CheckID string `json:"check_id,omitempty"`
EdgeID string `json:"edge_id"`
Edge string `json:"edge"`
StartedAt time.Time `json:"started_at"`
ResolvedAt *time.Time `json:"resolved_at,omitempty"`
Detail string `json:"detail,omitempty"`
Resolution string `json:"resolution,omitempty"`
}
IncidentJSON is an incident as a webhook sees it.
func ToJSON ¶
func ToJSON(i store.Incident) IncidentJSON
ToJSON describes an incident for the UI API and for webhooks alike.
type Payload ¶
type Payload struct {
Event string `json:"event"`
Text string `json:"text"`
Incident *IncidentJSON `json:"incident,omitempty"`
}
Payload is the JSON body posted to a channel. Text reads as a sentence, which is all that chat tools with incoming webhooks ask for.
func NewPayload ¶
func NewPayload(n store.Notification) Payload
NewPayload says what happened in a notification.
type Webhook ¶
Webhook posts payloads as JSON. Redirects are not followed: a channel is where the administrator said, nowhere else.
func NewWebhook ¶
NewWebhook returns a sender with a timeout and no redirects. It never connects to an address the policy denies, whatever name led to it.