checker: split monolithic rule into per-concern rules
Replace the single matrix_federation rule with individual rules for federation status, well-known delegation, SRV records, connection reachability, TLS checks, and homeserver version, so the UI surfaces a clear checklist. Drop the incorrect well-known/server_name equality check: m.server points at the delegated federation endpoint, which is intentionally distinct from server_name.
This commit is contained in:
parent
2bd0ae99bd
commit
e4b6481d32
8 changed files with 346 additions and 60 deletions
61
checker/rules_federation.go
Normal file
61
checker/rules_federation.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
// federationOKRule reflects the overall FederationOK flag reported by the
|
||||
// Matrix Federation Tester. Other rules isolate specific concerns; this
|
||||
// rule is the global verdict so callers get a single-line answer to
|
||||
// "does this homeserver federate?".
|
||||
type federationOKRule struct{}
|
||||
|
||||
func (r *federationOKRule) Name() string { return "matrix.federation_ok" }
|
||||
func (r *federationOKRule) Description() string {
|
||||
return "Reports the overall federation status returned by the Matrix Federation Tester."
|
||||
}
|
||||
|
||||
func (r *federationOKRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, opts sdk.CheckerOptions) []sdk.CheckState {
|
||||
data, errSt := loadMatrixData(ctx, obs)
|
||||
if errSt != nil {
|
||||
return []sdk.CheckState{*errSt}
|
||||
}
|
||||
|
||||
domain, _ := opts["serviceDomain"].(string)
|
||||
domain = strings.TrimSuffix(domain, ".")
|
||||
|
||||
if data.FederationOK {
|
||||
version := strings.TrimSpace(data.Version.Name + " " + data.Version.Version)
|
||||
st := passState("matrix.federation_ok.ok", "Matrix federation is working.")
|
||||
if version != "" {
|
||||
st.Message = fmt.Sprintf("Matrix federation is working (running %s).", version)
|
||||
st.Meta = map[string]any{"version": version}
|
||||
}
|
||||
return []sdk.CheckState{st}
|
||||
}
|
||||
|
||||
var statusLine string
|
||||
switch {
|
||||
case data.DNSResult.SRVError != nil && data.WellKnownResult.Result != "":
|
||||
statusLine = fmt.Sprintf("%s OR %s", data.DNSResult.SRVError.Message, data.WellKnownResult.Result)
|
||||
case len(data.ConnectionErrors) > 0:
|
||||
var msg strings.Builder
|
||||
for srv, cerr := range data.ConnectionErrors {
|
||||
if msg.Len() > 0 {
|
||||
msg.WriteString("; ")
|
||||
}
|
||||
msg.WriteString(srv)
|
||||
msg.WriteString(": ")
|
||||
msg.WriteString(cerr.Message)
|
||||
}
|
||||
statusLine = fmt.Sprintf("Connection errors: %s", msg.String())
|
||||
default:
|
||||
statusLine = fmt.Sprintf("Federation broken. Check https://federationtester.matrix.org/#%s", domain)
|
||||
}
|
||||
|
||||
return []sdk.CheckState{critState("matrix.federation_ok.fail", statusLine)}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue