f-29: watchdog: add checkvpc #29
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
f05c4e1fce
commit
ea60c0db54
6 changed files with 457 additions and 0 deletions
52
internal/watchdog/resources.go
Normal file
52
internal/watchdog/resources.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package watchdog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/netif"
|
||||
)
|
||||
|
||||
const (
|
||||
prefixVPC = "vpc/"
|
||||
prefixSubnet = "subnet/"
|
||||
prefixVM = "vm/"
|
||||
|
||||
kindVPC = "vpc"
|
||||
kindSubnet = "subnet"
|
||||
kindVM = "vm"
|
||||
|
||||
stateSuffix = "/state"
|
||||
)
|
||||
|
||||
func resourceNames(pairs map[string]string, prefix string) []string {
|
||||
names := make([]string, 0, len(pairs))
|
||||
for key := range pairs {
|
||||
name, ok := strings.CutPrefix(key, prefix)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
name, ok = strings.CutSuffix(name, stateSuffix)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if name == "" || strings.Contains(name, "/") {
|
||||
continue
|
||||
}
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
|
||||
func linkProblem(iface string) string {
|
||||
up, err := netif.LinkIsUp(iface)
|
||||
switch {
|
||||
case err != nil:
|
||||
return fmt.Sprintf("interface %s introuvable: %v", iface, err)
|
||||
case !up:
|
||||
return fmt.Sprintf("interface %s down", iface)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue