feat(alerts): add alert for failed systemd services (#2173)

Adds a user-configurable "Failed Services" alert that notifies when any
tracked systemd service enters the failed state, and again when all services
recover.

---------

Signed-off-by: Martin Stenröse <martin@stenrose.se>
Co-authored-by: henrygd <hank@henrygd.me>
This commit is contained in:
Martin Stenröse
2026-09-02 02:41:48 +02:00
committed by GitHub
parent ed88e6efae
commit 097180e8d7
17 changed files with 891 additions and 52 deletions

View File

@@ -0,0 +1,44 @@
package migrations
import (
"errors"
"slices"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
// alertNameSystemdFailed is the alerts.name select value for the
// "failed systemd services" alert type.
const alertNameSystemdFailed = "SystemdFailed"
func init() {
m.Register(func(app core.App) error {
return updateAlertNameValues(app, func(values []string) []string {
if slices.Contains(values, alertNameSystemdFailed) {
return values
}
return append(values, alertNameSystemdFailed)
})
}, func(app core.App) error {
return updateAlertNameValues(app, func(values []string) []string {
return slices.DeleteFunc(values, func(value string) bool {
return value == alertNameSystemdFailed
})
})
})
}
// updateAlertNameValues applies fn to the values of the alerts.name select field and saves the collection.
func updateAlertNameValues(app core.App, fn func([]string) []string) error {
collection, err := app.FindCollectionByNameOrId("alerts")
if err != nil {
return err
}
field, ok := collection.Fields.GetByName("name").(*core.SelectField)
if !ok {
return errors.New("alerts.name is not a select field")
}
field.Values = fn(field.Values)
return app.Save(collection)
}