Initial commit
This commit is contained in:
commit
612a19c01a
23 changed files with 2402 additions and 0 deletions
98
checker/rule.go
Normal file
98
checker/rule.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
// Rules returns the full list of CheckRules the SIP checker exposes. Each
|
||||
// rule covers a single concern so the UI can show granular pass/fail
|
||||
// instead of a monolithic aggregate. Shared helpers live at the bottom of
|
||||
// this file; per-concern logic is in rules_*.go.
|
||||
func Rules() []sdk.CheckRule {
|
||||
return []sdk.CheckRule{
|
||||
&srvPresenceRule{},
|
||||
&transportDiversityRule{},
|
||||
&srvTargetsResolvableRule{},
|
||||
&endpointReachableRule{},
|
||||
&optionsResponseRule{},
|
||||
&optionsCapabilitiesRule{},
|
||||
&ipv6CoverageRule{},
|
||||
&tlsQualityRule{},
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Shared helpers ──────────────────────────────────────────────────
|
||||
|
||||
// loadSIPData fetches the SIP observation. On error, returns a CheckState
|
||||
// the caller should emit to short-circuit its rule.
|
||||
func loadSIPData(ctx context.Context, obs sdk.ObservationGetter) (*SIPData, *sdk.CheckState) {
|
||||
var data SIPData
|
||||
if err := obs.Get(ctx, ObservationKeySIP, &data); err != nil {
|
||||
return nil, &sdk.CheckState{
|
||||
Status: sdk.StatusError,
|
||||
Message: fmt.Sprintf("failed to load SIP observation: %v", err),
|
||||
Code: "sip.observation_error",
|
||||
}
|
||||
}
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func statesFromIssues(issues []Issue) []sdk.CheckState {
|
||||
out := make([]sdk.CheckState, 0, len(issues))
|
||||
for _, is := range issues {
|
||||
out = append(out, issueToState(is))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func issueToState(is Issue) sdk.CheckState {
|
||||
st := sdk.CheckState{
|
||||
Status: severityToStatus(is.Severity),
|
||||
Message: is.Message,
|
||||
Code: is.Code,
|
||||
Subject: is.Endpoint,
|
||||
}
|
||||
if is.Fix != "" {
|
||||
st.Meta = map[string]any{"fix": is.Fix}
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
func severityToStatus(sev string) sdk.Status {
|
||||
switch sev {
|
||||
case SeverityCrit:
|
||||
return sdk.StatusCrit
|
||||
case SeverityWarn:
|
||||
return sdk.StatusWarn
|
||||
case SeverityInfo:
|
||||
return sdk.StatusInfo
|
||||
default:
|
||||
return sdk.StatusOK
|
||||
}
|
||||
}
|
||||
|
||||
// wantTLS returns whether the TLS transport was requested for this run.
|
||||
// Mirrors the default at Collect time (all three transports probed when
|
||||
// unset).
|
||||
func wantTLS(opts sdk.CheckerOptions) bool {
|
||||
return sdk.GetBoolOption(opts, "probeTLS", true)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue