consolidate migrations and add triggeredDesc for container health alert

This commit is contained in:
henrygd
2026-09-02 13:02:42 -04:00
parent 5969d36856
commit a4de2e87c4
5 changed files with 165 additions and 269 deletions
@@ -80,7 +80,10 @@ func init() {
"LoadAvg5",
"LoadAvg15",
"Battery",
"ContainerHealth"
"ContainerHealth",
"SystemdFailed",
"CPUIOWait",
"CPUSteal"
]
},
{
@@ -1711,7 +1714,165 @@ func init() {
"type": "base",
"updateRule": null,
"viewRule": null
}
},
{
"createRule": null,
"deleteRule": null,
"fields": [
{
"autogeneratePattern": "[a-z0-9]{15}",
"hidden": false,
"id": "text3208210256",
"max": 15,
"min": 15,
"name": "id",
"pattern": "^[a-z0-9]+$",
"presentable": false,
"primaryKey": true,
"required": true,
"system": true,
"type": "text"
},
{
"cascadeDelete": true,
"collectionId": "2hz5ncl8tizk5nx",
"hidden": false,
"id": "relation1204987316",
"maxSelect": 1,
"minSelect": 0,
"name": "system",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"autogeneratePattern": "",
"hidden": false,
"id": "text7739291048",
"max": 0,
"min": 0,
"name": "name",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"autogeneratePattern": "",
"hidden": false,
"id": "text5528164482",
"max": 0,
"min": 0,
"name": "health",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"hidden": false,
"id": "number8862034195",
"max": null,
"min": null,
"name": "size",
"onlyInt": true,
"presentable": false,
"required": false,
"system": false,
"type": "number"
},
{
"hidden": false,
"id": "number4418907321",
"max": null,
"min": null,
"name": "alloc",
"onlyInt": true,
"presentable": false,
"required": false,
"system": false,
"type": "number"
},
{
"hidden": false,
"id": "number2904183765",
"max": null,
"min": null,
"name": "free",
"onlyInt": true,
"presentable": false,
"required": false,
"system": false,
"type": "number"
},
{
"hidden": false,
"id": "json4466109723",
"maxSize": 0,
"name": "scrub",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json9012873456",
"maxSize": 0,
"name": "vdevs",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json7182045639",
"maxSize": 0,
"name": "datasets",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "date9274163058",
"max": "",
"min": "",
"name": "details_updated",
"presentable": false,
"required": false,
"system": false,
"type": "date"
},
{
"hidden": false,
"id": "autodate3332085495",
"name": "updated",
"onCreate": true,
"onUpdate": true,
"presentable": false,
"system": false,
"type": "autodate"
}
],
"id": "pbc_8441057391",
"indexes": [
"CREATE INDEX ` + "`" + `idx_zfsPoolsSystem` + "`" + ` ON ` + "`" + `zfs_pools` + "`" + ` (` + "`" + `system` + "`" + `)"
],
"listRule": null,
"name": "zfs_pools",
"system": false,
"type": "base",
"updateRule": null,
"viewRule": null
}
]`
err := app.ImportCollectionsByMarshaledJSON([]byte(jsonData), false)
@@ -1,36 +0,0 @@
package migrations
import (
"slices"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
var cpuStateAlertNames = []string{"CPUIOWait", "CPUSteal"}
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("alerts")
if err != nil {
return err
}
field := collection.Fields.GetByName("name").(*core.SelectField)
for _, name := range cpuStateAlertNames {
if !slices.Contains(field.Values, name) {
field.Values = append(field.Values, name)
}
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("alerts")
if err != nil {
return err
}
field := collection.Fields.GetByName("name").(*core.SelectField)
field.Values = slices.DeleteFunc(field.Values, func(name string) bool {
return slices.Contains(cpuStateAlertNames, name)
})
return app.Save(collection)
})
}
@@ -1,44 +0,0 @@
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)
}
-184
View File
@@ -1,184 +0,0 @@
package migrations
import (
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
// Creates the zfs_pools collection for per-system ZFS pool detail data
// (pool health, capacity, scrub, vdevs, datasets). Upserts rather than
// deletes missing collections, so it is safe on fresh and existing installs.
func init() {
m.Register(func(app core.App) error {
// update collections
jsonData := `[
{
"createRule": null,
"deleteRule": null,
"fields": [
{
"autogeneratePattern": "[a-z0-9]{15}",
"hidden": false,
"id": "text3208210256",
"max": 15,
"min": 15,
"name": "id",
"pattern": "^[a-z0-9]+$",
"presentable": false,
"primaryKey": true,
"required": true,
"system": true,
"type": "text"
},
{
"cascadeDelete": true,
"collectionId": "2hz5ncl8tizk5nx",
"hidden": false,
"id": "relation1204987316",
"maxSelect": 1,
"minSelect": 0,
"name": "system",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"autogeneratePattern": "",
"hidden": false,
"id": "text7739291048",
"max": 0,
"min": 0,
"name": "name",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"autogeneratePattern": "",
"hidden": false,
"id": "text5528164482",
"max": 0,
"min": 0,
"name": "health",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"hidden": false,
"id": "number8862034195",
"max": null,
"min": null,
"name": "size",
"onlyInt": true,
"presentable": false,
"required": false,
"system": false,
"type": "number"
},
{
"hidden": false,
"id": "number4418907321",
"max": null,
"min": null,
"name": "alloc",
"onlyInt": true,
"presentable": false,
"required": false,
"system": false,
"type": "number"
},
{
"hidden": false,
"id": "number2904183765",
"max": null,
"min": null,
"name": "free",
"onlyInt": true,
"presentable": false,
"required": false,
"system": false,
"type": "number"
},
{
"hidden": false,
"id": "json4466109723",
"maxSize": 0,
"name": "scrub",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json9012873456",
"maxSize": 0,
"name": "vdevs",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json7182045639",
"maxSize": 0,
"name": "datasets",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "date9274163058",
"max": "",
"min": "",
"name": "details_updated",
"presentable": false,
"required": false,
"system": false,
"type": "date"
},
{
"hidden": false,
"id": "autodate3332085495",
"name": "updated",
"onCreate": true,
"onUpdate": true,
"presentable": false,
"system": false,
"type": "autodate"
}
],
"id": "pbc_8441057391",
"indexes": [
"CREATE INDEX ` + "`" + `idx_zfsPoolsSystem` + "`" + ` ON ` + "`" + `zfs_pools` + "`" + ` (` + "`" + `system` + "`" + `)"
],
"listRule": null,
"name": "zfs_pools",
"system": false,
"type": "base",
"updateRule": null,
"viewRule": null
}
]`
err := app.ImportCollectionsByMarshaledJSON([]byte(jsonData), false)
if err != nil {
return err
}
return nil
}, func(app core.App) error {
return nil
})
}
+2 -3
View File
@@ -108,11 +108,10 @@ export const alertInfo: Record<string, AlertInfo> = {
name: () => t`Container Health`,
unit: "",
icon: ContainerIcon,
desc: () => t`Triggers when a Docker container's health check reports unhealthy`,
desc: () => t`Triggers when a container's health check reports unhealthy`,
note: () =>
t`Notifications may include recent container log excerpts.`,
/** "for x minutes" is appended to desc when only one value */
singleDesc: () => `${t`Container`} ${t`Unhealthy`}`,
triggeredDesc: () => t`One or more containers are unhealthy`,
},
SystemdFailed: {
name: () => t`Failed Services`,