github.com/netdata/go.d.plugin@v0.58.1/modules/dnsmasq/init.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package dnsmasq 4 5 import ( 6 "errors" 7 "fmt" 8 9 "github.com/netdata/go.d.plugin/agent/module" 10 ) 11 12 func (d Dnsmasq) validateConfig() error { 13 if d.Address == "" { 14 return errors.New("'address' parameter not set") 15 } 16 if !isProtocolValid(d.Protocol) { 17 return fmt.Errorf("'protocol' (%s) is not valid, expected one of %v", d.Protocol, validProtocols) 18 } 19 return nil 20 } 21 22 func (d Dnsmasq) initDNSClient() (dnsClient, error) { 23 return d.newDNSClient(d.Protocol, d.Timeout.Duration), nil 24 } 25 26 func (d Dnsmasq) initCharts() (*module.Charts, error) { 27 return cacheCharts.Copy(), nil 28 } 29 30 func isProtocolValid(protocol string) bool { 31 for _, v := range validProtocols { 32 if protocol == v { 33 return true 34 } 35 } 36 return false 37 } 38 39 var validProtocols = []string{ 40 "udp", 41 "tcp", 42 "tcp-tls", 43 }