Initial commit
This commit is contained in:
commit
2d9a821a65
18 changed files with 1821 additions and 0 deletions
46
checker/rule.go
Normal file
46
checker/rule.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
// Rule returns the alias check rule.
|
||||
func Rule() sdk.CheckRule {
|
||||
return &aliasRule{}
|
||||
}
|
||||
|
||||
type aliasRule struct{}
|
||||
|
||||
func (r *aliasRule) Name() string { return "alias_check" }
|
||||
|
||||
func (r *aliasRule) Description() string {
|
||||
return "Verifies a CNAME / DNAME / ALIAS chain: coexistence, loops, length, target resolvability, DNSSEC coverage."
|
||||
}
|
||||
|
||||
func (r *aliasRule) ValidateOptions(opts sdk.CheckerOptions) error {
|
||||
if v, ok := opts["maxChainLength"]; ok {
|
||||
f, ok := v.(float64)
|
||||
if !ok {
|
||||
return fmt.Errorf("maxChainLength must be a number")
|
||||
}
|
||||
if f < 1 {
|
||||
return fmt.Errorf("maxChainLength must be >= 1")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *aliasRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, opts sdk.CheckerOptions) []sdk.CheckState {
|
||||
var data AliasData
|
||||
if err := obs.Get(ctx, ObservationKeyAlias, &data); err != nil {
|
||||
return []sdk.CheckState{{
|
||||
Status: sdk.StatusError,
|
||||
Message: fmt.Sprintf("failed to get alias data: %v", err),
|
||||
Code: "alias_error",
|
||||
}}
|
||||
}
|
||||
return Evaluate(&data)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue