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