summaryrefslogtreecommitdiffstats
path: root/src/go/plugin/go.d/modules/vcsa
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/plugin/go.d/modules/vcsa')
-rw-r--r--src/go/plugin/go.d/modules/vcsa/client/client.go28
-rw-r--r--src/go/plugin/go.d/modules/vcsa/init.go2
-rw-r--r--src/go/plugin/go.d/modules/vcsa/integrations/vcenter_server_appliance.md4
-rw-r--r--src/go/plugin/go.d/modules/vcsa/vcsa.go20
-rw-r--r--src/go/plugin/go.d/modules/vcsa/vcsa_test.go2
5 files changed, 23 insertions, 33 deletions
diff --git a/src/go/plugin/go.d/modules/vcsa/client/client.go b/src/go/plugin/go.d/modules/vcsa/client/client.go
index ea0dd161..97d4102d 100644
--- a/src/go/plugin/go.d/modules/vcsa/client/client.go
+++ b/src/go/plugin/go.d/modules/vcsa/client/client.go
@@ -5,7 +5,6 @@ package client
import (
"encoding/json"
"fmt"
- "io"
"net/http"
"sync"
@@ -72,7 +71,7 @@ type Client struct {
// Login creates a session with the API. This operation exchanges user credentials supplied in the security context
// for a session identifier that is to be used for authenticating subsequent calls.
func (c *Client) Login() error {
- req := web.Request{
+ req := web.RequestConfig{
URL: fmt.Sprintf("%s%s", c.url, pathCISSession),
Username: c.username,
Password: c.password,
@@ -89,14 +88,14 @@ func (c *Client) Login() error {
// Logout terminates the validity of a session token.
func (c *Client) Logout() error {
- req := web.Request{
+ req := web.RequestConfig{
URL: fmt.Sprintf("%s%s", c.url, pathCISSession),
Method: http.MethodDelete,
Headers: map[string]string{apiSessIDKey: c.token.get()},
}
resp, err := c.doOK(req)
- closeBody(resp)
+ web.CloseBody(resp)
c.token.set("")
return err
}
@@ -104,13 +103,13 @@ func (c *Client) Logout() error {
// Ping sent a request to VCSA server to ensure the link is operating.
// In case of 401 error Ping tries to re authenticate.
func (c *Client) Ping() error {
- req := web.Request{
+ req := web.RequestConfig{
URL: fmt.Sprintf("%s%s?~action=get", c.url, pathCISSession),
Method: http.MethodPost,
Headers: map[string]string{apiSessIDKey: c.token.get()},
}
resp, err := c.doOK(req)
- defer closeBody(resp)
+ defer web.CloseBody(resp)
if resp != nil && resp.StatusCode == http.StatusUnauthorized {
return c.Login()
}
@@ -118,7 +117,7 @@ func (c *Client) Ping() error {
}
func (c *Client) health(urlPath string) (string, error) {
- req := web.Request{
+ req := web.RequestConfig{
URL: fmt.Sprintf("%s%s", c.url, urlPath),
Headers: map[string]string{apiSessIDKey: c.token.get()},
}
@@ -171,7 +170,7 @@ func (c *Client) System() (string, error) {
return c.health(pathHealthSystem)
}
-func (c *Client) do(req web.Request) (*http.Response, error) {
+func (c *Client) do(req web.RequestConfig) (*http.Response, error) {
httpReq, err := web.NewHTTPRequest(req)
if err != nil {
return nil, fmt.Errorf("error on creating http request to %s : %v", req.URL, err)
@@ -179,7 +178,7 @@ func (c *Client) do(req web.Request) (*http.Response, error) {
return c.httpClient.Do(httpReq)
}
-func (c *Client) doOK(req web.Request) (*http.Response, error) {
+func (c *Client) doOK(req web.RequestConfig) (*http.Response, error) {
resp, err := c.do(req)
if err != nil {
return nil, err
@@ -191,9 +190,9 @@ func (c *Client) doOK(req web.Request) (*http.Response, error) {
return resp, nil
}
-func (c *Client) doOKWithDecode(req web.Request, dst interface{}) error {
+func (c *Client) doOKWithDecode(req web.RequestConfig, dst any) error {
resp, err := c.doOK(req)
- defer closeBody(resp)
+ defer web.CloseBody(resp)
if err != nil {
return err
}
@@ -204,10 +203,3 @@ func (c *Client) doOKWithDecode(req web.Request, dst interface{}) error {
}
return nil
}
-
-func closeBody(resp *http.Response) {
- if resp != nil && resp.Body != nil {
- _, _ = io.Copy(io.Discard, resp.Body)
- _ = resp.Body.Close()
- }
-}
diff --git a/src/go/plugin/go.d/modules/vcsa/init.go b/src/go/plugin/go.d/modules/vcsa/init.go
index 20631ab4..6af0178a 100644
--- a/src/go/plugin/go.d/modules/vcsa/init.go
+++ b/src/go/plugin/go.d/modules/vcsa/init.go
@@ -20,7 +20,7 @@ func (vc *VCSA) validateConfig() error {
}
func (vc *VCSA) initHealthClient() (*client.Client, error) {
- httpClient, err := web.NewHTTPClient(vc.Client)
+ httpClient, err := web.NewHTTPClient(vc.ClientConfig)
if err != nil {
return nil, err
}
diff --git a/src/go/plugin/go.d/modules/vcsa/integrations/vcenter_server_appliance.md b/src/go/plugin/go.d/modules/vcsa/integrations/vcenter_server_appliance.md
index 99517af3..303cb0f0 100644
--- a/src/go/plugin/go.d/modules/vcsa/integrations/vcenter_server_appliance.md
+++ b/src/go/plugin/go.d/modules/vcsa/integrations/vcenter_server_appliance.md
@@ -148,8 +148,8 @@ No action required.
The configuration file name for this integration is `go.d/vcsa.conf`.
-You can edit the configuration file using the `edit-config` script from the
-Netdata [config directory](/docs/netdata-agent/configuration/README.md#the-netdata-config-directory).
+You can edit the configuration file using the [`edit-config`](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#edit-a-configuration-file-using-edit-config) script from the
+Netdata [config directory](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#the-netdata-config-directory).
```bash
cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata
diff --git a/src/go/plugin/go.d/modules/vcsa/vcsa.go b/src/go/plugin/go.d/modules/vcsa/vcsa.go
index aa12d7c6..d93e707a 100644
--- a/src/go/plugin/go.d/modules/vcsa/vcsa.go
+++ b/src/go/plugin/go.d/modules/vcsa/vcsa.go
@@ -5,9 +5,11 @@ package vcsa
import (
_ "embed"
"errors"
+ "fmt"
"time"
"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"
)
@@ -28,9 +30,9 @@ func init() {
func New() *VCSA {
return &VCSA{
Config: Config{
- HTTP: web.HTTP{
- Client: web.Client{
- Timeout: web.Duration(time.Second * 5),
+ HTTPConfig: web.HTTPConfig{
+ ClientConfig: web.ClientConfig{
+ Timeout: confopt.Duration(time.Second * 5),
},
},
},
@@ -39,8 +41,8 @@ func New() *VCSA {
}
type Config struct {
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
- web.HTTP `yaml:",inline" json:""`
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
+ web.HTTPConfig `yaml:",inline" json:""`
}
type (
@@ -74,14 +76,12 @@ func (vc *VCSA) Configuration() any {
func (vc *VCSA) Init() error {
if err := vc.validateConfig(); err != nil {
- vc.Error(err)
- return err
+ return fmt.Errorf("invalid config: %v", err)
}
c, err := vc.initHealthClient()
if err != nil {
- vc.Errorf("error on creating health client : %vc", err)
- return err
+ return fmt.Errorf("error on creating health client : %vc", err)
}
vc.client = c
@@ -94,13 +94,11 @@ func (vc *VCSA) Init() error {
func (vc *VCSA) Check() error {
err := vc.client.Login()
if err != nil {
- vc.Error(err)
return err
}
mx, err := vc.collect()
if err != nil {
- vc.Error(err)
return err
}
diff --git a/src/go/plugin/go.d/modules/vcsa/vcsa_test.go b/src/go/plugin/go.d/modules/vcsa/vcsa_test.go
index 2c51723d..f41a007a 100644
--- a/src/go/plugin/go.d/modules/vcsa/vcsa_test.go
+++ b/src/go/plugin/go.d/modules/vcsa/vcsa_test.go
@@ -46,7 +46,7 @@ func TestVCenter_InitErrorOnValidatingInitParameters(t *testing.T) {
func TestVCenter_InitErrorOnCreatingClient(t *testing.T) {
job := prepareVCSA()
- job.Client.TLSConfig.TLSCA = "testdata/tls"
+ job.ClientConfig.TLSConfig.TLSCA = "testdata/tls"
assert.Error(t, job.Init())
}