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
# #
enable = false
auto_detect_local_dns_server = false
## servers to query
# servers = ["8.8.8.8"]

View File

@ -49,7 +49,7 @@ func (dq *DnsQuery) GetInstances() []inputs.Instance {
type Instance struct {
config.InstanceConfig
Enable bool `toml:"enable"`
EnableAutoDetectDnsServer bool `toml:"auto_detect_local_dns_server"`
// Domains or subdomains to query
Domains []string `toml:"domains"`
@ -70,9 +70,7 @@ type Instance struct {
}
func (ins *Instance) Init() error {
if ins.Enable == false {
return nil
}
if ins.EnableAutoDetectDnsServer == true {
if len(ins.Servers) == 0 {
resolvPath := "/etc/resolv.conf"
if _, err := os.Stat(resolvPath); os.IsNotExist(err) {
@ -84,10 +82,11 @@ func (ins *Instance) Init() error {
Servers = append(Servers, ipAddress)
}
ins.Servers = Servers
}
}
if len(ins.Servers) == 0 {
return nil
}
}
if ins.Network == "" {
ins.Network = "udp"