// This file is part of the happyDomain (R) project. // Copyright (c) 2020-2026 happyDomain // Authors: Pierre-Olivier Mercier, et al. // // This program is offered under a commercial and under the AGPL license. // For commercial licensing, contact us at . // // For AGPL licensing: // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . 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."}} }