Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
option to enable soap client debugging (#2442)
Browse files Browse the repository at this point in the history
Signed-off-by: Dani Louca <[email protected]>

Signed-off-by: Dani Louca <[email protected]>
  • Loading branch information
dloucasfx authored Sep 7, 2022
1 parent c14862a commit 0c87d89
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/monitors/vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Configuration](../monitor-config.md#common-configuration).**
| `tlsCACertPath` | no | `string` | Path to the ca file |
| `tlsClientCertificatePath` | no | `string` | Configure client certs. Both tlsClientKeyPath and tlsClientCertificatePath must be present. The files must contain PEM encoded data. Path to the client certificate |
| `tlsClientKeyPath` | no | `string` | Path to the keyfile |
| `soapClientDebug` | no | `bool` | When set to true, all the SOAP requests and responses will be logged. This generates lots of data, only use it for debugging. For this setting to take effect, make sure to restart the agent (**default:** `false`) |


## Metrics
Expand Down
4 changes: 4 additions & 0 deletions pkg/monitors/vsphere/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ type Config struct {
TLSClientCertificatePath string `yaml:"tlsClientCertificatePath"`
// Path to the keyfile
TLSClientKeyPath string `yaml:"tlsClientKeyPath"`
// When set to true, all the SOAP requests and responses will be logged.
// This generates lots of data, only use it for debugging.
// For this setting to take effect, make sure to restart the agent
SOAPClientDebug bool `yaml:"soapClientDebug"`
}

type Dimensions map[string]string
Expand Down
4 changes: 4 additions & 0 deletions pkg/monitors/vsphere/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/session"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/debug"
"github.com/vmware/govmomi/vim25/soap"

"github.com/signalfx/signalfx-agent/pkg/monitors/vsphere/model"
Expand Down Expand Up @@ -60,6 +61,9 @@ func (svc *AuthService) newGovmomiClient(ctx context.Context, myURL *url.URL, co
}

func (svc *AuthService) newVimClient(ctx context.Context, myURL *url.URL, conf *model.Config) (*vim25.Client, error) {
if conf.SOAPClientDebug {
debug.SetProvider(&LogProvider{log: svc.log})
}
soapClient := soap.NewClient(myURL, conf.InsecureSkipVerify)
if conf.TLSCACertPath != "" {
svc.log.Info("Attempting to load TLSCACertPath from ", conf.TLSCACertPath)
Expand Down
42 changes: 42 additions & 0 deletions pkg/monitors/vsphere/service/log_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package service

import (
"io"
"regexp"

"github.com/sirupsen/logrus"
)

type LogWriterCloser struct {
log logrus.FieldLogger
}

func NewLogWriterCloser(log logrus.FieldLogger) *LogWriterCloser {
return &LogWriterCloser{log: log}
}

func (lwc *LogWriterCloser) Write(p []byte) (n int, err error) {
lwc.log.Info(string(Scrub(p)))
return len(p), nil
}

func (lwc *LogWriterCloser) Close() error {
return nil
}

type LogProvider struct {
log logrus.FieldLogger
}

func (s *LogProvider) NewFile(p string) io.WriteCloser {
return NewLogWriterCloser(s.log)
}

func (s *LogProvider) Flush() {
}

var scrubPassword = regexp.MustCompile(`<password>(.*)</password>`)

func Scrub(in []byte) []byte {
return scrubPassword.ReplaceAll(in, []byte(`<password>********</password>`))
}
8 changes: 8 additions & 0 deletions selfdescribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -56607,6 +56607,14 @@
"required": false,
"type": "string",
"elementKind": ""
},
{
"yamlName": "soapClientDebug",
"doc": "When set to true, all the SOAP requests and responses will be logged. This generates lots of data, only use it for debugging. For this setting to take effect, make sure to restart the agent",
"default": false,
"required": false,
"type": "bool",
"elementKind": ""
}
]
},
Expand Down

0 comments on commit 0c87d89

Please sign in to comment.