package checker import ( "context" "fmt" sdk "git.happydns.org/checker-sdk-go/checker" ) type ruleRedundancy struct{} func RuleRedundancy() sdk.CheckRule { return &ruleRedundancy{} } func (ruleRedundancy) Name() string { return "srv_redundancy" } func (ruleRedundancy) Description() string { return "At least two distinct SRV targets exist (avoids single point of failure)." } func (ruleRedundancy) Evaluate(ctx context.Context, obs sdk.ObservationGetter, _ sdk.CheckerOptions) []sdk.CheckState { d, cs := getData(ctx, obs) if cs != nil { return []sdk.CheckState{*cs} } targets := map[string]bool{} for _, r := range d.Records { if r.IsNullTarget { continue } targets[r.Target] = true } if len(targets) >= 2 { return []sdk.CheckState{{Status: sdk.StatusOK, Code: "srv_redundant", Message: fmt.Sprintf("%d distinct targets.", len(targets))}} } if len(targets) == 1 { return []sdk.CheckState{{Status: sdk.StatusInfo, Code: "srv_single_target", Message: "Single SRV target: no redundancy at DNS level."}} } return []sdk.CheckState{{Status: sdk.StatusUnknown, Code: "srv_no_targets_redundancy", Message: "No usable SRV targets."}} }