summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Kvashenkin <ak@gfoil.ru>2018-09-10 23:19:03 +0300
committerAnton Kvashenkin <ak@gfoil.ru>2018-09-10 23:19:03 +0300
commit5c79118e4a2aea3d009301171b64a8829f84ee28 (patch)
treea4c238fb60d91df131deb6bbfb97c0d59d690f9a
parent768632031bfe736a373d6c915732c4003f666e24 (diff)
downloadohai-5c79118e4a2aea3d009301171b64a8829f84ee28.tar.gz
Use wmi-lite for WMI query
Signed-off-by: Anton Kvashenkin <anton.jugatsu@gmail.com>
-rw-r--r--lib/ohai/plugins/root_group.rb38
1 files changed, 12 insertions, 26 deletions
diff --git a/lib/ohai/plugins/root_group.rb b/lib/ohai/plugins/root_group.rb
index 8b290987..3059fcae 100644
--- a/lib/ohai/plugins/root_group.rb
+++ b/lib/ohai/plugins/root_group.rb
@@ -18,33 +18,19 @@
Ohai.plugin(:RootGroup) do
provides "root_group"
- #
- # Performs a WMI query using WIN32OLE from the Ruby Stdlib
- #
- # @return [String]
- #
- def wmi_property_from_query(wmi_property, wmi_query)
- @wmi = ::WIN32OLE.connect("winmgmts://")
- result = @wmi.ExecQuery(wmi_query)
- return nil unless result.each.count > 0
- result.each.next.send(wmi_property)
- end
-
- # Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
- # internal name for the Administrators group, which lets us work
- # properly in environments with a renamed or localized name for the
- # Administrators group.
- # Use LocalAccount=True because otherwise WMI will attempt to include
- # (unneeded) Active Directory groups by querying AD, which is a performance
- # and reliability issue since AD might not be reachable.
- def windows_root_group_name
- wmi_property_from_query(
- :name,
- "select * from Win32_Group where sid like 'S-1-5-32-544' and LocalAccount=True"
- )
- end
-
collect_data(:windows) do
+ require "wmi-lite/wmi"
+
+ wmi = WmiLite::Wmi.new
+ # Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
+ # internal name for the Administrators group, which lets us work
+ # properly in environments with a renamed or localized name for the
+ # Administrators group.
+ # Use LocalAccount=True because otherwise WMI will attempt to include
+ # (unneeded) Active Directory groups by querying AD, which is a performance
+ # and reliability issue since AD might not be reachable.
+ groups = wmi.query("select * from Win32_Group where sid like 'S-1-5-32-544' and LocalAccount=True")
+ windows_root_group_name = groups[0]["name"]
root_group windows_root_group_name
end