Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: debug for win_wmi input plugin #13925

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
11 changes: 11 additions & 0 deletions plugins/inputs/win_wmi/win_wmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -32,6 +33,8 @@ type Query struct {
Filter string `toml:"filter"`
TagPropertiesInclude []string `toml:"tag_properties"`
tagFilter filter.Filter

Log telegraf.Logger
}

// Wmi struct
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/win_wmi/win_wmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
Loading