Issue #13535 has been updated by Jeff McCune.
Alex, I'm reviewing this now. Do you mind if I amend your work (you'll still be the author, I'll just be the committer) to rename `uptime_uptime` to `uptime_command`? -Jeff ---------------------------------------- Bug #13535: Facter uptime can be wrong or negative on AIX https://projects.puppetlabs.com/issues/13535#change-73589 Author: Malcolm Howe Status: In Topic Branch Pending Review Priority: Normal Assignee: Alex Harvey Category: library Target version: Keywords: Branch: https://github.com/alexharv074/facter/tree/ticket/1.6.x/13535_facter_uptime_can_be_wrong_on_AIX Affected Facter version: 1.6.6 On AIX facter can show a negative uptime uptime => -260 days uptime_days => -260 uptime_hours => -6219 uptime_seconds => -22385831 This occurs because of the four methods for calculating uptime in facter/util/uptime.rb the only one that can be used on AIX is who -b. But on AIX who -b doesn't display the year $ who -b . system boot 14 Dec 10:30 so the current year is assumed which in this example results in a negative uptime. A possible solution would be to use the uptime (or equivalently w -u) command which produces similar output on AIX as it does on Linux $ uptime 10:46AM up 106 days, 23:18, 3 users, load average: 0.03, 0.33, 0.53 For example --- uptime.rb.save 2012-02-28 11:25:38.000000000 +0000 +++ uptime.rb 2012-03-30 11:03:05.000000000 +0100 @@ -4,7 +4,7 @@ # module Facter::Util::Uptime def self.get_uptime_seconds_unix - uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_who_dash_b + uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_uptime or uptime_who_dash_b end def self.get_uptime_seconds_win @@ -37,6 +37,20 @@ end end + def self.uptime_uptime + if output = Facter::Util::Resolution.exec("#{uptime_uptime_cmd} 2>/dev/null") + up=0 + if output =~ /(\d+) days,\s+(\d+):(\d+)/ + up=86400*$1.to_i + 3600*$2.to_i + 60*$3.to_i + elsif output =~ /(\d+):(\d+),/ + up=3600*$1.to_i + 60*$2.to_i + elsif output =~ /(\d+) mins,/ + up=($1.to_i*60) + end + up + end + end + def self.uptime_who_dash_b if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null") compute_uptime(Time.parse(output)) @@ -57,6 +71,10 @@ def self.uptime_kstat_cmd 'kstat -p unix:::boot_time' + end + + def self.uptime_uptime_cmd + 'uptime' end def self.uptime_who_cmd results in the facter output uptime => 106 days uptime_days => 106 uptime_hours => 2567 uptime_seconds => 9242280 -- You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://projects.puppetlabs.com/my/account -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-bugs?hl=en.
