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

Commit 0c87d89

Browse files
authored
option to enable soap client debugging (#2442)
Signed-off-by: Dani Louca <[email protected]> Signed-off-by: Dani Louca <[email protected]>
1 parent c14862a commit 0c87d89

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

docs/monitors/vsphere.md

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Configuration](../monitor-config.md#common-configuration).**
7070
| `tlsCACertPath` | no | `string` | Path to the ca file |
7171
| `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 |
7272
| `tlsClientKeyPath` | no | `string` | Path to the keyfile |
73+
| `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`) |
7374

7475

7576
## Metrics

pkg/monitors/vsphere/model/model.go

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ type Config struct {
7272
TLSClientCertificatePath string `yaml:"tlsClientCertificatePath"`
7373
// Path to the keyfile
7474
TLSClientKeyPath string `yaml:"tlsClientKeyPath"`
75+
// When set to true, all the SOAP requests and responses will be logged.
76+
// This generates lots of data, only use it for debugging.
77+
// For this setting to take effect, make sure to restart the agent
78+
SOAPClientDebug bool `yaml:"soapClientDebug"`
7579
}
7680

7781
type Dimensions map[string]string

pkg/monitors/vsphere/service/auth.go

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/vmware/govmomi"
1010
"github.com/vmware/govmomi/session"
1111
"github.com/vmware/govmomi/vim25"
12+
"github.com/vmware/govmomi/vim25/debug"
1213
"github.com/vmware/govmomi/vim25/soap"
1314

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

6263
func (svc *AuthService) newVimClient(ctx context.Context, myURL *url.URL, conf *model.Config) (*vim25.Client, error) {
64+
if conf.SOAPClientDebug {
65+
debug.SetProvider(&LogProvider{log: svc.log})
66+
}
6367
soapClient := soap.NewClient(myURL, conf.InsecureSkipVerify)
6468
if conf.TLSCACertPath != "" {
6569
svc.log.Info("Attempting to load TLSCACertPath from ", conf.TLSCACertPath)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package service
2+
3+
import (
4+
"io"
5+
"regexp"
6+
7+
"github.com/sirupsen/logrus"
8+
)
9+
10+
type LogWriterCloser struct {
11+
log logrus.FieldLogger
12+
}
13+
14+
func NewLogWriterCloser(log logrus.FieldLogger) *LogWriterCloser {
15+
return &LogWriterCloser{log: log}
16+
}
17+
18+
func (lwc *LogWriterCloser) Write(p []byte) (n int, err error) {
19+
lwc.log.Info(string(Scrub(p)))
20+
return len(p), nil
21+
}
22+
23+
func (lwc *LogWriterCloser) Close() error {
24+
return nil
25+
}
26+
27+
type LogProvider struct {
28+
log logrus.FieldLogger
29+
}
30+
31+
func (s *LogProvider) NewFile(p string) io.WriteCloser {
32+
return NewLogWriterCloser(s.log)
33+
}
34+
35+
func (s *LogProvider) Flush() {
36+
}
37+
38+
var scrubPassword = regexp.MustCompile(`<password>(.*)</password>`)
39+
40+
func Scrub(in []byte) []byte {
41+
return scrubPassword.ReplaceAll(in, []byte(`<password>********</password>`))
42+
}

selfdescribe.json

+8
Original file line numberDiff line numberDiff line change
@@ -56607,6 +56607,14 @@
5660756607
"required": false,
5660856608
"type": "string",
5660956609
"elementKind": ""
56610+
},
56611+
{
56612+
"yamlName": "soapClientDebug",
56613+
"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",
56614+
"default": false,
56615+
"required": false,
56616+
"type": "bool",
56617+
"elementKind": ""
5661056618
}
5661156619
]
5661256620
},

0 commit comments

Comments
 (0)