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

Telegraf Windows Registry Input Plugin #14653

Closed
1tft opened this issue Jan 30, 2024 · 8 comments · Fixed by #15300
Closed

Telegraf Windows Registry Input Plugin #14653

1tft opened this issue Jan 30, 2024 · 8 comments · Fixed by #15300
Assignees
Labels
feature request Requests for new plugin and for new features to existing plugins platform/windows

Comments

@1tft
Copy link

1tft commented Jan 30, 2024

Use Case

We want to consume string and numeric values from Windows registry. Here you can find usefull generic windows information like windows version, settings and much more. Also some apps are storing important information here.

Expected behavior

Telegraf can read values (String, DWORD, QWORD) from given Windows Registry path like
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate

Actual behavior

Currently getting string and numeric values from Windows registry is not possible with Telegraf standard plugins. Also no chance with inputs.win_wmi because it uses WQL-Interface which does not support method-calls.

Additional info

Currently you have to use inputs.exec to execute a custom poweshell script to get Windows Regitry values. Executing powershell scripts is not always a good solution because of security concerns and for users without Powershell coding knowledge.

@1tft 1tft added the feature request Requests for new plugin and for new features to existing plugins label Jan 30, 2024
@srebhan srebhan self-assigned this Jan 30, 2024
@powersj
Copy link
Contributor

powersj commented Jan 30, 2024

Thanks for filing the feature request. We shall take a look!

@Flightliner380
Copy link

Flightliner380 commented Feb 2, 2024

We also need this function to get values from the registry, such as the UBR version, which is not included in any WMI class

@PSHWorkShop
Copy link

Yes, would be a very useful feature , we need.

@srebhan
Copy link
Member

srebhan commented May 6, 2024

@1tft and @PSHWorkShop, please test the binary in PR #15300 and let me know if that works for you! The new feature adds more than only querying the registry but allows to invoke arbitrary WMI methods. Therefore, to read a registry value you should do

# Input plugin to query Windows Management Instrumentation
# This plugin ONLY supports Windows
[[inputs.win_wmi]]
  ## Hostname or IP for remote connections, by default the local machine is queried
  # host = ""
  ## Credentials for the connection, by default no credentials are used
  # username = ""
  # password = ""

  [[inputs.win_wmi.method]]
    ## WMI namespace, class and method to use
    namespace = 'root\default'
    class_name = "StdRegProv"
    method = "GetStringValue"
    ## Returned WMI method values to use as tags instead of fields
    # tag_properties = ["ReturnValue"]
    ## Named arguments for the method call
    [inputs.win_wmi.method.arguments]
      hDefKey = '2147483650'
      sSubKeyName = 'Software\Microsoft\windows NT\CurrentVersion'
      sValueName = 'ProductName'

to read HKLM\Software\Microsoft\windows NT\CurrentVersion\ProductName...

@PSHWorkShop
Copy link

PSHWorkShop commented May 7, 2024

Hello,

The code works, but if you get multiple values from different registry code you get the same field name.

[[inputs.win_wmi]]

[[inputs.win_wmi.method]]
## WMI namespace, class and method to use
namespace = 'root\default'
class_name = "StdRegProv"
method = "GetStringValue"
#tag_properties = ["sValue"]
## Returned WMI method values to use as tags instead of fields
# tag_properties = ["ReturnValue"]
## Named arguments for the method call
[inputs.win_wmi.method.arguments]
hDefKey = '2147483650'
sSubKeyName = 'Software\Microsoft\windows NT\CurrentVersion'
sValueName = 'ProductName'

[[inputs.win_wmi.method]]
## WMI namespace, class and method to use
namespace = 'root\default'
class_name = "StdRegProv"
method = "GetDWORDValue"
## Returned WMI method values to use as tags instead of fields
# tag_properties = ["ReturnValue"]
## Named arguments for the method call
[inputs.win_wmi.method.arguments]
hDefKey = '2147483650'
sSubKeyName = 'Software\Microsoft\windows NT\CurrentVersion'
sValueName = 'UBR'

[[inputs.win_wmi.method]]
## WMI namespace, class and method to use
namespace = 'root\default'
class_name = "StdRegProv"
method = "GetStringValue"
#tag_properties = ["sValue"]
## Returned WMI method values to use as tags instead of fields
# tag_properties = ["ReturnValue"]
## Named arguments for the method call
[inputs.win_wmi.method.arguments]
hDefKey = '2147483650'
sSubKeyName = 'Software\Microsoft\windows NT\CurrentVersion'
sValueName = 'CurrentBuild'

Result:

StdRegProv,host=PC1 ReturnValue=0i,sValue="Windows Server 2021" 17150xxxxx000000000
StdRegProv,host=PC1 ReturnValue=0i,sValue="22631" 17150xxxxx0000000000
StdRegProv,host=PC1 ReturnValue=0i,uValue=3527i 17150xxxxx0000000000

Could you not use the value of sValueName = 'ProductName' field name, or specify the return field in parameters.
Example:
ReturnField = 'MyProductName'

[inputs.win_wmi.method.arguments]
hDefKey = '2147483650'
sSubKeyName = 'Software\Microsoft\windows NT\CurrentVersion'
sValueName = 'ProductName'
ReturnField = 'MyProductName'

Better should be:

StdRegProv,host=PC1 ReturnValue=0i,MyProductname="Windows 10 Pro" 1715058810000000000
StdRegProv,host=PC1 ReturnValue=0i,MyValueName="22631" 1715058810000000000
StdRegProv,host=PC1 ReturnValue=0i,myUBR=3527i 1715058810000000000

@srebhan
Copy link
Member

srebhan commented May 7, 2024

@PSHWorkShop currently we use the name of the value returned by the function call. Your approach will run into problems if the method returns multiple fields I think, therefore I'm not sure if this is a good idea.

I added a fields option where you can specify a mapping between the name of the returned value and the field name. Does that work for you?

@1tft
Copy link
Author

1tft commented May 8, 2024

Using this config

[[inputs.win_wmi]]
   name_override = "system_meta"

  [[inputs.win_wmi.method]]
    namespace = 'root/default'
    class_name = "StdRegProv"
    method = "GetStringValue"
    [inputs.win_wmi.method.arguments]
      hDefKey = '2147483650'
      sSubKeyName = 'Software\\Microsoft\\windows NT\\CurrentVersion'
      sValueName = 'ProductName'
      [inputs.win_wmi.method.fields]
        sValue = "ProductName"


  [[inputs.win_wmi.method]]
    namespace = 'root/default'
    class_name = "StdRegProv"
    method = "GetStringValue"
    [inputs.win_wmi.method.arguments]
      hDefKey = '2147483650'
      sSubKeyName = 'Software\\Microsoft\\windows NT\\CurrentVersion'
      sValueName = 'CurrentBuildNumber'
      [inputs.win_wmi.method.fields]
        sValue = "CurrentBuildNumber"


   [[inputs.win_wmi.method]]
     namespace = 'root/default'
     class_name = "StdRegProv"
     method = "GetDWORDValue"
     [inputs.win_wmi.method.arguments]
       hDefKey = '2147483650'
       sSubKeyName = 'Software\\Microsoft\\windows NT\\CurrentVersion'
       uValueName = 'UBR'
       [inputs.win_wmi.method.fields]
         uValue = "UBR"

prints out these metrics:

> system_meta,CurrentBuildNumber="20348",ReturnValue=0i 1715172372000000000
> system_meta,ProductName="Windows Server 2022 Standard",ReturnValue=0i 1715172372000000000
> system_meta,ReturnValue=0i,UBR=2402i 1715172372000000000

fields option works for us.

We dont know that one sValueName (property) can return more than 1 value and so you cant use automatically property name instead of "sValue", "uValue" etc..

Later we use merge aggregator plugin to get only one metric.

@srebhan
Copy link
Member

srebhan commented May 8, 2024

Yeah, there might be WMI calls that return more than one property (e.g. EnumValues) so we cannot autorename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Requests for new plugin and for new features to existing plugins platform/windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants