mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-21 17:07:47 +02:00
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>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
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)
|
|
}
|