package checker import ( "context" sdk "git.happydns.org/checker-sdk-go/checker" ) // simpleConcernRule is the common shape for "load SMTPData, derive the // issues, keep only those whose Code matches one of `codes`, and emit // either the matching states or a single pass state". type simpleConcernRule struct { name string description string codes []string passCode string passMessage string } func (r *simpleConcernRule) Name() string { return r.name } func (r *simpleConcernRule) Description() string { return r.description } func (r *simpleConcernRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, _ sdk.CheckerOptions) []sdk.CheckState { data, errSt := loadSMTPData(ctx, obs) if errSt != nil { return []sdk.CheckState{*errSt} } // Null-MX declares the domain does not accept mail; every other rule // becomes vacuous. Return "not tested" so those lines do not count as // a pass or fail in the aggregator. if data.MX.NullMX { return []sdk.CheckState{notTestedState(r.name+".skipped", "Skipped: domain declares a null MX (refuses mail).")} } issues := issuesByCodes(data, r.codes...) if len(issues) == 0 { return []sdk.CheckState{passState(r.passCode, r.passMessage)} } return statesFromIssues(issues) }