diff options
Diffstat (limited to 'lib/ohai/plugins/vmware.rb')
-rw-r--r-- | lib/ohai/plugins/vmware.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/ohai/plugins/vmware.rb b/lib/ohai/plugins/vmware.rb index 250a9e24..438efb41 100644 --- a/lib/ohai/plugins/vmware.rb +++ b/lib/ohai/plugins/vmware.rb @@ -53,6 +53,21 @@ Ohai.plugin(:VMware) do # 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]) + if param == "hosttime" && vmtools_path.include?("Program Files") + # popen and %x return stdout encoded as IBM437 in Windows but in a string marked + # UTF-8. The string doesn't throw an exception when encoded to "UTF-8" but + # displays [?] character in Windows without this. + # + # .force_encoding(Encoding::ISO_8859_1) causes the character to be dropped + # and .force_encoding(Encoding::Windows_1252) displays the „ character in place + # of an ä. .force_encoding(Encoding::IBM437) allows for the correct characters + # to be displayed. + # + # Note: + # * this is broken for at least Ruby 2.7 through 3.1.3 + # * confirmed that this is broken on Windows Server 2022 + vmware[param] = vmware[param].force_encoding(Encoding::IBM437).encode("UTF-8") + end if /UpdateInfo failed/.match?(vmware[param]) vmware[param] = nil end |