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

Improve the wmi beats module 42650 #42663

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f1f09e7
Add the Domain parameter. Remove reference to the IP address
herrBez Feb 10, 2025
64d5706
Merge branch 'main' of github.com:elastic/beats into improve-the-wmi-…
herrBez Feb 10, 2025
30a5f45
Add the domain to the wmi data
herrBez Feb 10, 2025
1186460
Improve the documentation of the WMI module
herrBez Feb 10, 2025
5eff223
Update metricbeat/module/windows/wmi/_meta/docs.asciidoc
herrBez Feb 12, 2025
461c09a
Update metricbeat/module/windows/wmi/_meta/docs.asciidoc
herrBez Feb 12, 2025
1cf6ef4
Add wmi.namespace and rewrite the Configuration section
herrBez Feb 17, 2025
77ab16b
Add section about best-practice and about Arbitrator
herrBez Feb 17, 2025
d8f479d
Improve phrasing of the best practices section
herrBez Feb 18, 2025
09a0c2e
Fix the convertDateTime function and add a test for the dates with ti…
herrBez Feb 18, 2025
1fe7f2e
Refactor replace fields with properties to be compliant with WMI docu…
herrBez Feb 18, 2025
4ed5563
Refactor the wmi.include_null and wmi.include_empty_string to a more …
herrBez Feb 18, 2025
afbced1
Run make update
herrBez Feb 18, 2025
c35c1e7
Make the warning more accurate
herrBez Feb 18, 2025
0974350
Fix typo
herrBez Feb 19, 2025
43af227
Fix linting error
herrBez Feb 19, 2025
e05a887
fix the example of the documentation + reorder the parameter definiti…
herrBez Feb 19, 2025
2c23092
Merge branch 'main' into improve-the-wmi-beats-module-42650
herrBez Feb 19, 2025
8249b47
remove reference to fields that should have been removed with the ref…
herrBez Feb 19, 2025
ac2f9a9
fix typos and make sure the period is 10 minutes in our examples
herrBez Feb 19, 2025
d2ecd8b
Fix the name of the test
herrBez Feb 19, 2025
3ce31bd
Hide the Remote WMI parameters
herrBez Feb 19, 2025
a779965
Merge branch 'main' into improve-the-wmi-beats-module-42650
ishleenk17 Mar 3, 2025
28ed9a7
Remove remote wmi logic from wmi.go. This can be reactivated by need
herrBez Mar 4, 2025
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
105 changes: 92 additions & 13 deletions metricbeat/module/windows/wmi/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,35 +1,114 @@
The `wmi` metricset of the Windows module reads metrics via Windows Management Instrumentation link:https://learn.microsoft.com/en-us/windows/win32/wmisdk/about-wmi[(WMI)], a core management technology in the Windows Operating system.
The `wmi` metricset of the Windows module collect metrics via link:https://learn.microsoft.com/en-us/windows/win32/wmisdk/about-wmi[Windows Management Instrumentation (WMI)], a core management technology in the Windows Operating system.

By leveraging WMI Query Language (WQL), this metricset allows you to extract detailed
system information and metrics to monitor the health and performance of Windows
Systems.

This metricset leverages the link:https://github.com/microsoft/wmi[Microsoft WMI], library a
convenient wrapper around the link:https://github.com/go-ole[GO-OLE] library which allows to
invoke the WMI Api.
This metricset leverages the link:https://github.com/microsoft/wmi[Microsoft WMI] library, a
convenient wrapper around the link:https://github.com/go-ole[Go-OLE]. This allows invoking the
link:https://learn.microsoft.com/en-us/windows/win32/wmisdk/scripting-api-for-wmi[Scripting API for WMI].

[float]
=== WMI Query Language (WQL) Support

This metricset supports the execution of link:https://learn.microsoft.com/en-us/windows/win32/wmisdk/wql-sql-for-wmi[WQL] queries, a SQL-like query language for retrieving information from WMI namespaces.

As of now, we only support and execute queries with `SELECT`, `FROM` and `WHERE` clauses.

[float]
=== Configuration

[source,yaml]
----
- module: windows
metricsets: ["wmi"]
period: 60s
namespace: "root\\cimv2" # Namespace
queries:
- class: Win32_OperatingSystem
fields:
- FreePhysicalMemory
- FreeSpaceInPaginFiles
- NumberOfUsers
# Where Clasue
where: ""
wmi:
# host: localhost
# domain: ""
# username: test
# password: foo
namespace: "root\\cimv2" # Default Namespace
warning_threshold: 60s
include_queries: true
include_null: false
include_empty_strings: false
queries:
- class: Win32_OperatingSystem
fields:
- FreePhysicalMemory
- FreeSpaceInPagingFiles
- NumberOfUsers
# Where Clasue
where: ""
- class: Win32_PowerPlan
fields: []
where: "IsActive = True"
namespace: "root\\cimv2\\power" # Overwrites the module namespace in this query
----


*`wmi.host`*:: The host for the remote WMI Connection. By default is localhost.

*`wmi.domain`*:: The domain for the remote WMI Connection. By default is the empty string.

*`wmi.username`*:: The username for the remote WMI Connection. By default is empty string.

*`wmi.password`*:: The password for the remote WMI Connection. By default is empty string.

*`wmi.warning_threshold`*:: The time threshold after which Metricbeat will stop
waiting for the query result and return control to the main flow of the program.
A warning is logged indicating that the query execution has exceeded the threshold.
By default is equal to the period.

*`wmi.queries`*:: The list of queries to execute. The list cannot be empty. See <<query-configuration, Query Configuration>> for the format of the queries.

*`wmi.include_queries`*:: A boolean option that causes the metricset to include the
query in the output document. False by default.

*`wmi.include_null`*:: A boolean option that causes the metricset to include the
properties that have a null value in the output document. False by default.

*`wmi.include_empty_string`*:: A boolean option that causes the metricset to include
the properties that are empty string. False by default.


[float]
[[query-configuration]]
==== Query Configuration

Each item in the `queries` list specifies a wmi query to perform.

*`class`*:: The wmi class. In the query it specifies the `FROM` clause. Required

*`fields`*:: List of fields to return. In the query it specifies the `SELECT` clause. Set it to the empty list (default value) to retrieve all available properties.

*`where`*:: The where clause. In the query it specifies the `WHERE` clause. Read more about the format https://learn.microsoft.com/en-us/windows/win32/wmisdk/where-clause.

*`namespace`*:: The WMI Namespace for this particular query (it overwrites the module's `namespace` value)

[float]
===== Example

Example WQL Query:

[source,sql]
----
SELECT Name, ProcessId, WorkingSetSize
FROM Win32_Process
WHERE Name = 'lsass.exe' AND WorkingSetSize > 104857600
----

Equivalent YAML Configuration:

[source,yaml]
----
- class: Win32_Process
fields:
- Name
- ProcessId
- WorkingSetSize
where: "Name = 'lsass.exe' AND WorkingSetSize > 104857600"
----

[float]
Expand Down
3 changes: 2 additions & 1 deletion metricbeat/module/windows/wmi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type Config struct {
IncludeQueries bool `config:"wmi.include_queries"` // Determines if the query string should be included in the output document
IncludeNull bool `config:"wmi.include_null"` // Specifies whether to include fields with nil values in the final document
IncludeEmptyString bool `config:"wmi.include_empty_string"` // Specifies whether to include fields with empty string values in the final document
Host string `config:"wmi.host"` // Hostname or IP address of the remote WMI server
Host string `config:"wmi.host"` // Hostname of the remote WMI server
Domain string `config:"wmi.domain"` // Domain of the remote WMI Server
User string `config:"wmi.username"` // Username for authentication on the remote WMI server
Password string `config:"wmi.password"` // Password for authentication on the remote WMI server
Namespace string `config:"wmi.namespace"` // Default WMI namespace for executing queries, used if not overridden by individual query configurations
Expand Down
6 changes: 5 additions & 1 deletion metricbeat/module/windows/wmi/wmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error {
// for each unique WMI namespace. This minimizes the number of session creations
for namespace, queries := range m.config.NamespaceQueryIndex {

session, err := sm.GetSession(namespace, m.config.Host, "", m.config.User, m.config.Password)
session, err := sm.GetSession(namespace, m.config.Host, m.config.Domain, m.config.User, m.config.Password)

if err != nil {
return fmt.Errorf("could not initialize session %w", err)
Expand Down Expand Up @@ -154,6 +154,10 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error {
},
}

if m.config.Domain != "" {
event.MetricSetFields.Put("domain", m.config.Domain)
}

if m.config.IncludeQueries {
event.MetricSetFields.Put("query", query)
}
Expand Down
Loading