Files
Vetting/internal/notify/build.go
T
josh 9bb4b09a04
CI / Lint + build + test (push) Has been cancelled
Initial commit: full Phases 1-6 implementation
Post-repair hardware validation pipeline for Proxmox cluster hosts.
Go orchestrator + in-image agent + mkosi live image + bundled dnsmasq
PXE + SQLite + HTMX/SSE UI + notify registry + janitor + full docs.
2026-04-17 21:32:10 -04:00

57 lines
1.4 KiB
Go

package notify
import (
"fmt"
"time"
"vetting/internal/config"
)
// BuildRegistry translates the config surface into a live Registry.
// Unknown notifier types produce an error so typos fail startup loudly
// rather than silently drop events.
func BuildRegistry(notifiers []config.Notifier, routes []config.Route) (*Registry, error) {
reg := NewRegistry(10 * time.Second)
for _, n := range notifiers {
switch n.Type {
case "":
continue // skip blank entries; useful for commented-out examples
case "ntfy":
reg.Register(NewNtfy(n.Name, n.Server, n.Topic))
case "discord":
reg.Register(NewDiscord(n.Name, n.WebhookURL))
case "smtp":
reg.Register(NewSMTP(n.Name, n.SMTP.Host, n.SMTP.Port, n.SMTP.From, n.SMTP.To))
default:
return nil, fmt.Errorf("notify: unknown notifier type %q (name=%q)", n.Type, n.Name)
}
}
for _, r := range routes {
if r.Notifier == "" {
return nil, fmt.Errorf("notify: route has no notifier name")
}
reg.AddRoute(Route{
MatchKind: toKinds(r.MatchKind),
MatchSeverity: toSeverities(r.MatchSeverity),
Notifier: r.Notifier,
})
}
return reg, nil
}
func toKinds(ss []string) []Kind {
out := make([]Kind, 0, len(ss))
for _, s := range ss {
out = append(out, Kind(s))
}
return out
}
func toSeverities(ss []string) []Severity {
out := make([]Severity, 0, len(ss))
for _, s := range ss {
out = append(out, Severity(s))
}
return out
}