summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliasgar16 <aliasgar.batterywala@clogeny.com>2016-09-12 16:18:40 +0530
committeraliasgar16 <aliasgar.batterywala@clogeny.com>2016-09-12 16:18:40 +0530
commit5526b86cd9aa87bf82d2d5f564256d3a1cbc06a2 (patch)
tree7e5729364960b6ee2b2f58ef6f82cfb738422df7
parent9e1d36e85b8317cf2999495768f641d7ab90f67f (diff)
downloadohai-5526b86cd9aa87bf82d2d5f564256d3a1cbc06a2.tar.gz
Modified code to use appropriate WMI class based on the Windows version.
-rw-r--r--lib/ohai/plugins/uptime.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb
index d8ffbdf9..45dcdbe4 100644
--- a/lib/ohai/plugins/uptime.rb
+++ b/lib/ohai/plugins/uptime.rb
@@ -29,6 +29,7 @@ require "ohai/mixin/seconds_to_human"
Ohai.plugin(:Uptime) do
provides "uptime", "uptime_seconds"
provides "idletime", "idletime_seconds" # linux only
+ depends "platform"
def collect_uptime(path)
# kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009
@@ -96,8 +97,12 @@ Ohai.plugin(:Uptime) do
collect_data(:windows) do
require "wmi-lite/wmi"
wmi = WmiLite::Wmi.new
- last_boot_up_time = wmi.first_of("Win32_OperatingSystem")["lastbootuptime"]
- uptime_seconds Time.new.to_i - Time.parse(last_boot_up_time).to_i
+ if platform_version.to_f >= 6.0 ## for newer version of Windows starting from Windows Server 2008 ##
+ last_boot_up_time = wmi.first_of("Win32_OperatingSystem")["lastbootuptime"]
+ uptime_seconds Time.new.to_i - Time.parse(last_boot_up_time).to_i
+ else ## for older version of Windows starting from Windows Server 2003 ##
+ uptime_seconds wmi.first_of("Win32_PerfFormattedData_PerfOS_System")["systemuptime"].to_i
+ end
uptime seconds_to_human(uptime_seconds)
end