From 0c87d89055b69e2c11ccc85d9abaf9ab5d55831b Mon Sep 17 00:00:00 2001 From: Dani Louca <59848726+dloucasfx@users.noreply.github.com> Date: Wed, 7 Sep 2022 09:03:20 -0400 Subject: [PATCH] option to enable soap client debugging (#2442) Signed-off-by: Dani Louca Signed-off-by: Dani Louca --- docs/monitors/vsphere.md | 1 + pkg/monitors/vsphere/model/model.go | 4 ++ pkg/monitors/vsphere/service/auth.go | 4 ++ pkg/monitors/vsphere/service/log_provider.go | 42 ++++++++++++++++++++ selfdescribe.json | 8 ++++ 5 files changed, 59 insertions(+) create mode 100644 pkg/monitors/vsphere/service/log_provider.go diff --git a/docs/monitors/vsphere.md b/docs/monitors/vsphere.md index a3b80bd58b..03c4de827e 100644 --- a/docs/monitors/vsphere.md +++ b/docs/monitors/vsphere.md @@ -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 diff --git a/pkg/monitors/vsphere/model/model.go b/pkg/monitors/vsphere/model/model.go index d2d2aec855..95790846c7 100644 --- a/pkg/monitors/vsphere/model/model.go +++ b/pkg/monitors/vsphere/model/model.go @@ -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 diff --git a/pkg/monitors/vsphere/service/auth.go b/pkg/monitors/vsphere/service/auth.go index b8051793d7..29d5e10135 100644 --- a/pkg/monitors/vsphere/service/auth.go +++ b/pkg/monitors/vsphere/service/auth.go @@ -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" @@ -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) diff --git a/pkg/monitors/vsphere/service/log_provider.go b/pkg/monitors/vsphere/service/log_provider.go new file mode 100644 index 0000000000..3bb9e439ac --- /dev/null +++ b/pkg/monitors/vsphere/service/log_provider.go @@ -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(`(.*)`) + +func Scrub(in []byte) []byte { + return scrubPassword.ReplaceAll(in, []byte(`********`)) +} diff --git a/selfdescribe.json b/selfdescribe.json index 17e30d2fb5..d813651529 100644 --- a/selfdescribe.json +++ b/selfdescribe.json @@ -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": "" } ] },