Documentation
¶
Overview ¶
Package alert batches and delivers watch alerts.
Delivery is best effort: a slow or failing channel never blocks the watchers, and alerts that do not fit are counted as dropped.
Index ¶
Constants ¶
const ( Warning = "warning" Info = "info" )
Severities.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActionLink ¶
type Alert ¶
type Alert struct {
Display *Display `json:"display,omitempty"`
Time time.Time `json:"time"`
Cluster string `json:"cluster"`
Severity string `json:"severity"`
Kind string `json:"kind"`
Namespace string `json:"namespace,omitempty"`
Name string `json:"name"`
// Reason is a short machine-readable cause, e.g. OOMKilled or ImageChanged.
Reason string `json:"reason"`
Summary string `json:"summary"`
// Hint is fixed advice chosen by the watcher. It never contains cluster text.
Hint string `json:"hint,omitempty"`
// Restart names a workload a person may choose to restart. Nothing acts on
// it automatically.
Restart *Workload `json:"restart,omitempty"`
// Suppressed counts repeats folded into this alert during the cooldown.
Suppressed int `json:"suppressed,omitempty"`
// Key identifies repeats; it includes the container for pod alerts.
Key string `json:"-"`
}
type Batch ¶
type Batch struct {
Language string `json:"language,omitempty"`
Actions []ActionLink `json:"actions,omitempty"`
Source string `json:"source"`
SentAt time.Time `json:"sent_at"`
Alerts []Alert `json:"alerts"`
// Dropped counts alerts lost to the queue or batch limit.
Dropped int `json:"dropped,omitempty"`
// Text renders the batch for chat forwarding without further code.
Text string `json:"text"`
}
Batch is one delivery, also the JSON body of a webhook POST.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher gathers and delivers alerts in batches.
func (*Dispatcher) Run ¶
func (d *Dispatcher) Run(ctx context.Context)
Run delivers batches until ctx ends, then sends what is pending.
type Display ¶
type Display struct {
Reason string `json:"reason"`
Summary string `json:"summary"`
Hint string `json:"hint,omitempty"`
}
Alert is one observed change. Text fields must already be redacted. Display holds human-facing localization while source fields stay unchanged.
type EmailOptions ¶
type EmailOptions struct {
Host string
Port int
Username string
Password string
From string
To []string
}
EmailOptions configures TLS-only SMTP delivery.
type Options ¶
type Options struct {
// Sender delivers batches; nil posts them to URL as a webhook.
Sender Sender
// ProblemsOnly drops every alert that is not a warning.
ProblemsOnly bool
Language string
URL string
Secret []byte
Batch time.Duration
Cooldown time.Duration
MaxAlerts int
// PrivateOnly refuses connections to addresses that are neither
// private nor loopback, checked after DNS resolution. Use it for
// plain http, where a host name could otherwise lead anywhere.
PrivateOnly bool
Client *http.Client
}
Options configures a Dispatcher.
type Sender ¶
Sender delivers one batch.
func NewEmail ¶
func NewEmail(opts EmailOptions) Sender
NewEmail returns an SMTP sender. Settings must already be validated.
func NewWebhook ¶
func NewWebhook(o WebhookOptions) (Sender, error)
NewWebhook builds a sender before watching starts. Templates receive Batch and a json helper; values from alerts are never evaluated as templates.
type WebhookOptions ¶
type WebhookOptions struct {
Options
Name string
Format string
Language string
Headers map[string]string
BodyTemplate string
}
WebhookOptions configures a named JSON POST destination.
type Workload ¶
type Workload struct {
// Kind is deployment, statefulset or daemonset.
Kind string `json:"kind"`
Namespace string `json:"namespace"`
Name string `json:"name"`
// URL opens the approval page for this restart, if the watcher knows it.
URL string `json:"url,omitempty"`
}
Workload identifies the target of a suggested k8s_rollout_restart call.