feat(dns): Support TXT query type (#1679)

Allows monitoring of things like spf records and others.

Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
Nils Herde
2026-06-05 22:00:42 -04:00
committed by GitHub
co-authored by TwiN
parent 809e5068d7
commit 08895200bb
2 changed files with 19 additions and 2 deletions
+7
View File
@@ -499,6 +499,13 @@ func QueryDNS(queryType, queryName, url string) (connected bool, dnsRcode string
if srv, ok := rr.(*dns.SRV); ok {
body = []byte(fmt.Sprintf("%s:%d", srv.Target, srv.Port))
}
case dns.TypeTXT:
if txt, ok := rr.(*dns.TXT); ok {
if len(body) > 0 {
body = append(body, '\n')
}
body = append(body, []byte(strings.Join(txt.Txt, ""))...)
}
default:
body = []byte("query type is not supported yet")
}
+12 -2
View File
@@ -507,6 +507,16 @@ func TestQueryDNS(t *testing.T) {
expectedDNSCode: "NOERROR",
expectedBody: "one.one.one.one.",
},
{
name: "test Config with type TXT",
inputDNS: dns.Config{
QueryType: "TXT",
QueryName: "example.com.",
},
inputURL: "1.1.1.1",
expectedDNSCode: "NOERROR",
expectedBody: "*v=spf1*",
},
{
name: "test Config with fake type and retrieve error",
inputDNS: dns.Config{
@@ -526,8 +536,8 @@ func TestQueryDNS(t *testing.T) {
if dnsRCode != scenario.expectedDNSCode {
t.Errorf("expected DNSRCode to be %s, got %s", scenario.expectedDNSCode, dnsRCode)
}
if scenario.inputDNS.QueryType == "NS" {
// Because there are often multiple nameservers backing a single domain, we'll only look at the suffix
if scenario.inputDNS.QueryType == "NS" || scenario.inputDNS.QueryType == "TXT" {
// Some record types can have multiple valid answers, so wildcard matching is used in those scenarios
if !pattern.Match(scenario.expectedBody, string(body)) {
t.Errorf("got %s, expected result %s,", string(body), scenario.expectedBody)
}