diff --git a/go.mod b/go.mod index b951cad018ae0..dee9e51c5edd8 100644 --- a/go.mod +++ b/go.mod @@ -73,7 +73,7 @@ require ( github.com/fatih/color v1.15.0 github.com/go-ldap/ldap/v3 v3.4.5 github.com/go-logfmt/logfmt v0.6.0 - github.com/go-ole/go-ole v1.2.6 + github.com/go-ole/go-ole v1.3.0 github.com/go-redis/redis/v7 v7.4.1 github.com/go-redis/redis/v8 v8.11.5 github.com/go-sql-driver/mysql v1.7.1 diff --git a/go.sum b/go.sum index a57a1b85b03b4..4a97705cbce22 100644 --- a/go.sum +++ b/go.sum @@ -563,8 +563,9 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-macaroon-bakery/macaroonpb v1.0.0 h1:It9exBaRMZ9iix1iJ6gwzfwsDE6ExNuwtAJ9e09v6XE= github.com/go-macaroon-bakery/macaroonpb v1.0.0/go.mod h1:UzrGOcbiwTXISFP2XDLDPjfhMINZa+fX/7A2lMd31zc= -github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ= github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA= diff --git a/plugins/inputs/win_wmi/win_wmi.go b/plugins/inputs/win_wmi/win_wmi.go index 59f7acba8efd8..fbc58e82f8895 100644 --- a/plugins/inputs/win_wmi/win_wmi.go +++ b/plugins/inputs/win_wmi/win_wmi.go @@ -17,6 +17,7 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/filter" "github.com/influxdata/telegraf/internal" + "github.com/influxdata/telegraf/models" "github.com/influxdata/telegraf/plugins/inputs" ) @@ -32,6 +33,8 @@ type Query struct { Filter string `toml:"filter"` TagPropertiesInclude []string `toml:"tag_properties"` tagFilter filter.Filter + + Log telegraf.Logger } // Wmi struct @@ -139,13 +142,21 @@ func (q *Query) doQuery(acc telegraf.Accumulator) error { defer serviceRaw.Clear() // result is a SWBemObjectSet + q.Log = models.NewLogger("input", "query", "") + q.Log.Infof("running query: %s\n", q.query) resultRaw, err := oleutil.CallMethod(service, "ExecQuery", q.query) if err != nil { return fmt.Errorf("failed calling method ExecQuery for query %s: %w", q.query, err) } + q.Log.Infof("raw result: %s\n", resultRaw.ToString()) result := resultRaw.ToIDispatch() defer resultRaw.Clear() + q.Log.Info("getting count property:") + v, ok := result.GetProperty("Count") + q.Log.Infof(" - error: %s\n", ok) + q.Log.Infof(" - value: %v\n", v) + count, err := oleInt64(result, "Count") if err != nil { return fmt.Errorf("failed getting Count: %w", err) diff --git a/plugins/inputs/win_wmi/win_wmi_test.go b/plugins/inputs/win_wmi/win_wmi_test.go index 175268aa45db6..1e3ee35d902c6 100644 --- a/plugins/inputs/win_wmi/win_wmi_test.go +++ b/plugins/inputs/win_wmi/win_wmi_test.go @@ -24,6 +24,7 @@ var testQuery = Query{ //nolint:gocritic // sprintfQuotedString - "%s" used by purpose, string escaping is done by special function Filter: fmt.Sprintf(`NOT Name LIKE "\\\\?\\%%" AND Name LIKE "%s"`, regexp.QuoteMeta(sysDrive)), TagPropertiesInclude: []string{"Name"}, + Log: new(testutil.Logger), tagFilter: nil, // this is filled in by CompileInputs() }