summaryrefslogtreecommitdiffstats
path: root/src/go/plugin/go.d/modules/bind
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-09 08:36:07 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-09 08:36:07 +0000
commite8c44275b9a1937b5948010a042294d580d36d7c (patch)
treee87c73e25556c3c9d5442f5ca4ba0cf46c64ec70 /src/go/plugin/go.d/modules/bind
parentAdding upstream version 1.47.5. (diff)
downloadnetdata-upstream.tar.xz
netdata-upstream.zip
Adding upstream version 2.0.0.upstream/2.0.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/go/plugin/go.d/modules/bind')
-rw-r--r--src/go/plugin/go.d/modules/bind/README.md10
-rw-r--r--src/go/plugin/go.d/modules/bind/bind.go36
-rw-r--r--src/go/plugin/go.d/modules/bind/init.go6
-rw-r--r--src/go/plugin/go.d/modules/bind/json_client.go44
-rw-r--r--src/go/plugin/go.d/modules/bind/xml3_client.go34
5 files changed, 34 insertions, 96 deletions
diff --git a/src/go/plugin/go.d/modules/bind/README.md b/src/go/plugin/go.d/modules/bind/README.md
index 90906ac2..e42a8c2e 100644
--- a/src/go/plugin/go.d/modules/bind/README.md
+++ b/src/go/plugin/go.d/modules/bind/README.md
@@ -1,13 +1,3 @@
-<!--
-title: "Bind9 monitoring with Netdata"
-description: "Monitor the health and performance of Bind9 DNS servers with zero configuration, per-second metric granularity, and interactive visualizations."
-custom_edit_url: "https://github.com/netdata/go.d.plugin/edit/master/modules/bind/README.md"
-sidebar_label: "Bind9"
-learn_status: "Published"
-learn_topic_type: "References"
-learn_rel_path: "Integrations/Monitor/Webapps"
--->
-
# Bind9 collector
[`Bind9`](https://www.isc.org/bind/) (or named) is a very flexible, full-featured DNS system.
diff --git a/src/go/plugin/go.d/modules/bind/bind.go b/src/go/plugin/go.d/modules/bind/bind.go
index 6087f6f7..91ca14fe 100644
--- a/src/go/plugin/go.d/modules/bind/bind.go
+++ b/src/go/plugin/go.d/modules/bind/bind.go
@@ -5,13 +5,14 @@ package bind
import (
_ "embed"
"errors"
+ "fmt"
"net/http"
"time"
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
-
+ "github.com/netdata/netdata/go/plugins/pkg/matcher"
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
)
//go:embed "config_schema.json"
@@ -28,12 +29,12 @@ func init() {
func New() *Bind {
return &Bind{
Config: Config{
- HTTP: web.HTTP{
- Request: web.Request{
+ HTTPConfig: web.HTTPConfig{
+ RequestConfig: web.RequestConfig{
URL: "http://127.0.0.1:8653/json/v1",
},
- Client: web.Client{
- Timeout: web.Duration(time.Second),
+ ClientConfig: web.ClientConfig{
+ Timeout: confopt.Duration(time.Second),
},
},
},
@@ -42,9 +43,9 @@ func New() *Bind {
}
type Config struct {
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
- web.HTTP `yaml:",inline" json:""`
- PermitView string `yaml:"permit_view,omitempty" json:"permit_view"`
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
+ web.HTTPConfig `yaml:",inline" json:""`
+ PermitView string `yaml:"permit_view,omitempty" json:"permit_view"`
}
type (
@@ -71,30 +72,26 @@ func (b *Bind) Configuration() any {
func (b *Bind) Init() error {
if err := b.validateConfig(); err != nil {
- b.Errorf("config verification: %v", err)
- return err
+ return fmt.Errorf("config verification: %v", err)
}
pvm, err := b.initPermitViewMatcher()
if err != nil {
- b.Error(err)
- return err
+ return fmt.Errorf("init permit view matcher: %v", err)
}
if pvm != nil {
b.permitView = pvm
}
- httpClient, err := web.NewHTTPClient(b.Client)
+ httpClient, err := web.NewHTTPClient(b.ClientConfig)
if err != nil {
- b.Errorf("creating http client : %v", err)
- return err
+ return fmt.Errorf("creating http client : %v", err)
}
b.httpClient = httpClient
bindClient, err := b.initBindApiClient(httpClient)
if err != nil {
- b.Error(err)
- return err
+ return fmt.Errorf("init bind api client: %v", err)
}
b.bindAPIClient = bindClient
@@ -104,7 +101,6 @@ func (b *Bind) Init() error {
func (b *Bind) Check() error {
mx, err := b.collect()
if err != nil {
- b.Error(err)
return err
}
if len(mx) == 0 {
diff --git a/src/go/plugin/go.d/modules/bind/init.go b/src/go/plugin/go.d/modules/bind/init.go
index fe533b97..7a02b1bf 100644
--- a/src/go/plugin/go.d/modules/bind/init.go
+++ b/src/go/plugin/go.d/modules/bind/init.go
@@ -8,7 +8,7 @@ import (
"net/http"
"strings"
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
+ "github.com/netdata/netdata/go/plugins/pkg/matcher"
)
func (b *Bind) validateConfig() error {
@@ -28,9 +28,9 @@ func (b *Bind) initPermitViewMatcher() (matcher.Matcher, error) {
func (b *Bind) initBindApiClient(httpClient *http.Client) (bindAPIClient, error) {
switch {
case strings.HasSuffix(b.URL, "/xml/v3"): // BIND 9.9+
- return newXML3Client(httpClient, b.Request), nil
+ return newXML3Client(httpClient, b.RequestConfig), nil
case strings.HasSuffix(b.URL, "/json/v1"): // BIND 9.10+
- return newJSONClient(httpClient, b.Request), nil
+ return newJSONClient(httpClient, b.RequestConfig), nil
default:
return nil, fmt.Errorf("URL %s is wrong, supported endpoints: `/xml/v3`, `/json/v1`", b.URL)
}
diff --git a/src/go/plugin/go.d/modules/bind/json_client.go b/src/go/plugin/go.d/modules/bind/json_client.go
index 04eecdb0..f6d7e575 100644
--- a/src/go/plugin/go.d/modules/bind/json_client.go
+++ b/src/go/plugin/go.d/modules/bind/json_client.go
@@ -3,12 +3,8 @@
package bind
import (
- "encoding/json"
"fmt"
- "io"
"net/http"
- "net/url"
- "path"
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
)
@@ -33,50 +29,26 @@ type jsonViewResolver struct {
CacheStats map[string]int64
}
-func newJSONClient(client *http.Client, request web.Request) *jsonClient {
+func newJSONClient(client *http.Client, request web.RequestConfig) *jsonClient {
return &jsonClient{httpClient: client, request: request}
}
type jsonClient struct {
httpClient *http.Client
- request web.Request
+ request web.RequestConfig
}
func (c jsonClient) serverStats() (*serverStats, error) {
- req := c.request.Copy()
- u, err := url.Parse(req.URL)
+ req, err := web.NewHTTPRequestWithPath(c.request, "/server")
if err != nil {
- return nil, fmt.Errorf("error on parsing URL: %v", err)
+ return nil, fmt.Errorf("failed to create HTTP request: %v", err)
}
- u.Path = path.Join(u.Path, "/server")
- req.URL = u.String()
+ var stats jsonServerStats
- httpReq, err := web.NewHTTPRequest(req)
- if err != nil {
- return nil, fmt.Errorf("error on creating HTTP request: %v", err)
- }
-
- resp, err := c.httpClient.Do(httpReq)
- if err != nil {
- return nil, fmt.Errorf("error on request : %v", err)
- }
- defer closeBody(resp)
-
- if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("%s returned HTTP status %d", httpReq.URL, resp.StatusCode)
+ if err := web.DoHTTP(c.httpClient).RequestJSON(req, &stats); err != nil {
+ return nil, err
}
- stats := &jsonServerStats{}
- if err = json.NewDecoder(resp.Body).Decode(stats); err != nil {
- return nil, fmt.Errorf("error on decoding response from %s : %v", httpReq.URL, err)
- }
- return stats, nil
-}
-
-func closeBody(resp *http.Response) {
- if resp != nil && resp.Body != nil {
- _, _ = io.Copy(io.Discard, resp.Body)
- _ = resp.Body.Close()
- }
+ return &stats, nil
}
diff --git a/src/go/plugin/go.d/modules/bind/xml3_client.go b/src/go/plugin/go.d/modules/bind/xml3_client.go
index c48d1af3..357bef67 100644
--- a/src/go/plugin/go.d/modules/bind/xml3_client.go
+++ b/src/go/plugin/go.d/modules/bind/xml3_client.go
@@ -3,11 +3,8 @@
package bind
import (
- "encoding/xml"
"fmt"
"net/http"
- "net/url"
- "path"
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
)
@@ -34,44 +31,27 @@ type xml3View struct {
CounterGroups []xml3CounterGroup `xml:"counters"`
}
-func newXML3Client(client *http.Client, request web.Request) *xml3Client {
+func newXML3Client(client *http.Client, request web.RequestConfig) *xml3Client {
return &xml3Client{httpClient: client, request: request}
}
type xml3Client struct {
httpClient *http.Client
- request web.Request
+ request web.RequestConfig
}
func (c xml3Client) serverStats() (*serverStats, error) {
- req := c.request.Copy()
- u, err := url.Parse(req.URL)
+ req, err := web.NewHTTPRequestWithPath(c.request, "/server")
if err != nil {
- return nil, fmt.Errorf("error on parsing URL: %v", err)
+ return nil, fmt.Errorf("failed to create HTTP request: %v", err)
}
- u.Path = path.Join(u.Path, "/server")
- req.URL = u.String()
+ var stats xml3Stats
- httpReq, err := web.NewHTTPRequest(req)
- if err != nil {
- return nil, fmt.Errorf("error on creating HTTP request: %v", err)
- }
-
- resp, err := c.httpClient.Do(httpReq)
- if err != nil {
- return nil, fmt.Errorf("error on request : %v", err)
+ if err := web.DoHTTP(c.httpClient).RequestXML(req, &stats); err != nil {
+ return nil, err
}
- defer closeBody(resp)
- if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("%s returned HTTP status %d", httpReq.URL, resp.StatusCode)
- }
-
- stats := xml3Stats{}
- if err = xml.NewDecoder(resp.Body).Decode(&stats); err != nil {
- return nil, fmt.Errorf("error on decoding response from %s : %v", httpReq.URL, err)
- }
return convertXML(stats), nil
}