facter 1.6.13 → 1.6.14.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of facter might be problematic. Click here for more details.
- data/Rakefile +1 -5
- data/bin/facter +11 -0
- data/ext/redhat/facter.spec.erb +16 -15
- data/lib/facter/application.rb +0 -1
- data/lib/facter/hardwareisa.rb +7 -2
- data/lib/facter/physicalprocessorcount.rb +13 -1
- data/lib/facter/processor.rb +37 -39
- data/lib/facter/util/ip.rb +2 -2
- data/lib/facter/util/monkey_patches.rb +32 -0
- data/lib/facter/util/processor.rb +74 -23
- data/lib/facter/util/uptime.rb +27 -16
- data/lib/facter/util/virtual.rb +15 -0
- data/lib/facter/version.rb +1 -1
- data/lib/facter/virtual.rb +34 -1
- data/spec/fixtures/ifconfig/centos_5_5 +1 -1
- data/spec/fixtures/ifconfig/centos_5_5_eth0 +1 -1
- data/spec/fixtures/ifconfig/darwin_10_3_0 +1 -1
- data/spec/fixtures/ifconfig/darwin_10_3_0_en0 +1 -1
- data/spec/fixtures/ifconfig/darwin_9_8_0 +1 -1
- data/spec/fixtures/ifconfig/darwin_9_8_0_en0 +1 -1
- data/spec/fixtures/ifconfig/fedora_10 +1 -1
- data/spec/fixtures/ifconfig/fedora_10_eth0 +1 -1
- data/spec/fixtures/ifconfig/fedora_13 +1 -1
- data/spec/fixtures/ifconfig/fedora_13_eth0 +1 -1
- data/spec/fixtures/ifconfig/fedora_8 +1 -1
- data/spec/fixtures/ifconfig/fedora_8_eth0 +1 -1
- data/spec/fixtures/ifconfig/freebsd_6_0 +1 -1
- data/spec/fixtures/ifconfig/open_solaris_10 +1 -1
- data/spec/fixtures/ifconfig/open_solaris_b132 +1 -1
- data/spec/fixtures/ifconfig/ubuntu_7_04 +1 -1
- data/spec/fixtures/ifconfig/ubuntu_7_04_eth0 +1 -1
- data/spec/fixtures/netstat/centos_5_5 +1 -1
- data/spec/fixtures/netstat/darwin_10_3_0 +1 -1
- data/spec/fixtures/netstat/darwin_9_8_0 +1 -1
- data/spec/fixtures/netstat/fedora_10 +1 -1
- data/spec/fixtures/netstat/open_solaris_10 +1 -1
- data/spec/fixtures/netstat/open_solaris_b132 +1 -1
- data/spec/fixtures/netstat/ubuntu_7_04 +1 -1
- data/spec/fixtures/unit/util/ec2/centos-arp-ec2.out +1 -1
- data/spec/fixtures/unit/util/ec2/windows-2008-arp-a.out +1 -1
- data/spec/fixtures/unit/util/ip/6.0-STABLE_FreeBSD_ifconfig +1 -1
- data/spec/fixtures/unit/util/ip/linux_get_single_interface_ib0 +1 -1
- data/spec/fixtures/unit/util/ip/linux_ifconfig_all_with_single_interface +1 -1
- data/spec/fixtures/unit/util/ip/linux_ifconfig_ib0 +1 -1
- data/spec/fixtures/unit/util/ip/solaris_ifconfig_single_interface +1 -1
- data/spec/integration/facter_spec.rb +1 -1
- data/spec/unit/architecture_spec.rb +1 -1
- data/spec/unit/domain_spec.rb +1 -1
- data/spec/unit/ec2_spec.rb +1 -1
- data/spec/unit/facter_spec.rb +1 -1
- data/spec/unit/hardwareisa_spec.rb +7 -0
- data/spec/unit/hostname_spec.rb +1 -1
- data/spec/unit/id_spec.rb +1 -1
- data/spec/unit/interfaces_spec.rb +1 -1
- data/spec/unit/ipaddress6_spec.rb +1 -1
- data/spec/unit/lsbdistcodename_spec.rb +1 -1
- data/spec/unit/lsbdistdescription_spec.rb +1 -1
- data/spec/unit/lsbdistid_spec.rb +1 -1
- data/spec/unit/lsbdistrelease_spec.rb +1 -1
- data/spec/unit/lsbrelease_spec.rb +1 -1
- data/spec/unit/macaddress_spec.rb +1 -1
- data/spec/unit/memory_spec.rb +1 -1
- data/spec/unit/operatingsystem_spec.rb +1 -1
- data/spec/unit/operatingsystemrelease_spec.rb +1 -1
- data/spec/unit/physicalprocessorcount_spec.rb +24 -5
- data/spec/unit/processor_spec.rb +75 -9
- data/spec/unit/selinux_spec.rb +1 -1
- data/spec/unit/uptime_spec.rb +1 -1
- data/spec/unit/util/collection_spec.rb +1 -1
- data/spec/unit/util/config_spec.rb +1 -1
- data/spec/unit/util/confine_spec.rb +1 -1
- data/spec/unit/util/ec2_spec.rb +1 -1
- data/spec/unit/util/fact_spec.rb +1 -1
- data/spec/unit/util/ip_spec.rb +3 -3
- data/spec/unit/util/loader_spec.rb +1 -1
- data/spec/unit/util/macaddress_spec.rb +1 -1
- data/spec/unit/util/macosx_spec.rb +1 -1
- data/spec/unit/util/manufacturer_spec.rb +1 -1
- data/spec/unit/util/monkey_patches_spec.rb +42 -0
- data/spec/unit/util/processor_spec.rb +1 -9
- data/spec/unit/util/registry_spec.rb +1 -1
- data/spec/unit/util/resolution_spec.rb +1 -1
- data/spec/unit/util/uptime_spec.rb +61 -20
- data/spec/unit/util/virtual_spec.rb +1 -1
- data/spec/unit/util/vlans_spec.rb +1 -1
- data/spec/unit/util/wmi_spec.rb +1 -1
- data/spec/unit/util/xendomains_spec.rb +1 -1
- data/spec/unit/virtual_spec.rb +66 -34
- metadata +7 -7
- data/spec/fixtures/unit/util/uptime/who_b_boottime +0 -1
data/Rakefile
CHANGED
@@ -55,12 +55,8 @@ task :default do
|
|
55
55
|
sh %{rake -T}
|
56
56
|
end
|
57
57
|
|
58
|
-
# Aliases for spec
|
59
|
-
task :tests => [:test]
|
60
|
-
task :specs => [:test]
|
61
|
-
|
62
58
|
desc "Run all specs"
|
63
|
-
RSpec::Core::RakeTask.new
|
59
|
+
RSpec::Core::RakeTask.new do |t|
|
64
60
|
t.pattern ='spec/{unit,integration}/**/*_spec.rb'
|
65
61
|
t.fail_on_error = true
|
66
62
|
end
|
data/bin/facter
CHANGED
@@ -55,6 +55,17 @@
|
|
55
55
|
# Copyright (c) 2011 Puppet Labs, Inc
|
56
56
|
# Licensed under the Apache 2.0 license
|
57
57
|
|
58
|
+
# Bundler and rubygems maintain a set of directories from which to
|
59
|
+
# load gems. If Bundler is loaded, let it determine what can be
|
60
|
+
# loaded. If it's not loaded, then use rubygems. But do this before
|
61
|
+
# loading any facter code, so that our gem loading system is sane.
|
62
|
+
if not defined? ::Bundler
|
63
|
+
begin
|
64
|
+
require 'rubygems'
|
65
|
+
rescue LoadError
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
58
69
|
require 'facter/application'
|
59
70
|
|
60
71
|
Facter::Application.run(ARGV)
|
data/ext/redhat/facter.spec.erb
CHANGED
@@ -10,21 +10,22 @@
|
|
10
10
|
%global realversion <%= @version %>
|
11
11
|
%global rpmversion <%= @rpmversion %>
|
12
12
|
|
13
|
-
Summary:
|
14
|
-
Name:
|
15
|
-
Version:
|
16
|
-
Release:
|
17
|
-
Epoch:
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Requires:
|
13
|
+
Summary: Ruby module for collecting simple facts about a host operating system
|
14
|
+
Name: facter
|
15
|
+
Version: %{rpmversion}
|
16
|
+
Release: <%= @rpmrelease -%>%{?dist}
|
17
|
+
Epoch: 1
|
18
|
+
Vendor: %{?_host_vendor}
|
19
|
+
License: ASL 2.0
|
20
|
+
Group: System Environment/Base
|
21
|
+
URL: http://www.puppetlabs.com/puppet/related-projects/%{name}
|
22
|
+
# Note this URL will only be valid at official tags from Puppet Labs
|
23
|
+
Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{realversion}.tar.gz
|
24
|
+
|
25
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
26
|
+
|
27
|
+
Requires: ruby >= 1.8.5
|
28
|
+
Requires: which
|
28
29
|
# dmidecode and pciutils are not available on all arches
|
29
30
|
%ifarch %ix86 x86_64 ia64
|
30
31
|
Requires: dmidecode
|
data/lib/facter/application.rb
CHANGED
data/lib/facter/hardwareisa.rb
CHANGED
@@ -4,12 +4,17 @@
|
|
4
4
|
# Returns hardware processor type.
|
5
5
|
#
|
6
6
|
# Resolution:
|
7
|
-
# On Solaris, Linux and the BSDs simply uses the output of "uname -p"
|
7
|
+
# On Solaris, AIX, Linux and the BSDs simply uses the output of "uname -p"
|
8
|
+
# On HP-UX, "uname -m" gives us the same information.
|
8
9
|
#
|
9
10
|
# Caveats:
|
10
11
|
# Some linuxes return unknown to uname -p with relative ease.
|
11
12
|
#
|
12
13
|
|
13
14
|
Facter.add(:hardwareisa) do
|
14
|
-
|
15
|
+
if Facter.value(:kernel) == 'HP-UX'
|
16
|
+
setcode 'uname -m'
|
17
|
+
else
|
18
|
+
setcode 'uname -p'
|
19
|
+
end
|
15
20
|
end
|
@@ -67,6 +67,18 @@ Facter.add('physicalprocessorcount') do
|
|
67
67
|
confine :kernel => :sunos
|
68
68
|
|
69
69
|
setcode do
|
70
|
-
|
70
|
+
# (#16526) The -p flag was not added until Solaris 8. Our intent is to
|
71
|
+
# split the kernel release fact value on the dot, take the second element,
|
72
|
+
# and disable the -p flag for values < 8 when.
|
73
|
+
kernelrelease = Facter.value(:kernelrelease)
|
74
|
+
(major_version, minor_version) = kernelrelease.split(".").map { |str| str.to_i }
|
75
|
+
cmd = "/usr/sbin/psrinfo"
|
76
|
+
result = nil
|
77
|
+
if (major_version > 5) or (major_version == 5 and minor_version >= 8) then
|
78
|
+
result = Facter::Util::Resolution.exec("#{cmd} -p")
|
79
|
+
else
|
80
|
+
output = Facter::Util::Resolution.exec(cmd)
|
81
|
+
result = output.split("\n").length.to_s
|
82
|
+
end
|
71
83
|
end
|
72
84
|
end
|
data/lib/facter/processor.rb
CHANGED
@@ -22,6 +22,26 @@
|
|
22
22
|
require 'thread'
|
23
23
|
require 'facter/util/processor'
|
24
24
|
|
25
|
+
## We have to enumerate these outside a Facter.add block to get the processorN descriptions iteratively
|
26
|
+
## (but we need them inside the Facter.add block above for tests on processorcount to work)
|
27
|
+
processor_list = case Facter::Util::Processor.kernel_fact_value
|
28
|
+
when "AIX"
|
29
|
+
Facter::Util::Processor.aix_processor_list
|
30
|
+
when "SunOS"
|
31
|
+
Facter::Util::Processor.enum_kstat
|
32
|
+
else
|
33
|
+
Facter::Util::Processor.enum_cpuinfo
|
34
|
+
end
|
35
|
+
|
36
|
+
processor_list.each_with_index do |desc, i|
|
37
|
+
Facter.add("Processor#{i}") do
|
38
|
+
confine :kernel => [ :aix, :sunos, :linux, :"gnu/kfreebsd" ]
|
39
|
+
setcode do
|
40
|
+
desc
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
25
45
|
Facter.add("ProcessorCount") do
|
26
46
|
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
27
47
|
setcode do
|
@@ -51,7 +71,7 @@ end
|
|
51
71
|
Facter.add("ProcessorCount") do
|
52
72
|
confine :kernel => :aix
|
53
73
|
setcode do
|
54
|
-
processor_list = Facter::Util::Processor.
|
74
|
+
processor_list = Facter::Util::Processor.aix_processor_list
|
55
75
|
|
56
76
|
processor_list.length.to_s
|
57
77
|
end
|
@@ -78,41 +98,6 @@ Facter.add("ProcessorCount") do
|
|
78
98
|
end
|
79
99
|
end
|
80
100
|
|
81
|
-
## We have to enumerate these outside a Facter.add block to get the processorN descriptions iteratively
|
82
|
-
## (but we need them inside the Facter.add block above for tests on processorcount to work)
|
83
|
-
processor_list = Facter::Util::Processor.enum_cpuinfo
|
84
|
-
processor_list_aix = Facter::Util::Processor.enum_lsdev
|
85
|
-
processor_list_sunos = Facter::Util::Processor.enum_kstat
|
86
|
-
|
87
|
-
if processor_list.length != 0
|
88
|
-
processor_list.each_with_index do |desc, i|
|
89
|
-
Facter.add("Processor#{i}") do
|
90
|
-
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
91
|
-
setcode do
|
92
|
-
desc
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
elsif processor_list_aix.length != 0
|
97
|
-
processor_list_aix.each_with_index do |desc, i|
|
98
|
-
Facter.add("Processor#{i}") do
|
99
|
-
confine :kernel => [ :aix ]
|
100
|
-
setcode do
|
101
|
-
desc
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
elsif processor_list_sunos.length != 0
|
106
|
-
processor_list_sunos.each_with_index do |desc, i|
|
107
|
-
Facter.add("Processor#{i}") do
|
108
|
-
confine :kernel => [ :sunos ]
|
109
|
-
setcode do
|
110
|
-
desc
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
101
|
if Facter.value(:kernel) == "windows"
|
117
102
|
processor_list = []
|
118
103
|
|
@@ -165,10 +150,23 @@ Facter.add("ProcessorCount") do
|
|
165
150
|
end
|
166
151
|
end
|
167
152
|
|
168
|
-
Facter.add("
|
153
|
+
Facter.add("ProcessorCount") do
|
169
154
|
confine :kernel => :sunos
|
170
155
|
setcode do
|
171
|
-
|
172
|
-
|
156
|
+
kernelrelease = Facter.value(:kernelrelease)
|
157
|
+
(major_version, minor_version) = kernelrelease.split(".").map { |str| str.to_i }
|
158
|
+
result = nil
|
159
|
+
|
160
|
+
if (major_version > 5) or (major_version == 5 and minor_version >= 8) then
|
161
|
+
if kstat = Facter::Util::Resolution.exec("/usr/bin/kstat cpu_info")
|
162
|
+
result = kstat.scan(/\bcore_id\b\s+\d+/).uniq.length
|
163
|
+
end
|
164
|
+
else
|
165
|
+
if output = Facter::Util::Resolution.exec("/usr/sbin/psrinfo") then
|
166
|
+
result = output.split("\n").length
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
result
|
173
171
|
end
|
174
172
|
end
|
data/lib/facter/util/ip.rb
CHANGED
@@ -87,9 +87,9 @@ module Facter::Util::IP
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def self.get_infiniband_macaddress(interface)
|
90
|
-
if File
|
90
|
+
if File.exists?("/sys/class/net/#{interface}/address") then
|
91
91
|
ib_mac_address = `cat /sys/class/net/#{interface}/address`.chomp
|
92
|
-
elsif File
|
92
|
+
elsif File.exists?("/sbin/ip") then
|
93
93
|
ip_output = %x{/sbin/ip link show #{interface}}
|
94
94
|
ib_mac_address = ip_output.scan(%r{infiniband\s+((\w{1,2}:){5,}\w{1,2})})
|
95
95
|
else
|
@@ -2,6 +2,38 @@
|
|
2
2
|
# version 1.8.5. This allows us to use RbConfig in place of the older Config in
|
3
3
|
# our code and still be compatible with at least Ruby 1.8.1.
|
4
4
|
require 'rbconfig'
|
5
|
+
require 'enumerator'
|
6
|
+
|
5
7
|
unless defined? ::RbConfig
|
6
8
|
::RbConfig = ::Config
|
7
9
|
end
|
10
|
+
|
11
|
+
module Facter
|
12
|
+
module Util
|
13
|
+
module MonkeyPatches
|
14
|
+
module Lines
|
15
|
+
def lines(separator = $/)
|
16
|
+
if block_given?
|
17
|
+
self.each_line(separator) {|line| yield line }
|
18
|
+
return self
|
19
|
+
else
|
20
|
+
return enum_for(:each_line, separator)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
public
|
29
|
+
class String
|
30
|
+
unless method_defined? :lines
|
31
|
+
include Facter::Util::MonkeyPatches::Lines
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class IO
|
36
|
+
unless method_defined? :lines
|
37
|
+
include Facter::Util::MonkeyPatches::Lines
|
38
|
+
end
|
39
|
+
end
|
@@ -1,4 +1,75 @@
|
|
1
|
-
module Facter
|
1
|
+
module Facter
|
2
|
+
module Util
|
3
|
+
module Processor
|
4
|
+
##
|
5
|
+
# aix_processor_list is intended to generate a list of values for the
|
6
|
+
# processorX facts. The behavior is as follows from
|
7
|
+
# [#11609](http://projects.puppetlabs.com/issues/11609)
|
8
|
+
#
|
9
|
+
# 1. Take a list of all the processor identifiers for the platform,
|
10
|
+
# represented as system-native identifiers in strings.
|
11
|
+
# 2. Sort the list
|
12
|
+
# 3. Assign an incrementing from 0 integer index to each identifier.
|
13
|
+
# 4. Store the value of the system identifier in the processorX fact where X
|
14
|
+
# is the incrementing index.
|
15
|
+
#
|
16
|
+
# Returns an Array, sorted, containing the values for the facts.
|
17
|
+
def self.aix_processor_list
|
18
|
+
return_value = []
|
19
|
+
aix_proc_id_list = []
|
20
|
+
|
21
|
+
if output = lsdev then
|
22
|
+
output.split("\n").each do |line|
|
23
|
+
if match = line.match(/proc\d+/)
|
24
|
+
aix_proc_id_list << match[0]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Generalized alphanumeric sort to put "proc12" behind "proc4"
|
30
|
+
padding = 8
|
31
|
+
aix_proc_id_list = aix_proc_id_list.sort do |a,b|
|
32
|
+
a,b = [a,b].map do |s|
|
33
|
+
s.gsub(/\d+/) { |m| "0"*(padding - m.size) + m }
|
34
|
+
end
|
35
|
+
a<=>b
|
36
|
+
end
|
37
|
+
|
38
|
+
aix_proc_id_list.each do |proc_id|
|
39
|
+
if output = lsattr("lsattr -El #{proc_id} -a type")
|
40
|
+
if match = output.match(/type\s+([^\s]+)\s+Processor/i)
|
41
|
+
return_value << match[1]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
return_value
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# lsdev is intended to directly delegate to Facter::Util::Resolution.exec in an
|
51
|
+
# effort to make the processorX facts easier to test by stubbing only the
|
52
|
+
# behaviors we need to stub to get the output of the system command.
|
53
|
+
def self.lsdev(command="lsdev -Cc processor")
|
54
|
+
Facter::Util::Resolution.exec(command)
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# lsattr is intended to directly delegate to Facter::Util::Resolution.exec in
|
59
|
+
# an effort to make the processorX facts easier to test. See also the
|
60
|
+
# {lsdev} method.
|
61
|
+
def self.lsattr(command="lsattr -El proc0 -a type")
|
62
|
+
Facter::Util::Resolution.exec(command)
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# kernel_fact_value is intended to directly delegate to Facter.value(:kernel)
|
67
|
+
# to make it easier to stub the kernel fact without affecting the entire
|
68
|
+
# system.
|
69
|
+
def self.kernel_fact_value
|
70
|
+
Facter.value(:kernel)
|
71
|
+
end
|
72
|
+
|
2
73
|
def self.enum_cpuinfo
|
3
74
|
processor_num = -1
|
4
75
|
processor_list = []
|
@@ -64,28 +135,6 @@ module Facter::Util::Processor
|
|
64
135
|
processor_list
|
65
136
|
end
|
66
137
|
|
67
|
-
def self.enum_lsdev
|
68
|
-
processor_num = -1
|
69
|
-
processor_list = {}
|
70
|
-
Thread::exclusive do
|
71
|
-
procs = Facter::Util::Resolution.exec('lsdev -Cc processor')
|
72
|
-
if procs
|
73
|
-
procs.each_line do |proc|
|
74
|
-
if proc =~ /^proc(\d+)/
|
75
|
-
processor_num = $1.to_i
|
76
|
-
# Not retrieving the frequency since AIX 4.3.3 doesn't support the
|
77
|
-
# attribute and some people still use the OS.
|
78
|
-
proctype = Facter::Util::Resolution.exec('lsattr -El proc0 -a type')
|
79
|
-
if proctype =~ /^type\s+(\S+)\s+/
|
80
|
-
processor_list[processor_num] = $1
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
processor_list
|
87
|
-
end
|
88
|
-
|
89
138
|
def self.enum_kstat
|
90
139
|
processor_num = -1
|
91
140
|
processor_list = []
|
@@ -105,3 +154,5 @@ module Facter::Util::Processor
|
|
105
154
|
processor_list
|
106
155
|
end
|
107
156
|
end
|
157
|
+
end
|
158
|
+
end
|
data/lib/facter/util/uptime.rb
CHANGED
@@ -4,7 +4,7 @@ require 'time'
|
|
4
4
|
#
|
5
5
|
module Facter::Util::Uptime
|
6
6
|
def self.get_uptime_seconds_unix
|
7
|
-
uptime_proc_uptime or uptime_sysctl or
|
7
|
+
uptime_proc_uptime or uptime_sysctl or uptime_executable
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.get_uptime_seconds_win
|
@@ -31,15 +31,30 @@ module Facter::Util::Uptime
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def self.
|
35
|
-
if output = Facter::Util::Resolution.exec("#{
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
def self.uptime_executable
|
35
|
+
if output = Facter::Util::Resolution.exec("#{uptime_executable_cmd} 2>/dev/null")
|
36
|
+
up=0
|
37
|
+
if output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+):(\d+)/
|
38
|
+
# Regexp handles Solaris, AIX, HP-UX, and Tru64.
|
39
|
+
# 'day(?:s|\(s\))?' says maybe 'day', 'days',
|
40
|
+
# or 'day(s)', and don't set $2.
|
41
|
+
up=86400*$1.to_i + 3600*$2.to_i + 60*$3.to_i
|
42
|
+
elsif output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+) hr(?:s|\(s\))?,/
|
43
|
+
up=86400*$1.to_i + 3600*$2.to_i
|
44
|
+
elsif output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+) min(?:s|\(s\))?,/
|
45
|
+
up=86400*$1.to_i + 60*$2.to_i
|
46
|
+
elsif output =~ /(\d+) day(?:s|\(s\))?,/
|
47
|
+
up=86400*$1.to_i
|
48
|
+
elsif output =~ /up\s+(\d+):(\d+),/
|
49
|
+
# must anchor to 'up' to avoid matching time of day
|
50
|
+
# at beginning of line.
|
51
|
+
up=3600*$1.to_i + 60*$2.to_i
|
52
|
+
elsif output =~ /(\d+) hr(?:s|\(s\))?,/
|
53
|
+
up=3600*$1.to_i
|
54
|
+
elsif output =~ /(\d+) min(?:s|\(s\))?,/
|
55
|
+
up=60*$1.to_i
|
56
|
+
end
|
57
|
+
up
|
43
58
|
end
|
44
59
|
end
|
45
60
|
|
@@ -55,11 +70,7 @@ module Facter::Util::Uptime
|
|
55
70
|
'sysctl -n kern.boottime'
|
56
71
|
end
|
57
72
|
|
58
|
-
def self.
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.uptime_who_cmd
|
63
|
-
'who -b'
|
73
|
+
def self.uptime_executable_cmd
|
74
|
+
"uptime"
|
64
75
|
end
|
65
76
|
end
|