| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package bind |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "fmt" |
| 8 | "net/http" |
| 9 | "strings" |
| 10 | |
| 11 | "github.com/netdata/netdata/go/plugins/pkg/matcher" |
| 12 | ) |
| 13 | |
| 14 | func (c *Collector) validateConfig() error { |
| 15 | if c.URL == "" { |
| 16 | return errors.New("url not set") |
| 17 | } |
| 18 | return nil |
| 19 | } |
| 20 | |
| 21 | func (c *Collector) initPermitViewMatcher() (matcher.Matcher, error) { |
| 22 | if c.PermitView == "" { |
| 23 | return nil, nil |
| 24 | } |
| 25 | return matcher.NewSimplePatternsMatcher(c.PermitView) |
| 26 | } |
| 27 | |
| 28 | func (c *Collector) initBindApiClient(httpClient *http.Client) (bindAPIClient, error) { |
| 29 | switch { |
| 30 | case strings.HasSuffix(c.URL, "/xml/v3"): // BIND 9.9+ |
| 31 | return newXML3Client(httpClient, c.RequestConfig), nil |
| 32 | case strings.HasSuffix(c.URL, "/json/v1"): // BIND 9.10+ |
| 33 | return newJSONClient(httpClient, c.RequestConfig), nil |
| 34 | default: |
| 35 | return nil, fmt.Errorf("URL %s is wrong, supported endpoints: `/xml/v3`, `/json/v1`", c.URL) |
| 36 | } |
| 37 | } |