diff options
author | Thomas Heinen <theinen@tecracer.de> | 2021-12-09 13:29:37 +0100 |
---|---|---|
committer | Thomas Heinen <theinen@tecracer.de> | 2021-12-09 15:33:12 +0100 |
commit | a60d6f11dbd214790a09cb350927a9061c627cb3 (patch) | |
tree | b768a163d1de2bed6b1c8304dd2f18cc0fc049c0 | |
parent | a2c2f9658402406dcbfb8e205dc6086ad38cb0d6 (diff) | |
download | ohai-a60d6f11dbd214790a09cb350927a9061c627cb3.tar.gz |
Add support for VMware detection on Windows and details about virtualization platform
Signed-off-by: Thomas Heinen <theinen@tecracer.de>
-rw-r--r-- | lib/ohai/plugins/vmware.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/ohai/plugins/vmware.rb b/lib/ohai/plugins/vmware.rb index d8c89e66..d5759a76 100644 --- a/lib/ohai/plugins/vmware.rb +++ b/lib/ohai/plugins/vmware.rb @@ -45,12 +45,14 @@ Ohai.plugin(:VMware) do logger.trace("Plugin VMware: #{vmtools_path} not found") else vmware Mash.new + vmware[:host] = Mash.new + vmware[:guest] = Mash.new begin # vmware-toolbox-cmd stat <param> commands # Iterate through each parameter supported by the "vwware-toolbox-cmd stat" command, assign value # to attribute "vmware[:<parameter>]" %w{hosttime speed sessionid balloon swap memlimit memres cpures cpulimit}.each do |param| - vmware[param] = from_cmd("#{vmtools_path} stat #{param}") + vmware[param] = from_cmd([vmtools_path, "stat", param]) if /UpdateInfo failed/.match?(vmware[param]) vmware[param] = nil end @@ -59,8 +61,23 @@ Ohai.plugin(:VMware) do # Iterate through each parameter supported by the "vmware-toolbox-cmd status" command, assign value # to attribute "vmware[:<parameter>]" %w{upgrade timesync}.each do |param| - vmware[param] = from_cmd("#{vmtools_path} #{param} status") + vmware[param] = from_cmd([vmtools_path, param, "status"]) end + # Distinguish hypervisors by presence of raw session data (vSphere only) + raw_session = from_cmd([vmtools_path, %w{stat raw json session}]) + if raw_session.empty? + vmware[:host] = { + type: "vmware_desktop", + } + else + require "json" unless defined?(JSON) + session = JSON.parse(raw_session) + vmware[:host] = { + type: "vmware_vsphere", + version: session["version"], + } + end + vmware[:guest][:vmware_tools_version] = from_cmd([vmtools_path, "-v"]).split(" ").first rescue logger.trace("Plugin VMware: Error while collecting VMware guest attributes") end @@ -71,4 +88,7 @@ Ohai.plugin(:VMware) do get_vm_attributes("/usr/bin/vmware-toolbox-cmd") if virtualization[:systems][:vmware] end + collect_data(:windows) do + get_vm_attributes("C:/Program Files/VMWare/VMware Tools/VMwareToolboxCmd.exe") if virtualization[:systems][:vmware] + end end |