Documentation
¶
Overview ¶
Package alert tells people when tasks and schedule runs fail: by email, or in Slack through an incoming webhook.
The Notifier runs on the dispatcher's leader. Every Interval it finds the queues and schedules with failures since their last alert and, once a subject's cooldown has passed, sends each of the workspace's channels one message covering them all. Alerts are sent at least once: a failed send is retried on the next check, and a channel that already got it may get it again.
Index ¶
- Constants
- Variables
- func Masked(c store.AlertChannel) string
- func ParseTarget(typ store.AlertChannelType, target string) (string, error)
- func WorkspaceName(ctx context.Context, st store.Store, ws workspace.ID) (string, error)
- type Email
- type Links
- type Mailer
- type Message
- type Notifier
- type SMTP
- type Sender
Constants ¶
const MaxChannels = 10
MaxChannels is how many channels a workspace can have.
const SlackPrefix = "https://hooks.slack.com/"
SlackPrefix is how every Slack incoming webhook URL starts. Only these are accepted, so a channel can't make Workly call other addresses.
Variables ¶
var ErrNoMailer = errors.New("this server isn't set up to send email")
ErrNoMailer is returned when sending email from a server that can't.
Functions ¶
func Masked ¶
func Masked(c store.AlertChannel) string
Masked returns a channel's target to show: a Slack webhook URL is a secret, so only its start and last characters are shown.
func ParseTarget ¶
func ParseTarget(typ store.AlertChannelType, target string) (string, error)
ParseTarget checks a channel's target and returns it as stored.
Types ¶
type Links ¶
type Links string
Links builds links into the dashboard at its base URL, e.g. https://workly.example.com. The zero value builds none.
type Mailer ¶
type Mailer interface {
// CheckRecipient is called before an email channel is added and may
// refuse the address, e.g. to only send to a workspace's members.
CheckRecipient(ctx context.Context, ws workspace.ID, address string) error
Send(ctx context.Context, ws workspace.ID, e Email) error
}
Mailer sends alert emails. A server without one can't have email channels.
type Message ¶
type Message struct {
Subject string
// Text is the email body.
Text string
// Slack is the Slack message, in Slack's mrkdwn.
Slack string
}
Message is an alert, written for both kinds of channel.
type Notifier ¶
type Notifier struct {
Store store.Store
Sender *Sender
Logger *slog.Logger
// Interval is how often failures are checked. Default 1m.
Interval time.Duration
// Cooldown is how long a queue or schedule waits after an alert before
// the next. Default 30m.
Cooldown time.Duration
// Settle leaves out failures this recent, whose results may still be
// on their way to the database with an earlier finish time. Default
// 15s.
Settle time.Duration
}
Notifier sends the alerts. Run it on one process at a time (the dispatcher's leader).
func (*Notifier) AutoPaused ¶ added in v0.5.0
func (n *Notifier) AutoPaused(ev store.AutoPauseEvent)
AutoPaused sends the alert about a queue that paused itself or resumed, at once rather than at the next check, and outside the cooldown: both are news. It returns at once and sends in the background.
type SMTP ¶
type SMTP struct {
// contains filtered or unexported fields
}
SMTP sends alert emails through an SMTP server.
func NewSMTP ¶
NewSMTP parses an SMTP URL: smtp://user:pass@host:587 upgrades the connection with STARTTLS when the server offers it (and refuses to send the password otherwise, except to localhost), smtps://user:pass@host:465 uses TLS from the start. from is the sender, e.g. "Workly <alerts@example.com>".
func (*SMTP) CheckRecipient ¶
CheckRecipient accepts any address: whoever runs the server chooses them.
type Sender ¶
type Sender struct {
// Mailer is nil if the server can't send email.
Mailer Mailer
// Client posts to Slack. It must not follow redirects.
Client *http.Client
// Links builds links to the dashboard; it's empty when the server
// doesn't know its URL.
Links Links
}
Sender sends messages to channels.
func (*Sender) CanSend ¶
func (s *Sender) CanSend(c store.AlertChannel) bool
CanSend reports whether the channel's type can be sent to.