add variable auto_detect_local_dns_server

This commit is contained in:
lsy1990 2022-07-26 16:05:55 +08:00
parent cfba6f692e
commit 6c4ae75562
2 changed files with 16 additions and 17 deletions

View File

@ -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"]

View File

@ -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,9 +70,7 @@ 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 { if len(ins.Servers) == 0 {
resolvPath := "/etc/resolv.conf" resolvPath := "/etc/resolv.conf"
if _, err := os.Stat(resolvPath); os.IsNotExist(err) { if _, err := os.Stat(resolvPath); os.IsNotExist(err) {
@ -84,10 +82,11 @@ func (ins *Instance) Init() error {
Servers = append(Servers, ipAddress) Servers = append(Servers, ipAddress)
} }
ins.Servers = Servers ins.Servers = Servers
}
}
if len(ins.Servers) == 0 { if len(ins.Servers) == 0 {
return nil return nil
} }
}
if ins.Network == "" { if ins.Network == "" {
ins.Network = "udp" ins.Network = "udp"