fix(inputs.dns_query): Fill out additional record fields (#14979)

This commit is contained in:
Joshua Powers 2024-03-14 12:32:14 -06:00 committed by GitHub
parent 7ce22b2490
commit 70e2ab6c5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -155,6 +155,20 @@ func (d *DNSQuery) query(domain string, server string) (map[string]interface{},
tags["result"] = "success"
fields["result_code"] = uint64(Success)
// Fill out custom fields for specific record types
for _, record := range r.Answer {
switch x := record.(type) {
case *dns.MX:
fields["preference"] = x.Preference
case *dns.SOA:
fields["serial"] = x.Serial
fields["refresh"] = x.Refresh
fields["retry"] = x.Retry
fields["expire"] = x.Expire
fields["minttl"] = x.Minttl
}
}
if d.fieldEnabled["first_ip"] {
for _, record := range r.Answer {
if ip, found := extractIP(record); found {

View File

@ -57,6 +57,9 @@ func TestGatheringMxRecord(t *testing.T) {
queryTime, ok := m.Fields["query_time_ms"].(float64)
require.True(t, ok)
require.NotEqual(t, float64(0), queryTime)
preference, ok := m.Fields["preference"].(uint16)
require.True(t, ok)
require.NotEqual(t, 0, preference)
}
func TestGatheringRootDomain(t *testing.T) {