diff --git a/checker/collect.go b/checker/collect.go index 153ab32..7e1f4b5 100644 --- a/checker/collect.go +++ b/checker/collect.go @@ -21,6 +21,7 @@ import ( "time" sdk "git.happydns.org/checker-sdk-go/checker" + happydns "git.happydns.org/happyDomain/model" "golang.org/x/net/html" ) @@ -143,7 +144,22 @@ func buildTarget(ctx context.Context, opts sdk.CheckerOptions) (Target, error) { userAgent = v } - host, ips := addressesFromServer(server) + // Origin is the FQDN where the service is mounted: svc.Domain holds the + // subdomain (relative to apex; "@" for apex), and the domain_name + // autofill carries the zone apex. + apex := "" + if v, ok := sdk.GetOption[string](opts, OptionDomainName); ok { + apex = strings.TrimSuffix(v, ".") + } + subdomain := "" + if svc, ok := sdk.GetOption[happydns.ServiceMessage](opts, OptionService); ok { + subdomain = strings.TrimSuffix(svc.Domain, ".") + } + origin := sdk.JoinRelative(subdomain, apex) + host, ips := addressesFromServer(server, origin) + if host == "" { + host = origin + } // abstract.Server only pins one A and one AAAA. Resolve the host to // pick up any additional records the authoritative DNS exposes, so // multi-IP deployments aren't silently under-probed. Failures are diff --git a/checker/definition.go b/checker/definition.go index 74b1a3f..0aeaffa 100644 --- a/checker/definition.go +++ b/checker/definition.go @@ -82,6 +82,12 @@ func (p *httpProvider) Definition() *sdk.CheckerDefinition { AutoFill: sdk.AutoFillService, Hide: true, }, + { + Id: OptionDomainName, + Label: "Parent domain name", + AutoFill: sdk.AutoFillDomainName, + Hide: true, + }, }, }, Rules: Rules(), diff --git a/checker/provider_test.go b/checker/provider_test.go index feb9f0c..86a5bf0 100644 --- a/checker/provider_test.go +++ b/checker/provider_test.go @@ -227,7 +227,7 @@ func TestAddressesFromServer(t *testing.T) { } for _, c := range cases { t.Run(c.name, func(t *testing.T) { - host, ips := addressesFromServer(c.srv) + host, ips := addressesFromServer(c.srv, "") if host != c.wantHost { t.Errorf("host = %q, want %q", host, c.wantHost) } diff --git a/checker/service.go b/checker/service.go index f4fbb9c..0ec5c87 100644 --- a/checker/service.go +++ b/checker/service.go @@ -9,7 +9,6 @@ import ( "encoding/json" "fmt" "net" - "strings" sdk "git.happydns.org/checker-sdk-go/checker" happydns "git.happydns.org/happyDomain/model" @@ -36,15 +35,17 @@ func resolveServer(opts sdk.CheckerOptions) (*abstract.Server, error) { return &server, nil } -// addressesFromServer returns the (host, ips) tuple to probe. -func addressesFromServer(server *abstract.Server) (host string, ips []string) { +// addressesFromServer returns the (host, ips) tuple to probe. origin is +// the service's parent zone; the A/AAAA Hdr.Name is relative to it as +// happyDomain encodes service owners, so we must join before using as FQDN. +func addressesFromServer(server *abstract.Server, origin string) (host string, ips []string) { if server.A != nil && len(server.A.A) > 0 { - host = strings.TrimSuffix(server.A.Hdr.Name, ".") + host = sdk.JoinRelative(server.A.Hdr.Name, origin) ips = append(ips, server.A.A.String()) } if server.AAAA != nil && len(server.AAAA.AAAA) > 0 { if host == "" { - host = strings.TrimSuffix(server.AAAA.Hdr.Name, ".") + host = sdk.JoinRelative(server.AAAA.Hdr.Name, origin) } ips = append(ips, server.AAAA.AAAA.String()) } diff --git a/checker/types.go b/checker/types.go index 2c11eac..142c653 100644 --- a/checker/types.go +++ b/checker/types.go @@ -24,6 +24,7 @@ const ObservationKeyHTTP = "http" const ( OptionService = "service" + OptionDomainName = "domain_name" OptionProbeTimeoutMs = "probeTimeoutMs" OptionMaxRedirects = "maxRedirects" OptionUserAgent = "userAgent"