feat(alerts): add CPU state notifications (#2249)

This commit is contained in:
spatiumstas
2026-09-02 02:10:31 +03:00
committed by GitHub
parent b670224ed8
commit ed88e6efae
37 changed files with 615 additions and 3 deletions

View File

@@ -0,0 +1,36 @@
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)
})
}