The SDK split the HTTP server scaffolding into the new checker-sdk-go/checker/server subpackage and CheckRule.Evaluate now returns []CheckState. Update main.go to import server and call server.New, switch the rule and the package-level Evaluate helper to the new slice return type, and isolate the interactive form code behind the standalone build tag so plugin/builtin builds skip net/http and html/template entirely.
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package checker
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
sdk "git.happydns.org/checker-sdk-go/checker"
|
|
)
|
|
|
|
// Rule returns the delegation check rule.
|
|
func Rule() sdk.CheckRule {
|
|
return &delegationRule{}
|
|
}
|
|
|
|
type delegationRule struct{}
|
|
|
|
func (r *delegationRule) Name() string { return "delegation_check" }
|
|
|
|
func (r *delegationRule) Description() string {
|
|
return "Verifies a DNS delegation against its parent zone and the delegated name servers"
|
|
}
|
|
|
|
func (r *delegationRule) ValidateOptions(opts sdk.CheckerOptions) error {
|
|
if v, ok := opts["minNameServers"]; ok {
|
|
f, ok := v.(float64)
|
|
if !ok {
|
|
return fmt.Errorf("minNameServers must be a number")
|
|
}
|
|
if f < 1 {
|
|
return fmt.Errorf("minNameServers must be >= 1")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *delegationRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, opts sdk.CheckerOptions) []sdk.CheckState {
|
|
var data DelegationData
|
|
if err := obs.Get(ctx, ObservationKeyDelegation, &data); err != nil {
|
|
return []sdk.CheckState{{
|
|
Status: sdk.StatusError,
|
|
Message: fmt.Sprintf("Failed to get delegation data: %v", err),
|
|
Code: "delegation_error",
|
|
}}
|
|
}
|
|
return Evaluate(&data)
|
|
}
|