add variable auto_detect_local_dns_server
This commit is contained in:
parent
cfba6f692e
commit
6c4ae75562
|
@ -9,7 +9,7 @@
|
||||||
# interval_times = 1
|
# interval_times = 1
|
||||||
|
|
||||||
# #
|
# #
|
||||||
enable = false
|
auto_detect_local_dns_server = false
|
||||||
|
|
||||||
## servers to query
|
## servers to query
|
||||||
# servers = ["8.8.8.8"]
|
# servers = ["8.8.8.8"]
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (dq *DnsQuery) GetInstances() []inputs.Instance {
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
config.InstanceConfig
|
config.InstanceConfig
|
||||||
|
|
||||||
Enable bool `toml:"enable"`
|
EnableAutoDetectDnsServer bool `toml:"auto_detect_local_dns_server"`
|
||||||
// Domains or subdomains to query
|
// Domains or subdomains to query
|
||||||
Domains []string `toml:"domains"`
|
Domains []string `toml:"domains"`
|
||||||
|
|
||||||
|
@ -70,23 +70,22 @@ type Instance struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ins *Instance) Init() error {
|
func (ins *Instance) Init() error {
|
||||||
if ins.Enable == false {
|
if ins.EnableAutoDetectDnsServer == true {
|
||||||
return nil
|
if len(ins.Servers) == 0 {
|
||||||
|
resolvPath := "/etc/resolv.conf"
|
||||||
|
if _, err := os.Stat(resolvPath); os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
config, _ := dns.ClientConfigFromFile(resolvPath)
|
||||||
|
Servers := []string{}
|
||||||
|
for _, ipAddress := range config.Servers {
|
||||||
|
Servers = append(Servers, ipAddress)
|
||||||
|
}
|
||||||
|
ins.Servers = Servers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(ins.Servers) == 0 {
|
if len(ins.Servers) == 0 {
|
||||||
resolvPath := "/etc/resolv.conf"
|
return nil
|
||||||
if _, err := os.Stat(resolvPath); os.IsNotExist(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
config, _ := dns.ClientConfigFromFile(resolvPath)
|
|
||||||
Servers := []string{}
|
|
||||||
for _, ipAddress := range config.Servers {
|
|
||||||
Servers = append(Servers, ipAddress)
|
|
||||||
}
|
|
||||||
ins.Servers = Servers
|
|
||||||
if len(ins.Servers) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ins.Network == "" {
|
if ins.Network == "" {
|
||||||
|
|
Loading…
Reference in New Issue