mirror of
https://github.com/TwiN/gatus.git
synced 2026-08-16 12:16:04 +00:00
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:
@@ -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
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user