f-29: watchdog: add checksubnet #29

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-08-17 23:28:32 +02:00
commit 0fa84b8320
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
7 changed files with 497 additions and 2 deletions

View file

@ -6,6 +6,8 @@ import (
"strings"
"git.g3e.fr/syonad/two/internal/netif"
"git.g3e.fr/syonad/two/internal/watchdog/notify"
"git.g3e.fr/syonad/two/pkg/systemd"
)
const (
@ -40,6 +42,24 @@ func resourceNames(pairs map[string]string, prefix string) []string {
return names
}
type unitChecker interface {
Status(unit string) (*systemd.ServiceStatus, error)
}
func checkUnit(kind, name, unit string, u unitChecker, n notify.Notifier) {
if u == nil {
return
}
st, err := u.Status(unit)
if err != nil {
n.Notify(kind, name, fmt.Sprintf("unit %s illisible: %v", unit, err))
return
}
if st.ActiveState != "active" {
n.Notify(kind, name, fmt.Sprintf("unit %s %s (%s)", unit, st.ActiveState, st.SubState))
}
}
func linkProblem(iface string) string {
up, err := netif.LinkIsUp(iface)
switch {