Initial commit
This commit is contained in:
commit
7ca2fb60c6
24 changed files with 3098 additions and 0 deletions
90
checker/rule.go
Normal file
90
checker/rule.go
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
// Rules returns the full list of CheckRules exposed by the authoritative-consistency
|
||||
// checker. Each rule covers one concern so the UI can list what passed and
|
||||
// what did not without peeking at a single monolithic code field.
|
||||
func Rules() []sdk.CheckRule {
|
||||
return []sdk.CheckRule{
|
||||
&nsDeclaredRule{},
|
||||
&parentDelegationRule{},
|
||||
&nsResolvableRule{},
|
||||
&nsReachableRule{},
|
||||
&authoritativeRule{},
|
||||
&ednsRule{},
|
||||
&latencyRule{},
|
||||
&serialConsistencyRule{},
|
||||
&serialVsSavedRule{},
|
||||
&soaFieldsConsistencyRule{},
|
||||
&nsRRsetConsistencyRule{},
|
||||
}
|
||||
}
|
||||
|
||||
// loadObservation fetches the authoritative-consistency observation. On error, returns
|
||||
// a CheckState the caller should emit to short-circuit its rule.
|
||||
func loadObservation(ctx context.Context, obs sdk.ObservationGetter) (*ObservationData, *sdk.CheckState) {
|
||||
var data ObservationData
|
||||
if err := obs.Get(ctx, ObservationKey, &data); err != nil {
|
||||
return nil, &sdk.CheckState{
|
||||
Status: sdk.StatusError,
|
||||
Message: fmt.Sprintf("Failed to get observation: %v", err),
|
||||
Code: "authoritative_consistency_error",
|
||||
}
|
||||
}
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
// findingsToStates converts findings into CheckStates. The per-finding
|
||||
// remediation hint (if any) is copied into Meta["fix"] so the HTML reporter
|
||||
// can surface it without re-deriving.
|
||||
func findingsToStates(findings []Finding) []sdk.CheckState {
|
||||
out := make([]sdk.CheckState, 0, len(findings))
|
||||
for _, f := range findings {
|
||||
st := sdk.CheckState{
|
||||
Status: severityToStatus(f.Severity),
|
||||
Message: f.Message,
|
||||
Code: f.Code,
|
||||
Subject: f.Server,
|
||||
}
|
||||
if hint, ok := remediationHints[f.Code]; ok && hint != "" {
|
||||
st.Meta = map[string]any{"fix": hint}
|
||||
}
|
||||
out = append(out, st)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func severityToStatus(sev Severity) sdk.Status {
|
||||
switch sev {
|
||||
case SeverityCrit:
|
||||
return sdk.StatusCrit
|
||||
case SeverityWarn:
|
||||
return sdk.StatusWarn
|
||||
case SeverityInfo:
|
||||
return sdk.StatusInfo
|
||||
default:
|
||||
return sdk.StatusOK
|
||||
}
|
||||
}
|
||||
|
||||
func passState(code, message string) sdk.CheckState {
|
||||
return sdk.CheckState{
|
||||
Status: sdk.StatusOK,
|
||||
Message: message,
|
||||
Code: code,
|
||||
}
|
||||
}
|
||||
|
||||
func notTestedState(code, message string) sdk.CheckState {
|
||||
return sdk.CheckState{
|
||||
Status: sdk.StatusUnknown,
|
||||
Message: message,
|
||||
Code: code,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue