Skip to content

Commit

Permalink
fix: debug for win_wmi input plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Sep 18, 2023
1 parent f434272 commit f309f9e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
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
8 changes: 8 additions & 0 deletions plugins/inputs/win_wmi/win_wmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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,6 +141,7 @@ func (q *Query) doQuery(acc telegraf.Accumulator) error {
defer serviceRaw.Clear()

// result is a SWBemObjectSet
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)
Expand All @@ -151,6 +154,11 @@ func (q *Query) doQuery(acc telegraf.Accumulator) error {
return fmt.Errorf("failed getting Count: %w", err)
}

q.Log.Info("getting count property:")
v, ok := result.GetProperty("Count")
q.Log.Info(ok)
q.Log.Info(v)

for i := int64(0); i < count; i++ {
// item is a SWbemObject
itemRaw, err := oleutil.CallMethod(result, "ItemIndex", i)
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

0 comments on commit f309f9e

Please sign in to comment.