ohai 8.20.0 → 8.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09b47a615ee064d16781e8ce7a847d71035d535a
4
- data.tar.gz: fd200214865bb27d7ebce651d06798ac8d1b401a
3
+ metadata.gz: 9adc486c591d6c788a28df54f4b3019649143fbf
4
+ data.tar.gz: 84178b71f088420c0f8aa6162bb8c16ab6ec117c
5
5
  SHA512:
6
- metadata.gz: 42971e6add7b1e917f52bd5d416d622555c03764ae6c7e8090cf945ab77e0fba561719c7e8c4210169f164b2967a68df5cda3d6c5ed8ce87522a618466bf22de
7
- data.tar.gz: b34aa2275ff4f580d1c37de0234a92ff7a0e6b1a98161e38e8c0ebbe4f7c0fa9aef36c1dcccc21a42a7deb99d920e9830214932ef6720adf247a81b17752772e
6
+ metadata.gz: ed8f9a5cc316288abffcde24a126b76de94e9160c4c1a4220881759700fdb60ee2a9cb8808f8bd621b8be903b881aa5d62d384e059c3e15b18d652a2f7060d3c
7
+ data.tar.gz: c8720f2368a29fab4f218f4035992d07a3b02370a6e121edd5cb0bf9198bf54e7e7c99aea6d1d0238b5e2905d1237ded01cba89d64f793cce6473b72562af432
data/README.md CHANGED
@@ -1,84 +1,72 @@
1
1
  # ohai
2
- [![Build Status Master](https://travis-ci.org/chef/ohai.svg?branch=master)](https://travis-ci.org/chef/ohai)
3
- [![Build Status Master](https://ci.appveyor.com/api/projects/status/github/chef/ohai?branch=master&svg=true&passingText=master%20-%20Ok&pendingText=master%20-%20Pending&failingText=master%20-%20Failing)](https://ci.appveyor.com/project/Chef/ohai/branch/master)
4
- [![Gem Version](https://badge.fury.io/rb/ohai.svg)](https://badge.fury.io/rb/ohai)
5
2
 
3
+ [![Build Status Master](https://travis-ci.org/chef/ohai.svg?branch=master)](https://travis-ci.org/chef/ohai) [![Build Status Master](https://ci.appveyor.com/api/projects/status/github/chef/ohai?branch=master&svg=true&passingText=master%20-%20Ok&pendingText=master%20-%20Pending&failingText=master%20-%20Failing)](https://ci.appveyor.com/project/Chef/ohai/branch/master) [![Gem Version](https://badge.fury.io/rb/ohai.svg)](https://badge.fury.io/rb/ohai)
6
4
 
7
- # DESCRIPTION:
5
+ ## Description
8
6
 
9
- Ohai detects data about your operating system. It can be used
10
- standalone, but its primary purpose is to provide node data to Chef.
7
+ Ohai detects data about your operating system. It can be used standalone, but its primary purpose is to provide node data to Chef.
11
8
 
12
- Ohai will print out a JSON data blob for all the known data about your
13
- system. When used with Chef, that data is reported back via node
14
- attributes.
9
+ Ohai will print out a JSON data blob for all the known data about your system. When used with Chef, that data is reported back via node attributes.
15
10
 
16
- Chef distributes ohai as a RubyGem. This README is for developers who
17
- want to modify the Ohai source code. For users who want to write plugins
18
- for Ohai, see the docs:
11
+ Chef distributes ohai as a RubyGem. This README is for developers who want to modify the Ohai source code. For users who want to write plugins for Ohai, see the docs:
19
12
 
20
- * General documentation: https://docs.chef.io/ohai.html
21
- * Custom plugin documentation: https://docs.chef.io/ohai_custom.html
13
+ - General documentation: <https://docs.chef.io/ohai.html>
14
+ - Custom plugin documentation: <https://docs.chef.io/ohai_custom.html>
22
15
 
23
- # DEVELOPMENT:
16
+ ## Development Environment:
24
17
 
25
- Before working on the code, if you plan to contribute your changes, you
26
- should read the contributing guidelines:
27
-
28
- * https://github.com/chef/ohai/blob/master/CONTRIBUTING.md
29
-
30
- The basic process for contributing is:
31
-
32
- 1. Fork this repo on GitHub.
33
- 2. Create a feature branch for your work.
34
- 3. Make your change, including tests.
35
- 4. Submit a pull request.
36
-
37
- # ENVIRONMENT:
38
-
39
- Ohai's development dependencies should be installed with bundler. Just
40
- run `bundle install` in the root of the repo.
18
+ Ohai's development dependencies should be installed with bundler. Just run `bundle install` in the root of the repo.
41
19
 
42
20
  ## Spec Testing:
43
21
 
44
22
  We use RSpec for unit/spec tests. To run the full suite, run:
45
23
 
46
- bundle exec rake spec
24
+ ```
25
+ bundle exec rake spec
26
+ ```
47
27
 
48
28
  You can run individual test files by running the rspec executable:
49
29
 
50
- bundle exec rspec spec/unit/FILE.rb
30
+ ```
31
+ bundle exec rspec spec/unit/FILE.rb
32
+ ```
51
33
 
52
34
  ## Rake Tasks
53
35
 
54
36
  Ohai has some Rake tasks for doing various things.
55
37
 
56
- rake -T
57
- rake build # Build the gem file ohai-$VERSION.gem
58
- rake install # install the gem locally
59
- rake install:local # install the gem locally without network access
60
- rake release # Create tag $VERSION, build gem, and push to Rubygems
61
- rake spec # Run RSpec tests
62
-
63
- ($VERSION is the current version, from the GemSpec in Rakefile)
38
+ ```
39
+ rake -T
40
+ rake build # Build the gem file ohai-$VERSION.gem
41
+ rake install # install the gem locally
42
+ rake install:local # install the gem locally without network access
43
+ rake release # Create tag $VERSION, build gem, and push to Rubygems
44
+ rake spec # Run RSpec tests
45
+
46
+ ($VERSION is the current version, from the GemSpec in Rakefile)
47
+ ```
64
48
 
65
- # LINKS:
49
+ ## Links:
66
50
 
67
51
  Source:
68
52
 
69
- * https://github.com/chef/ohai/tree/master
53
+ - <https://github.com/chef/ohai/tree/master>
70
54
 
71
55
  Issues:
72
56
 
73
- * https://github.com/chef/ohai/issues
57
+ - <https://github.com/chef/ohai/issues>
58
+
59
+ ## Contributing
60
+
61
+ For information on contributing to this project see <https://github.com/chef/chef/blob/master/CONTRIBUTING.md>
74
62
 
75
- # LICENSE:
63
+ ## License
76
64
 
77
65
  Ohai - system information application
78
66
 
79
- * Author:: Adam Jacob (<adam@chef.io>)
80
- * Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
81
- * License:: Apache License, Version 2.0
67
+ - Author:: Adam Jacob ([adam@chef.io](mailto:adam@chef.io))
68
+ - Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
69
+ - License:: Apache License, Version 2.0
82
70
 
83
71
  ```text
84
72
  Licensed under the Apache License, Version 2.0 (the "License");
@@ -0,0 +1,82 @@
1
+ #
2
+ # Author:: Phil Dibowitz <phil@ipom.com>
3
+ # Copyright:: Copyright (c) 2016 Facebook, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "digest/md5"
20
+
21
+ Ohai.plugin(:ShardSeed) do
22
+ depends "hostname", "dmi", "machine_id", "machinename"
23
+ provides "shard_seed"
24
+
25
+ def get_dmi_property(dmi, thing)
26
+ %w{system base_board chassis}.each do |section|
27
+ unless dmi[section][thing].strip.empty?
28
+ return dmi[section][thing]
29
+ end
30
+ end
31
+ end
32
+
33
+ def default_sources
34
+ [:machinename, :serial, :uuid]
35
+ end
36
+
37
+ # Common sources go here. Put sources that need to be different per-platform
38
+ # under their collect_data block.
39
+ def create_seed(&block)
40
+ sources = Ohai.config[:plugin][:shard_seed][:sources] || default_sources
41
+ data = ""
42
+ sources.each do |src|
43
+ data << case src
44
+ when :fqdn
45
+ fqdn
46
+ when :hostname
47
+ hostname
48
+ when :machine_id
49
+ machine_id
50
+ when :machinename
51
+ machinename
52
+ else
53
+ yield(src)
54
+ end
55
+ end
56
+ shard_seed Digest::MD5.hexdigest(data)[0...7].to_i(16)
57
+ end
58
+
59
+ collect_data(:darwin) do
60
+ create_seed do |src|
61
+ case src
62
+ when :serial
63
+ hardware["serial_number"]
64
+ when :uuid
65
+ hardware["platform_UUID"]
66
+ end
67
+ end
68
+ end
69
+
70
+ collect_data(:linux) do
71
+ create_seed do |src|
72
+ case src
73
+ when :serial
74
+ get_dmi_property(dmi, :serial_number)
75
+ when :uuid
76
+ get_dmi_property(dmi, :uuid)
77
+ else
78
+ raise "No such shard_seed source: #{src}"
79
+ end
80
+ end
81
+ end
82
+ end
@@ -29,6 +29,7 @@ require "ohai/mixin/seconds_to_human"
29
29
  Ohai.plugin(:Uptime) do
30
30
  provides "uptime", "uptime_seconds"
31
31
  provides "idletime", "idletime_seconds" # linux only
32
+ depends "platform_version"
32
33
 
33
34
  def collect_uptime(path)
34
35
  # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009
@@ -96,7 +97,12 @@ Ohai.plugin(:Uptime) do
96
97
  collect_data(:windows) do
97
98
  require "wmi-lite/wmi"
98
99
  wmi = WmiLite::Wmi.new
99
- uptime_seconds wmi.first_of("Win32_PerfFormattedData_PerfOS_System")["systemuptime"].to_i
100
+ if platform_version.to_f >= 6.0 ## for newer version of Windows starting from Windows Server 2008 ##
101
+ last_boot_up_time = wmi.first_of("Win32_OperatingSystem")["lastbootuptime"]
102
+ uptime_seconds Time.new.to_i - Time.parse(last_boot_up_time).to_i
103
+ else ## for older version of Windows starting from Windows Server 2003 ##
104
+ uptime_seconds wmi.first_of("Win32_PerfFormattedData_PerfOS_System")["systemuptime"].to_i
105
+ end
100
106
  uptime seconds_to_human(uptime_seconds)
101
107
  end
102
108
 
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "8.20.0"
21
+ VERSION = "8.21.0"
22
22
  end
@@ -0,0 +1,81 @@
1
+ #
2
+ # Author:: Aliasgar Batterywala (<aliasgar.batterywala@msystechnologies.com>)
3
+ # Copyright:: Copyright (c) 2016 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
20
+
21
+ describe Ohai::System, "Windows plugin uptime" do
22
+
23
+ context "for newer version of Windows" do
24
+ let(:uptime_plugin) do
25
+ get_plugin("uptime").tap do |plugin|
26
+ plugin[:platform_version] = "6.3.9600"
27
+ end
28
+ end
29
+
30
+ let(:wmi) do
31
+ double("wmi", { :first_of =>
32
+ { "lastbootuptime" => "20160912103128.597219+0000" },
33
+ })
34
+ end
35
+
36
+ before(:each) do
37
+ allow(uptime_plugin).to receive(:collect_os).and_return(:windows)
38
+ allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
39
+ allow(Time).to receive_message_chain(:new, :to_i).and_return(1473756619)
40
+ end
41
+
42
+ it "should set uptime_seconds to uptime" do
43
+ uptime_plugin.run
44
+ expect(uptime_plugin[:uptime_seconds]).to be == 80331
45
+ end
46
+
47
+ it "should set uptime to a human readable value" do
48
+ uptime_plugin.run
49
+ expect(uptime_plugin[:uptime]).to eq("22 hours 18 minutes 51 seconds")
50
+ end
51
+ end
52
+
53
+ context "for older version of Windows" do
54
+ let(:uptime_plugin) do
55
+ get_plugin("uptime").tap do |plugin|
56
+ plugin[:platform_version] = "5.0.2195"
57
+ end
58
+ end
59
+
60
+ let(:wmi) do
61
+ double("wmi", { :first_of =>
62
+ { "systemuptime" => "785345" },
63
+ })
64
+ end
65
+
66
+ before(:each) do
67
+ allow(uptime_plugin).to receive(:collect_os).and_return(:windows)
68
+ allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
69
+ end
70
+
71
+ it "should set uptime_seconds to uptime" do
72
+ uptime_plugin.run
73
+ expect(uptime_plugin[:uptime_seconds]).to be == 785345
74
+ end
75
+
76
+ it "should set uptime to a human readable value" do
77
+ uptime_plugin.run
78
+ expect(uptime_plugin[:uptime]).to eq("9 days 02 hours 09 minutes 05 seconds")
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,60 @@
1
+ #
2
+ # Author:: Davide Cavalca <dcavalca@fb.com>
3
+ # Copyright:: Copyright (c) 2016 Facebook
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "digest/md5"
20
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
21
+
22
+ describe Ohai::System, "shard plugin" do
23
+ let(:plugin) { get_plugin("shard") }
24
+ let(:fqdn) { "somehost004.someregion.somecompany.com" }
25
+ let(:uuid) { "48555CF4-5BB1-21D9-BC4C-E8B73DDE5801" }
26
+ let(:serial) { "234du3m4i498xdjr2" }
27
+ let(:machine_id) { "0a1f869f457a4c8080ab19faf80af9cc" }
28
+ let(:machinename) { "somehost004" }
29
+
30
+ before(:each) do
31
+ allow(plugin).to receive(:collect_os).and_return(:linux)
32
+ plugin["machinename"] = machinename
33
+ plugin["machine_id"] = machine_id
34
+ plugin["fqdn"] = fqdn
35
+ plugin["dmi"] = { "system" => {} }
36
+ plugin["dmi"]["system"]["uuid"] = uuid
37
+ plugin["dmi"]["system"]["serial_number"] = serial
38
+ allow(plugin).to receive(:collect_os).and_return(:linux)
39
+ end
40
+
41
+ it "should provide a shard with a default-safe set of sources" do
42
+ plugin.run
43
+ result = Digest::MD5.hexdigest(
44
+ "#{machinename}#{serial}#{uuid}"
45
+ )[0...7].to_i(16)
46
+ expect(plugin[:shard_seed]).to eq(result)
47
+ end
48
+
49
+ it "should provide a shard with a configured source" do
50
+ Ohai.config[:plugin][:shard_seed][:sources] = [:fqdn]
51
+ plugin.run
52
+ result = Digest::MD5.hexdigest(fqdn)[0...7].to_i(16)
53
+ expect(plugin[:shard_seed]).to eq(result)
54
+ end
55
+
56
+ it "fails on an unrecognized source" do
57
+ Ohai.config[:plugin][:shard_seed][:sources] = [:GreatGooglyMoogly]
58
+ expect { plugin.run }.to raise_error(RuntimeError)
59
+ end
60
+ end
@@ -0,0 +1,88 @@
1
+ #
2
+ # Author:: Aliasgar Batterywala (<aliasgar.batterywala@msystechnologies.com>)
3
+ # Copyright:: Copyright (c) 2016 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
20
+
21
+ describe Ohai::System, "Windows plugin uptime" do
22
+
23
+ let(:wmi) { double("wmi", { :first_of => "" }) }
24
+
25
+ before(:each) do
26
+ allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
27
+ end
28
+
29
+ ## Windows newer versions category here includes server OS starting from Windows Server 2008 ##
30
+ shared_context "WMI class for newer versions of Windows platform" do
31
+ before do
32
+ allow(uptime_plugin).to receive(:collect_os).and_return(:windows)
33
+ end
34
+
35
+ it "uses Win32_OperatingSystem WMI class to fetch the system's uptime" do
36
+ expect(wmi).to receive(:first_of).with("Win32_OperatingSystem")
37
+ expect(Time).to receive(:new)
38
+ expect(Time).to receive(:parse)
39
+ expect(uptime_plugin).to receive(:seconds_to_human)
40
+ uptime_plugin.run
41
+ end
42
+ end
43
+
44
+ ## Windows older versions category here includes server OS starting from Windows Server 2003 ##
45
+ shared_context "WMI class for older versions of Windows platform" do
46
+ before do
47
+ allow(uptime_plugin).to receive(:collect_os).and_return(:windows)
48
+ end
49
+
50
+ it "uses Win32_PerfFormattedData_PerfOS_System WMI class to fetch the system's uptime" do
51
+ expect(wmi).to receive(:first_of).with("Win32_PerfFormattedData_PerfOS_System")
52
+ expect(Time).to_not receive(:new)
53
+ expect(Time).to_not receive(:parse)
54
+ expect(uptime_plugin).to receive(:seconds_to_human)
55
+ uptime_plugin.run
56
+ end
57
+ end
58
+
59
+ context "platform is Windows Server 2008 R2" do
60
+ let(:uptime_plugin) do
61
+ get_plugin("uptime").tap do |plugin|
62
+ plugin[:platform_version] = "6.1.7601"
63
+ end
64
+ end
65
+
66
+ include_context "WMI class for newer versions of Windows platform"
67
+ end
68
+
69
+ context "platform is Windows Server 2003 R2" do
70
+ let(:uptime_plugin) do
71
+ get_plugin("uptime").tap do |plugin|
72
+ plugin[:platform_version] = "5.2.3790"
73
+ end
74
+ end
75
+
76
+ include_context "WMI class for older versions of Windows platform"
77
+ end
78
+
79
+ context "platform is Windows Server 2012" do
80
+ let(:uptime_plugin) do
81
+ get_plugin("uptime").tap do |plugin|
82
+ plugin[:platform_version] = "6.2.9200"
83
+ end
84
+ end
85
+
86
+ include_context "WMI class for newer versions of Windows platform"
87
+ end
88
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.20.0
4
+ version: 8.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-07 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: systemu
@@ -429,6 +429,7 @@ files:
429
429
  - lib/ohai/plugins/ruby.rb
430
430
  - lib/ohai/plugins/rust.rb
431
431
  - lib/ohai/plugins/scala.rb
432
+ - lib/ohai/plugins/shard.rb
432
433
  - lib/ohai/plugins/shells.rb
433
434
  - lib/ohai/plugins/sigar/cpu.rb
434
435
  - lib/ohai/plugins/sigar/filesystem.rb
@@ -499,6 +500,7 @@ files:
499
500
  - spec/functional/loader_spec.rb
500
501
  - spec/functional/plugins/powershell_spec.rb
501
502
  - spec/functional/plugins/root_group_spec.rb
503
+ - spec/functional/plugins/windows/uptime_spec.rb
502
504
  - spec/ohai_spec.rb
503
505
  - spec/rcov.opts
504
506
  - spec/spec.opts
@@ -610,6 +612,7 @@ files:
610
612
  - spec/unit/plugins/ruby_spec.rb
611
613
  - spec/unit/plugins/rust_spec.rb
612
614
  - spec/unit/plugins/scala_spec.rb
615
+ - spec/unit/plugins/shard_spec.rb
613
616
  - spec/unit/plugins/shells_spec.rb
614
617
  - spec/unit/plugins/sigar/network_route_spec.rb
615
618
  - spec/unit/plugins/softlayer_spec.rb
@@ -630,6 +633,7 @@ files:
630
633
  - spec/unit/plugins/windows/cpu_spec.rb
631
634
  - spec/unit/plugins/windows/fips_spec.rb
632
635
  - spec/unit/plugins/windows/memory_spec.rb
636
+ - spec/unit/plugins/windows/uptime_spec.rb
633
637
  - spec/unit/plugins/windows/virtualization_spec.rb
634
638
  - spec/unit/provides_map_spec.rb
635
639
  - spec/unit/runner_spec.rb
@@ -656,7 +660,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
656
660
  version: '0'
657
661
  requirements: []
658
662
  rubyforge_project:
659
- rubygems_version: 2.5.1
663
+ rubygems_version: 2.6.7
660
664
  signing_key:
661
665
  specification_version: 4
662
666
  summary: Ohai profiles your system and emits JSON