This commit is contained in:
henrygd
2026-04-19 21:44:21 -04:00
parent ea19ef6334
commit e71ffd4d2a
15 changed files with 136 additions and 113 deletions

View File

@@ -1,10 +1,27 @@
package hub
import (
"github.com/henrygd/beszel/internal/entities/probe"
"github.com/henrygd/beszel/internal/hub/systems"
"github.com/pocketbase/pocketbase/core"
)
func bindNetworkProbesEvents(h *Hub) {
// on create, make sure the id is set to a stable hash
h.OnRecordCreate("network_probes").BindFunc(func(e *core.RecordEvent) error {
systemID := e.Record.GetString("system")
config := &probe.Config{
Target: e.Record.GetString("target"),
Protocol: e.Record.GetString("protocol"),
Port: uint16(e.Record.GetInt("port")),
Interval: uint16(e.Record.GetInt("interval")),
}
key := config.Key()
id := systems.MakeStableHashId(systemID, key)
e.Record.Set("id", id)
return e.Next()
})
// sync probe to agent on creation
h.OnRecordAfterCreateSuccess("network_probes").BindFunc(func(e *core.RecordEvent) error {
systemID := e.Record.GetString("system")
@@ -17,6 +34,7 @@ func bindNetworkProbesEvents(h *Hub) {
h.syncProbesToAgent(systemID)
return e.Next()
})
// TODO: if enabled changes, sync to agent
}
// syncProbesToAgent fetches enabled probes for a system and sends them to the agent.