master
go 39 lines 829 Bytes
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package dnsmasq
4
5 import (
6 "errors"
7 "fmt"
8 "slices"
9
10 "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi"
11 )
12
13 func (c *Collector) validateConfig() error {
14 if c.Address == "" {
15 return errors.New("'address' parameter not set")
16 }
17 if !isProtocolValid(c.Protocol) {
18 return fmt.Errorf("'protocol' (%s) is not valid, expected one of %v", c.Protocol, validProtocols)
19 }
20 return nil
21 }
22
23 func (c *Collector) initDNSClient() (dnsClient, error) {
24 return c.newDNSClient(c.Protocol, c.Timeout.Duration()), nil
25 }
26
27 func (c *Collector) initCharts() (*collectorapi.Charts, error) {
28 return cacheCharts.Copy(), nil
29 }
30
31 func isProtocolValid(protocol string) bool {
32 return slices.Contains(validProtocols, protocol)
33 }
34
35 var validProtocols = []string{
36 "udp",
37 "tcp",
38 "tcp-tls",
39 }