diff --git a/plugins/inputs/dns_query/README.md b/plugins/inputs/dns_query/README.md index 033261441..6110f5a7d 100644 --- a/plugins/inputs/dns_query/README.md +++ b/plugins/inputs/dns_query/README.md @@ -8,19 +8,23 @@ The DNS plugin gathers dns query times in miliseconds - like [Dig](https://en.wi # Sample Config: [[inputs.dns_query]] ## servers to query - servers = ["8.8.8.8"] # required + servers = ["8.8.8.8"] - ## Domains or subdomains to query. "." (root) is default - domains = ["."] # optional + ## Network is the network protocol name. + # network = "udp" - ## Query record type. Posible values: A, AAAA, ANY, CNAME, MX, NS, PTR, SOA, SPF, SRV, TXT. Default is "NS" - record_type = "A" # optional + ## Domains or subdomains to query. + # domains = ["."] - ## Dns server port. 53 is default - port = 53 # optional + ## Query record type. + ## Posible values: A, AAAA, CNAME, MX, NS, PTR, TXT, SOA, SPF, SRV. + # record_type = "A" - ## Query timeout in seconds. Default is 2 seconds - timeout = 2 # optional + ## Dns server port. + # port = 53 + + ## Query timeout in seconds. + # timeout = 2 ``` For querying more than one record type make: @@ -46,6 +50,6 @@ For querying more than one record type make: ### Example output: ``` -./telegraf --config telegraf.conf --input-filter dns_query --test +telegraf --input-filter dns_query --test > dns_query,domain=mjasion.pl,record_type=A,server=8.8.8.8 query_time_ms=67.189842 1456082743585760680 ``` diff --git a/plugins/inputs/dns_query/dns_query.go b/plugins/inputs/dns_query/dns_query.go index 2f1fc5482..98b3dce73 100644 --- a/plugins/inputs/dns_query/dns_query.go +++ b/plugins/inputs/dns_query/dns_query.go @@ -3,11 +3,12 @@ package dns_query import ( "errors" "fmt" - "github.com/miekg/dns" "net" "strconv" "time" + "github.com/miekg/dns" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" ) @@ -16,6 +17,9 @@ type DnsQuery struct { // Domains or subdomains to query Domains []string + // Network protocl name + Network string + // Server to query Servers []string @@ -31,20 +35,23 @@ type DnsQuery struct { var sampleConfig = ` ## servers to query - servers = ["8.8.8.8"] # required + servers = ["8.8.8.8"] - ## Domains or subdomains to query. "."(root) is default - domains = ["."] # optional + ## Network is the network protocol name. + # network = "udp" - ## Query record type. Default is "A" + ## Domains or subdomains to query. + # domains = ["."] + + ## Query record type. ## Posible values: A, AAAA, CNAME, MX, NS, PTR, TXT, SOA, SPF, SRV. - record_type = "A" # optional + # record_type = "A" - ## Dns server port. 53 is default - port = 53 # optional + ## Dns server port. + # port = 53 - ## Query timeout in seconds. Default is 2 seconds - timeout = 2 # optional + ## Query timeout in seconds. + # timeout = 2 ` func (d *DnsQuery) SampleConfig() string { @@ -76,6 +83,10 @@ func (d *DnsQuery) Gather(acc telegraf.Accumulator) error { } func (d *DnsQuery) setDefaultValues() { + if d.Network == "" { + d.Network = "udp" + } + if len(d.RecordType) == 0 { d.RecordType = "NS" } @@ -99,6 +110,7 @@ func (d *DnsQuery) getDnsQueryTime(domain string, server string) (float64, error c := new(dns.Client) c.ReadTimeout = time.Duration(d.Timeout) * time.Second + c.Net = d.Network m := new(dns.Msg) recordType, err := d.parseRecordType()