mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-21 17:07:47 +02:00
feat(alerts): add CPU state notifications (#2249)
This commit is contained in:
36
internal/migrations/1787356800_cpu_state_alerts.go
Normal file
36
internal/migrations/1787356800_cpu_state_alerts.go
Normal 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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user