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

[Metricbeat] Windows Module add wmi metricset #42017

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

herrBez
Copy link
Contributor

@herrBez herrBez commented Dec 12, 2024

Proposed commit message

[Metricbeat][Windows] Add experimental wmi metricset

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

This PR does not have impact to existing use-cases

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

As a windows user I want to leverage WMI (and in particular WQL, SQL for WMI) to extract detailed system information and metrics.

Screenshots

Logs

@herrBez herrBez self-assigned this Dec 12, 2024
@herrBez herrBez requested review from a team as code owners December 12, 2024 15:57
@herrBez herrBez requested review from faec and VihasMakwana December 12, 2024 15:57
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Dec 12, 2024
@botelastic
Copy link

botelastic bot commented Dec 12, 2024

This pull request doesn't have a Team:<team> label.

Copy link
Contributor

mergify bot commented Dec 12, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @herrBez? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit

Copy link
Contributor

mergify bot commented Dec 12, 2024

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label and remove the backport-8.x label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Dec 12, 2024
@strawgate
Copy link
Contributor

One of the challenges with running arbitrary WMI queries is that WMI queries can be extremely slow and certain WMI queries can actually result in changes to the system -- have we considered whether or how we might provide timeout functionality for running WMI queries?

@herrBez
Copy link
Contributor Author

herrBez commented Dec 13, 2024

Hi, good points! Thank you for the comment :).

One of the challenges with running arbitrary WMI queries is that WMI queries can be extremely slow and certain WMI queries can actually result in changes to the system -- have we considered whether or how we might provide timeout functionality for running WMI queries?

About the timing issues: I don't see a parameter in the library to stop a query after X seconds (I would need to understand if the underlying library/WMI have a similar mechanism). Maybe by leveraging an ExecAsyncQuery (there is no "exposed" method for this) we can stop after a timeout. Similarly to what is done here: https://github.com/microsoft/wmi/blob/v0.25.0/pkg/wmiinstance/WmiEventSink_test.go#L66. Not sure it's actually stopping the underlying query after some time.

About the "can actually result in changes to the system": with the current implementation we can only build queries of type SELECT * FROM Class WHERE .... This should prevent changes to the system, right?

@strawgate
Copy link
Contributor

A WMI query does whatever the underlying WMI provider decides it should do. This means a developer can create a WMI provider which upon a Select * from MyCustomProvider, performs a change to the system.

A common bad actor example is the win32_product provider. When queried, the win32_product provider verifies the integrity of all installed MSI packages on the system. For any products where integrity cannot be verified it performs a repair install of the MSI.

You have to read quite a bit of documentation to land on this fact:

The Win32_Product class enables you to enumerate the software installed on a computer, provided the software was installed by using the Windows Installer.

...

Warning  Win32_Product is not query optimized. Queries such as "select * from Win32_Product where (name like 'Sniffer%')" require WMI to use the MSI provider to enumerate all of the installed products and then parse the full list sequentially to handle the “where” clause. This process also initiates a consistency check of packages installed, verifying and repairing the install. With an account with only user privileges, as the user account may not have access to quite a few locations, may cause delay in application launch and an event 11708 stating an installation failure. For more information, see [KB Article 794524](https://support.microsoft.com/kb/974524).

This means a simple select name from Win32_Product where (name like 'Google Chrome%') can take upwards of an hour to complete and can result in significant changes to the underlying system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify needs_team Indicates that the issue/PR needs a Team:* label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants