alerts

package
v0.4.63 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 27 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	Backups = "backups"
	Disks   = "disks"
	Updates = "updates"
	Apps    = "apps"
)

The categories of an alert, each on unless the owner turns it off.

View Source
const ConfigFile = "/var/lib/casaos/alerts.json"

ConfigFile holds the channels, the categories and the disk threshold (root, 0600: the URLs carry tokens).

Variables

View Source
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")
)
View Source
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 Channel

type Channel struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	URL  string `json:"url"`
}

Channel is where alerts go: a Shoutrrr URL, never answered back.

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

func New(root string) *Hub

New keeps alerts.json under root and sends through Shoutrrr. Address, Latest and AutoUpdates are left to the caller.

func (*Hub) AutoUpdate

func (h *Hub) AutoUpdate(result, release string)

AutoUpdate is pkg/autoupdate's hook: an automatic update of release that succeeded, failed, or failed a second time and paused.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context)

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.

func (*Hub) Status

func (h *Hub) Status() Status

Status reads alerts.json.

func (*Hub) Test

func (h *Hub) Test(id string) ([]Result, error)

Test sends a test message to the channel id, or to every channel when id is "", and answers per channel once each has answered, in 15 seconds at most.

func (*Hub) Update

func (h *Hub) Update(change Change) (Status, error)

Update applies c, rewriting a malformed alerts.json, and answers the new status. A body that is not one is ErrInvalid, and nothing is written.

type Result

type Result struct {
	ID    string `json:"id"`
	OK    bool   `json:"ok"`
	Error string `json:"error"`
}

Result is one channel's answer to a test.

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.

Jump to

Keyboard shortcuts

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