ohai 13.12.6 → 14.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -12
  3. data/README.md +7 -12
  4. data/Rakefile +16 -23
  5. data/docs/man/man1/ohai.1 +97 -0
  6. data/lib/ohai/application.rb +9 -4
  7. data/lib/ohai/common/dmi.rb +4 -16
  8. data/lib/ohai/config.rb +5 -1
  9. data/lib/ohai/dsl.rb +0 -1
  10. data/lib/ohai/dsl/plugin.rb +12 -16
  11. data/lib/ohai/dsl/plugin/versionvii.rb +17 -5
  12. data/lib/ohai/hints.rb +2 -2
  13. data/lib/ohai/loader.rb +21 -70
  14. data/lib/ohai/log.rb +1 -1
  15. data/lib/ohai/mixin/azure_metadata.rb +4 -4
  16. data/lib/ohai/mixin/command.rb +3 -3
  17. data/lib/ohai/mixin/dmi_decode.rb +0 -2
  18. data/lib/ohai/mixin/do_metadata.rb +1 -1
  19. data/lib/ohai/mixin/ec2_metadata.rb +8 -8
  20. data/lib/ohai/mixin/gce_metadata.rb +1 -5
  21. data/lib/ohai/mixin/http_helper.rb +3 -3
  22. data/lib/ohai/mixin/scaleway_metadata.rb +46 -0
  23. data/lib/ohai/mixin/softlayer_metadata.rb +3 -3
  24. data/lib/ohai/plugins/aix/filesystem.rb +1 -1
  25. data/lib/ohai/plugins/aix/memory.rb +1 -1
  26. data/lib/ohai/plugins/aix/network.rb +2 -2
  27. data/lib/ohai/plugins/aix/virtualization.rb +1 -1
  28. data/lib/ohai/plugins/azure.rb +5 -5
  29. data/lib/ohai/plugins/bsd/virtualization.rb +11 -11
  30. data/lib/ohai/plugins/c.rb +8 -8
  31. data/lib/ohai/plugins/chef.rb +2 -1
  32. data/lib/ohai/plugins/cloud.rb +0 -3
  33. data/lib/ohai/plugins/darwin/cpu.rb +2 -2
  34. data/lib/ohai/plugins/darwin/filesystem.rb +0 -2
  35. data/lib/ohai/plugins/darwin/hardware.rb +9 -3
  36. data/lib/ohai/plugins/darwin/network.rb +2 -2
  37. data/lib/ohai/plugins/darwin/system_profiler.rb +19 -19
  38. data/lib/ohai/plugins/darwin/virtualization.rb +10 -0
  39. data/lib/ohai/plugins/digital_ocean.rb +4 -4
  40. data/lib/ohai/plugins/dmi.rb +15 -14
  41. data/lib/ohai/plugins/docker.rb +57 -0
  42. data/lib/ohai/plugins/ec2.rb +11 -11
  43. data/lib/ohai/plugins/elixir.rb +1 -1
  44. data/lib/ohai/plugins/erlang.rb +2 -2
  45. data/lib/ohai/plugins/eucalyptus.rb +5 -5
  46. data/lib/ohai/plugins/gce.rb +2 -2
  47. data/lib/ohai/plugins/go.rb +1 -1
  48. data/lib/ohai/plugins/groovy.rb +1 -1
  49. data/lib/ohai/plugins/haskell.rb +4 -4
  50. data/lib/ohai/plugins/hostname.rb +6 -6
  51. data/lib/ohai/plugins/init_package.rb +1 -1
  52. data/lib/ohai/plugins/java.rb +1 -1
  53. data/lib/ohai/plugins/kernel.rb +109 -40
  54. data/lib/ohai/plugins/libvirt.rb +113 -0
  55. data/lib/ohai/plugins/linode.rb +4 -4
  56. data/lib/ohai/plugins/linux/block_device.rb +4 -4
  57. data/lib/ohai/plugins/linux/cpu.rb +3 -3
  58. data/lib/ohai/plugins/linux/filesystem.rb +4 -6
  59. data/lib/ohai/plugins/linux/lsb.rb +3 -3
  60. data/lib/ohai/plugins/linux/lspci.rb +2 -1
  61. data/lib/ohai/plugins/linux/machineid.rb +4 -4
  62. data/lib/ohai/plugins/linux/network.rb +16 -16
  63. data/lib/ohai/plugins/linux/platform.rb +4 -10
  64. data/lib/ohai/plugins/linux/sessions.rb +2 -1
  65. data/lib/ohai/plugins/linux/virtualization.rb +53 -31
  66. data/lib/ohai/plugins/lua.rb +1 -1
  67. data/lib/ohai/plugins/mono.rb +2 -2
  68. data/lib/ohai/plugins/network.rb +11 -11
  69. data/lib/ohai/plugins/nodejs.rb +1 -1
  70. data/lib/ohai/plugins/ohai.rb +0 -2
  71. data/lib/ohai/plugins/openstack.rb +7 -10
  72. data/lib/ohai/plugins/packages.rb +1 -1
  73. data/lib/ohai/plugins/passwd.rb +1 -0
  74. data/lib/ohai/plugins/perl.rb +1 -1
  75. data/lib/ohai/plugins/php.rb +1 -1
  76. data/lib/ohai/plugins/powershell.rb +1 -1
  77. data/lib/ohai/plugins/python.rb +1 -1
  78. data/lib/ohai/plugins/rackspace.rb +5 -5
  79. data/lib/ohai/plugins/root_group.rb +6 -9
  80. data/lib/ohai/plugins/ruby.rb +2 -2
  81. data/lib/ohai/plugins/rust.rb +1 -1
  82. data/lib/ohai/plugins/scala.rb +1 -1
  83. data/lib/ohai/plugins/scaleway.rb +56 -0
  84. data/lib/ohai/plugins/shard.rb +1 -0
  85. data/lib/ohai/plugins/softlayer.rb +2 -2
  86. data/lib/ohai/plugins/solaris2/cpu.rb +1 -1
  87. data/lib/ohai/plugins/solaris2/dmi.rb +13 -13
  88. data/lib/ohai/plugins/solaris2/network.rb +6 -6
  89. data/lib/ohai/plugins/solaris2/platform.rb +2 -2
  90. data/lib/ohai/plugins/ssh_host_key.rb +7 -7
  91. data/lib/ohai/plugins/uptime.rb +2 -7
  92. data/lib/ohai/plugins/virtualbox.rb +1 -1
  93. data/lib/ohai/plugins/vmware.rb +2 -2
  94. data/lib/ohai/plugins/windows/cpu.rb +2 -16
  95. data/lib/ohai/plugins/windows/network.rb +4 -2
  96. data/lib/ohai/plugins/zpools.rb +3 -3
  97. data/lib/ohai/provides_map.rb +1 -1
  98. data/lib/ohai/runner.rb +11 -14
  99. data/lib/ohai/system.rb +8 -71
  100. data/lib/ohai/util/file_helper.rb +2 -2
  101. data/lib/ohai/util/win32/group_helper.rb +0 -2
  102. data/lib/ohai/version.rb +1 -1
  103. data/ohai.gemspec +6 -5
  104. data/spec/functional/plugins/root_group_spec.rb +2 -2
  105. data/spec/functional/plugins/windows/uptime_spec.rb +0 -29
  106. data/spec/unit/dsl/plugin_spec.rb +14 -46
  107. data/spec/unit/loader_spec.rb +8 -70
  108. data/spec/unit/mixin/azure_metadata_spec.rb +9 -4
  109. data/spec/unit/mixin/command_spec.rb +11 -8
  110. data/spec/unit/mixin/ec2_metadata_spec.rb +5 -0
  111. data/spec/unit/mixin/softlayer_metadata_spec.rb +6 -1
  112. data/spec/unit/plugins/aix/filesystem_spec.rb +10 -10
  113. data/spec/unit/plugins/aix/network_spec.rb +1 -1
  114. data/spec/unit/plugins/aix/virtualization_spec.rb +3 -3
  115. data/spec/unit/plugins/cloud_spec.rb +0 -12
  116. data/spec/unit/plugins/darwin/cpu_spec.rb +2 -2
  117. data/spec/unit/plugins/darwin/filesystem_spec.rb +1 -6
  118. data/spec/unit/plugins/darwin/hardware_spec.rb +1 -1
  119. data/spec/unit/plugins/darwin/virtualization_spec.rb +8 -0
  120. data/spec/unit/plugins/dmi_spec.rb +17 -25
  121. data/spec/unit/plugins/docker_spec.rb +100 -0
  122. data/spec/unit/plugins/fail_spec.rb +3 -58
  123. data/spec/unit/plugins/haskell_spec.rb +1 -1
  124. data/spec/unit/plugins/init_package_spec.rb +1 -1
  125. data/spec/unit/plugins/kernel_spec.rb +0 -52
  126. data/spec/unit/plugins/linux/block_device_spec.rb +2 -2
  127. data/spec/unit/plugins/linux/filesystem_spec.rb +2 -7
  128. data/spec/unit/plugins/linux/lsb_spec.rb +5 -5
  129. data/spec/unit/plugins/linux/lspci_spec.rb +2 -2
  130. data/spec/unit/plugins/linux/machineid_spec.rb +5 -5
  131. data/spec/unit/plugins/linux/network_spec.rb +16 -16
  132. data/spec/unit/plugins/linux/platform_spec.rb +1 -17
  133. data/spec/unit/plugins/linux/virtualization_spec.rb +21 -1
  134. data/spec/unit/plugins/network_spec.rb +58 -58
  135. data/spec/unit/plugins/openstack_spec.rb +5 -24
  136. data/spec/unit/plugins/rackspace_spec.rb +6 -6
  137. data/spec/unit/plugins/root_group_spec.rb +1 -1
  138. data/spec/unit/plugins/ruby_spec.rb +1 -1
  139. data/spec/unit/plugins/rust_spec.rb +1 -1
  140. data/spec/unit/plugins/scala_spec.rb +1 -1
  141. data/spec/unit/plugins/scaleway_spec.rb +91 -0
  142. data/spec/unit/plugins/solaris2/cpu_spec.rb +3 -3
  143. data/spec/unit/plugins/solaris2/platform_spec.rb +2 -2
  144. data/spec/unit/plugins/ssh_host_keys_spec.rb +8 -8
  145. data/spec/unit/plugins/sysconf_spec.rb +1 -0
  146. data/spec/unit/plugins/windows/kernel_spec.rb +79 -0
  147. data/spec/unit/plugins/windows/uptime_spec.rb +8 -58
  148. data/spec/unit/provides_map_spec.rb +4 -4
  149. data/spec/unit/runner_spec.rb +15 -54
  150. data/spec/unit/system_spec.rb +35 -348
  151. data/spec/unit/util/file_helper_spec.rb +2 -0
  152. metadata +28 -28
  153. data/lib/ohai/dsl/plugin/versionvi.rb +0 -61
  154. data/lib/ohai/plugins/bsd/filesystem2.rb +0 -121
  155. data/lib/ohai/plugins/ip_scopes.rb +0 -67
  156. data/lib/ohai/plugins/virtualization.rb +0 -83
  157. data/spec/data/plugins/messages.rb +0 -8
  158. data/spec/data/plugins/v6message.rb +0 -2
  159. data/spec/unit/plugins/bsd/filesystem2_spec.rb +0 -126
  160. data/spec/unit/plugins/ip_scopes_spec.rb +0 -139
@@ -0,0 +1,57 @@
1
+ #
2
+ # Copyright:: 2018 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ Ohai.plugin(:Docker) do
19
+ require "json"
20
+
21
+ provides "docker"
22
+ depends "virtualization"
23
+
24
+ def docker_info_json
25
+ so = shell_out("docker info --format '{{json .}}'")
26
+ if so.exitstatus == 0
27
+ return JSON.parse(so.stdout)
28
+ end
29
+ rescue Ohai::Exceptions::Exec
30
+ logger.trace('Plugin Docker: Could not shell_out "docker info --format \'{{json .}}\'". Skipping plugin')
31
+ end
32
+
33
+ def docker_ohai_data(shellout_data)
34
+ docker Mash.new
35
+ docker[:version_string] = shellout_data["ServerVersion"]
36
+ docker[:version] = shellout_data["ServerVersion"].split("-")[0] if shellout_data["ServerVersion"] # guard this so missing data doesn't fail the run
37
+ docker[:runtimes] = shellout_data["Runtimes"]
38
+ docker[:root_dir] = shellout_data["DockerRootDir"]
39
+ docker[:containers] = {}
40
+ docker[:containers][:total] = shellout_data["Containers"]
41
+ docker[:containers][:running] = shellout_data["ContainersRunning"]
42
+ docker[:containers][:paused] = shellout_data["ContainersPaused"]
43
+ docker[:containers][:stopped] = shellout_data["ContainersStopped"]
44
+ docker[:plugins] = shellout_data["Plugins"]
45
+ docker[:networking] = {}
46
+ docker[:networking][:ipv4_forwarding] = shellout_data["IPv4Forwarding"]
47
+ docker[:networking][:bridge_nf_iptables] = shellout_data["BridgeNfIptables"]
48
+ docker[:networking][:bridge_nf_ipv6_iptables] = shellout_data["BridgeNfIp6tables"]
49
+ docker[:swarm] = shellout_data["Swarm"]
50
+ end
51
+
52
+ collect_data do
53
+ if virtualization[:systems][:docker]
54
+ docker_ohai_data(docker_info_json)
55
+ end
56
+ end
57
+ end
@@ -42,10 +42,10 @@ Ohai.plugin(:EC2) do
42
42
  def has_ec2_amazon_dmi?
43
43
  # detect a version of '4.2.amazon'
44
44
  if file_val_if_exists("/sys/class/dmi/id/bios_vendor") =~ /Amazon/
45
- Ohai::Log.debug("Plugin EC2: has_ec2_amazon_dmi? == true")
45
+ logger.trace("Plugin EC2: has_ec2_amazon_dmi? == true")
46
46
  true
47
47
  else
48
- Ohai::Log.debug("Plugin EC2: has_ec2_amazon_dmi? == false")
48
+ logger.trace("Plugin EC2: has_ec2_amazon_dmi? == false")
49
49
  false
50
50
  end
51
51
  end
@@ -57,10 +57,10 @@ Ohai.plugin(:EC2) do
57
57
  def has_ec2_xen_dmi?
58
58
  # detect a version of '4.2.amazon'
59
59
  if file_val_if_exists("/sys/class/dmi/id/bios_version") =~ /amazon/
60
- Ohai::Log.debug("Plugin EC2: has_ec2_xen_dmi? == true")
60
+ logger.trace("Plugin EC2: has_ec2_xen_dmi? == true")
61
61
  true
62
62
  else
63
- Ohai::Log.debug("Plugin EC2: has_ec2_xen_dmi? == false")
63
+ logger.trace("Plugin EC2: has_ec2_xen_dmi? == false")
64
64
  false
65
65
  end
66
66
  end
@@ -69,10 +69,10 @@ Ohai.plugin(:EC2) do
69
69
  # @return [Boolean] do we have a Xen UUID or not?
70
70
  def has_ec2_xen_uuid?
71
71
  if file_val_if_exists("/sys/hypervisor/uuid") =~ /^ec2/
72
- Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == true")
72
+ logger.trace("Plugin EC2: has_ec2_xen_uuid? == true")
73
73
  return true
74
74
  end
75
- Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == false")
75
+ logger.trace("Plugin EC2: has_ec2_xen_uuid? == false")
76
76
  false
77
77
  end
78
78
 
@@ -85,11 +85,11 @@ Ohai.plugin(:EC2) do
85
85
  require "wmi-lite/wmi"
86
86
  wmi = WmiLite::Wmi.new
87
87
  if wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"] =~ /^ec2/
88
- Ohai::Log.debug("Plugin EC2: has_ec2_identifying_number? == true")
88
+ logger.trace("Plugin EC2: has_ec2_identifying_number? == true")
89
89
  return true
90
90
  end
91
91
  else
92
- Ohai::Log.debug("Plugin EC2: has_ec2_identifying_number? == false")
92
+ logger.trace("Plugin EC2: has_ec2_identifying_number? == false")
93
93
  false
94
94
  end
95
95
  end
@@ -116,7 +116,7 @@ Ohai.plugin(:EC2) do
116
116
 
117
117
  collect_data do
118
118
  if looks_like_ec2?
119
- Ohai::Log.debug("Plugin EC2: looks_like_ec2? == true")
119
+ logger.trace("Plugin EC2: looks_like_ec2? == true")
120
120
  ec2 Mash.new
121
121
  fetch_metadata.each do |k, v|
122
122
  # fetch_metadata returns IAM security credentials, including the IAM user's
@@ -132,11 +132,11 @@ Ohai.plugin(:EC2) do
132
132
  ec2[:region] = fetch_dynamic_data["region"]
133
133
  # ASCII-8BIT is equivalent to BINARY in this case
134
134
  if ec2[:userdata] && ec2[:userdata].encoding.to_s == "ASCII-8BIT"
135
- Ohai::Log.debug("Plugin EC2: Binary UserData Found. Storing in base64")
135
+ logger.trace("Plugin EC2: Binary UserData Found. Storing in base64")
136
136
  ec2[:userdata] = Base64.encode64(ec2[:userdata])
137
137
  end
138
138
  else
139
- Ohai::Log.debug("Plugin EC2: looks_like_ec2? == false")
139
+ logger.trace("Plugin EC2: looks_like_ec2? == false")
140
140
  false
141
141
  end
142
142
  end
@@ -30,7 +30,7 @@ Ohai.plugin(:Elixir) do
30
30
  languages[:elixir] = elixir
31
31
  end
32
32
  rescue Ohai::Exceptions::Exec
33
- Ohai::Log.debug('Plugin Elixir: Could not shell_out "elixir -v". Skipping plugin')
33
+ logger.trace('Plugin Elixir: Could not shell_out "elixir -v". Skipping plugin')
34
34
  end
35
35
  end
36
36
  end
@@ -34,7 +34,7 @@ Ohai.plugin(:Erlang) do
34
34
  erlang[:nif_version] = output[2]
35
35
  end
36
36
  rescue Ohai::Exceptions::Exec
37
- Ohai::Log.debug('Plugin Erlang: Could not shell_out "erl -eval \'erlang:display(erlang:system_info(otp_release)), erlang:display(erlang:system_info(version)), erlang:display(erlang:system_info(nif_version)), halt().\' -noshell". Skipping data')
37
+ logger.trace('Plugin Erlang: Could not shell_out "erl -eval \'erlang:display(erlang:system_info(otp_release)), erlang:display(erlang:system_info(version)), erlang:display(erlang:system_info(nif_version)), halt().\' -noshell". Skipping data')
38
38
  end
39
39
 
40
40
  begin
@@ -51,7 +51,7 @@ Ohai.plugin(:Erlang) do
51
51
  end
52
52
  end
53
53
  rescue Ohai::Exceptions::Exec
54
- Ohai::Log.debug('Plugin Erlang: Could not shell_out "erl +V". Skipping data')
54
+ logger.trace('Plugin Erlang: Could not shell_out "erl +V". Skipping data')
55
55
  end
56
56
 
57
57
  languages[:erlang] = erlang unless erlang.empty?
@@ -40,15 +40,15 @@ Ohai.plugin(:Eucalyptus) do
40
40
 
41
41
  # detect if the mac address starts with d0:0d
42
42
  def has_euca_mac?
43
- network[:interfaces].values.each do |iface|
43
+ network[:interfaces].each_value do |iface|
44
44
  mac = get_mac_address(iface[:addresses])
45
45
  if mac =~ /^[dD]0:0[dD]:/
46
- Ohai::Log.debug("Plugin Eucalyptus: has_euca_mac? == true (#{mac})")
46
+ logger.trace("Plugin Eucalyptus: has_euca_mac? == true (#{mac})")
47
47
  return true
48
48
  end
49
49
  end
50
50
 
51
- Ohai::Log.debug("Plugin Eucalyptus: has_euca_mac? == false")
51
+ logger.trace("Plugin Eucalyptus: has_euca_mac? == false")
52
52
  false
53
53
  end
54
54
 
@@ -60,7 +60,7 @@ Ohai.plugin(:Eucalyptus) do
60
60
 
61
61
  collect_data do
62
62
  if looks_like_euca?
63
- Ohai::Log.debug("Plugin Eucalyptus: looks_like_euca? == true")
63
+ logger.trace("Plugin Eucalyptus: looks_like_euca? == true")
64
64
  eucalyptus Mash.new
65
65
  fetch_metadata.each do |k, v|
66
66
  # Eucalyptus 3.4+ supports IAM roles and Instance Profiles much like AWS
@@ -75,7 +75,7 @@ Ohai.plugin(:Eucalyptus) do
75
75
  end
76
76
  eucalyptus[:userdata] = fetch_userdata
77
77
  else
78
- Ohai::Log.debug("Plugin Eucalyptus: looks_like_euca? == false")
78
+ logger.trace("Plugin Eucalyptus: looks_like_euca? == false")
79
79
  false
80
80
  end
81
81
  end
@@ -43,11 +43,11 @@ Ohai.plugin(:GCE) do
43
43
 
44
44
  collect_data do
45
45
  if looks_like_gce?
46
- Ohai::Log.debug("Plugin GCE: looks_like_gce? == true")
46
+ logger.trace("Plugin GCE: looks_like_gce? == true")
47
47
  gce Mash.new
48
48
  fetch_metadata.each { |k, v| gce[k] = v }
49
49
  else
50
- Ohai::Log.debug("Plugin GCE: looks_like_gce? == false")
50
+ logger.trace("Plugin GCE: looks_like_gce? == false")
51
51
  false
52
52
  end
53
53
  end
@@ -28,7 +28,7 @@ Ohai.plugin(:Go) do
28
28
  languages[:go] = go
29
29
  end
30
30
  rescue Ohai::Exceptions::Exec
31
- Ohai::Log.debug('Plugin Go: Could not shell_out "go version". Skipping plugin')
31
+ logger.trace('Plugin Go: Could not shell_out "go version". Skipping plugin')
32
32
  end
33
33
  end
34
34
  end
@@ -32,7 +32,7 @@ Ohai.plugin(:Groovy) do
32
32
  languages[:groovy] = groovy
33
33
  end
34
34
  rescue Ohai::Exceptions::Exec
35
- Ohai::Log.debug('Plugin Groovy: Could not shell_out "groovy -v". Skipping plugin')
35
+ logger.trace('Plugin Groovy: Could not shell_out "groovy -v". Skipping plugin')
36
36
  end
37
37
  end
38
38
  end
@@ -39,7 +39,7 @@ Ohai.plugin(:Haskell) do
39
39
  haskell[:ghc][:description] = so.stdout.chomp
40
40
  end
41
41
  rescue Ohai::Exceptions::Exec
42
- Ohai::Log.debug('Plugin Haskell: Could not shell_out "ghc --version". Skipping data')
42
+ logger.trace('Plugin Haskell: Could not shell_out "ghc --version". Skipping data')
43
43
  end
44
44
 
45
45
  # Check for ghci
@@ -54,7 +54,7 @@ Ohai.plugin(:Haskell) do
54
54
  haskell[:ghci][:description] = so.stdout.chomp
55
55
  end
56
56
  rescue Ohai::Exceptions::Exec
57
- Ohai::Log.debug('Plugin Haskell: Could not shell_out "ghci --version". Skipping data')
57
+ logger.trace('Plugin Haskell: Could not shell_out "ghci --version". Skipping data')
58
58
  end
59
59
 
60
60
  # Check for cabal
@@ -70,7 +70,7 @@ Ohai.plugin(:Haskell) do
70
70
  haskell[:cabal][:description] = so.stdout.split("\n")[0].chomp
71
71
  end
72
72
  rescue Ohai::Exceptions::Exec
73
- Ohai::Log.debug('Plugin Haskell: Could not shell_out "cabal --version". Skipping data')
73
+ logger.trace('Plugin Haskell: Could not shell_out "cabal --version". Skipping data')
74
74
  end
75
75
 
76
76
  # Check for stack
@@ -87,7 +87,7 @@ Ohai.plugin(:Haskell) do
87
87
  haskell[:stack][:description] = so.stdout.chomp
88
88
  end
89
89
  rescue Ohai::Exceptions::Exec
90
- Ohai::Log.debug('Plugin Haskell: Could not shell_out "stack --version". Skipping data')
90
+ logger.trace('Plugin Haskell: Could not shell_out "stack --version". Skipping data')
91
91
  end
92
92
 
93
93
  languages[:haskell] = haskell unless haskell.empty?
@@ -103,18 +103,18 @@ Ohai.plugin(:Hostname) do
103
103
  # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
104
104
  # returns a blank string. WTF.
105
105
  if ourfqdn.nil? || ourfqdn.empty?
106
- Ohai::Log.debug("Plugin Hostname: hostname returned an empty string, retrying once.")
106
+ logger.trace("Plugin Hostname: hostname returned an empty string, retrying once.")
107
107
  ourfqdn = resolve_fqdn
108
108
  end
109
109
 
110
110
  if ourfqdn.nil? || ourfqdn.empty?
111
- Ohai::Log.debug("Plugin Hostname: hostname returned an empty string twice and will" +
111
+ logger.trace("Plugin Hostname: hostname returned an empty string twice and will" +
112
112
  "not be set.")
113
113
  else
114
114
  fqdn ourfqdn
115
115
  end
116
116
  rescue
117
- Ohai::Log.debug(
117
+ logger.trace(
118
118
  "Plugin Hostname: hostname returned an error, probably no domain set")
119
119
  end
120
120
  domain collect_domain
@@ -135,19 +135,19 @@ Ohai.plugin(:Hostname) do
135
135
  # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
136
136
  # returns a blank string. WTF.
137
137
  if ourfqdn.nil? || ourfqdn.empty?
138
- Ohai::Log.debug("Plugin Hostname: hostname --fqdn returned an empty string, retrying " +
138
+ logger.trace("Plugin Hostname: hostname --fqdn returned an empty string, retrying " +
139
139
  "once.")
140
140
  ourfqdn = from_cmd("hostname --fqdn")
141
141
  end
142
142
 
143
143
  if ourfqdn.nil? || ourfqdn.empty?
144
- Ohai::Log.debug("Plugin Hostname: hostname --fqdn returned an empty string twice and " +
144
+ logger.trace("Plugin Hostname: hostname --fqdn returned an empty string twice and " +
145
145
  "will not be set.")
146
146
  else
147
147
  fqdn ourfqdn
148
148
  end
149
149
  rescue
150
- Ohai::Log.debug("Plugin Hostname: hostname --fqdn returned an error, probably no domain set")
150
+ logger.trace("Plugin Hostname: hostname --fqdn returned an error, probably no domain set")
151
151
  end
152
152
  domain collect_domain
153
153
  end
@@ -20,6 +20,6 @@ Ohai.plugin(:InitPackage) do
20
20
  provides "init_package"
21
21
 
22
22
  collect_data(:linux) do
23
- init_package File.exists?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : "init"
23
+ init_package File.exist?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : "init"
24
24
  end
25
25
  end
@@ -42,7 +42,7 @@ Ohai.plugin(:Java) do
42
42
  languages[:java] = java unless java.empty?
43
43
  end
44
44
  rescue Ohai::Exceptions::Exec
45
- Ohai::Log.debug('Plugin Java: Could not shell_out "java -mx64m -version". Skipping plugin')
45
+ logger.trace('Plugin Java: Could not shell_out "java -mx64m -version". Skipping plugin')
46
46
  end
47
47
 
48
48
  # On Mac OS X, the development tools include "stubs" for JVM executables that
@@ -4,7 +4,7 @@
4
4
  # Author:: Bryan McLellan (<btm@loftninjas.org>)
5
5
  # Author:: Claire McQuin (<claire@chef.io>)
6
6
  # Author:: James Gartrell (<jgartrel@gmail.com>)
7
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
7
+ # Copyright:: Copyright (c) 2008-2018 Chef Software, Inc.
8
8
  # Copyright:: Copyright (c) 2009 Bryan McLellan
9
9
  # License:: Apache License, Version 2.0
10
10
  #
@@ -26,6 +26,7 @@ Ohai.plugin(:Kernel) do
26
26
  provides "kernel", "kernel/modules"
27
27
 
28
28
  # common initial kernel attribute values
29
+ # @return [Mash] basic kernel properties from uname
29
30
  def init_kernel
30
31
  kernel Mash.new
31
32
  [["uname -s", :name], ["uname -r", :release],
@@ -38,6 +39,7 @@ Ohai.plugin(:Kernel) do
38
39
  end
39
40
 
40
41
  # common *bsd code for collecting modules data
42
+ # @return [Mash]
41
43
  def bsd_modules(path)
42
44
  modules = Mash.new
43
45
  so = shell_out("#{Ohai.abs_path(path)}")
@@ -50,24 +52,104 @@ Ohai.plugin(:Kernel) do
50
52
  modules
51
53
  end
52
54
 
53
- # windows
54
- def machine_lookup(sys_type)
55
- return "i386" if sys_type.eql?("X86-based PC")
56
- return "x86_64" if sys_type.eql?("x64-based PC")
55
+ # given the OperatingSystemSKU value from WMI's Win32_OperatingSystem class
56
+ # https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
57
+ # return if we're on a Server Core installation
58
+ # @param [String] sku OperatingSystemSKU value from Win32_OperatingSystem
59
+ # @return [boolean]
60
+ def server_core?(sku)
61
+ return true if [
62
+ 12, # Server Datacenter Core
63
+ 39, # Server Datacenter without Hyper-V Core
64
+ 14, # Server Enterprise Core
65
+ 41, # Server Enterprise without Hyper-V Core
66
+ 13, # Server Standard Core
67
+ 40, # Server Standard without Hyper-V Core
68
+ 63, # Small Business Server Premium Core
69
+ 53, # Server Solutions Premium Core
70
+ 46, # Storage Server Enterprise Core
71
+ 43, # Storage Server Express Core
72
+ 44, # Storage Server Standard Core
73
+ 45, # Storage Server Workgroup Core
74
+ 29 # Web Server Core
75
+ ].include?(sku)
76
+ false
77
+ end
78
+
79
+ # given the SystemType value from WMI's Win32_ComputerSystem class
80
+ # https://msdn.microsoft.com/en-us/library/aa394102(v=vs.85).aspx
81
+ # return the architecture type
82
+ # @param [String] sys_type SystemType value from Win32_ComputerSystem
83
+ # @return [String] x86_64 or i386
84
+ def arch_lookup(sys_type)
85
+ return "x86_64" if sys_type == "x64-based PC"
86
+ return "i386" if sys_type == "X86-based PC"
57
87
  sys_type
58
88
  end
59
89
 
60
- # windows
61
- def os_lookup(sys_type)
62
- return "Unknown" if sys_type.to_s.eql?("0")
63
- return "Other" if sys_type.to_s.eql?("1")
64
- return "MSDOS" if sys_type.to_s.eql?("14")
65
- return "WIN3x" if sys_type.to_s.eql?("15")
66
- return "WIN95" if sys_type.to_s.eql?("16")
67
- return "WIN98" if sys_type.to_s.eql?("17")
68
- return "WINNT" if sys_type.to_s.eql?("18")
69
- return "WINCE" if sys_type.to_s.eql?("19")
70
- nil
90
+ # given the ProductType value from WMI's Win32_OperatingSystem class
91
+ # https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
92
+ # return either workstation or server
93
+ # @param [Integer] type ProductType value from Win32_OperatingSystem
94
+ # @return [String] Workstation or Server
95
+ def product_type_decode(type)
96
+ return "Workstation" if type == 1
97
+ "Server"
98
+ end
99
+
100
+ # decode the OSType field from WMI Win32_OperatingSystem class
101
+ # https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
102
+ # @param [Integer] sys_type OSType value from Win32_OperatingSystem
103
+ # @return [String] the human consumable OS type value
104
+ def os_type_decode(sys_type)
105
+ case sys_type
106
+ when 18 then "WINNT" # most likely so first
107
+ when 0 then "Unknown"
108
+ when 1 then "Other"
109
+ when 14 then "MSDOS"
110
+ when 15 then "WIN3x"
111
+ when 16 then "WIN95"
112
+ when 17 then "WIN98"
113
+ when 19 then "WINCE"
114
+ else nil
115
+ end
116
+ end
117
+
118
+ # decode the PCSystemType field from WMI Win32_OperatingSystem class
119
+ # https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
120
+ # @param [Integer] type the integer value from PCSystemType
121
+ # @return [String] the human consumable OS type value
122
+ def pc_system_type_decode(type)
123
+ case type
124
+ when 4 then "Enterprise Server" # most likely so first
125
+ when 0 then "Unspecified"
126
+ when 1 then "Desktop"
127
+ when 2 then "Mobile"
128
+ when 3 then "Workstation"
129
+ when 5 then "SOHO Server"
130
+ when 6 then "Appliance PC"
131
+ when 7 then "Performance Server"
132
+ when 8 then "Maximum"
133
+ else nil
134
+ end
135
+ end
136
+
137
+ # see if a WMI name is blacklisted so we can avoid writing out
138
+ # useless data to ohai
139
+ # @param [String] name the wmi name to check
140
+ # @return [Boolean] is the wmi name blacklisted
141
+ def blacklisted_wmi_name?(name)
142
+ [
143
+ "creation_class_name", # this is just the wmi name
144
+ "cs_creation_class_name", # this is just the wmi name
145
+ "oem_logo_bitmap", # this is the entire OEM bitmap file
146
+ "total_swap_space_size", # already in memory plugin
147
+ "total_virtual_memory_size", # already in memory plugin
148
+ "total_virtual_memory_size", # already in memory plugin
149
+ "free_physical_memory", # already in memory plugin
150
+ "free_space_in_paging_files", # already in memory plugin
151
+ "free_virtual_memory", # already in memory plugin
152
+ ].include?(name)
71
153
  end
72
154
 
73
155
  collect_data(:default) do
@@ -94,7 +176,7 @@ Ohai.plugin(:Kernel) do
94
176
  kernel[:modules] = modules
95
177
  end
96
178
 
97
- collect_data(:freebsd) do
179
+ collect_data(:freebsd, :dragonflybsd) do
98
180
  kernel init_kernel
99
181
  kernel[:os] = kernel[:name]
100
182
 
@@ -138,18 +220,6 @@ Ohai.plugin(:Kernel) do
138
220
  kernel[:modules] = bsd_modules("/usr/bin/modstat")
139
221
  end
140
222
 
141
- collect_data(:dragonflybsd) do
142
- kernel init_kernel
143
- kernel[:os] = kernel[:name]
144
-
145
- so = shell_out("uname -i")
146
- kernel[:ident] = so.stdout.split($/)[0]
147
- so = shell_out("sysctl kern.securelevel")
148
- kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }
149
-
150
- kernel[:modules] = bsd_modules("/sbin/kldstat")
151
- end
152
-
153
223
  collect_data(:solaris2) do
154
224
  kernel init_kernel
155
225
 
@@ -168,7 +238,7 @@ Ohai.plugin(:Kernel) do
168
238
  # 6 1180000 4623 1 1 specfs (filesystem for specfs)
169
239
  module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
170
240
  so.stdout.lines do |line|
171
- if mod = module_description.match(line)
241
+ if ( mod = module_description.match(line) )
172
242
  modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5] }
173
243
  end
174
244
  end
@@ -189,26 +259,25 @@ Ohai.plugin(:Kernel) do
189
259
  host = wmi.first_of("Win32_OperatingSystem")
190
260
  kernel[:os_info] = Mash.new
191
261
  host.wmi_ole_object.properties_.each do |p|
262
+ next if blacklisted_wmi_name?(p.name.wmi_underscore)
192
263
  kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
193
264
  end
194
265
 
195
266
  kernel[:name] = "#{kernel[:os_info][:caption]}"
196
267
  kernel[:release] = "#{kernel[:os_info][:version]}"
197
268
  kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
198
- kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
269
+ kernel[:os] = os_type_decode(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
270
+ kernel[:product_type] = product_type_decode(kernel[:os_info][:product_type])
271
+ kernel[:server_core] = server_core?(kernel[:os_info][:operating_system_sku])
199
272
 
200
- host = wmi.first_of("Win32_ComputerSystem")
201
273
  kernel[:cs_info] = Mash.new
202
- cs_info_blacklist = [
203
- "oem_logo_bitmap",
204
- ]
274
+ host = wmi.first_of("Win32_ComputerSystem")
205
275
  host.wmi_ole_object.properties_.each do |p|
206
- if !cs_info_blacklist.include?(p.name.wmi_underscore)
207
- kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
208
- end
276
+ next if blacklisted_wmi_name?(p.name.wmi_underscore)
277
+ kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
209
278
  end
210
279
 
211
- kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")
212
-
280
+ kernel[:machine] = arch_lookup("#{kernel[:cs_info][:system_type]}")
281
+ kernel[:system_type] = pc_system_type_decode(kernel[:cs_info][:pc_system_type])
213
282
  end
214
283
  end