Documentation
¶
Overview ¶
Package alerts tells the owner, on their phone or by mail, that something needs them: a backup that failed, a disk failing or full, an app that crashed, an automatic update that failed or paused. Its channels are Shoutrrr service URLs (ntfy://, telegram://, smtp://, ...) kept in alerts.json, and every alert goes to every channel.
The alerts come from AppManagement's events on the message bus, from an hourly look at LocalStorage's disks and storages, and from pkg/autoupdate, in-process. An alert already sent is not sent again for six hours, even when it cleared and came back meanwhile, and a condition that clears sends one "resolved" message, only if its alert was sent and once per alert sent. That memory is the core's: a restart forgets it, and at worst a reminder comes early.
Index ¶
Constants ¶
const ( Backups = "backups" Disks = "disks" Updates = "updates" Apps = "apps" )
The categories of an alert, each on unless the owner turns it off.
const ConfigFile = "/var/lib/casaos/alerts.json"
ConfigFile holds the channels, the categories and the disk threshold (root, 0600: the URLs carry tokens).
Variables ¶
var ( // ErrInvalid is a PUT body that is not one: a URL Shoutrrr cannot parse, a // new channel without a URL, an unknown channel id, a threshold outside 50 // to 99. Nothing is written. ErrInvalid = errors.New("invalid alerts settings") // ErrNoChannel is a test of a channel id that is not one. ErrNoChannel = errors.New("no such channel") )
var Default = New("/")
Default is the box's own: the API answers from it and main runs its sources.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
Channels []Channel `json:"channels"`
Categories map[string]bool `json:"categories"`
DiskThreshold *int `json:"disk_threshold"`
}
Change is PUT /v1/sys/alerts's body, each field optional, others ignored. Channels replaces the list: an entry with an id and no url keeps its stored URL, a new entry needs a url.
type ChannelStatus ¶
type ChannelStatus struct {
ID string `json:"id"`
Name string `json:"name"`
Service string `json:"service"`
Host string `json:"host"`
}
ChannelStatus is a channel as the dashboard sees it: service is the URL's scheme, host its host part (the ntfy server, the SMTP host), enough to recognise it. Host is "" for a service whose host part is not a server.
type Config ¶
type Config struct {
Channels []Channel `json:"channels"`
Categories map[string]bool `json:"categories"`
DiskThreshold int `json:"disk_threshold"` // a percentage, 50 to 99
}
Config is alerts.json.
type Failure ¶
type Failure struct {
At time.Time `json:"at"`
Channel string `json:"channel"` // its name
Error string `json:"error"`
}
Failure is the last send that failed, since the core started.
type Hub ¶
type Hub struct {
// Root is where alerts.json is kept: "/" on a box, a temporary directory
// in tests.
Root string
// RuntimePath is where the other services leave their addresses and this
// boot's secret.
RuntimePath func() string
Now func() time.Time
Hostname func() (string, error)
// Address is the dashboard's address, or "" when the core does not know it.
Address func() string
// Send delivers one message to one channel URL.
Send func(rawURL, title, message string) error
// Latest is the newest release as the update button reads it, Current the
// installed one, and AutoUpdates whether automatic updates are on: with
// them off, a newer release is an alert of its own.
Latest func() string
Current func() string
AutoUpdates func() bool
// contains filtered or unexported fields
}
Hub is the alerts of one box.
func New ¶
New keeps alerts.json under root and sends through Shoutrrr. Address, Latest and AutoUpdates are left to the caller.
func (*Hub) AutoUpdate ¶
AutoUpdate is pkg/autoupdate's hook: an automatic update of release that succeeded, failed, or failed a second time and paused.
func (*Hub) Run ¶
Run follows the message bus until ctx is done, and looks at the disks and for a newer release five minutes after the start, then every hour.
type Status ¶
type Status struct {
Channels []ChannelStatus `json:"channels"`
Categories map[string]bool `json:"categories"`
DiskThreshold int `json:"disk_threshold"`
LastFailure *Failure `json:"last_failure"`
}
Status is what GET and PUT /v1/sys/alerts answer in data: the channels without their URLs, which never leave the box's disk.