ohai-6.14.0/0000755000175000017500000000000011761755160012037 5ustar tfheentfheenohai-6.14.0/spec/0000755000175000017500000000000011761755160012771 5ustar tfheentfheenohai-6.14.0/spec/rcov.opts0000644000175000017500000000004111761755160014644 0ustar tfheentfheen--exclude spec,bin,/Library/Ruby ohai-6.14.0/spec/spec.opts0000644000175000017500000000003211761755160014625 0ustar tfheentfheen--format specdoc --colour ohai-6.14.0/spec/ohai_spec.rb0000644000175000017500000000156111761755160015253 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb') describe Ohai do it "should have a version constant defined" do Ohai::VERSION.should be_a_kind_of(String) end end ohai-6.14.0/spec/ohai/0000755000175000017500000000000011761755160013711 5ustar tfheentfheenohai-6.14.0/spec/ohai/mixin/0000755000175000017500000000000011761755160015035 5ustar tfheentfheenohai-6.14.0/spec/ohai/mixin/command_spec.rb0000644000175000017500000000322011761755160020007 0ustar tfheentfheen# encoding: utf-8 # # Author:: Diego Algorta (diego@oboxodo.com) # Copyright:: Copyright (c) 2009 Diego Algorta # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::Mixin::Command, "popen4" do break if RUBY_PLATFORM =~ /(win|w)32$/ it "should default all commands to be run in the POSIX standard C locale" do Ohai::Mixin::Command.popen4("echo $LC_ALL") do |pid, stdin, stdout, stderr| stdin.close stdout.read.strip.should == "C" end end it "should respect locale when specified explicitly" do Ohai::Mixin::Command.popen4("echo $LC_ALL", :environment => {"LC_ALL" => "es"}) do |pid, stdin, stdout, stderr| stdin.close stdout.read.strip.should == "es" end end if defined?(::Encoding) && "".respond_to?(:force_encoding) #i.e., ruby 1.9 it "[OHAI-275] should mark strings as in the default external encoding" do extend Ohai::Mixin::Command snowy = run_command(:command => ("echo '" + ('☃' * 8096) + "'"))[1] snowy.encoding.should == Encoding.default_external end end end ohai-6.14.0/spec/ohai/mixin/from_file_spec.rb0000644000175000017500000000342111761755160020336 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "from_file" do before(:each) do @ohai = Ohai::System.new File.stub!(:exists?).and_return(true) File.stub!(:readable?).and_return(true) IO.stub!(:read).and_return("king 'herod'") end it "should check to see that the file exists" do File.should_receive(:exists?).and_return(true) @ohai.from_file("/tmp/foo") end it "should check to see that the file is readable" do File.should_receive(:readable?).and_return(true) @ohai.from_file("/tmp/foo") end it "should actually read the file" do IO.should_receive(:read).and_return("king 'herod'") @ohai.from_file("/tmp/foo") end it "should call instance_eval with the contents of the file, file name, and line 1" do @ohai.should_receive(:instance_eval).with("king 'herod'", "/tmp/foo", 1) @ohai.from_file("/tmp/foo") end it "should raise an IOError if it cannot read the file" do File.stub!(:exists?).and_return(false) lambda { @ohai.from_file("/tmp/foo") }.should raise_error(IOError) end end ohai-6.14.0/spec/ohai/system_spec.rb0000644000175000017500000001020711761755160016574 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') describe Ohai::System, "initialize" do it "should return an Ohai::System object" do Ohai::System.new.should be_a_kind_of(Ohai::System) end it "should set @data to a Mash" do Ohai::System.new.data.should be_a_kind_of(Mash) end it "should set @seen_plugins to a Hash" do Ohai::System.new.seen_plugins.should be_a_kind_of(Hash) end end describe Ohai::System, "method_missing" do before(:each) do @ohai = Ohai::System.new end it "should take a missing method and store the method name as a key, with its arguments as values" do @ohai.guns_n_roses("chinese democracy") @ohai.data["guns_n_roses"].should eql("chinese democracy") end it "should return the current value of the method name" do @ohai.guns_n_roses("chinese democracy").should eql("chinese democracy") end it "should allow you to get the value of a key by calling method_missing with no arguments" do @ohai.guns_n_roses("chinese democracy") @ohai.guns_n_roses.should eql("chinese democracy") end end describe Ohai::System, "attribute?" do before(:each) do @ohai = Ohai::System.new @ohai.metallica("death magnetic") end it "should return true if an attribute exists with the given name" do @ohai.attribute?("metallica").should eql(true) end it "should return false if an attribute does not exist with the given name" do @ohai.attribute?("alice in chains").should eql(false) end end describe Ohai::System, "set_attribute" do before(:each) do @ohai = Ohai::System.new end it "should let you set an attribute" do @ohai.set_attribute(:tea, "is soothing") @ohai.data["tea"].should eql("is soothing") end end describe Ohai::System, "get_attribute" do before(:each) do @ohai = Ohai::System.new @ohai.set_attribute(:tea, "is soothing") end it "should let you get an attribute" do @ohai.get_attribute("tea").should eql("is soothing") end end describe Ohai::System, "require_plugin" do tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp' before(:each) do @plugin_path = Ohai::Config[:plugin_path] Ohai::Config[:plugin_path] = ["#{tmp}/plugins"] File.stub!(:exists?).and_return(true) @ohai = Ohai::System.new @ohai.stub!(:from_file).and_return(true) end after(:each) do Ohai::Config[:plugin_path] = @plugin_path end it "should convert the name of the plugin to a file path" do plugin_name = "foo::bar" plugin_name.should_receive(:gsub).with("::", File::SEPARATOR) @ohai.require_plugin(plugin_name) end it "should check each part of the Ohai::Config[:plugin_path] for the plugin_filename.rb" do @ohai.should_receive(:from_file).with(File.expand_path("#{tmp}/plugins/foo.rb")).and_return(true) @ohai.require_plugin("foo") end it "should add a found plugin to the list of seen plugins" do @ohai.require_plugin("foo") @ohai.seen_plugins["foo"].should eql(true) end it "should return true if the plugin has been seen" do @ohai.seen_plugins["foo"] = true @ohai.require_plugin("foo") end it "should return true if the plugin has been loaded" do @ohai.require_plugin("foo").should eql(true) end it "should return false if the plugin is in the disabled plugins list" do Ohai::Config[:disabled_plugins] = [ "foo" ] Ohai::Log.should_receive(:debug).with("Skipping disabled plugin foo") @ohai.require_plugin("foo").should eql(false) end end ohai-6.14.0/spec/ohai/plugins/0000755000175000017500000000000011761755160015372 5ustar tfheentfheenohai-6.14.0/spec/ohai/plugins/kernel_spec.rb0000644000175000017500000000332111761755160020210 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin kernel" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:languages] = Mash.new @ohai[:languages][:ruby] = Mash.new @ohai.stub!(:from).with("uname -s").and_return("Darwin") @ohai.stub!(:from).with("uname -r").and_return("9.5.0") @ohai.stub!(:from).with("uname -v").and_return("Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386") @ohai.stub!(:from).with("uname -m").and_return("i386") @ohai.stub!(:from).with("uname -o").and_return("Linux") end it_should_check_from_mash("kernel", "name", "uname -s", "Darwin") it_should_check_from_mash("kernel", "release", "uname -r", "9.5.0") it_should_check_from_mash("kernel", "version", "uname -v", "Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386") it_should_check_from_mash("kernel", "machine", "uname -m", "i386") end ohai-6.14.0/spec/ohai/plugins/hostname_spec.rb0000644000175000017500000000233511761755160020552 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "hostname plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) end it "should set the domain to everything after the first dot of the fqdn" do @ohai[:fqdn] = "katie.bethell" @ohai._require_plugin("hostname") @ohai.domain.should == "bethell" end it "should not set a domain if fqdn is not set" do @ohai._require_plugin("hostname") @ohai.domain.should == nil end end ohai-6.14.0/spec/ohai/plugins/perl_spec.rb0000644000175000017500000000513511761755160017677 0ustar tfheentfheen# # Author:: Joshua Timberman() # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin perl" do before(:each) do @ohai = Ohai::System.new @ohai[:languages] = Mash.new @ohai.stub!(:require_plugin).and_return(true) @pid = 2342 @stderr = StringIO.new @stdout = StringIO.new(<<-OUT) version='5.8.8'; archname='darwin-thread-multi-2level'; OUT @stdin = StringIO.new @status = 0 @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ @status, @stdout, @stderr ]) end it "should run perl -V:version -V:archname" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return(true) @ohai._require_plugin("perl") end it "should iterate over each line of perl command's stdout" do @stdout.should_receive(:each_line).and_return(true) @ohai._require_plugin("perl") end it "should set languages[:perl][:version]" do @ohai._require_plugin("perl") @ohai.languages[:perl][:version].should eql("5.8.8") end it "should set languages[:perl][:archname]" do @ohai._require_plugin("perl") @ohai.languages[:perl][:archname].should eql("darwin-thread-multi-2level") end it "should set languages[:perl] if perl command succeeds" do @status = 0 @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ @status, @stdout, @stderr ]) @ohai._require_plugin("perl") @ohai.languages.should have_key(:perl) end it "should not set languages[:perl] if perl command fails" do @status = 1 @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ @status, @stdout, @stderr ]) @ohai._require_plugin("perl") @ohai.languages.should_not have_key(:perl) end end ohai-6.14.0/spec/ohai/plugins/ec2_spec.rb0000644000175000017500000001043411761755160017404 0ustar tfheentfheen# # Author:: Tim Dysinger () # Author:: Christopher Brown (cb@opscode.com) # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDIT"Net::HTTP Response"NS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'open-uri' describe Ohai::System, "plugin ec2" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:network] = {:interfaces => {:eth0 => {} } } end shared_examples_for "!ec2" do it "should NOT attempt to fetch the ec2 metadata" do @ohai.should_not_receive(:http_client) @ohai._require_plugin("ec2") end end shared_examples_for "ec2" do before(:each) do @http_client = mock("Net::HTTP client") @ohai.stub!(:http_client).and_return(@http_client) @http_client.should_receive(:get). with("/2008-02-01/meta-data/"). and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups")) @http_client.should_receive(:get). with("/2008-02-01/meta-data/instance_type"). and_return(mock("Net::HTTP Response", :body => "c1.medium")) @http_client.should_receive(:get). with("/2008-02-01/meta-data/ami_id"). and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934")) @http_client.should_receive(:get). with("/2008-02-01/meta-data/security-groups"). and_return(mock("Net::HTTP Response", :body => "group1\ngroup2")) @http_client.should_receive(:get). with("/2008-02-01/user-data/"). and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) end it "should recursively fetch all the ec2 metadata" do IO.stub!(:select).and_return([[],[1],[]]) t = mock("connection") t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS) Socket.stub!(:new).and_return(t) @ohai._require_plugin("ec2") @ohai[:ec2].should_not be_nil @ohai[:ec2]['instance_type'].should == "c1.medium" @ohai[:ec2]['ami_id'].should == "ami-5d2dc934" @ohai[:ec2]['security_groups'].should eql ['group1', 'group2'] end end describe "with ec2 mac and metadata address connected" do it_should_behave_like "ec2" before(:each) do IO.stub!(:select).and_return([[],[1],[]]) @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"} end end describe "without ec2 mac and metadata address connected" do it_should_behave_like "!ec2" before(:each) do @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"} end end describe "with ec2 cloud file" do it_should_behave_like "ec2" before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true) File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('') File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true) File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('') end end describe "without cloud file" do it_should_behave_like "!ec2" before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(false) File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false) end end describe "with rackspace cloud file" do it_should_behave_like "!ec2" before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true) File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('') File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true) File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('') end end end ohai-6.14.0/spec/ohai/plugins/os_spec.rb0000644000175000017500000000441211761755160017353 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG['host_os'] describe Ohai::System, "plugin os" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:languages] = Mash.new @ohai[:languages][:ruby] = Mash.new @ohai[:kernel] = Mash.new @ohai[:kernel][:release] = "kings of leon" end after do ::RbConfig::CONFIG['host_os'] = ORIGINAL_CONFIG_HOST_OS end it "should set os_version to kernel_release" do @ohai._require_plugin("os") @ohai[:os_version].should == @ohai[:kernel][:release] end describe "on linux" do before(:each) do ::RbConfig::CONFIG['host_os'] = "linux" end it "should set the os to linux" do @ohai._require_plugin("os") @ohai[:os].should == "linux" end end describe "on darwin" do before(:each) do ::RbConfig::CONFIG['host_os'] = "darwin10.0" end it "should set the os to darwin" do @ohai._require_plugin("os") @ohai[:os].should == "darwin" end end describe "on solaris" do before do ::RbConfig::CONFIG['host_os'] = "solaris2.42" #heh end it "sets the os to solaris2" do @ohai._require_plugin("os") @ohai[:os].should == "solaris2" end end describe "on something we have never seen before, but ruby has" do before do ::RbConfig::CONFIG['host_os'] = "tron" end it "sets the os to the ruby 'host_os'" do @ohai._require_plugin("os") @ohai[:os].should == "tron" end end end ohai-6.14.0/spec/ohai/plugins/dmi_spec.rb0000644000175000017500000000721011761755160017502 0ustar tfheentfheen# # Author:: Bryan McLellan () # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') # NOTE: These data lines must be prefixed with one or two tabs, not spaces. DMI_OUT = <<-EOS # dmidecode 2.9 SMBIOS 2.4 present. 98 structures occupying 3699 bytes. Table at 0x000E0010. Handle 0x0000, DMI type 0, 24 bytes BIOS Information Vendor: Phoenix Technologies LTD Version: 6.00 Release Date: 12/31/2009 Address: 0xEA2E0 Runtime Size: 89376 bytes ROM Size: 64 kB Characteristics: ISA is supported PCI is supported PC Card (PCMCIA) is supported PNP is supported APM is supported BIOS is upgradeable BIOS shadowing is allowed ESCD support is available USB legacy is supported Smart battery is supported BIOS boot specification is supported Targeted content distribution is supported BIOS Revision: 4.6 Firmware Revision: 0.0 Handle 0x0001, DMI type 1, 27 bytes System Information Manufacturer: VMware, Inc. Product Name: VMware Virtual Platform Version: None Serial Number: VMware-56 4d 71 d1 65 70 83 a8-df c8 14 12 19 41 71 45 UUID: 564D71D1-6570-83A8-DFC8-141219417145 Wake-up Type: Power Switch SKU Number: Not Specified Family: Not Specified Handle 0x0002, DMI type 2, 15 bytes Base Board Information Manufacturer: Intel Corporation Product Name: 440BX Desktop Reference Platform Version: None Serial Number: None Asset Tag: Not Specified Features: None Location In Chassis: Not Specified Chassis Handle: 0x0000 Type: Unknown Contained Object Handles: 0 Handle 0x0003, DMI type 3, 21 bytes Chassis Information Manufacturer: No Enclosure Type: Other Lock: Not Present Version: N/A Serial Number: None Asset Tag: No Asset Tag Boot-up State: Safe Power Supply State: Safe Thermal State: Safe Security Status: None OEM Information: 0x00001234 Height: Unspecified Number Of Power Cords: Unspecified Contained Elements: 0 EOS describe Ohai::System, "plugin dmi" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = StringIO.new(DMI_OUT) @status = 0 @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "should run dmidecode" do @ohai.should_receive(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("dmi") end # Test some simple sample data { :bios => { :vendor => "Phoenix Technologies LTD", :release_date => "12/31/2009" }, :system => { :manufacturer => "VMware, Inc.", :product_name => "VMware Virtual Platform" }, :chassis => { :lock => "Not Present", :asset_tag => "No Asset Tag" } }.each do |id, data| data.each do |attribute, value| it "should have [:dmi][:#{id}][:#{attribute}] set" do @ohai._require_plugin("dmi") @ohai[:dmi][id][attribute].should eql(value) end end end end ohai-6.14.0/spec/ohai/plugins/freebsd/0000755000175000017500000000000011761755160017004 5ustar tfheentfheenohai-6.14.0/spec/ohai/plugins/freebsd/kernel_spec.rb0000644000175000017500000000245011761755160021624 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "FreeBSD kernel plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai.stub!(:from).with("uname -i").and_return("foo") @ohai.stub!(:from_with_regex).with("sysctl kern.securelevel").and_return("kern.securelevel: 1") @ohai[:kernel] = Mash.new @ohai[:kernel][:name] = "freebsd" end it "should set the kernel_os to the kernel_name value" do @ohai._require_plugin("freebsd::kernel") @ohai[:kernel][:os].should == @ohai[:kernel][:name] end end ohai-6.14.0/spec/ohai/plugins/freebsd/hostname_spec.rb0000644000175000017500000000235211761755160022163 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "FreeBSD hostname plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "freebsd" @ohai.stub!(:from).with("hostname -s").and_return("katie") @ohai.stub!(:from).with("hostname -f").and_return("katie.bethell") end it_should_check_from("freebsd::hostname", "hostname", "hostname -s", "katie") it_should_check_from("freebsd::hostname", "fqdn", "hostname -f", "katie.bethell") end ohai-6.14.0/spec/ohai/plugins/freebsd/platform_spec.rb0000644000175000017500000000255611761755160022177 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "FreeBSD plugin platform" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai.stub!(:from).with("uname -s").and_return("FreeBSD") @ohai.stub!(:from).with("uname -r").and_return("7.1") @ohai[:os] = "freebsd" end it "should set platform to lowercased lsb[:id]" do @ohai._require_plugin("freebsd::platform") @ohai[:platform].should == "freebsd" end it "should set platform_version to lsb[:release]" do @ohai._require_plugin("freebsd::platform") @ohai[:platform_version].should == "7.1" end end ohai-6.14.0/spec/ohai/plugins/lua_spec.rb0000644000175000017500000000366511761755160017524 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2009 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')) describe Ohai::System, "plugin lua" do before(:each) do @ohai = Ohai::System.new @ohai[:languages] = Mash.new @ohai.stub!(:require_plugin).and_return(true) @status = 0 @stdout = "" @stderr = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([@status, @stdout, @stderr]) end it "should get the lua version from running lua -v" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([0, "", "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n"]) @ohai._require_plugin("lua") end it "should set languages[:lua][:version]" do @ohai._require_plugin("lua") @ohai.languages[:lua][:version].should eql("5.1.2") end it "should not set the languages[:lua] tree up if lua command fails" do @status = 1 @stdout = "" @stderr = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("lua") @ohai.languages.should_not have_key(:lua) end end ohai-6.14.0/spec/ohai/plugins/ohai_spec.rb0000644000175000017500000000226311761755160017654 0ustar tfheentfheen# # Author:: Adam Jacob () # Author:: Tollef Fog Heen # Copyright:: Copyright (c) 2008 Opscode, Inc. # Copyright:: Copyright (c) 2010 Tollef Fog Heen # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin ohai" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) end it "should set [:chef_packages][:ohai][:version] to the current version" do @ohai._require_plugin("ohai") @ohai[:chef_packages][:ohai][:version].should == Ohai::VERSION end end ohai-6.14.0/spec/ohai/plugins/chef_spec.rb0000644000175000017500000000242411761755160017640 0ustar tfheentfheen# # Author:: Adam Jacob () # Author:: Tollef Fog Heen # Copyright:: Copyright (c) 2008 Opscode, Inc. # Copyright:: Copyright (c) 2010 Tollef Fog Heen # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # begin require 'chef' require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin chef" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) end it "should set [:chef_packages][:chef][:version] to the current chef version" do @ohai._require_plugin("chef") @ohai[:chef_packages][:chef][:version].should == Chef::VERSION end end rescue LoadError # the chef module is not available, ignoring. end ohai-6.14.0/spec/ohai/plugins/cloud_spec.rb0000644000175000017500000000670711761755160020051 0ustar tfheentfheen# # Author:: Cary Penniman () # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin cloud" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) end describe "no cloud" do it "should NOT populate the cloud data" do @ohai[:ec2] = nil @ohai[:rackspace] = nil @ohai[:eucalyptus] = nil @ohai._require_plugin("cloud") @ohai[:cloud].should be_nil end end describe "with EC2" do before(:each) do @ohai[:ec2] = Mash.new() end it "should populate cloud public ip" do @ohai[:ec2]['public_ipv4'] = "174.129.150.8" @ohai._require_plugin("cloud") @ohai[:cloud][:public_ips][0].should == @ohai[:ec2]['public_ipv4'] end it "should populate cloud private ip" do @ohai[:ec2]['local_ipv4'] = "10.252.42.149" @ohai._require_plugin("cloud") @ohai[:cloud][:private_ips][0].should == @ohai[:ec2]['local_ipv4'] end it "should populate cloud provider" do @ohai._require_plugin("cloud") @ohai[:cloud][:provider].should == "ec2" end end describe "with rackspace" do before(:each) do @ohai[:rackspace] = Mash.new() end it "should populate cloud public ip" do @ohai[:rackspace]['public_ip'] = "174.129.150.8" @ohai._require_plugin("cloud") @ohai[:cloud][:public_ips][0].should == @ohai[:rackspace][:public_ip] end it "should populate cloud private ip" do @ohai[:rackspace]['private_ip'] = "10.252.42.149" @ohai._require_plugin("cloud") @ohai[:cloud][:private_ips][0].should == @ohai[:rackspace][:private_ip] end it "should populate first cloud public ip" do @ohai[:rackspace]['public_ip'] = "174.129.150.8" @ohai._require_plugin("cloud") @ohai[:cloud][:public_ips].first.should == @ohai[:rackspace][:public_ip] end it "should populate cloud provider" do @ohai._require_plugin("cloud") @ohai[:cloud][:provider].should == "rackspace" end end describe "with eucalyptus" do before(:each) do @ohai[:eucalyptus] = Mash.new() end it "should populate cloud public ip" do @ohai[:eucalyptus]['public_ipv4'] = "174.129.150.8" @ohai._require_plugin("cloud") @ohai[:cloud][:public_ips][0].should == @ohai[:eucalyptus]['public_ipv4'] end it "should populate cloud private ip" do @ohai[:eucalyptus]['local_ipv4'] = "10.252.42.149" @ohai._require_plugin("cloud") @ohai[:cloud][:private_ips][0].should == @ohai[:eucalyptus]['local_ipv4'] end it "should populate cloud provider" do @ohai._require_plugin("cloud") @ohai[:cloud][:provider].should == "eucalyptus" end end end ohai-6.14.0/spec/ohai/plugins/rackspace_spec.rb0000644000175000017500000001041411761755160020665 0ustar tfheentfheen# # Author:: Cary Penniman () # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin rackspace" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:network] = {:interfaces => {:eth0 => {"addresses"=> { "1.2.3.4"=> { "broadcast"=> "67.23.20.255", "netmask"=> "255.255.255.0", "family"=> "inet" }, "fe80::4240:95ff:fe47:6eed"=> { "scope"=> "Link", "prefixlen"=> "64", "family"=> "inet6" }, "40:40:95:47:6E:ED"=> { "family"=> "lladdr" } }} } } @ohai[:network][:interfaces][:eth1] = {:addresses => { "fe80::4240:f5ff:feab:2836" => { "scope"=> "Link", "prefixlen"=> "64", "family"=> "inet6" }, "5.6.7.8"=> { "broadcast"=> "10.176.191.255", "netmask"=> "255.255.224.0", "family"=> "inet" }, "40:40:F5:AB:28:36" => { "family"=> "lladdr" } }} end shared_examples_for "!rackspace" do it "should NOT create rackspace" do @ohai._require_plugin("rackspace") @ohai[:rackspace].should be_nil end end shared_examples_for "rackspace" do it "should create rackspace" do @ohai._require_plugin("rackspace") @ohai[:rackspace].should_not be_nil end it "should have all required attributes" do @ohai._require_plugin("rackspace") @ohai[:rackspace][:public_ip].should_not be_nil @ohai[:rackspace][:private_ip].should_not be_nil end it "should have correct values for all attributes" do @ohai._require_plugin("rackspace") @ohai[:rackspace][:public_ip].should == "1.2.3.4" @ohai[:rackspace][:private_ip].should == "5.6.7.8" end end describe "with rackspace mac and hostname" do it_should_behave_like "rackspace" before(:each) do IO.stub!(:select).and_return([[],[1],[]]) @ohai[:hostname] = "slice74976" @ohai[:network][:interfaces][:eth0][:arp] = {"67.23.20.1" => "00:00:0c:07:ac:01"} end end describe "without rackspace mac" do it_should_behave_like "!rackspace" before(:each) do @ohai[:hostname] = "slice74976" @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"} end end describe "without rackspace hostname" do it_should_behave_like "rackspace" before(:each) do @ohai[:hostname] = "bubba" @ohai[:network][:interfaces][:eth0][:arp] = {"67.23.20.1" => "00:00:0c:07:ac:01"} end end describe "with rackspace cloud file" do it_should_behave_like "rackspace" before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true) File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('') File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true) File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('') end end describe "without cloud file" do it_should_behave_like "!rackspace" before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(false) File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(false) end end describe "with ec2 cloud file" do it_should_behave_like "!rackspace" before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true) File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('') File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true) File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('') end end end ohai-6.14.0/spec/ohai/plugins/groovy_spec.rb0000644000175000017500000000365411761755160020266 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2009 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')) describe Ohai::System, "plugin groovy" do before(:each) do @ohai = Ohai::System.new @ohai[:languages] = Mash.new @ohai.stub!(:require_plugin).and_return(true) @status = 0 @stdout = "Groovy Version: 1.6.3 JVM: 1.6.0_0\n" @stderr = "" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([@status, @stdout, @stderr]) end it "should get the groovy version from running groovy -v" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([0, "Groovy Version: 1.6.3 JVM: 1.6.0_0\n", ""]) @ohai._require_plugin("groovy") end it "should set languages[:groovy][:version]" do @ohai._require_plugin("groovy") @ohai.languages[:groovy][:version].should eql("1.6.3") end it "should not set the languages[:groovy] tree up if groovy command fails" do @status = 1 @stdout = "Groovy Version: 1.6.3 JVM: 1.6.0_0\n" @stderr = "" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("groovy") @ohai.languages.should_not have_key(:groovy) end end ohai-6.14.0/spec/ohai/plugins/openbsd/0000755000175000017500000000000011761755160017024 5ustar tfheentfheenohai-6.14.0/spec/ohai/plugins/openbsd/kernel_spec.rb0000644000175000017500000000245011761755160021644 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "OpenBSD kernel plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai.stub!(:from).with("uname -i").and_return("foo") @ohai.stub!(:from_with_regex).with("sysctl kern.securelevel").and_return("kern.securelevel: 1") @ohai[:kernel] = Mash.new @ohai[:kernel][:name] = "openbsd" end it "should set the kernel_os to the kernel_name value" do @ohai._require_plugin("openbsd::kernel") @ohai[:kernel][:os].should == @ohai[:kernel][:name] end end ohai-6.14.0/spec/ohai/plugins/openbsd/hostname_spec.rb0000644000175000017500000000234411761755160022204 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "OpenBSD hostname plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "openbsd" @ohai.stub!(:from).with("hostname -s").and_return("katie") @ohai.stub!(:from).with("hostname").and_return("katie.bethell") end it_should_check_from("openbsd::hostname", "hostname", "hostname -s", "katie") it_should_check_from("openbsd::hostname", "fqdn", "hostname", "katie.bethell") end ohai-6.14.0/spec/ohai/plugins/openbsd/platform_spec.rb0000644000175000017500000000255611761755160022217 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "OpenBSD plugin platform" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai.stub!(:from).with("uname -s").and_return("OpenBSD") @ohai.stub!(:from).with("uname -r").and_return("4.5") @ohai[:os] = "openbsd" end it "should set platform to lowercased lsb[:id]" do @ohai._require_plugin("openbsd::platform") @ohai[:platform].should == "openbsd" end it "should set platform_version to lsb[:release]" do @ohai._require_plugin("openbsd::platform") @ohai[:platform_version].should == "4.5" end end ohai-6.14.0/spec/ohai/plugins/ohai_time_spec.rb0000644000175000017500000000263011761755160020670 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin ohai_time" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) end it "should get the current time" do Time.should_receive(:now) @ohai._require_plugin("ohai_time") end it "should turn the time into a floating point number" do time = Time.now time.should_receive(:to_f) Time.stub!(:now).and_return(time) @ohai._require_plugin("ohai_time") end it "should set ohai_time to the current time" do time = Time.now Time.stub!(:now).and_return(time) @ohai._require_plugin("ohai_time") @ohai[:ohai_time].should == time.to_f end endohai-6.14.0/spec/ohai/plugins/c_spec.rb0000644000175000017500000003006011761755160017152 0ustar tfheentfheen # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'rbconfig' require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')) C_GCC = <. EOF C_GLIBC_2_5 = <. EOF C_CL = <true, :command=>"gcc -v"}).and_return([0, "", C_GCC]) #glibc @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""]) #ms cl @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL]) #ms vs @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""]) #ibm xlc @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""]) #sun pro @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN]) #hpux cc @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([0, C_HPUX, ""]) end #gcc it "should get the gcc version from running gcc -v" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC]) @ohai._require_plugin("c") end it "should set languages[:c][:gcc][:version]" do @ohai._require_plugin("c") @ohai.languages[:c][:gcc][:version].should eql("3.4.6") end it "should set languages[:c][:gcc][:description]" do @ohai._require_plugin("c") @ohai.languages[:c][:gcc][:description].should eql(C_GCC.split($/).last) end it "should not set the languages[:c][:gcc] tree up if gcc command fails" do @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([1, "", ""]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:gcc) if @ohai[:languages][:c] end #glibc it "should get the glibc x.x.x version from running /lib/libc.so.6" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""]) @ohai._require_plugin("c") end it "should set languages[:c][:glibc][:version]" do @ohai._require_plugin("c") @ohai.languages[:c][:glibc][:version].should eql("2.3.4") end it "should set languages[:c][:glibc][:description]" do @ohai._require_plugin("c") @ohai.languages[:c][:glibc][:description].should eql(C_GLIBC_2_3_4.split($/).first) end it "should not set the languages[:c][:glibc] tree up if glibc command fails" do @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([1, "", ""]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:glibc) if @ohai[:languages][:c] end it "should get the glibc x.x version from running /lib/libc.so.6" do @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_5, ""]) @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_5, ""]) @ohai._require_plugin("c") @ohai.languages[:c][:glibc][:version].should eql("2.5") end #ms cl it "should get the cl version from running cl /?" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL]) @ohai._require_plugin("c") end it "should set languages[:c][:cl][:version]" do @ohai._require_plugin("c") @ohai.languages[:c][:cl][:version].should eql("14.00.50727.762") end it "should set languages[:c][:cl][:description]" do @ohai._require_plugin("c") @ohai.languages[:c][:cl][:description].should eql(C_CL.split($/).first) end it "should not set the languages[:c][:cl] tree up if cl command fails" do @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([1, "", ""]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:cl) if @ohai[:languages][:c] end #ms vs it "should get the vs version from running devenv.com /?" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""]) @ohai._require_plugin("c") end it "should set languages[:c][:vs][:version]" do @ohai._require_plugin("c") @ohai.languages[:c][:vs][:version].should eql("8.0.50727.762") end it "should set languages[:c][:vs][:description]" do @ohai._require_plugin("c") @ohai.languages[:c][:vs][:description].should eql(C_VS.split($/)[1]) end it "should not set the languages[:c][:vs] tree up if devenv command fails" do @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([1, "", ""]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:vs) if @ohai[:languages][:c] end #ibm xlc it "should get the xlc version from running xlc -qversion" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""]) @ohai._require_plugin("c") end it "should set languages[:c][:xlc][:version]" do @ohai._require_plugin("c") @ohai.languages[:c][:xlc][:version].should eql("9.0") end it "should set languages[:c][:xlc][:description]" do @ohai._require_plugin("c") @ohai.languages[:c][:xlc][:description].should eql(C_XLC.split($/).first) end it "should not set the languages[:c][:xlc] tree up if xlc command fails" do @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([1, "", ""]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:xlc) if @ohai[:languages][:c] end it "should set the languages[:c][:xlc] tree up if xlc exit status is 249" do @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([63744, "", ""]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:xlc) if @ohai[:languages][:c] end #sun pro it "should get the cc version from running cc -V -flags" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN]) @ohai._require_plugin("c") end it "should set languages[:c][:sunpro][:version]" do @ohai._require_plugin("c") @ohai.languages[:c][:sunpro][:version].should eql("5.8") end it "should set languages[:c][:sunpro][:description]" do @ohai._require_plugin("c") @ohai.languages[:c][:sunpro][:description].should eql(C_SUN.chomp) end it "should not set the languages[:c][:sunpro] tree up if cc command fails" do @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([1, "", ""]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:sunpro) if @ohai[:languages][:c] end it "should not set the languages[:c][:sunpro] tree if the corresponding cc command fails on linux" do fedora_error_message = "cc: error trying to exec 'i686-redhat-linux-gcc--flags': execvp: No such file or directory" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", fedora_error_message]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:sunpro) if @ohai[:languages][:c] end it "should not set the languages[:c][:sunpro] tree if the corresponding cc command fails on hpux" do hpux_error_message = "cc: warning 901: unknown option: `-flags': use +help for online documentation.\ncc: HP C/aC++ B3910B A.06.25 [Nov 30 2009]" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", hpux_error_message]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:sunpro) if @ohai[:languages][:c] end #hpux cc it "should get the cc version from running what cc" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([0, C_HPUX, ""]) @ohai._require_plugin("c") end it "should set languages[:c][:hpcc][:version]" do @ohai._require_plugin("c") @ohai.languages[:c][:hpcc][:version].should eql("B.11.11.16") end it "should set languages[:c][:hpcc][:description]" do @ohai._require_plugin("c") @ohai.languages[:c][:hpcc][:description].should eql(C_HPUX.split($/)[3].strip) end it "should not set the languages[:c][:hpcc] tree up if cc command fails" do @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([1, "", ""]) @ohai._require_plugin("c") @ohai[:languages][:c].should_not have_key(:hpcc) if @ohai[:languages][:c] end end ohai-6.14.0/spec/ohai/plugins/fail_spec.rb0000644000175000017500000000366511761755160017656 0ustar tfheentfheen# # Author:: Toomas Pelberg (toomas.pelberg@playtech.com>) # Copyright:: Copyright (c) 2011 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')) tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp' describe Ohai::System, "plugin fail" do before(:all) do begin Dir.mkdir("#{tmp}/plugins") rescue Errno::EEXIST # Ignore it end fail_plugin=File.open("#{tmp}/plugins/fail.rb","w+") fail_plugin.write("provides \"fail\"require 'thiswillblowupinyourface'\nk=MissingClassName.new\nfail \"ohnoes\"") fail_plugin.close real_plugin=File.open("#{tmp}/plugins/real.rb","w+") real_plugin.write("provides \"real\"\nreal \"useful\"\n") real_plugin.close @plugin_path=Ohai::Config[:plugin_path] end before(:each) do Ohai::Config[:plugin_path]=["#{tmp}/plugins"] @ohai=Ohai::System.new end after(:all) do File.delete("#{tmp}/plugins/fail.rb") File.delete("#{tmp}/plugins/real.rb") begin Dir.delete("#{tmp}/plugins") rescue # Don't care if it fails end Ohai::Config[:plugin_path]=@plugin_path end it "should continue gracefully if plugin loading fails" do @ohai.require_plugin("fail") @ohai.require_plugin("real") @ohai.data[:real].should eql("useful") @ohai.data.should_not have_key("fail") end end ohai-6.14.0/spec/ohai/plugins/php_spec.rb0000644000175000017500000000432411761755160017523 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2009 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')) describe Ohai::System, "plugin php" do before(:each) do @ohai = Ohai::System.new @ohai[:languages] = Mash.new @ohai.stub!(:require_plugin).and_return(true) @status = 0 @stdout = "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n" @stderr = "" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([@status, @stdout, @stderr]) end it "should get the php version from running php -V" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([0, "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n", ""]) @ohai._require_plugin("php") end it "should set languages[:php][:version]" do @ohai._require_plugin("php") @ohai.languages[:php][:version].should eql("5.1.6") end it "should not set the languages[:php] tree up if php command fails" do @status = 1 @stdout = "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n" @stderr = "" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("php") @ohai.languages.should_not have_key(:php) end end ohai-6.14.0/spec/ohai/plugins/python_spec.rb0000644000175000017500000000413411761755160020254 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin python" do before(:each) do @ohai = Ohai::System.new @ohai[:languages] = Mash.new @ohai.stub!(:require_plugin).and_return(true) @status = 0 @stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n" @stderr = "" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr]) end it "should get the python version from printing sys.version and sys.platform" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([0, "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n", ""]) @ohai._require_plugin("python") end it "should set languages[:python][:version]" do @ohai._require_plugin("python") @ohai.languages[:python][:version].should eql("2.5.2") end it "should not set the languages[:python] tree up if python command fails" do @status = 1 @stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n" @stderr = "" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("python") @ohai.languages.should_not have_key(:python) end end ohai-6.14.0/spec/ohai/plugins/ruby_spec.rb0000644000175000017500000000377111761755160017722 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') ruby_bin = File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name']) describe Ohai::System, "plugin ruby" do before(:all) do @ohai = Ohai::System.new @ohai[:languages] = Mash.new @ohai.require_plugin("ruby") @ruby_ohai_data_pristine = @ohai[:languages][:ruby] end before(:each) do @ruby_ohai_data = @ruby_ohai_data_pristine.dup end { :platform => RUBY_PLATFORM, :version => RUBY_VERSION, :release_date => RUBY_RELEASE_DATE, :target => ::Config::CONFIG['target'], :target_cpu => ::Config::CONFIG['target_cpu'], :target_vendor => ::Config::CONFIG['target_vendor'], :target_os => ::Config::CONFIG['target_os'], :host => ::Config::CONFIG['host'], :host_cpu => ::Config::CONFIG['host_cpu'], :host_os => ::Config::CONFIG['host_os'], :host_vendor => ::Config::CONFIG['host_vendor'], :gems_dir => %x{#{ruby_bin} #{::Config::CONFIG['bindir']}/gem env gemdir}.chomp!, :gem_bin => [ ::Gem.default_exec_format % 'gem', 'gem' ].map{|bin| "#{::Config::CONFIG['bindir']}/#{bin}" }.find{|bin| ::File.exists? bin}, :ruby_bin => ruby_bin }.each do |attribute, value| it "should have #{attribute} set" do @ruby_ohai_data[attribute].should eql(value) end end end ohai-6.14.0/spec/ohai/plugins/platform_spec.rb0000644000175000017500000000462111761755160020560 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin platform" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = 'monkey' @ohai[:os_version] = 'poop' end it "should require the os platform plugin" do @ohai.should_receive(:require_plugin).with("monkey::platform") @ohai._require_plugin("platform") end it "should set the platform and platform family to the os if it was not set earlier" do @ohai._require_plugin("platform") @ohai[:platform].should eql("monkey") @ohai[:platform_family].should eql("monkey") end it "should not set the platform to the os if it was set earlier" do @ohai[:platform] = 'lars' @ohai._require_plugin("platform") @ohai[:platform].should eql("lars") end it "should set the platform_family to the platform if platform was set earlier but not platform_family" do @ohai[:platform] = 'lars' @ohai[:platform_family] = 'jack' @ohai._require_plugin("platform") @ohai[:platform_family].should eql("jack") end it "should not set the platform_family if the platform_family was set earlier." do @ohai[:platform] = 'lars' @ohai._require_plugin("platform") @ohai[:platform].should eql("lars") @ohai[:platform_family].should eql("lars") end it "should set the platform_version to the os_version if it was not set earlier" do @ohai._require_plugin("platform") @ohai[:os_version].should eql("poop") end it "should not set the platform to the os if it was set earlier" do @ohai[:platform_version] = 'ulrich' @ohai._require_plugin("platform") @ohai[:platform_version].should eql("ulrich") end end ohai-6.14.0/spec/ohai/plugins/java_spec.rb0000644000175000017500000001166311761755160017661 0ustar tfheentfheen# # Author:: Benjamin Black () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin java (Java5 Client VM)" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:languages] = Mash.new @status = 0 @stdout = "" @stderr = "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)" @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr]) end it "should run java -version" do @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([0, "", "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)"]) @ohai._require_plugin("java") end it "should set java[:version]" do @ohai._require_plugin("java") @ohai.languages[:java][:version].should eql("1.5.0_16") end it "should set java[:runtime][:name] to runtime name" do @ohai._require_plugin("java") @ohai.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment, Standard Edition") end it "should set java[:runtime][:build] to runtime build" do @ohai._require_plugin("java") @ohai.languages[:java][:runtime][:build].should eql("1.5.0_16-b06-284") end it "should set java[:hotspot][:name] to hotspot name" do @ohai._require_plugin("java") @ohai.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Client VM") end it "should set java[:hotspot][:build] to hotspot build" do @ohai._require_plugin("java") @ohai.languages[:java][:hotspot][:build].should eql("1.5.0_16-133, mixed mode, sharing") end it "should not set the languages[:java] tree up if java command fails" do @status = 1 @stdout = "" @stderr = "Some error output here" @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("java") @ohai.languages.should_not have_key(:java) end end describe Ohai::System, "plugin java (Java6 Server VM)" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:languages] = Mash.new @status = 0 @stdout = "" @stderr = "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)" @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr]) end it "should run java -version" do @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([0, "", "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)"]) @ohai._require_plugin("java") end it "should set java[:version]" do @ohai._require_plugin("java") @ohai.languages[:java][:version].should eql("1.6.0_22") end it "should set java[:runtime][:name] to runtime name" do @ohai._require_plugin("java") @ohai.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment") end it "should set java[:runtime][:build] to runtime build" do @ohai._require_plugin("java") @ohai.languages[:java][:runtime][:build].should eql("1.6.0_22-b04") end it "should set java[:hotspot][:name] to hotspot name" do @ohai._require_plugin("java") @ohai.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Server VM") end it "should set java[:hotspot][:build] to hotspot build" do @ohai._require_plugin("java") @ohai.languages[:java][:hotspot][:build].should eql("17.1-b03, mixed mode") end it "should not set the languages[:java] tree up if java command fails" do @status = 1 @stdout = "" @stderr = "Some error output here" @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("java") @ohai.languages.should_not have_key(:java) end end ohai-6.14.0/spec/ohai/plugins/darwin/0000755000175000017500000000000011761755160016656 5ustar tfheentfheenohai-6.14.0/spec/ohai/plugins/darwin/kernel_spec.rb0000644000175000017500000000311511761755160021475 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin kernel plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:kernel] = Mash.new @ohai[:kernel][:name] = "darwin" end it "should not set kernel_machine to x86_64" do @ohai.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("0") @ohai._require_plugin("darwin::kernel") @ohai[:kernel][:machine].should_not == 'x86_64' end it "should set kernel_machine to x86_64" do @ohai.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("1") @ohai._require_plugin("darwin::kernel") @ohai[:kernel][:machine].should == 'x86_64' end it "should set the kernel_os to the kernel_name value" do @ohai._require_plugin("darwin::kernel") @ohai[:kernel][:os].should == @ohai[:kernel][:name] end endohai-6.14.0/spec/ohai/plugins/darwin/hostname_spec.rb0000644000175000017500000000233711761755160022040 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin hostname plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "darwin" @ohai.stub!(:from).with("hostname -s").and_return("katie") @ohai.stub!(:from).with("hostname").and_return("katie.bethell") end it_should_check_from("darwin::hostname", "hostname", "hostname -s", "katie") it_should_check_from("darwin::hostname", "fqdn", "hostname", "katie.bethell") endohai-6.14.0/spec/ohai/plugins/darwin/network_spec.rb0000644000175000017500000013250611761755160021715 0ustar tfheentfheen# # Author:: Alan Harper # Copyright:: Copyright (c) 2012 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin Network Plugin" do before do darwin_ifconfig = <<-DARWIN_IFCONFIG lo0: flags=8049 mtu 16384 options=3 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fd54:185f:37df:cad2:ba8d:12ff:fe3a:32de prefixlen 128 gif0: flags=8010 mtu 1280 stf0: flags=0<> mtu 1280 en1: flags=8863 mtu 1500 ether b8:8d:12:3a:32:de inet6 fe80::ba8d:12ff:fe3a:32de%en1 prefixlen 64 scopeid 0x4 inet 10.20.10.144 netmask 0xffffff00 broadcast 10.20.10.255 inet6 2001:44b8:4186:1100:ba8d:12ff:fe3a:32de prefixlen 64 autoconf inet6 2001:44b8:4186:1100:7dba:7a60:97a:e14a prefixlen 64 autoconf temporary media: autoselect status: active p2p0: flags=8843 mtu 2304 ether 0a:8d:12:3a:32:de media: autoselect status: inactive en0: flags=8863 mtu 1500 options=2b ether 3c:07:54:4e:0e:35 media: autoselect (none) status: inactive fw0: flags=8822 mtu 4078 lladdr a4:b1:97:ff:fe:b9:3a:d4 media: autoselect status: inactive utun0: flags=8051 mtu 1380 inet6 fe80::ba8d:12ff:fe3a:32de%utun0 prefixlen 64 scopeid 0x8 inet6 fd00:6587:52d7:c87:ba8d:12ff:fe3a:32de prefixlen 64 DARWIN_IFCONFIG darwin_arp = <<-DARWIN_ARP ? (10.20.10.1) at 0:4:ed:de:41:bf on en1 ifscope [ethernet] ? (10.20.10.2) at 0:1e:c9:55:7e:ee on en1 ifscope [ethernet] ? (10.20.10.6) at 34:15:9e:18:a1:20 on en1 ifscope [ethernet] ? (10.20.10.57) at cc:8:e0:e0:8a:2 on en1 ifscope [ethernet] ? (10.20.10.61) at 28:37:37:12:5:77 on en1 ifscope [ethernet] ? (10.20.10.73) at e0:f8:47:8:86:2 on en1 ifscope [ethernet] ? (10.20.10.130) at 68:a8:6d:da:2b:24 on en1 ifscope [ethernet] ? (10.20.10.138) at 8:0:37:8c:d2:23 on en1 ifscope [ethernet] ? (10.20.10.141) at b8:8d:12:28:c5:90 on en1 ifscope [ethernet] ? (10.20.10.166) at 0:1b:63:a0:1:3a on en1 ifscope [ethernet] ? (10.20.10.174) at 98:d6:bb:bd:37:ad on en1 ifscope [ethernet] ? (10.20.10.178) at 24:ab:81:2d:a3:c5 on en1 ifscope [ethernet] ? (10.20.10.181) at 78:a3:e4:e4:16:32 on en1 ifscope [ethernet] ? (10.20.10.185) at 0:26:8:9a:e8:a3 on en1 ifscope [ethernet] ? (10.20.10.200) at b8:8d:12:55:7f:7f on en1 ifscope [ethernet] ? (10.20.10.255) at ff:ff:ff:ff:ff:ff on en1 ifscope [ethernet] DARWIN_ARP darwin_route = <<-DARWIN_ROUTE route to: default destination: default mask: default gateway: 10.20.10.1 interface: en1 flags: recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 0 0 0 0 0 0 1500 0 DARWIN_ROUTE darwin_netstat = <<-DARWIN_NETSTAT Name Mtu Network Address Ipkts Ierrs Ibytes Opkts Oerrs Obytes Coll Drop lo0 16384 174982 0 25774844 174982 0 25774844 0 lo0 16384 fe80::1%lo0 fe80:1::1 174982 - 25774844 174982 - 25774844 - - lo0 16384 127 127.0.0.1 174982 - 25774844 174982 - 25774844 - - lo0 16384 ::1/128 ::1 174982 - 25774844 174982 - 25774844 - - lo0 16384 fd54:185f:3 fd54:185f:37df:ca 174982 - 25774844 174982 - 25774844 - - gif0* 1280 0 0 0 0 0 0 0 stf0* 1280 0 0 0 0 0 0 0 en1 1500 b8:8d:12:3a:32:de 5921903 0 2530556736 14314573 0 18228234970 0 en1 1500 fe80::ba8d: fe80:4::ba8d:12ff 5921903 - 2530556736 14314573 - 18228234970 - - en1 1500 10.20.10/24 10.20.10.144 5921903 - 2530556736 14314573 - 18228234970 - - en1 1500 2001:44b8:4 2001:44b8:4186:11 5921903 - 2530556736 14314573 - 18228234970 - - en1 1500 2001:44b8:4 2001:44b8:4186:11 5921903 - 2530556736 14314573 - 18228234970 - - p2p0 2304 0a:8d:12:3a:32:de 0 0 0 0 0 0 0 en0 1500 3c:07:54:4e:0e:35 0 0 0 0 0 2394 0 fw0* 4078 a4:b1:97:ff:fe:b9:3a:d4 0 0 0 0 0 1038 0 utun0 1380 5 0 324 13 0 740 0 utun0 1380 fe80::ba8d: fe80:8::ba8d:12ff 5 - 324 13 - 740 - - utun0 1380 fd00:6587:5 fd00:6587:52d7:c8 5 - 324 13 - 740 - - DARWIN_NETSTAT darwin_sysctl = <<-DARWIN_SYSCTL net.local.stream.sendspace: 8192 net.local.stream.recvspace: 8192 net.local.stream.tracemdns: 0 net.local.dgram.maxdgram: 2048 net.local.dgram.recvspace: 4096 net.local.inflight: 0 net.inet.ip.portrange.lowfirst: 1023 net.inet.ip.portrange.lowlast: 600 net.inet.ip.portrange.first: 49152 net.inet.ip.portrange.last: 65535 net.inet.ip.portrange.hifirst: 49152 net.inet.ip.portrange.hilast: 65535 net.inet.ip.forwarding: 1 net.inet.ip.redirect: 1 net.inet.ip.ttl: 64 net.inet.ip.rtexpire: 12 net.inet.ip.rtminexpire: 10 net.inet.ip.rtmaxcache: 128 net.inet.ip.sourceroute: 0 net.inet.ip.intr_queue_maxlen: 50 net.inet.ip.intr_queue_drops: 0 net.inet.ip.accept_sourceroute: 0 net.inet.ip.keepfaith: 0 net.inet.ip.gifttl: 30 net.inet.ip.subnets_are_local: 0 net.inet.ip.mcast.maxgrpsrc: 512 net.inet.ip.mcast.maxsocksrc: 128 net.inet.ip.mcast.loop: 1 net.inet.ip.check_route_selfref: 1 net.inet.ip.use_route_genid: 1 net.inet.ip.dummynet.hash_size: 64 net.inet.ip.dummynet.curr_time: 0 net.inet.ip.dummynet.ready_heap: 0 net.inet.ip.dummynet.extract_heap: 0 net.inet.ip.dummynet.searches: 0 net.inet.ip.dummynet.search_steps: 0 net.inet.ip.dummynet.expire: 1 net.inet.ip.dummynet.max_chain_len: 16 net.inet.ip.dummynet.red_lookup_depth: 256 net.inet.ip.dummynet.red_avg_pkt_size: 512 net.inet.ip.dummynet.red_max_pkt_size: 1500 net.inet.ip.dummynet.debug: 0 net.inet.ip.fw.enable: 1 net.inet.ip.fw.autoinc_step: 100 net.inet.ip.fw.one_pass: 0 net.inet.ip.fw.debug: 0 net.inet.ip.fw.verbose: 0 net.inet.ip.fw.verbose_limit: 0 net.inet.ip.fw.dyn_buckets: 256 net.inet.ip.fw.curr_dyn_buckets: 256 net.inet.ip.fw.dyn_count: 0 net.inet.ip.fw.dyn_max: 4096 net.inet.ip.fw.static_count: 2 net.inet.ip.fw.dyn_ack_lifetime: 300 net.inet.ip.fw.dyn_syn_lifetime: 20 net.inet.ip.fw.dyn_fin_lifetime: 1 net.inet.ip.fw.dyn_rst_lifetime: 1 net.inet.ip.fw.dyn_udp_lifetime: 10 net.inet.ip.fw.dyn_short_lifetime: 5 net.inet.ip.fw.dyn_keepalive: 1 net.inet.ip.maxfragpackets: 1536 net.inet.ip.maxfragsperpacket: 128 net.inet.ip.maxfrags: 3072 net.inet.ip.scopedroute: 1 net.inet.ip.check_interface: 0 net.inet.ip.linklocal.in.allowbadttl: 1 net.inet.ip.random_id: 1 net.inet.ip.maxchainsent: 0 net.inet.ip.select_srcif_debug: 0 net.inet.icmp.maskrepl: 0 net.inet.icmp.icmplim: 250 net.inet.icmp.timestamp: 0 net.inet.icmp.drop_redirect: 0 net.inet.icmp.log_redirect: 0 net.inet.icmp.bmcastecho: 1 net.inet.igmp.recvifkludge: 1 net.inet.igmp.sendra: 1 net.inet.igmp.sendlocal: 1 net.inet.igmp.v1enable: 1 net.inet.igmp.v2enable: 1 net.inet.igmp.legacysupp: 0 net.inet.igmp.default_version: 3 net.inet.igmp.gsrdelay: 10 net.inet.igmp.debug: 0 net.inet.tcp.rfc1323: 1 net.inet.tcp.rfc1644: 0 net.inet.tcp.mssdflt: 512 net.inet.tcp.keepidle: 7200000 net.inet.tcp.keepintvl: 75000 net.inet.tcp.sendspace: 65536 net.inet.tcp.recvspace: 65536 net.inet.tcp.keepinit: 75000 net.inet.tcp.v6mssdflt: 1024 net.inet.tcp.log_in_vain: 0 net.inet.tcp.blackhole: 0 net.inet.tcp.delayed_ack: 3 net.inet.tcp.tcp_lq_overflow: 1 net.inet.tcp.recvbg: 0 net.inet.tcp.drop_synfin: 1 net.inet.tcp.reass.maxsegments: 3072 net.inet.tcp.reass.cursegments: 0 net.inet.tcp.reass.overflows: 0 net.inet.tcp.slowlink_wsize: 8192 net.inet.tcp.maxseg_unacked: 8 net.inet.tcp.rfc3465: 1 net.inet.tcp.rfc3465_lim2: 1 net.inet.tcp.rtt_samples_per_slot: 20 net.inet.tcp.recv_allowed_iaj: 5 net.inet.tcp.acc_iaj_high_thresh: 100 net.inet.tcp.rexmt_thresh: 2 net.inet.tcp.path_mtu_discovery: 1 net.inet.tcp.slowstart_flightsize: 1 net.inet.tcp.local_slowstart_flightsize: 8 net.inet.tcp.tso: 1 net.inet.tcp.ecn_initiate_out: 0 net.inet.tcp.ecn_negotiate_in: 0 net.inet.tcp.packetchain: 50 net.inet.tcp.socket_unlocked_on_output: 1 net.inet.tcp.rfc3390: 1 net.inet.tcp.min_iaj_win: 4 net.inet.tcp.acc_iaj_react_limit: 200 net.inet.tcp.sack: 1 net.inet.tcp.sack_maxholes: 128 net.inet.tcp.sack_globalmaxholes: 65536 net.inet.tcp.sack_globalholes: 0 net.inet.tcp.minmss: 216 net.inet.tcp.minmssoverload: 0 net.inet.tcp.do_tcpdrain: 0 net.inet.tcp.pcbcount: 86 net.inet.tcp.icmp_may_rst: 1 net.inet.tcp.strict_rfc1948: 0 net.inet.tcp.isn_reseed_interval: 0 net.inet.tcp.background_io_enabled: 1 net.inet.tcp.rtt_min: 100 net.inet.tcp.rexmt_slop: 200 net.inet.tcp.randomize_ports: 0 net.inet.tcp.newreno_sockets: 81 net.inet.tcp.background_sockets: -1 net.inet.tcp.tcbhashsize: 4096 net.inet.tcp.background_io_trigger: 5 net.inet.tcp.msl: 15000 net.inet.tcp.max_persist_timeout: 0 net.inet.tcp.always_keepalive: 0 net.inet.tcp.timer_fastmode_idlemax: 20 net.inet.tcp.broken_peer_syn_rxmit_thres: 7 net.inet.tcp.tcp_timer_advanced: 5 net.inet.tcp.tcp_resched_timerlist: 12209 net.inet.tcp.pmtud_blackhole_detection: 1 net.inet.tcp.pmtud_blackhole_mss: 1200 net.inet.tcp.timer_fastquantum: 100 net.inet.tcp.timer_slowquantum: 500 net.inet.tcp.win_scale_factor: 3 net.inet.tcp.in_sw_cksum: 5658081 net.inet.tcp.in_sw_cksum_bytes: 2198681467 net.inet.tcp.out_sw_cksum: 14166053 net.inet.tcp.out_sw_cksum_bytes: 17732561863 net.inet.tcp.sockthreshold: 64 net.inet.tcp.bg_target_qdelay: 100 net.inet.tcp.bg_allowed_increase: 2 net.inet.tcp.bg_tether_shift: 1 net.inet.tcp.bg_ss_fltsz: 2 net.inet.udp.checksum: 1 net.inet.udp.maxdgram: 9216 net.inet.udp.recvspace: 42080 net.inet.udp.in_sw_cksum: 19639 net.inet.udp.in_sw_cksum_bytes: 3928092 net.inet.udp.out_sw_cksum: 17436 net.inet.udp.out_sw_cksum_bytes: 2495444 net.inet.udp.log_in_vain: 0 net.inet.udp.blackhole: 0 net.inet.udp.pcbcount: 72 net.inet.udp.randomize_ports: 1 net.inet.ipsec.def_policy: 1 net.inet.ipsec.esp_trans_deflev: 1 net.inet.ipsec.esp_net_deflev: 1 net.inet.ipsec.ah_trans_deflev: 1 net.inet.ipsec.ah_net_deflev: 1 net.inet.ipsec.ah_cleartos: 1 net.inet.ipsec.ah_offsetmask: 0 net.inet.ipsec.dfbit: 0 net.inet.ipsec.ecn: 0 net.inet.ipsec.debug: 0 net.inet.ipsec.esp_randpad: -1 net.inet.ipsec.bypass: 0 net.inet.ipsec.esp_port: 4500 net.inet.raw.maxdgram: 8192 net.inet.raw.recvspace: 8192 net.link.generic.system.ifcount: 10 net.link.generic.system.dlil_verbose: 0 net.link.generic.system.multi_threaded_input: 1 net.link.generic.system.dlil_input_sanity_check: 0 net.link.ether.inet.prune_intvl: 300 net.link.ether.inet.max_age: 1200 net.link.ether.inet.host_down_time: 20 net.link.ether.inet.apple_hwcksum_tx: 1 net.link.ether.inet.apple_hwcksum_rx: 1 net.link.ether.inet.arp_llreach_base: 30 net.link.ether.inet.maxtries: 5 net.link.ether.inet.useloopback: 1 net.link.ether.inet.proxyall: 0 net.link.ether.inet.sendllconflict: 0 net.link.ether.inet.log_arp_warnings: 0 net.link.ether.inet.keep_announcements: 1 net.link.ether.inet.send_conflicting_probes: 1 net.link.bridge.log_stp: 0 net.link.bridge.debug: 0 net.key.debug: 0 net.key.spi_trycnt: 1000 net.key.spi_minval: 256 net.key.spi_maxval: 268435455 net.key.int_random: 60 net.key.larval_lifetime: 30 net.key.blockacq_count: 10 net.key.blockacq_lifetime: 20 net.key.esp_keymin: 256 net.key.esp_auth: 0 net.key.ah_keymin: 128 net.key.prefered_oldsa: 0 net.key.natt_keepalive_interval: 20 net.inet6.ip6.forwarding: 0 net.inet6.ip6.redirect: 1 net.inet6.ip6.hlim: 64 net.inet6.ip6.maxfragpackets: 1536 net.inet6.ip6.accept_rtadv: 0 net.inet6.ip6.keepfaith: 0 net.inet6.ip6.log_interval: 5 net.inet6.ip6.hdrnestlimit: 15 net.inet6.ip6.dad_count: 1 net.inet6.ip6.auto_flowlabel: 1 net.inet6.ip6.defmcasthlim: 1 net.inet6.ip6.gifhlim: 0 net.inet6.ip6.kame_version: 2009/apple-darwin net.inet6.ip6.use_deprecated: 1 net.inet6.ip6.rr_prune: 5 net.inet6.ip6.v6only: 0 net.inet6.ip6.rtexpire: 3600 net.inet6.ip6.rtminexpire: 10 net.inet6.ip6.rtmaxcache: 128 net.inet6.ip6.use_tempaddr: 1 net.inet6.ip6.temppltime: 86400 net.inet6.ip6.tempvltime: 604800 net.inet6.ip6.auto_linklocal: 1 net.inet6.ip6.prefer_tempaddr: 1 net.inet6.ip6.use_defaultzone: 0 net.inet6.ip6.maxfrags: 12288 net.inet6.ip6.mcast_pmtu: 0 net.inet6.ip6.neighborgcthresh: 1024 net.inet6.ip6.maxifprefixes: 16 net.inet6.ip6.maxifdefrouters: 16 net.inet6.ip6.maxdynroutes: 1024 net.inet6.ip6.fw.enable: 1 net.inet6.ip6.fw.debug: 0 net.inet6.ip6.fw.verbose: 0 net.inet6.ip6.fw.verbose_limit: 0 net.inet6.ip6.scopedroute: 1 net.inet6.ip6.select_srcif_debug: 0 net.inet6.ip6.mcast.maxgrpsrc: 512 net.inet6.ip6.mcast.maxsocksrc: 128 net.inet6.ip6.mcast.loop: 1 net.inet6.ip6.only_allow_rfc4193_prefixes: 0 net.inet6.ipsec6.def_policy: 1 net.inet6.ipsec6.esp_trans_deflev: 1 net.inet6.ipsec6.esp_net_deflev: 1 net.inet6.ipsec6.ah_trans_deflev: 1 net.inet6.ipsec6.ah_net_deflev: 1 net.inet6.ipsec6.ecn: 0 net.inet6.ipsec6.debug: 0 net.inet6.ipsec6.esp_randpad: -1 net.inet6.icmp6.rediraccept: 1 net.inet6.icmp6.redirtimeout: 600 net.inet6.icmp6.nd6_prune: 1 net.inet6.icmp6.nd6_delay: 5 net.inet6.icmp6.nd6_umaxtries: 3 net.inet6.icmp6.nd6_mmaxtries: 3 net.inet6.icmp6.nd6_useloopback: 1 net.inet6.icmp6.nodeinfo: 3 net.inet6.icmp6.errppslimit: 500 net.inet6.icmp6.nd6_maxnudhint: 0 net.inet6.icmp6.nd6_debug: 0 net.inet6.icmp6.nd6_accept_6to4: 1 net.inet6.icmp6.nd6_onlink_ns_rfc4861: 0 net.inet6.icmp6.nd6_llreach_base: 30 net.inet6.mld.gsrdelay: 10 net.inet6.mld.v1enable: 1 net.inet6.mld.use_allow: 1 net.inet6.mld.debug: 0 net.idle.route.expire_timeout: 30 net.idle.route.drain_interval: 10 net.statistics: 1 net.alf.loglevel: 55 net.alf.perm: 0 net.alf.defaultaction: 1 net.alf.mqcount: 0 net.smb.fs.version: 107000 net.smb.fs.loglevel: 0 net.smb.fs.kern_ntlmssp: 0 net.smb.fs.kern_deprecatePreXPServers: 1 net.smb.fs.kern_deadtimer: 60 net.smb.fs.kern_hard_deadtimer: 600 net.smb.fs.kern_soft_deadtimer: 30 net.smb.fs.tcpsndbuf: 261120 net.smb.fs.tcprcvbuf: 261120 DARWIN_SYSCTL @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @stdin_ifconfig = StringIO.new @stdin_arp = StringIO.new @stdin_sysctl = StringIO.new @stdin_netstat = StringIO.new @ifconfig_lines = darwin_ifconfig.split("\n") @arp_lines = darwin_arp.split("\n") @netstat_lines = darwin_netstat.split("\n") @sysctl_lines = darwin_sysctl.split("\n") @ohai.stub(:from).with("route -n get default").and_return(darwin_route) @ohai.stub(:popen4).with("netstat -i -d -l -b -n") end describe "gathering IP layer address info" do before do @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil) @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil) @ohai.stub(:popen4).with("netstat -i -d -l -b -n").and_yield(nil, @stdin_netstat, @netstat_lines, nil) @ohai.stub(:popen4).with("sysctl net").and_yield(nil, @stdin_sysctl, @sysctl_lines, nil) @ohai._require_plugin("network") @ohai._require_plugin("darwin::network") end it "completes the run" do @ohai['network'].should_not be_nil end it "detects the interfaces" do @ohai['network']['interfaces'].keys.sort.should == ["en0", "en1", "fw0", "gif0", "lo0", "p2p0", "stf0", "utun0"] end it "detects the ipv4 addresses of the ethernet interface" do @ohai['network']['interfaces']['en1']['addresses'].keys.should include('10.20.10.144') @ohai['network']['interfaces']['en1']['addresses']['10.20.10.144']['netmask'].should == '255.255.255.0' @ohai['network']['interfaces']['en1']['addresses']['10.20.10.144']['broadcast'].should == '10.20.10.255' @ohai['network']['interfaces']['en1']['addresses']['10.20.10.144']['family'].should == 'inet' end it "detects the ipv6 addresses of the ethernet interface" do @ohai['network']['interfaces']['en1']['addresses'].keys.should include('fe80::ba8d:12ff:fe3a:32de') @ohai['network']['interfaces']['en1']['addresses']['fe80::ba8d:12ff:fe3a:32de']['scope'].should == 'Link' @ohai['network']['interfaces']['en1']['addresses']['fe80::ba8d:12ff:fe3a:32de']['prefixlen'].should == '64' @ohai['network']['interfaces']['en1']['addresses']['fe80::ba8d:12ff:fe3a:32de']['family'].should == 'inet6' @ohai['network']['interfaces']['en1']['addresses'].keys.should include('2001:44b8:4186:1100:ba8d:12ff:fe3a:32de') @ohai['network']['interfaces']['en1']['addresses']['2001:44b8:4186:1100:ba8d:12ff:fe3a:32de']['scope'].should == 'Global' @ohai['network']['interfaces']['en1']['addresses']['2001:44b8:4186:1100:ba8d:12ff:fe3a:32de']['prefixlen'].should == '64' @ohai['network']['interfaces']['en1']['addresses']['2001:44b8:4186:1100:ba8d:12ff:fe3a:32de']['family'].should == 'inet6' end it "detects the mac addresses of the ethernet interface" do @ohai['network']['interfaces']['en1']['addresses'].keys.should include('b8:8d:12:3a:32:de') @ohai['network']['interfaces']['en1']['addresses']['b8:8d:12:3a:32:de']['family'].should == 'lladdr' end it "detects the encapsulation type of the ethernet interface" do @ohai['network']['interfaces']['en1']['encapsulation'].should == 'Ethernet' end it "detects the flags of the ethernet interface" do @ohai['network']['interfaces']['en1']['flags'].sort.should == ["BROADCAST", "MULTICAST", "RUNNING", "SIMPLEX", "SMART", "UP"] end it "detects the mtu of the ethernet interface" do @ohai['network']['interfaces']['en1']['mtu'].should == "1500" end it "detects the ipv4 addresses of the loopback interface" do @ohai['network']['interfaces']['lo0']['addresses'].keys.should include('127.0.0.1') @ohai['network']['interfaces']['lo0']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0' @ohai['network']['interfaces']['lo0']['addresses']['127.0.0.1']['family'].should == 'inet' end it "detects the ipv6 addresses of the loopback interface" do @ohai['network']['interfaces']['lo0']['addresses'].keys.should include('::1') @ohai['network']['interfaces']['lo0']['addresses']['::1']['scope'].should == 'Node' @ohai['network']['interfaces']['lo0']['addresses']['::1']['prefixlen'].should == '128' @ohai['network']['interfaces']['lo0']['addresses']['::1']['family'].should == 'inet6' end it "detects the encapsulation type of the loopback interface" do @ohai['network']['interfaces']['lo0']['encapsulation'].should == 'Loopback' end it "detects the flags of the ethernet interface" do @ohai['network']['interfaces']['lo0']['flags'].sort.should == ["LOOPBACK", "MULTICAST", "RUNNING", "UP"] end it "detects the mtu of the loopback interface" do @ohai['network']['interfaces']['lo0']['mtu'].should == "16384" end it "detects the arp entries" do @ohai['network']['interfaces']['en1']['arp']['10.20.10.1'].should == '0:4:ed:de:41:bf' end it "detects the ethernet counters" do @ohai['counters']['network']['interfaces']['en1']['tx']['bytes'].should == "18228234970" @ohai['counters']['network']['interfaces']['en1']['tx']['packets'].should == "14314573" @ohai['counters']['network']['interfaces']['en1']['tx']['collisions'].should == "0" @ohai['counters']['network']['interfaces']['en1']['tx']['errors'].should == "0" @ohai['counters']['network']['interfaces']['en1']['tx']['carrier'].should == 0 @ohai['counters']['network']['interfaces']['en1']['tx']['drop'].should == 0 @ohai['counters']['network']['interfaces']['en1']['rx']['bytes'].should == "2530556736" @ohai['counters']['network']['interfaces']['en1']['rx']['packets'].should == "5921903" @ohai['counters']['network']['interfaces']['en1']['rx']['errors'].should == "0" @ohai['counters']['network']['interfaces']['en1']['rx']['overrun'].should == 0 @ohai['counters']['network']['interfaces']['en1']['rx']['drop'].should == 0 end it "detects the loopback counters" do @ohai['counters']['network']['interfaces']['lo0']['tx']['bytes'].should == "25774844" @ohai['counters']['network']['interfaces']['lo0']['tx']['packets'].should == "174982" @ohai['counters']['network']['interfaces']['lo0']['tx']['collisions'].should == "0" @ohai['counters']['network']['interfaces']['lo0']['tx']['errors'].should == "0" @ohai['counters']['network']['interfaces']['lo0']['tx']['carrier'].should == 0 @ohai['counters']['network']['interfaces']['lo0']['tx']['drop'].should == 0 @ohai['counters']['network']['interfaces']['lo0']['rx']['bytes'].should == "25774844" @ohai['counters']['network']['interfaces']['lo0']['rx']['packets'].should == "174982" @ohai['counters']['network']['interfaces']['lo0']['rx']['errors'].should == "0" @ohai['counters']['network']['interfaces']['lo0']['rx']['overrun'].should == 0 @ohai['counters']['network']['interfaces']['lo0']['rx']['drop'].should == 0 end it "finds the default interface by asking which iface has the default route" do @ohai['network'][:default_interface].should == 'en1' end it "finds the default interface by asking which iface has the default route" do @ohai['network'][:default_gateway].should == '10.20.10.1' end it "should detect network settings" do @ohai['network']['settings']['net.local.stream.sendspace'].should == '8192' @ohai["network"]["settings"]['net.local.stream.recvspace'].should == '8192' @ohai["network"]["settings"]['net.local.stream.tracemdns'].should == '0' @ohai["network"]["settings"]['net.local.dgram.maxdgram'].should == '2048' @ohai["network"]["settings"]['net.local.dgram.recvspace'].should == '4096' @ohai["network"]["settings"]['net.local.inflight'].should == '0' @ohai["network"]["settings"]['net.inet.ip.portrange.lowfirst'].should == '1023' @ohai["network"]["settings"]['net.inet.ip.portrange.lowlast'].should == '600' @ohai["network"]["settings"]['net.inet.ip.portrange.first'].should == '49152' @ohai["network"]["settings"]['net.inet.ip.portrange.last'].should == '65535' @ohai["network"]["settings"]['net.inet.ip.portrange.hifirst'].should == '49152' @ohai["network"]["settings"]['net.inet.ip.portrange.hilast'].should == '65535' @ohai["network"]["settings"]['net.inet.ip.forwarding'].should == '1' @ohai["network"]["settings"]['net.inet.ip.redirect'].should == '1' @ohai["network"]["settings"]['net.inet.ip.ttl'].should == '64' @ohai["network"]["settings"]['net.inet.ip.rtexpire'].should == '12' @ohai["network"]["settings"]['net.inet.ip.rtminexpire'].should == '10' @ohai["network"]["settings"]['net.inet.ip.rtmaxcache'].should == '128' @ohai["network"]["settings"]['net.inet.ip.sourceroute'].should == '0' @ohai["network"]["settings"]['net.inet.ip.intr_queue_maxlen'].should == '50' @ohai["network"]["settings"]['net.inet.ip.intr_queue_drops'].should == '0' @ohai["network"]["settings"]['net.inet.ip.accept_sourceroute'].should == '0' @ohai["network"]["settings"]['net.inet.ip.keepfaith'].should == '0' @ohai["network"]["settings"]['net.inet.ip.gifttl'].should == '30' @ohai["network"]["settings"]['net.inet.ip.subnets_are_local'].should == '0' @ohai["network"]["settings"]['net.inet.ip.mcast.maxgrpsrc'].should == '512' @ohai["network"]["settings"]['net.inet.ip.mcast.maxsocksrc'].should == '128' @ohai["network"]["settings"]['net.inet.ip.mcast.loop'].should == '1' @ohai["network"]["settings"]['net.inet.ip.check_route_selfref'].should == '1' @ohai["network"]["settings"]['net.inet.ip.use_route_genid'].should == '1' @ohai["network"]["settings"]['net.inet.ip.dummynet.hash_size'].should == '64' @ohai["network"]["settings"]['net.inet.ip.dummynet.curr_time'].should == '0' @ohai["network"]["settings"]['net.inet.ip.dummynet.ready_heap'].should == '0' @ohai["network"]["settings"]['net.inet.ip.dummynet.extract_heap'].should == '0' @ohai["network"]["settings"]['net.inet.ip.dummynet.searches'].should == '0' @ohai["network"]["settings"]['net.inet.ip.dummynet.search_steps'].should == '0' @ohai["network"]["settings"]['net.inet.ip.dummynet.expire'].should == '1' @ohai["network"]["settings"]['net.inet.ip.dummynet.max_chain_len'].should == '16' @ohai["network"]["settings"]['net.inet.ip.dummynet.red_lookup_depth'].should == '256' @ohai["network"]["settings"]['net.inet.ip.dummynet.red_avg_pkt_size'].should == '512' @ohai["network"]["settings"]['net.inet.ip.dummynet.red_max_pkt_size'].should == '1500' @ohai["network"]["settings"]['net.inet.ip.dummynet.debug'].should == '0' @ohai["network"]["settings"]['net.inet.ip.fw.enable'].should == '1' @ohai["network"]["settings"]['net.inet.ip.fw.autoinc_step'].should == '100' @ohai["network"]["settings"]['net.inet.ip.fw.one_pass'].should == '0' @ohai["network"]["settings"]['net.inet.ip.fw.debug'].should == '0' @ohai["network"]["settings"]['net.inet.ip.fw.verbose'].should == '0' @ohai["network"]["settings"]['net.inet.ip.fw.verbose_limit'].should == '0' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_buckets'].should == '256' @ohai["network"]["settings"]['net.inet.ip.fw.curr_dyn_buckets'].should == '256' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_count'].should == '0' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_max'].should == '4096' @ohai["network"]["settings"]['net.inet.ip.fw.static_count'].should == '2' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_ack_lifetime'].should == '300' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_syn_lifetime'].should == '20' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_fin_lifetime'].should == '1' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_rst_lifetime'].should == '1' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_udp_lifetime'].should == '10' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_short_lifetime'].should == '5' @ohai["network"]["settings"]['net.inet.ip.fw.dyn_keepalive'].should == '1' @ohai["network"]["settings"]['net.inet.ip.maxfragpackets'].should == '1536' @ohai["network"]["settings"]['net.inet.ip.maxfragsperpacket'].should == '128' @ohai["network"]["settings"]['net.inet.ip.maxfrags'].should == '3072' @ohai["network"]["settings"]['net.inet.ip.scopedroute'].should == '1' @ohai["network"]["settings"]['net.inet.ip.check_interface'].should == '0' @ohai["network"]["settings"]['net.inet.ip.linklocal.in.allowbadttl'].should == '1' @ohai["network"]["settings"]['net.inet.ip.random_id'].should == '1' @ohai["network"]["settings"]['net.inet.ip.maxchainsent'].should == '0' @ohai["network"]["settings"]['net.inet.ip.select_srcif_debug'].should == '0' @ohai["network"]["settings"]['net.inet.icmp.maskrepl'].should == '0' @ohai["network"]["settings"]['net.inet.icmp.icmplim'].should == '250' @ohai["network"]["settings"]['net.inet.icmp.timestamp'].should == '0' @ohai["network"]["settings"]['net.inet.icmp.drop_redirect'].should == '0' @ohai["network"]["settings"]['net.inet.icmp.log_redirect'].should == '0' @ohai["network"]["settings"]['net.inet.icmp.bmcastecho'].should == '1' @ohai["network"]["settings"]['net.inet.igmp.recvifkludge'].should == '1' @ohai["network"]["settings"]['net.inet.igmp.sendra'].should == '1' @ohai["network"]["settings"]['net.inet.igmp.sendlocal'].should == '1' @ohai["network"]["settings"]['net.inet.igmp.v1enable'].should == '1' @ohai["network"]["settings"]['net.inet.igmp.v2enable'].should == '1' @ohai["network"]["settings"]['net.inet.igmp.legacysupp'].should == '0' @ohai["network"]["settings"]['net.inet.igmp.default_version'].should == '3' @ohai["network"]["settings"]['net.inet.igmp.gsrdelay'].should == '10' @ohai["network"]["settings"]['net.inet.igmp.debug'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.rfc1323'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.rfc1644'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.mssdflt'].should == '512' @ohai["network"]["settings"]['net.inet.tcp.keepidle'].should == '7200000' @ohai["network"]["settings"]['net.inet.tcp.keepintvl'].should == '75000' @ohai["network"]["settings"]['net.inet.tcp.sendspace'].should == '65536' @ohai["network"]["settings"]['net.inet.tcp.recvspace'].should == '65536' @ohai["network"]["settings"]['net.inet.tcp.keepinit'].should == '75000' @ohai["network"]["settings"]['net.inet.tcp.v6mssdflt'].should == '1024' @ohai["network"]["settings"]['net.inet.tcp.log_in_vain'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.blackhole'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.delayed_ack'].should == '3' @ohai["network"]["settings"]['net.inet.tcp.tcp_lq_overflow'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.recvbg'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.drop_synfin'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.reass.maxsegments'].should == '3072' @ohai["network"]["settings"]['net.inet.tcp.reass.cursegments'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.reass.overflows'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.slowlink_wsize'].should == '8192' @ohai["network"]["settings"]['net.inet.tcp.maxseg_unacked'].should == '8' @ohai["network"]["settings"]['net.inet.tcp.rfc3465'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.rfc3465_lim2'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.rtt_samples_per_slot'].should == '20' @ohai["network"]["settings"]['net.inet.tcp.recv_allowed_iaj'].should == '5' @ohai["network"]["settings"]['net.inet.tcp.acc_iaj_high_thresh'].should == '100' @ohai["network"]["settings"]['net.inet.tcp.rexmt_thresh'].should == '2' @ohai["network"]["settings"]['net.inet.tcp.path_mtu_discovery'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.slowstart_flightsize'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.local_slowstart_flightsize'].should == '8' @ohai["network"]["settings"]['net.inet.tcp.tso'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.ecn_initiate_out'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.ecn_negotiate_in'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.packetchain'].should == '50' @ohai["network"]["settings"]['net.inet.tcp.socket_unlocked_on_output'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.rfc3390'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.min_iaj_win'].should == '4' @ohai["network"]["settings"]['net.inet.tcp.acc_iaj_react_limit'].should == '200' @ohai["network"]["settings"]['net.inet.tcp.sack'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.sack_maxholes'].should == '128' @ohai["network"]["settings"]['net.inet.tcp.sack_globalmaxholes'].should == '65536' @ohai["network"]["settings"]['net.inet.tcp.sack_globalholes'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.minmss'].should == '216' @ohai["network"]["settings"]['net.inet.tcp.minmssoverload'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.do_tcpdrain'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.pcbcount'].should == '86' @ohai["network"]["settings"]['net.inet.tcp.icmp_may_rst'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.strict_rfc1948'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.isn_reseed_interval'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.background_io_enabled'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.rtt_min'].should == '100' @ohai["network"]["settings"]['net.inet.tcp.rexmt_slop'].should == '200' @ohai["network"]["settings"]['net.inet.tcp.randomize_ports'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.newreno_sockets'].should == '81' @ohai["network"]["settings"]['net.inet.tcp.background_sockets'].should == '-1' @ohai["network"]["settings"]['net.inet.tcp.tcbhashsize'].should == '4096' @ohai["network"]["settings"]['net.inet.tcp.background_io_trigger'].should == '5' @ohai["network"]["settings"]['net.inet.tcp.msl'].should == '15000' @ohai["network"]["settings"]['net.inet.tcp.max_persist_timeout'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.always_keepalive'].should == '0' @ohai["network"]["settings"]['net.inet.tcp.timer_fastmode_idlemax'].should == '20' @ohai["network"]["settings"]['net.inet.tcp.broken_peer_syn_rxmit_thres'].should == '7' @ohai["network"]["settings"]['net.inet.tcp.tcp_timer_advanced'].should == '5' @ohai["network"]["settings"]['net.inet.tcp.tcp_resched_timerlist'].should == '12209' @ohai["network"]["settings"]['net.inet.tcp.pmtud_blackhole_detection'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.pmtud_blackhole_mss'].should == '1200' @ohai["network"]["settings"]['net.inet.tcp.timer_fastquantum'].should == '100' @ohai["network"]["settings"]['net.inet.tcp.timer_slowquantum'].should == '500' @ohai["network"]["settings"]['net.inet.tcp.win_scale_factor'].should == '3' @ohai["network"]["settings"]['net.inet.tcp.sockthreshold'].should == '64' @ohai["network"]["settings"]['net.inet.tcp.bg_target_qdelay'].should == '100' @ohai["network"]["settings"]['net.inet.tcp.bg_allowed_increase'].should == '2' @ohai["network"]["settings"]['net.inet.tcp.bg_tether_shift'].should == '1' @ohai["network"]["settings"]['net.inet.tcp.bg_ss_fltsz'].should == '2' @ohai["network"]["settings"]['net.inet.udp.checksum'].should == '1' @ohai["network"]["settings"]['net.inet.udp.maxdgram'].should == '9216' @ohai["network"]["settings"]['net.inet.udp.recvspace'].should == '42080' @ohai["network"]["settings"]['net.inet.udp.log_in_vain'].should == '0' @ohai["network"]["settings"]['net.inet.udp.blackhole'].should == '0' @ohai["network"]["settings"]['net.inet.udp.pcbcount'].should == '72' @ohai["network"]["settings"]['net.inet.udp.randomize_ports'].should == '1' @ohai["network"]["settings"]['net.inet.ipsec.def_policy'].should == '1' @ohai["network"]["settings"]['net.inet.ipsec.esp_trans_deflev'].should == '1' @ohai["network"]["settings"]['net.inet.ipsec.esp_net_deflev'].should == '1' @ohai["network"]["settings"]['net.inet.ipsec.ah_trans_deflev'].should == '1' @ohai["network"]["settings"]['net.inet.ipsec.ah_net_deflev'].should == '1' @ohai["network"]["settings"]['net.inet.ipsec.ah_cleartos'].should == '1' @ohai["network"]["settings"]['net.inet.ipsec.ah_offsetmask'].should == '0' @ohai["network"]["settings"]['net.inet.ipsec.dfbit'].should == '0' @ohai["network"]["settings"]['net.inet.ipsec.ecn'].should == '0' @ohai["network"]["settings"]['net.inet.ipsec.debug'].should == '0' @ohai["network"]["settings"]['net.inet.ipsec.esp_randpad'].should == '-1' @ohai["network"]["settings"]['net.inet.ipsec.bypass'].should == '0' @ohai["network"]["settings"]['net.inet.ipsec.esp_port'].should == '4500' @ohai["network"]["settings"]['net.inet.raw.maxdgram'].should == '8192' @ohai["network"]["settings"]['net.inet.raw.recvspace'].should == '8192' @ohai["network"]["settings"]['net.link.generic.system.ifcount'].should == '10' @ohai["network"]["settings"]['net.link.generic.system.dlil_verbose'].should == '0' @ohai["network"]["settings"]['net.link.generic.system.multi_threaded_input'].should == '1' @ohai["network"]["settings"]['net.link.generic.system.dlil_input_sanity_check'].should == '0' @ohai["network"]["settings"]['net.link.ether.inet.prune_intvl'].should == '300' @ohai["network"]["settings"]['net.link.ether.inet.max_age'].should == '1200' @ohai["network"]["settings"]['net.link.ether.inet.host_down_time'].should == '20' @ohai["network"]["settings"]['net.link.ether.inet.apple_hwcksum_tx'].should == '1' @ohai["network"]["settings"]['net.link.ether.inet.apple_hwcksum_rx'].should == '1' @ohai["network"]["settings"]['net.link.ether.inet.arp_llreach_base'].should == '30' @ohai["network"]["settings"]['net.link.ether.inet.maxtries'].should == '5' @ohai["network"]["settings"]['net.link.ether.inet.useloopback'].should == '1' @ohai["network"]["settings"]['net.link.ether.inet.proxyall'].should == '0' @ohai["network"]["settings"]['net.link.ether.inet.sendllconflict'].should == '0' @ohai["network"]["settings"]['net.link.ether.inet.log_arp_warnings'].should == '0' @ohai["network"]["settings"]['net.link.ether.inet.keep_announcements'].should == '1' @ohai["network"]["settings"]['net.link.ether.inet.send_conflicting_probes'].should == '1' @ohai["network"]["settings"]['net.link.bridge.log_stp'].should == '0' @ohai["network"]["settings"]['net.link.bridge.debug'].should == '0' @ohai["network"]["settings"]['net.key.debug'].should == '0' @ohai["network"]["settings"]['net.key.spi_trycnt'].should == '1000' @ohai["network"]["settings"]['net.key.spi_minval'].should == '256' @ohai["network"]["settings"]['net.key.spi_maxval'].should == '268435455' @ohai["network"]["settings"]['net.key.int_random'].should == '60' @ohai["network"]["settings"]['net.key.larval_lifetime'].should == '30' @ohai["network"]["settings"]['net.key.blockacq_count'].should == '10' @ohai["network"]["settings"]['net.key.blockacq_lifetime'].should == '20' @ohai["network"]["settings"]['net.key.esp_keymin'].should == '256' @ohai["network"]["settings"]['net.key.esp_auth'].should == '0' @ohai["network"]["settings"]['net.key.ah_keymin'].should == '128' @ohai["network"]["settings"]['net.key.prefered_oldsa'].should == '0' @ohai["network"]["settings"]['net.key.natt_keepalive_interval'].should == '20' @ohai["network"]["settings"]['net.inet6.ip6.forwarding'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.redirect'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.hlim'].should == '64' @ohai["network"]["settings"]['net.inet6.ip6.maxfragpackets'].should == '1536' @ohai["network"]["settings"]['net.inet6.ip6.accept_rtadv'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.keepfaith'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.log_interval'].should == '5' @ohai["network"]["settings"]['net.inet6.ip6.hdrnestlimit'].should == '15' @ohai["network"]["settings"]['net.inet6.ip6.dad_count'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.auto_flowlabel'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.defmcasthlim'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.gifhlim'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.kame_version'].should == '2009/apple-darwin' @ohai["network"]["settings"]['net.inet6.ip6.use_deprecated'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.rr_prune'].should == '5' @ohai["network"]["settings"]['net.inet6.ip6.v6only'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.rtexpire'].should == '3600' @ohai["network"]["settings"]['net.inet6.ip6.rtminexpire'].should == '10' @ohai["network"]["settings"]['net.inet6.ip6.rtmaxcache'].should == '128' @ohai["network"]["settings"]['net.inet6.ip6.use_tempaddr'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.temppltime'].should == '86400' @ohai["network"]["settings"]['net.inet6.ip6.tempvltime'].should == '604800' @ohai["network"]["settings"]['net.inet6.ip6.auto_linklocal'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.prefer_tempaddr'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.use_defaultzone'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.maxfrags'].should == '12288' @ohai["network"]["settings"]['net.inet6.ip6.mcast_pmtu'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.neighborgcthresh'].should == '1024' @ohai["network"]["settings"]['net.inet6.ip6.maxifprefixes'].should == '16' @ohai["network"]["settings"]['net.inet6.ip6.maxifdefrouters'].should == '16' @ohai["network"]["settings"]['net.inet6.ip6.maxdynroutes'].should == '1024' @ohai["network"]["settings"]['net.inet6.ip6.fw.enable'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.fw.debug'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.fw.verbose'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.fw.verbose_limit'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.scopedroute'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.select_srcif_debug'].should == '0' @ohai["network"]["settings"]['net.inet6.ip6.mcast.maxgrpsrc'].should == '512' @ohai["network"]["settings"]['net.inet6.ip6.mcast.maxsocksrc'].should == '128' @ohai["network"]["settings"]['net.inet6.ip6.mcast.loop'].should == '1' @ohai["network"]["settings"]['net.inet6.ip6.only_allow_rfc4193_prefixes'].should == '0' @ohai["network"]["settings"]['net.inet6.ipsec6.def_policy'].should == '1' @ohai["network"]["settings"]['net.inet6.ipsec6.esp_trans_deflev'].should == '1' @ohai["network"]["settings"]['net.inet6.ipsec6.esp_net_deflev'].should == '1' @ohai["network"]["settings"]['net.inet6.ipsec6.ah_trans_deflev'].should == '1' @ohai["network"]["settings"]['net.inet6.ipsec6.ah_net_deflev'].should == '1' @ohai["network"]["settings"]['net.inet6.ipsec6.ecn'].should == '0' @ohai["network"]["settings"]['net.inet6.ipsec6.debug'].should == '0' @ohai["network"]["settings"]['net.inet6.ipsec6.esp_randpad'].should == '-1' @ohai["network"]["settings"]['net.inet6.icmp6.rediraccept'].should == '1' @ohai["network"]["settings"]['net.inet6.icmp6.redirtimeout'].should == '600' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_prune'].should == '1' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_delay'].should == '5' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_umaxtries'].should == '3' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_mmaxtries'].should == '3' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_useloopback'].should == '1' @ohai["network"]["settings"]['net.inet6.icmp6.nodeinfo'].should == '3' @ohai["network"]["settings"]['net.inet6.icmp6.errppslimit'].should == '500' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_maxnudhint'].should == '0' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_debug'].should == '0' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_accept_6to4'].should == '1' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_onlink_ns_rfc4861'].should == '0' @ohai["network"]["settings"]['net.inet6.icmp6.nd6_llreach_base'].should == '30' @ohai["network"]["settings"]['net.inet6.mld.gsrdelay'].should == '10' @ohai["network"]["settings"]['net.inet6.mld.v1enable'].should == '1' @ohai["network"]["settings"]['net.inet6.mld.use_allow'].should == '1' @ohai["network"]["settings"]['net.inet6.mld.debug'].should == '0' @ohai["network"]["settings"]['net.idle.route.expire_timeout'].should == '30' @ohai["network"]["settings"]['net.idle.route.drain_interval'].should == '10' @ohai["network"]["settings"]['net.statistics'].should == '1' @ohai["network"]["settings"]['net.alf.loglevel'].should == '55' @ohai["network"]["settings"]['net.alf.perm'].should == '0' @ohai["network"]["settings"]['net.alf.defaultaction'].should == '1' @ohai["network"]["settings"]['net.alf.mqcount'].should == '0' @ohai["network"]["settings"]['net.smb.fs.version'].should == '107000' @ohai["network"]["settings"]['net.smb.fs.loglevel'].should == '0' @ohai["network"]["settings"]['net.smb.fs.kern_ntlmssp'].should == '0' @ohai["network"]["settings"]['net.smb.fs.kern_deprecatePreXPServers'].should == '1' @ohai["network"]["settings"]['net.smb.fs.kern_deadtimer'].should == '60' @ohai["network"]["settings"]['net.smb.fs.kern_hard_deadtimer'].should == '600' @ohai["network"]["settings"]['net.smb.fs.kern_soft_deadtimer'].should == '30' @ohai["network"]["settings"]['net.smb.fs.tcpsndbuf'].should == '261120' @ohai["network"]["settings"]['net.smb.fs.tcprcvbuf'].should == '261120' end end endohai-6.14.0/spec/ohai/plugins/darwin/platform_spec.rb0000644000175000017500000000631211761755160022043 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin plugin platform" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "darwin" @pid = 10 @stdin = mock("STDIN", { :close => true }) @stdout = mock("STDOUT") @stdout.stub!(:each). and_yield("ProductName: Mac OS X"). and_yield("ProductVersion: 10.5.5"). and_yield("BuildVersion: 9F33") @stderr = mock("STDERR") @ohai.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr) end it "should run sw_vers" do @ohai.should_receive(:popen4).with("/usr/bin/sw_vers").and_return(true) @ohai._require_plugin("darwin::platform") end it "should close sw_vers stdin" do @stdin.should_receive(:close) @ohai._require_plugin("darwin::platform") end it "should iterate over each line of sw_vers stdout" do @stdout.should_receive(:each).and_return(true) @ohai._require_plugin("darwin::platform") end it "should set platform to ProductName, downcased with _ for \\s" do @ohai._require_plugin("darwin::platform") @ohai[:platform].should == "mac_os_x" end it "should set platform_version to ProductVersion" do @ohai._require_plugin("darwin::platform") @ohai[:platform_version].should == "10.5.5" end it "should set platform_build to BuildVersion" do @ohai._require_plugin("darwin::platform") @ohai[:platform_build].should == "9F33" end it "should set platform_family to mac_os_x" do @ohai._require_plugin("darwin::platform") @ohai[:platform_family].should == "mac_os_x" end describe "on os x server" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "darwin" @pid = 10 @stdin = mock("STDIN", { :close => true }) @stdout = mock("STDOUT") @stdout.stub!(:each). and_yield("ProductName: Mac OS X Server"). and_yield("ProductVersion: 10.6.8"). and_yield("BuildVersion: 10K549") @stderr = mock("STDERR") @ohai.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr) end it "should set platform to mac_os_x_server" do @ohai._require_plugin("darwin::platform") @ohai[:platform].should == "mac_os_x_server" end it "should set platform_family to mac_os_x" do @ohai._require_plugin("darwin::platform") @ohai[:platform_family].should == "mac_os_x" end end end ohai-6.14.0/spec/ohai/plugins/solaris2/0000755000175000017500000000000011761755160017130 5ustar tfheentfheenohai-6.14.0/spec/ohai/plugins/solaris2/kernel_spec.rb0000644000175000017500000002144011761755160021750 0ustar tfheentfheen# # Author:: Daniel DeLeo # Copyright:: Copyright (c) 2009 Daniel DeLeo # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Solaris2.X kernel plugin" do # NOTE: Solaris will report the same module loaded multiple times # with the same ID, Loadaddr, etc. and only the info column different # ignoring it, and removing the data from this fixture. MODINFO=<<-TOOMUCH Id Loadaddr Size Info Rev Module Name 6 1180000 4623 1 1 specfs (filesystem for specfs) 8 1185df0 38c4 1 1 TS (time sharing sched class) 9 1188f50 8dc - 1 TS_DPTBL (Time sharing dispatch table) 10 1188fe0 3623e 2 1 ufs (filesystem for ufs) 11 11bc7ae 1ef - 1 fssnap_if (File System Snapshot Interface) 12 11bc8f6 1b3a 1 1 rootnex (sun4u root nexus 1.95) 13 11be023 210 57 1 options (options driver) 15 11be6ff 181a 12 1 sad (STREAMS Administrative Driver ') 16 11bfc79 64b 2 1 pseudo (nexus driver for 'pseudo') 17 11c0152 23563 32 1 sd (SCSI Disk Driver 1.447) 18 11e160d 8c49 - 1 scsi (SCSI Bus Utility Routines) 23 12171db 1072b 50 1 glm (GLM SCSI HBA Driver 1.191.) 24 1225816 edcb 111 1 pcipsy (PCI Bus nexus driver 1.214) 26 123e0eb 15b7 - 1 dada ( ATA Bus Utility Routines) 27 123f30a 722 - 1 todmostek (tod module for Mostek M48T59 1.) 28 11e7342 1a902 5 1 procfs (filesystem for proc) 29 12335a1 da0 134 1 power (power button driver v1.10) 30 1234199 15cb 126 1 ebus (ebus nexus driver 1.44) 32 123f9a4 12215 6 1 sockfs (filesystem for sockfs) 34 12365ba 6ae 11 1 clone (Clone Pseudodriver 'clone') 35 1251709 7b1a6 0 1 ip (IP Streams module) 36 1236a10 34f 1 1 ip6 (IP Streams module) 37 12c56af 282d1 2 1 tcp (TCP Streams module) 38 1236ba4 107d - 1 md5 (MD5 Message-Digest Algorithm) 39 1237b6c 365 3 1 tcp6 (TCP Streams module) 40 1201148 a22f 4 1 udp (UDP Streams module) 41 1237d11 365 5 1 udp6 (UDP Streams module) 42 12096ef 86eb 6 1 icmp (ICMP Streams module) 43 1237eb6 351 7 1 icmp6 (ICMP Streams module) 44 123804c 6d5b 8 1 arp (ARP Streams module) 45 1210282 46ba 9 1 timod (transport interface str mod) 47 12152d1 c53 16 1 conskbd (Console kbd Multiplexer driver ) 48 1215b88 1ec2 15 1 wc (Workstation multiplexer Driver ) 49 12e66d4 516c 37 1 su (su driver 1.80) 51 12ed065 4026 10 1 kb (streams module for keyboard) 52 12efe3b 18c0 11 1 ms (streams module for mouse) 53 12f14f7 a87 17 1 consms (Mouse Driver for Sun 'consms' 5) 54 12f1bf6 b9d6 166 1 gfxp (TSI tspci driver %I%) 55 12fb934 d77 14 1 iwscn (Workstation Redirection driver ) 58 1321301 4a4e 1 1 elfexec (exec module for elf) 62 1328758 10bca - 1 usba (USBA: USB Architecture 1.36) 64 1337002 4884 - 1 mpxio (Multipath Interface Library v1.) 68 131ded0 36d9 3 1 fifofs (filesystem for fifo) 69 131248e 6888 - 1 fctl (Sun FC Transport Library v1.14) 71 1345ddc 18cff - 1 usba10 (USBA10: USB 1.0 Architecture 1.) 75 135b92b f0e2 12 1 ldterm (terminal line discipline) 76 1326309 246d 13 1 ttcompat (alt ioctl calls) 77 133b574 8cbb 29 1 zs (Z8530 serial driver V4.128) 78 1343d27 15d0 26 1 ptsl (tty pseudo driver slave 'ptsl' ) 79 12fc4f3 1e77 25 1 ptc (tty pseudo driver control 'ptc') 81 13748db 1d2c 14 1 rts (Routing Socket Streams module) 88 136a112 ac5a 20 1 se (Siemens SAB 82532 ESCC2 1.128) 89 13cf520 4be3 105 1 tl (TPI Local Transport Driver - tl) 90 13d3d1b 48d3 17 1 keysock (PF_KEY Socket Streams module) 91 13d7766 323f 234 1 spdsock (PF_POLICY Socket Streams device) 92 137c3fb 1672 97 1 sysmsg (System message redirection (fan) 93 12fe1ba 82c 0 1 cn (Console redirection driver 5.57) 94 7814fba6 4b5 2 1 intpexec (exec mod for interp) 95 12fe826 2cb 42 1 pipe (pipe(2) syscall) 96 137d2dd 112d 13 1 mm (memory driver 1.68) 97 13da515 ea79 7 1 hme (10/100Mb Ethernet Driver v1.167) 98 78058000 2e313 85 1 md (Solaris Volume Manager base mod) 99 13e6c82 127bc 226 1 rpcmod (RPC syscall) 100 13f6ab6 1f99 - 1 tlimod (KTLI misc module) 101 13f89a9 54e8 - 1 md_stripe (Solaris Volume Manager stripes ) 102 78086000 13316 - 1 md_mirror (Solaris Volume Manager mirrors ) 103 78084c17 1669 15 1 mntfs (mount information file system) 105 78098156 fe0 12 1 fdfs (filesystem for fd) 106 7809a000 46d7 201 1 doorfs (doors) 107 7809e3c4 16e2 4 1 namefs (filesystem for namefs) 108 780a0000 15ef2 11 1 tmpfs (filesystem for tmpfs) 109 78098ca6 1054 90 1 kstat (kernel statistics driver 1.18) 110 1375e9f 3aa9 88 1 devinfo (DEVINFO Driver 1.48) 111 13fda05 25b9 38 1 openeepr (OPENPROM/NVRAM Driver v1.14) 112 780a5886 9c7 21 1 log (streams log driver) 113 780bc000 2c080 106 1 nfs (NFS syscall, client, and common) 114 780ea000 4e43 - 1 rpcsec (kernel RPC security module.) 115 780f4000 8667 - 1 klmmod (lock mgr common module) 116 780f0000 354c 2 1 FX (Fixed priority sched class) 117 137e232 2ae - 1 FX_DPTBL (Fixed priority dispatch table) 118 780fc000 668b 17 1 autofs (filesystem for autofs) 119 780eeaab 1bba 104 1 random (random number device v1.8) 120 12eb400 1b66 - 1 sha1 (SHA1 Message-Digest Algorithm) 122 780f2788 13b8 - 1 bootdev (bootdev misc module 1.18) 124 78124000 579e 127 1 pm (power management driver v1.104) 125 781106aa 10b7 207 1 pset (processor sets) 126 7812a000 289d 52 1 shmsys (System V shared memory) 127 1216e2a 3dc - 1 ipc (common ipc code) 128 7812e000 ee14 - 1 md_raid (Solaris Volume Manager raid mod) 129 7813e000 d0cd - 1 md_trans (Solaris Volume Manager trans mo) 130 7814c000 2a03 - 1 md_hotspares (Solaris Volume Manager hot spar) 131 7814ab55 1004 - 1 md_notify (Solaris Volume Manager notifica) 132 7809f7f6 903 22 1 sy (Indirect driver for tty 'sy' 1.) 133 780e541c d34 23 1 ptm (Master streams driver 'ptm' 1.4) 134 7812c76d d36 24 1 pts (Slave Stream Pseudo Terminal dr) 135 7814e728 1617 19 1 ptem (pty hardware emulator) 136 780e5eb8 2a5 20 1 redirmod (redirection module) 137 78150000 6b71 91 1 vol (Volume Management Driver, 1.93) 138 13285ad 2cf 21 1 connld (Streams-based pipes) 139 137e27a 109 3 1 IA (interactive scheduling class) 140 7813c544 1b10 22 1 hwc (streams module for hardware cur) 141 78156871 170f 23 1 bufmod (streams buffer mod) 142 1325c4c 838 72 1 ksyms (kernel symbols driver 1.25) 143 12fea22 14864 33 1 st (SCSI tape Driver 1.238) 144 1379790 2a12 53 1 semsys (System V semaphore facility) 145 12138e4 15e4 4 1 RT (realtime scheduling class) 146 121719e 28c - 1 RT_DPTBL (realtime dispatch table) TOOMUCH before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:kernel] = Mash.new @ohai.stub(:from).with("uname -s").and_return("SunOS") end it_should_check_from_deep_mash("solaris2::kernel", "kernel", "os", "uname -s", "SunOS") it "gives excruciating detail about kernel modules" do stdin = StringIO.new @modinfo_stdout = StringIO.new(MODINFO) @ohai.stub!(:popen4).with("modinfo").and_yield(nil, stdin, @modinfo_stdout, nil) @ohai._require_plugin("solaris2::kernel") @ohai[:kernel][:modules].should have(107).modules # Teh daterz # Id Loadaddr Size Info Rev Module Name # 6 1180000 4623 1 1 specfs (filesystem for specfs) teh_daterz = { "id" => 6, "loadaddr" => "1180000", "size" => 17955, "description" => "filesystem for specfs"} @ohai[:kernel][:modules].keys.should include("specfs") @ohai[:kernel][:modules].keys.should_not include("Module") @ohai[:kernel][:modules]["specfs"].should == teh_daterz end end ohai-6.14.0/spec/ohai/plugins/solaris2/hostname_spec.rb0000644000175000017500000000263411761755160022312 0ustar tfheentfheen# # Author:: Daniel DeLeo # Copyright:: Copyright (c) 2009 Daniel DeLeo # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Solaris2.X hostname plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "solaris2" @ohai.stub!(:from).with("hostname").and_return("kitteh") Socket.stub!(:getaddrinfo).and_return( [["AF_INET", 0, "kitteh.inurfridge.eatinurfoodz", "10.1.2.3", 2, 0, 0]] ); end it_should_check_from("solaris2::hostname", "hostname", "hostname", "kitteh") it "should get the fqdn value from socket getaddrinfo" do Socket.should_receive(:getaddrinfo) @ohai._require_plugin("solaris2::hostname") @ohai["fqdn"].should == "kitteh.inurfridge.eatinurfoodz" end endohai-6.14.0/spec/ohai/plugins/solaris2/network_spec.rb0000644000175000017500000001244511761755160022166 0ustar tfheentfheen# # Author:: Daniel DeLeo # Copyright:: Copyright (c) 2010 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Solaris2.X network plugin" do before do solaris_ifconfig = <<-ENDIFCONFIG lo0:3: flags=2001000849 mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 e1000g0:3: flags=201000843 mtu 1500 index 3 inet 72.2.115.28 netmask ffffff80 broadcast 72.2.115.127 e1000g2:1: flags=201000843 mtu 1500 index 4 inet 10.2.115.28 netmask ffffff80 broadcast 10.2.115.127 inet6 2001:0db8:3c4d:55:a00:20ff:fe8e:f3ad/64 ip.tun0: flags=2200851 mtu 1480 index 3 inet tunnel src 109.146.85.57 tunnel dst 109.146.85.212 tunnel security settings --> use 'ipsecconf -ln -i ip.tun1' tunnel hop limit 60 inet6 fe80::6d92:5539/10 --> fe80::6d92:55d4 ip.tun0:1: flags=2200851 mtu 1480 index 3 inet6 2::45/128 --> 2::46 lo0: flags=1000849 mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 eri0: flags=1004843 mtu 1500 \ index 2 inet 172.17.128.208 netmask ffffff00 broadcast 172.17.128.255 ip6.tun0: flags=10008d1 \ mtu 1460 index 3 inet6 tunnel src fe80::1 tunnel dst fe80::2 tunnel security settings --> use 'ipsecconf -ln -i ip.tun1' tunnel hop limit 60 tunnel encapsulation limit 4 inet 10.0.0.208 --> 10.0.0.210 netmask ff000000 qfe1: flags=2000841 mtu 1500 index 3 usesrc vni0 inet6 fe80::203:baff:fe17:4be0/10 ether 0:3:ba:17:4b:e0 vni0: flags=2002210041 mtu 0 index 5 srcof qfe1 inet6 fe80::203:baff:fe17:4444/128 ENDIFCONFIG solaris_netstat_rn = <<-NETSTAT_RN Routing Table: IPv4 Destination Gateway Flags Ref Use Interface -------------------- -------------------- ----- ----- ---------- --------- default 10.13.37.1 UG 1 0 e1000g0 10.13.37.0 10.13.37.157 U 1 2 e1000g0 127.0.0.1 127.0.0.1 UH 1 35 lo0 Routing Table: IPv6 Destination/Mask Gateway Flags Ref Use If --------------------------- --------------------------- ----- --- ------- ----- fe80::/10 fe80::250:56ff:fe13:3757 U 1 0 e1000g0 ::1 ::1 UH 1 0 lo0 NETSTAT_RN @solaris_route_get = <<-ROUTE_GET route to: default destination: default mask: default gateway: 10.13.37.1 interface: e1000g0 flags: recvpipe sendpipe ssthresh rtt,ms rttvar,ms hopcount mtu expire 0 0 0 0 0 0 1500 0 ROUTE_GET @stdin = StringIO.new @ifconfig_lines = solaris_ifconfig.split("\n") @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:network] = Mash.new @ohai.stub(:popen4).with("ifconfig -a") @ohai.stub(:popen4).with("arp -an") end describe "gathering IP layer address info" do before do @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin, @ifconfig_lines, nil) @ohai._require_plugin("solaris2::network") end it "completes the run" do @ohai['network'].should_not be_nil end it "detects the interfaces" do @ohai['network']['interfaces'].keys.sort.should == ["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "lo0", "lo0:3", "qfe1"] end it "detects the ip addresses of the interfaces" do @ohai['network']['interfaces']['e1000g0:3']['addresses'].keys.should include('72.2.115.28') end it "detects the encapsulation type of the interfaces" do @ohai['network']['interfaces']['e1000g0:3']['encapsulation'].should == 'Ethernet' end end # TODO: specs for the arp -an stuff, check that it correctly adds the MAC addr to the right iface, etc. describe "setting the node's default IP address attribute" do before do @stdout = mock("Pipe, stdout, cmd=`route get default`", :read => @solaris_route_get) @ohai.stub!(:popen4).with("route -n get default").and_yield(nil,@stdin, @stdout, nil) @ohai._require_plugin("solaris2::network") end it "finds the default interface by asking which iface has the default route" do @ohai[:network][:default_interface].should == 'e1000g0' end end end ohai-6.14.0/spec/ohai/plugins/solaris2/virtualization_spec.rb0000644000175000017500000001133611761755160023557 0ustar tfheentfheen# # Author:: Sean Walbran () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Solaris virtualization platform" do before(:each) do @ohai = Ohai::System.new @ohai[:os] = "solaris2" @ohai.stub!(:require_plugin).and_return(true) @ohai.extend(SimpleFromFile) # default to all requested Files not existing File.stub!(:exists?).with("/usr/sbin/psrinfo").and_return(false) File.stub!(:exists?).with("/usr/sbin/smbios").and_return(false) File.stub!(:exists?).with("/usr/sbin/zoneadm").and_return(false) end describe "when we are checking for kvm" do before(:each) do File.should_receive(:exists?).with("/usr/sbin/psrinfo").and_return(true) @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 end it "should run psrinfo -pv" do @ohai.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true) @ohai._require_plugin("solaris2::virtualization") end it "Should set kvm guest if psrinfo -pv contains QEMU Virtual CPU" do @stdout.stub!(:read).and_return("QEMU Virtual CPU") @ohai.stub!(:popen4).with("/usr/sbin/psrinfo -pv").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("solaris2::virtualization") @ohai[:virtualization][:system].should == "kvm" @ohai[:virtualization][:role].should == "guest" end it "should not set virtualization if kvm isn't there" do @ohai.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true) @ohai._require_plugin("solaris2::virtualization") @ohai[:virtualization].should == {} end end describe "when we are parsing smbios" do before(:each) do File.should_receive(:exists?).with("/usr/sbin/smbios").and_return(true) @stdin = mock("STDIN", { :close => true }) @pid = 20 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 end it "should run smbios" do @ohai.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true) @ohai._require_plugin("solaris2::virtualization") end it "should set virtualpc guest if smbios detects Microsoft Virtual Machine" do ms_vpc_smbios=<<-MSVPC ID SIZE TYPE 1 72 SMB_TYPE_SYSTEM (system information) Manufacturer: Microsoft Corporation Product: Virtual Machine Version: VS2005R2 Serial Number: 1688-7189-5337-7903-2297-1012-52 UUID: D29974A4-BE51-044C-BDC6-EFBC4B87A8E9 Wake-Up Event: 0x6 (power switch) MSVPC @stdout.stub!(:read).and_return(ms_vpc_smbios) @ohai.stub!(:popen4).with("/usr/sbin/smbios").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("solaris2::virtualization") @ohai[:virtualization][:system].should == "virtualpc" @ohai[:virtualization][:role].should == "guest" end it "should set vmware guest if smbios detects VMware Virtual Platform" do vmware_smbios=<<-VMWARE ID SIZE TYPE 1 72 SMB_TYPE_SYSTEM (system information) Manufacturer: VMware, Inc. Product: VMware Virtual Platform Version: None Serial Number: VMware-50 3f f7 14 42 d1 f1 da-3b 46 27 d0 29 b4 74 1d UUID: a86cc405-e1b9-447b-ad05-6f8db39d876a Wake-Up Event: 0x6 (power switch) VMWARE @stdout.stub!(:read).and_return(vmware_smbios) @ohai.stub!(:popen4).with("/usr/sbin/smbios").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("solaris2::virtualization") @ohai[:virtualization][:system].should == "vmware" @ohai[:virtualization][:role].should == "guest" end it "should run smbios and not set virtualization if nothing is detected" do @ohai.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true) @ohai._require_plugin("solaris2::virtualization") @ohai[:virtualization].should == {} end end it "should not set virtualization if no tests match" do @ohai._require_plugin("solaris2::virtualization") @ohai[:virtualization].should == {} end end ohai-6.14.0/spec/ohai/plugins/solaris2/platform_spec.rb0000644000175000017500000000442711761755160022322 0ustar tfheentfheen# # Author:: Trevor O () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Solaris plugin platform" do before(:each) do @ohai = Ohai::System.new @ohai.extend(SimpleFromFile) @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "solaris2" @ohai.stub!(:popen4).with("/sbin/uname -X") end describe "on SmartOS" do before(:each) do uname_x = <<-UNAME_X System = SunOS Node = node.example.com Release = 5.11 KernelID = joyent_20120130T201844Z Machine = i86pc BusType = Serial = Users = OEM# = 0 Origin# = 1 NumCPU = 16 UNAME_X @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @status = 0 @uname_x_lines = uname_x.split("\n") File.stub!(:exists?).with("/sbin/uname").and_return(true) @ohai.stub(:popen4).with("/sbin/uname -X").and_yield(@pid, @stdin, @uname_x_lines, @stderr).and_return(@status) @release = StringIO.new(" SmartOS 20120130T201844Z x86_64\n") @mock_file.stub!(:close).and_return(0) File.stub!(:open).with("/etc/release").and_yield(@release) end it "should run uname and set platform and build" do @ohai._require_plugin("solaris2::platform") @ohai[:platform_build].should == "joyent_20120130T201844Z" end it "should set the platform" do @ohai._require_plugin("solaris2::platform") @ohai[:platform].should == "smartos" end it "should set the platform_version" do @ohai._require_plugin("solaris2::platform") @ohai[:platform_version].should == "5.11" end end end ohai-6.14.0/spec/ohai/plugins/netbsd/0000755000175000017500000000000011761755160016651 5ustar tfheentfheenohai-6.14.0/spec/ohai/plugins/netbsd/kernel_spec.rb0000644000175000017500000000243611761755160021475 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "NetBSD kernel plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai.stub!(:from).with("uname -i").and_return("foo") @ohai.stub!(:from_with_regex).with("sysctl kern.securelevel").and_return("kern.securelevel: 1") @ohai[:kernel] = Mash.new @ohai[:kernel][:name] = "netbsd" end it "should set the kernel_os to the kernel_name value" do @ohai._require_plugin("netbsd::kernel") @ohai[:kernel][:os].should == @ohai[:kernel][:name] end end ohai-6.14.0/spec/ohai/plugins/netbsd/hostname_spec.rb0000644000175000017500000000232611761755160022031 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "NetBSD hostname plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "netbsd" @ohai.stub!(:from).with("hostname -s").and_return("katie") @ohai.stub!(:from).with("hostname").and_return("katie.bethell") end it_should_check_from("netbsd::hostname", "hostname", "hostname -s", "katie") it_should_check_from("netbsd::hostname", "fqdn", "hostname", "katie.bethell") end ohai-6.14.0/spec/ohai/plugins/netbsd/platform_spec.rb0000644000175000017500000000252411761755160022037 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "NetBSD plugin platform" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai.stub!(:from).with("uname -s").and_return("NetBSD") @ohai.stub!(:from).with("uname -r").and_return("4.5") @ohai[:os] = "netbsd" end it "should set platform to lowercased lsb[:id]" do @ohai._require_plugin("netbsd::platform") @ohai[:platform].should == "netbsd" end it "should set platform_version to lsb[:release]" do @ohai._require_plugin("netbsd::platform") @ohai[:platform_version].should == "4.5" end end ohai-6.14.0/spec/ohai/plugins/erlang_spec.rb0000644000175000017500000000447311761755160020211 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin erlang" do before(:each) do @ohai = Ohai::System.new @ohai[:languages] = Mash.new @ohai.stub!(:require_plugin).and_return(true) @status = 0 @stdin = "" @stderr = "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n" @ohai.stub!(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([@status, @stdout, @stderr]) end it "should get the erlang version from erl +V" do @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([0, "", "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"]) @ohai._require_plugin("erlang") end it "should set languages[:erlang][:version]" do @ohai._require_plugin("erlang") @ohai.languages[:erlang][:version].should eql("5.6.2") end it "should set languages[:erlang][:options]" do @ohai._require_plugin("erlang") @ohai.languages[:erlang][:options].should eql(["ASYNC_THREADS", "SMP", "HIPE"]) end it "should set languages[:erlang][:emulator]" do @ohai._require_plugin("erlang") @ohai.languages[:erlang][:emulator].should eql("BEAM") end it "should not set the languages[:erlang] tree up if erlang command fails" do @status = 1 @stdin = "" @stderr = "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n" @ohai.stub!(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("erlang") @ohai.languages.should_not have_key(:erlang) end end ohai-6.14.0/spec/ohai/plugins/mono_spec.rb0000644000175000017500000000421111761755160017677 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2009 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')) describe Ohai::System, "plugin mono" do before(:each) do @ohai = Ohai::System.new @ohai[:languages] = Mash.new @ohai.stub!(:require_plugin).and_return(true) @status = 0 @stdout = "Mono JIT compiler version 1.2.6 (tarball)\nCopyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com\n" @stderr = "" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([@status, @stdout, @stderr]) end it "should get the mono version from running mono -V" do @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([0, "Mono JIT compiler version 1.2.6 (tarball)\nCopyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com\n", ""]) @ohai._require_plugin("mono") end it "should set languages[:mono][:version]" do @ohai._require_plugin("mono") @ohai.languages[:mono][:version].should eql("1.2.6") end it "should not set the languages[:mono] tree up if mono command fails" do @status = 1 @stdout = "Mono JIT compiler version 1.2.6 (tarball)\nCopyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com\n" @stderr = "" @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([@status, @stdout, @stderr]) @ohai._require_plugin("mono") @ohai.languages.should_not have_key(:mono) end end ohai-6.14.0/spec/ohai/plugins/linux/0000755000175000017500000000000011761755160016531 5ustar tfheentfheenohai-6.14.0/spec/ohai/plugins/linux/kernel_spec.rb0000644000175000017500000000211611761755160021350 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux kernel plugin" do before(:each) do @ohai = Ohai::System.new @ohai._require_plugin("kernel") @ohai.stub!(:require_plugin).and_return(true) @ohai.stub!(:from).with("uname -o").and_return("Linux") end it_should_check_from_deep_mash("linux::kernel", "kernel", "os", "uname -o", "Linux") endohai-6.14.0/spec/ohai/plugins/linux/hostname_spec.rb0000644000175000017500000000322211761755160021705 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux hostname plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "linux" @ohai.stub!(:from).with("hostname -s").and_return("katie") @ohai.stub!(:from).with("hostname --fqdn").and_return("katie.bethell") end it_should_check_from("linux::hostname", "hostname", "hostname -s", "katie") it_should_check_from("linux::hostname", "fqdn", "hostname --fqdn", "katie.bethell") describe "when domain name is unset" do before(:each) do @ohai.should_receive(:from).with("hostname --fqdn").and_raise("Ohai::Exception::Exec") end it "should not raise an error" do lambda { @ohai._require_plugin("linux::hostname") }.should_not raise_error end it "should not set fqdn" do @ohai._require_plugin("linux::hostname") @ohai.fqdn.should == nil end end end ohai-6.14.0/spec/ohai/plugins/linux/network_spec.rb0000644000175000017500000012565411761755160021576 0ustar tfheentfheen# # Author:: Caleb Tennis # Copyright:: Copyright (c) 2011 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') begin require 'ipaddress' rescue LoadError => e puts "The linux network plugin spec tests will fail without the 'ipaddress' library/gem.\n\n" raise e end def prepare_data @ifconfig_lines = @linux_ifconfig.split("\n") @route_lines = @linux_route_n.split("\n") @arp_lines = @linux_arp_an.split("\n") @ipaddr_lines = @linux_ip_addr.split("\n") @iplink_lines = @linux_ip_link_s_d.split("\n") @ipneighbor_lines = @linux_ip_neighbor_show.split("\n") @ipneighbor_lines_inet6 = @linux_ip_inet6_neighbor_show.split("\n") @ip_route_lines = @linux_ip_route.split("\n") @ip_route_inet6_lines = @linux_ip_route_inet6.split("\n") end def do_stubs @ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last) @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil) @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil) @ohai.stub!(:popen4).with("ip -f inet neigh show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil) @ohai.stub!(:popen4).with("ip -f inet6 neigh show").and_yield(nil, @stdin_ipneighbor_inet6, @ipneighbor_lines_inet6, nil) @ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil) @ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil) @ohai.stub!(:popen4).with("ip -f inet route show").and_yield(nil, @stdin_ip_route, @ip_route_lines, nil) @ohai.stub!(:popen4).with("ip -f inet6 route show").and_yield(nil, @stdin_ip_route_inet6, @ip_route_inet6_lines, nil) end describe Ohai::System, "Linux Network Plugin" do before do @linux_ifconfig = <<-ENDIFCONFIG eth0 Link encap:Ethernet HWaddr 12:31:3D:02:BE:A2 inet addr:10.116.201.76 Bcast:10.116.201.255 Mask:255.255.255.0 inet6 addr: fe80::1031:3dff:fe02:bea2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2659966 errors:0 dropped:0 overruns:0 frame:0 TX packets:1919690 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1392844460 (1.2 GiB) TX bytes:691785313 (659.7 MiB) Interrupt:16 eth0:5 Link encap:Ethernet HWaddr 00:0c:29:41:71:45 inet addr:192.168.5.1 Bcast:192.168.5.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 eth0.11 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link inet6 addr: 1111:2222:3333:4444::2/64 Scope:Global inet6 addr: 1111:2222:3333:4444::3/64 Scope:Global UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1208795008 errors:0 dropped:0 overruns:0 frame:0 TX packets:3269635153 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1751940374 (1.6 GiB) TX bytes:2195567597 (2.0 GiB) eth0.151 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee inet addr:10.151.0.16 Bcast:10.151.0.255 Mask:255.255.255.0 inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:206553677 errors:0 dropped:0 overruns:0 frame:0 TX packets:163901336 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:3190792261 (2.9 GiB) TX bytes:755086548 (720.1 MiB) eth0.152 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee inet addr:10.152.1.16 Bcast:10.152.3.255 Mask:255.255.252.0 inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:14016741 errors:0 dropped:0 overruns:0 frame:0 TX packets:55232 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:664957462 (634.1 MiB) TX bytes:4876434 (4.6 MiB) eth0.153 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee inet addr:10.153.1.16 Bcast:10.153.3.255 Mask:255.255.252.0 inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2022667595 errors:0 dropped:0 overruns:0 frame:0 TX packets:1798627472 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4047036732 (3.7 GiB) TX bytes:3451231474 (3.2 GiB) foo:veth0@eth0 Link encap:Ethernet HWaddr ca:b3:73:8b:0c:e4 BROADCAST MULTICAST MTU:1500 Metric:1 tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:172.16.19.39 P-t-P:172.16.19.1 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1 RX packets:57200 errors:0 dropped:0 overruns:0 frame:0 TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB) venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1 RX packets:57200 errors:0 dropped:0 overruns:0 frame:0 TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB) venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1 RX packets:57200 errors:0 dropped:0 overruns:0 frame:0 TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:524 errors:0 dropped:0 overruns:0 frame:0 TX packets:524 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:35224 (34.3 KiB) TX bytes:35224 (34.3 KiB) ENDIFCONFIG # Note that ifconfig shows foo:veth0@eth0 but fails to show any address information. # This was not a mistake collecting the output and Apparently ifconfig is broken in this regard. @linux_ip_addr = <<-IP_ADDR 1: lo: mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff inet 10.116.201.76/24 brd 10.116.201.255 scope global eth0 inet 10.116.201.75/32 scope global eth0 inet 10.116.201.74/24 scope global secondary eth0 inet 192.168.5.1/24 brd 192.168.5.255 scope global eth0:5 inet6 fe80::1031:3dff:fe02:bea2/64 scope link valid_lft forever preferred_lft forever inet6 2001:44b8:4160:8f00:a00:27ff:fe13:eacd/64 scope global dynamic valid_lft 6128sec preferred_lft 2526sec 3: eth0.11@eth0: mtu 1500 qdisc noqueue state UP link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff inet 192.168.0.16/24 brd 192.168.0.255 scope global eth0.11 inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link inet6 1111:2222:3333:4444::2/64 scope global valid_lft forever preferred_lft forever inet6 1111:2222:3333:4444::3/64 scope global valid_lft forever preferred_lft forever 4: eth0.151@eth0: mtu 1500 qdisc noqueue state UP link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff inet 10.151.0.16/24 brd 10.151.0.255 scope global eth0.151 inet 10.151.1.16/24 scope global eth0.151 inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link valid_lft forever preferred_lft forever 5: eth0.152@eth0: mtu 1500 qdisc noqueue state UP link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff inet 10.152.1.16/22 brd 10.152.3.255 scope global eth0.152 inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link valid_lft forever preferred_lft forever 6: eth0.153@eth0: mtu 1500 qdisc noqueue state UP link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff inet 10.153.1.16/22 brd 10.153.3.255 scope global eth0.153 inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link valid_lft forever preferred_lft forever 7: foo:veth0@eth0@veth0: mtu 1500 qdisc noop state DOWN link/ether ca:b3:73:8b:0c:e4 brd ff:ff:ff:ff:ff:ff inet 192.168.212.2/24 scope global foo:veth0@eth0 8: tun0: mtu 1500 qdisc mq state UP qlen 1000 link/none inet 172.16.19.39 peer 172.16.19.1 scope global tun0 9: venet0: mtu 1500 qdisc mq state UP qlen 1000 link/void inet 127.0.0.2/32 scope host venet0 inet 172.16.19.48/32 scope global venet0:0 IP_ADDR @linux_ip_link_s_d = <<-IP_LINK_S 1: lo: mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 RX: bytes packets errors dropped overrun mcast 35224 524 0 0 0 0 TX: bytes packets errors dropped carrier collsns 35224 524 0 0 0 0 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast 1392844460 2659966 0 0 0 0 TX: bytes packets errors dropped carrier collsns 691785313 1919690 0 0 0 0 3: eth0.11@eth0: mtu 1500 qdisc noqueue state UP link/ether 00:0c:29:41:71:45 brd ff:ff:ff:ff:ff:ff vlan id 11 RX: bytes packets errors dropped overrun mcast 0 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 0 0 0 0 0 0 4: tun0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100 link/none RX: bytes packets errors dropped overrun mcast 1392844460 2659966 0 0 0 0 TX: bytes packets errors dropped carrier collsns 691785313 1919690 0 0 0 0 5: venet0: mtu 1500 qdisc mq state UP qlen 1000 link/void RX: bytes packets errors dropped overrun mcast 1392844460 2659966 0 0 0 0 TX: bytes packets errors dropped carrier collsns 691785313 1919690 0 0 0 0 IP_LINK_S @linux_route_n = <<-ROUTE_N Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 0.0.0.0 10.116.201.1 0.0.0.0 UG 0 0 0 eth0 ROUTE_N @linux_arp_an = <<-ARP_AN ? (10.116.201.1) at fe:ff:ff:ff:ff:ff [ether] on eth0 ARP_AN @linux_ip_neighbor_show = <<-NEIGHBOR_SHOW 10.116.201.1 dev eth0 lladdr fe:ff:ff:ff:ff:ff REACHABLE NEIGHBOR_SHOW @linux_ip_inet6_neighbor_show = <<-NEIGHBOR_SHOW 1111:2222:3333:4444::1 dev eth0.11 lladdr 00:1c:0e:12:34:56 router REACHABLE fe80::21c:eff:fe12:3456 dev eth0.11 lladdr 00:1c:0e:30:28:00 router REACHABLE fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE NEIGHBOR_SHOW @linux_ip_route = <<-IP_ROUTE_SCOPE 10.116.201.0/24 dev eth0 proto kernel 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 default via 10.116.201.1 dev eth0 IP_ROUTE_SCOPE @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 expires 86023sec default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 IP_ROUTE_SCOPE @stdin_ifconfig = StringIO.new @stdin_arp = StringIO.new @stdin_ipaddr = StringIO.new @stdin_iplink = StringIO.new @stdin_ipneighbor = StringIO.new @stdin_ipneighbor_inet6 = StringIO.new @stdin_ip_route = StringIO.new @stdin_ip_route_inet6 = StringIO.new prepare_data @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai.stub(:popen4).with("ifconfig -a") @ohai.stub(:popen4).with("arp -an") end ["ifconfig","iproute2"].each do |network_method| describe "gathering IP layer address info via #{network_method}" do before do File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" ) do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "detects the interfaces" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces'].keys.sort.should == ["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "foo:veth0@eth0", "lo", "tun0", "venet0", "venet0:0"] end it "detects the ipv4 addresses of the ethernet interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('10.116.201.76') @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['netmask'].should == '255.255.255.0' @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['broadcast'].should == '10.116.201.255' @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['family'].should == 'inet' end it "detects the ipv4 addresses of an ethernet subinterface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0.11']['addresses'].keys.should include('192.168.0.16') @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['netmask'].should == '255.255.255.0' @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['broadcast'].should == '192.168.0.255' @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['family'].should == 'inet' end it "detects the ipv6 addresses of the ethernet interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('fe80::1031:3dff:fe02:bea2') @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['scope'].should == 'Link' @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['prefixlen'].should == '64' @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['family'].should == 'inet6' end it "detects the ipv6 addresses of an ethernet subinterface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") %w[ 1111:2222:3333:4444::2 1111:2222:3333:4444::3 ].each do |addr| @ohai['network']['interfaces']['eth0.11']['addresses'].keys.should include(addr) @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['scope'].should == 'Global' @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['prefixlen'].should == '64' @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['family'].should == 'inet6' end end it "detects the mac addresses of the ethernet interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('12:31:3D:02:BE:A2') @ohai['network']['interfaces']['eth0']['addresses']['12:31:3D:02:BE:A2']['family'].should == 'lladdr' end it "detects the encapsulation type of the ethernet interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0']['encapsulation'].should == 'Ethernet' end it "detects the flags of the ethernet interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") if network_method == "ifconfig" @ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','MULTICAST','RUNNING','UP'] else @ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','LOWER_UP','MULTICAST','UP'] end end it "detects the number of the ethernet interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0']['number'].should == "0" end it "detects the mtu of the ethernet interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0']['mtu'].should == "1500" end it "detects the ipv4 addresses of the loopback interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['lo']['addresses'].keys.should include('127.0.0.1') @ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0' @ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['family'].should == 'inet' end it "detects the ipv6 addresses of the loopback interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['lo']['addresses'].keys.should include('::1') @ohai['network']['interfaces']['lo']['addresses']['::1']['scope'].should == 'Node' @ohai['network']['interfaces']['lo']['addresses']['::1']['prefixlen'].should == '128' @ohai['network']['interfaces']['lo']['addresses']['::1']['family'].should == 'inet6' end it "detects the encapsulation type of the loopback interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['lo']['encapsulation'].should == 'Loopback' end it "detects the flags of the ethernet interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") if network_method == "ifconfig" @ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','RUNNING','UP'] else @ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','LOWER_UP','UP'] end end it "detects the mtu of the loopback interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['lo']['mtu'].should == "16436" end it "detects the arp entries" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0']['arp']['10.116.201.1'].should == 'fe:ff:ff:ff:ff:ff' end end describe "gathering interface counters via #{network_method}" do before do File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" ) do_stubs @ohai._require_plugin("network") @ohai._require_plugin("linux::network") end it "detects the ethernet counters" do @ohai['counters']['network']['interfaces']['eth0']['tx']['bytes'].should == "691785313" @ohai['counters']['network']['interfaces']['eth0']['tx']['packets'].should == "1919690" @ohai['counters']['network']['interfaces']['eth0']['tx']['collisions'].should == "0" @ohai['counters']['network']['interfaces']['eth0']['tx']['queuelen'].should == "1000" @ohai['counters']['network']['interfaces']['eth0']['tx']['errors'].should == "0" @ohai['counters']['network']['interfaces']['eth0']['tx']['carrier'].should == "0" @ohai['counters']['network']['interfaces']['eth0']['tx']['drop'].should == "0" @ohai['counters']['network']['interfaces']['eth0']['rx']['bytes'].should == "1392844460" @ohai['counters']['network']['interfaces']['eth0']['rx']['packets'].should == "2659966" @ohai['counters']['network']['interfaces']['eth0']['rx']['errors'].should == "0" @ohai['counters']['network']['interfaces']['eth0']['rx']['overrun'].should == "0" @ohai['counters']['network']['interfaces']['eth0']['rx']['drop'].should == "0" end it "detects the loopback counters" do @ohai['counters']['network']['interfaces']['lo']['tx']['bytes'].should == "35224" @ohai['counters']['network']['interfaces']['lo']['tx']['packets'].should == "524" @ohai['counters']['network']['interfaces']['lo']['tx']['collisions'].should == "0" @ohai['counters']['network']['interfaces']['lo']['tx']['errors'].should == "0" @ohai['counters']['network']['interfaces']['lo']['tx']['carrier'].should == "0" @ohai['counters']['network']['interfaces']['lo']['tx']['drop'].should == "0" @ohai['counters']['network']['interfaces']['lo']['rx']['bytes'].should == "35224" @ohai['counters']['network']['interfaces']['lo']['rx']['packets'].should == "524" @ohai['counters']['network']['interfaces']['lo']['rx']['errors'].should == "0" @ohai['counters']['network']['interfaces']['lo']['rx']['overrun'].should == "0" @ohai['counters']['network']['interfaces']['lo']['rx']['drop'].should == "0" end end describe "setting the node's default IP address attribute with #{network_method}" do before do File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" ) do_stubs end describe "without a subinterface" do before do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") end it "finds the default interface by asking which iface has the default route" do @ohai['network']['default_interface'].should == 'eth0' end it "finds the default gateway by asking which iface has the default route" do @ohai['network']['default_gateway'].should == '10.116.201.1' end end describe "with a link level default route" do before do @linux_ip_route = <<-IP_ROUTE 10.116.201.0/24 dev eth0 proto kernel default dev eth0 scope link IP_ROUTE @linux_route_n = <<-ROUTE_N Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth0 ROUTE_N prepare_data do_stubs @ohai._require_plugin("network") @ohai._require_plugin("linux::network") end it "finds the default interface by asking which iface has the default route" do @ohai['network']['default_interface'].should == 'eth0' end it "finds the default interface by asking which iface has the default route" do @ohai['network']['default_gateway'].should == '0.0.0.0' end end describe "with a subinterface" do before do @linux_ip_route = <<-IP_ROUTE 192.168.0.0/24 dev eth0.11 proto kernel src 192.168.0.2 default via 192.168.0.15 dev eth0.11 IP_ROUTE @linux_route_n = <<-ROUTE_N Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.11 0.0.0.0 192.168.0.15 0.0.0.0 UG 0 0 0 eth0.11 ROUTE_N prepare_data do_stubs @ohai._require_plugin("network") @ohai._require_plugin("linux::network") end it "finds the default interface by asking which iface has the default route" do @ohai['network']["default_interface"].should == 'eth0.11' end it "finds the default interface by asking which iface has the default route" do @ohai['network']["default_gateway"].should == '192.168.0.15' end end end end describe "for newer network features using iproute2 only" do before do File.stub!(:exist?).with("/sbin/ip").and_return(true) # iproute2 only do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "finds the default inet6 interface if there's a inet6 default route" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['default_inet6_interface'].should == 'eth0.11' end it "finds the default inet6 gateway if there's a inet6 default route" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::1' end it "finds inet6 neighbours" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0.11']['neighbour_inet6']['1111:2222:3333:4444::1'].should == '00:1c:0e:12:34:56' end it "detects the ipv4 addresses of an ethernet interface with a crazy name" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['foo:veth0@eth0']['addresses'].keys.should include('192.168.212.2') @ohai['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['netmask'].should == '255.255.255.0' @ohai['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['family'].should == 'inet' end it "generates a fake interface for ip aliases for backward compatibility" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0:5']['addresses'].keys.should include('192.168.5.1') @ohai['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['netmask'].should == '255.255.255.0' @ohai['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['family'].should == 'inet' end it "adds the vlan information of an interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0.11']['vlan']['id'].should == '11' @ohai['network']['interfaces']['eth0.11']['vlan']['flags'].should == [ 'REORDER_HDR' ] end it "adds the state of an interface" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0.11']['state'].should == 'up' end describe "when dealing with routes" do it "adds routes" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.116.201.0/24", :proto => "kernel", :family =>"inet" ) @ohai['network']['interfaces']['foo:veth0@eth0']['routes'].should include Mash.new( :destination => "192.168.212.0/24", :proto => "kernel", :src => "192.168.212.2", :family =>"inet" ) @ohai['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "fe80::/64", :metric => "256", :proto => "kernel", :family => "inet6" ) @ohai['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "1111:2222:3333:4444::/64", :metric => "1024", :family => "inet6" ) @ohai['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "default", :via => "1111:2222:3333:4444::1", :metric => "1024", :family => "inet6") end describe "when there isn't a source field in route entries " do it "doesn't set ipaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ipaddress'].should be nil end it "doesn't set macaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['macaddress'].should be nil end it "doesn't set ip6address" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ip6address'].should be nil end end describe "when there's a source field in the default route entry" do before do @linux_ip_route = <<-IP_ROUTE_SCOPE 10.116.201.0/24 dev eth0 proto kernel 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 default via 10.116.201.1 dev eth0 src 10.116.201.76 IP_ROUTE_SCOPE @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 IP_ROUTE_SCOPE prepare_data do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "sets ipaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ipaddress'].should == "10.116.201.76" end it "sets ip6address" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ip6address'].should == "1111:2222:3333:4444::3" end end describe "when there're several default routes" do before do @linux_ip_route = <<-IP_ROUTE_SCOPE 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 default via 10.116.201.1 dev eth0 metric 10 default via 10.116.201.254 dev eth0 metric 9 IP_ROUTE_SCOPE @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 IP_ROUTE_SCOPE prepare_data do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "sets default ipv4 interface and gateway" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['default_interface'].should == 'eth0' @ohai['network']['default_gateway'].should == '10.116.201.254' end it "sets default ipv6 interface and gateway" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['default_inet6_interface'].should == 'eth0.11' @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::ffff' end end describe "when there're a mixed setup of routes that could be used to set ipaddress" do before do @linux_ip_route = <<-IP_ROUTE_SCOPE 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 default via 10.116.201.1 dev eth0 metric 10 default via 10.116.201.254 dev eth0 metric 9 src 10.116.201.74 IP_ROUTE_SCOPE @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 src 1111:2222:3333:4444::2 IP_ROUTE_SCOPE prepare_data do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "sets ipaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai["ipaddress"].should == "10.116.201.74" end it "sets ip6address" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai["ip6address"].should == "1111:2222:3333:4444::2" end end describe "when there's a source field in a local route entry " do before do @linux_ip_route = <<-IP_ROUTE_SCOPE 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 default via 10.116.201.1 dev eth0 IP_ROUTE_SCOPE @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 IP_ROUTE_SCOPE prepare_data do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "sets ipaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ipaddress'].should == "10.116.201.76" end describe "when about to set macaddress" do it "sets macaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['macaddress'].should == "12:31:3D:02:BE:A2" end describe "when then interface has the NOARP flag" do before do @linux_ip_route = <<-IP_ROUTE 10.118.19.1 dev tun0 proto kernel src 10.118.19.39 default via 172.16.19.1 dev tun0 IP_ROUTE prepare_data do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "doesn't set macaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['macaddress'].should be_nil end end end it "sets ip6address" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ip6address'].should == "1111:2222:3333:4444::3" end end describe "with a link level default route" do before do @linux_ip_route = <<-IP_ROUTE default dev venet0 scope link IP_ROUTE prepare_data do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "doesn't set ipaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ipaddress'].should be_nil end end describe "when not having a global scope ipv6 address" do before do @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE fe80::/64 dev eth0 proto kernel metric 256 default via fe80::21c:eff:fe12:3456 dev eth0.153 src fe80::2e0:81ff:fe2b:48e7 metric 1024 IP_ROUTE_SCOPE prepare_data do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "doesn't set ip6address" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ip6address'].should be_nil end end describe "with no default route" do before do @linux_ip_route = <<-IP_ROUTE 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 IP_ROUTE @linux_ip_route_inet6 = <<-IP_ROUTE fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 IP_ROUTE prepare_data do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "doesn't set ipaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ipaddress'].should be_nil end it "doesn't set ip6address" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ip6address'].should be_nil end end describe "with irrelevant routes (container setups)" do before do @linux_ip_route = <<-IP_ROUTE 10.116.201.0/26 dev eth0 proto kernel src 10.116.201.39 10.116.201.0/26 dev if4 proto kernel src 10.116.201.45 10.118.19.0/26 dev eth0 proto kernel src 10.118.19.39 10.118.19.0/26 dev if5 proto kernel src 10.118.19.45 default via 10.116.201.1 dev eth0 src 10.116.201.99 IP_ROUTE @linux_ip_route_inet6 = <<-IP_ROUTE fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::FFFF:2 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 IP_ROUTE prepare_data do_stubs end it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network'].should_not be_nil end it "doesn't add bogus routes" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.116.201.0/26", :proto => "kernel", :family => "inet", :via => "10.116.201.39" ) @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.118.19.0/26", :proto => "kernel", :family => "inet", :via => "10.118.19.39" ) @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "1111:2222:3333:4444::/64", :family => "inet6", :metric => "1024" ) end it "doesn't set ipaddress" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ipaddress'].should be_nil end it "doesn't set ip6address" do @ohai._require_plugin("network") @ohai._require_plugin("linux::network") @ohai['ip6address'].should be_nil end end # This should never happen in the real world. describe "when encountering a surprise interface" do before do @linux_ip_route = <<-IP_ROUTE 192.168.122.0/24 dev virbr0 proto kernel src 192.168.122.1 IP_ROUTE prepare_data do_stubs end it "logs a message and skips previously unseen interfaces in 'ip route show'" do Ohai::Log.should_receive(:debug).with("Skipping previously unseen interface from 'ip route show': virbr0").once Ohai::Log.should_receive(:debug).any_number_of_times # Catches the 'Loading plugin network' type messages @ohai._require_plugin("network") @ohai._require_plugin("linux::network") end end end end end ohai-6.14.0/spec/ohai/plugins/linux/lsb_spec.rb0000644000175000017500000001160511761755160020653 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') # We do not alter case for lsb attributes and consume them as provided describe Ohai::System, "Linux lsb plugin" do before(:each) do @ohai = Ohai::System.new @ohai[:os] = "linux" @ohai.stub!(:require_plugin).and_return(true) @ohai.extend(SimpleFromFile) end describe "on systems with /etc/lsb-release" do before(:each) do @mock_file = mock("/etc/lsb-release") @mock_file.stub!(:each). and_yield("DISTRIB_ID=Ubuntu"). and_yield("DISTRIB_RELEASE=8.04"). and_yield("DISTRIB_CODENAME=hardy"). and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"') File.stub!(:open).with("/etc/lsb-release").and_return(@mock_file) File.stub!(:exists?).with("/etc/lsb-release").and_return(true) end it "should set lsb[:id]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:id].should == "Ubuntu" end it "should set lsb[:release]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:release].should == "8.04" end it "should set lsb[:codename]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:codename].should == "hardy" end it "should set lsb[:description]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:description].should == "Ubuntu 8.04" end end describe "on systems with /usr/bin/lsb_release" do before(:each) do File.stub!(:exists?).with("/etc/lsb-release").and_return(false) File.stub!(:exists?).with("/usr/bin/lsb_release").and_return(true) @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 end describe "on Centos 5.4 correctly" do before(:each) do @stdout.stub!(:each). and_yield("LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch"). and_yield("Distributor ID: CentOS"). and_yield("Description: CentOS release 5.4 (Final)"). and_yield("Release: 5.4"). and_yield("Codename: Final") @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "should set lsb[:id]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:id].should == "CentOS" end it "should set lsb[:release]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:release].should == "5.4" end it "should set lsb[:codename]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:codename].should == "Final" end it "should set lsb[:description]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:description].should == "CentOS release 5.4 (Final)" end end describe "on Fedora 14 correctly" do before(:each) do @stdout.stub!(:each). and_yield("LSB Version: :core-4.0-ia32:core-4.0-noarch"). and_yield("Distributor ID: Fedora"). and_yield("Description: Fedora release 14 (Laughlin)"). and_yield("Release: 14"). and_yield("Codename: Laughlin") @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "should set lsb[:id]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:id].should == "Fedora" end it "should set lsb[:release]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:release].should == "14" end it "should set lsb[:codename]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:codename].should == "Laughlin" end it "should set lsb[:description]" do @ohai._require_plugin("linux::lsb") @ohai[:lsb][:description].should == "Fedora release 14 (Laughlin)" end end end it "should not set any lsb values if /etc/lsb-release or /usr/bin/lsb_release do not exist " do File.stub!(:exists?).with("/etc/lsb-release").and_return(false) File.stub!(:exists?).with("/usr/bin/lsb_release").and_return(false) @ohai.attribute?(:lsb).should be(false) end end ohai-6.14.0/spec/ohai/plugins/linux/virtualization_spec.rb0000644000175000017500000002474411761755160023167 0ustar tfheentfheen# # Author:: Thom May () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux virtualization platform" do before(:each) do @ohai = Ohai::System.new @ohai[:os] = "linux" @ohai.stub!(:require_plugin).and_return(true) @ohai.extend(SimpleFromFile) # default to all requested Files not existing File.stub!(:exists?).with("/proc/xen").and_return(false) File.stub!(:exists?).with("/proc/xen/capabilities").and_return(false) File.stub!(:exists?).with("/proc/modules").and_return(false) File.stub!(:exists?).with("/proc/cpuinfo").and_return(false) File.stub!(:exists?).with("/usr/sbin/dmidecode").and_return(false) File.stub!(:exists?).with("/proc/self/status").and_return(false) File.stub!(:exists?).with("/proc/bc/0").and_return(false) File.stub!(:exists?).with("/proc/vz").and_return(false) end describe "when we are checking for xen" do it "should set xen guest if /proc/xen exists but /proc/xen/capabilities does not" do File.should_receive(:exists?).with("/proc/xen").and_return(true) File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(false) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "xen" @ohai[:virtualization][:role].should == "guest" end it "should set xen host if /proc/xen/capabilities contains control_d " do File.should_receive(:exists?).with("/proc/xen").and_return(true) File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true) File.stub!(:read).with("/proc/xen/capabilities").and_return("control_d") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "xen" @ohai[:virtualization][:role].should == "host" end it "should set xen guest if /proc/xen/capabilities exists but is empty" do File.should_receive(:exists?).with("/proc/xen").and_return(true) File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true) File.stub!(:read).with("/proc/xen/capabilities").and_return("") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "xen" @ohai[:virtualization][:role].should == "guest" end it "should not set virtualization if xen isn't there" do File.should_receive(:exists?).at_least(:once).and_return(false) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization].should == {} end end describe "when we are checking for kvm" do it "should set kvm host if /proc/modules contains kvm" do File.should_receive(:exists?).with("/proc/modules").and_return(true) File.stub!(:read).with("/proc/modules").and_return("kvm 165872 1 kvm_intel") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "kvm" @ohai[:virtualization][:role].should == "host" end it "should set kvm guest if /proc/cpuinfo contains QEMU Virtual CPU" do File.should_receive(:exists?).with("/proc/cpuinfo").and_return(true) File.stub!(:read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "kvm" @ohai[:virtualization][:role].should == "guest" end it "should not set virtualization if kvm isn't there" do File.should_receive(:exists?).at_least(:once).and_return(false) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization].should == {} end end describe "when we are checking for VirtualBox" do it "should set vbox host if /proc/modules contains vboxdrv" do File.should_receive(:exists?).with("/proc/modules").and_return(true) File.stub!(:read).with("/proc/modules").and_return("vboxdrv 268268 3 vboxnetadp,vboxnetflt") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "vbox" @ohai[:virtualization][:role].should == "host" end it "should set vbox guest if /proc/modules contains vboxguest" do File.should_receive(:exists?).with("/proc/modules").and_return(true) File.stub!(:read).with("/proc/modules").and_return("vboxguest 177749 2 vboxsf") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "vbox" @ohai[:virtualization][:role].should == "guest" end it "should not set virtualization if vbox isn't there" do File.should_receive(:exists?).at_least(:once).and_return(false) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization].should == {} end end describe "when we are parsing dmidecode" do before(:each) do File.should_receive(:exists?).with("/usr/sbin/dmidecode").and_return(true) @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 end it "should run dmidecode" do @ohai.should_receive(:popen4).with("dmidecode").and_return(true) @ohai._require_plugin("linux::virtualization") end it "should set virtualpc guest if dmidecode detects Microsoft Virtual Machine" do ms_vpc_dmidecode=<<-MSVPC System Information Manufacturer: Microsoft Corporation Product Name: Virtual Machine Version: VS2005R2 Serial Number: 1688-7189-5337-7903-2297-1012-52 UUID: D29974A4-BE51-044C-BDC6-EFBC4B87A8E9 Wake-up Type: Power Switch MSVPC @stdout.stub!(:read).and_return(ms_vpc_dmidecode) @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "virtualpc" @ohai[:virtualization][:role].should == "guest" end it "should set vmware guest if dmidecode detects VMware Virtual Platform" do vmware_dmidecode=<<-VMWARE System Information Manufacturer: VMware, Inc. Product Name: VMware Virtual Platform Version: None Serial Number: VMware-50 3f f7 14 42 d1 f1 da-3b 46 27 d0 29 b4 74 1d UUID: a86cc405-e1b9-447b-ad05-6f8db39d876a Wake-up Type: Power Switch SKU Number: Not Specified Family: Not Specified VMWARE @stdout.stub!(:read).and_return(vmware_dmidecode) @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "vmware" @ohai[:virtualization][:role].should == "guest" end it "should run dmidecode and not set virtualization if nothing is detected" do @ohai.should_receive(:popen4).with("dmidecode").and_return(true) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization].should == {} end end describe "when we are checking for Linux-VServer" do it "should set Linux-VServer host if /proc/self/status contains s_context: 0" do File.should_receive(:exists?).with("/proc/self/status").and_return(true) File.stub!(:read).with("/proc/self/status").and_return("s_context: 0") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "linux-vserver" @ohai[:virtualization][:role].should == "host" end it "should set Linux-VServer host if /proc/self/status contains VxID: 0" do File.should_receive(:exists?).with("/proc/self/status").and_return(true) File.stub!(:read).with("/proc/self/status").and_return("VxID: 0") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "linux-vserver" @ohai[:virtualization][:role].should == "host" end it "should set Linux-VServer guest if /proc/self/status contains s_context > 0" do File.should_receive(:exists?).with("/proc/self/status").and_return(true) File.stub!(:read).with("/proc/self/status").and_return("s_context: 2") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "linux-vserver" @ohai[:virtualization][:role].should == "guest" end it "should set Linux-VServer guest if /proc/self/status contains VxID > 0" do File.should_receive(:exists?).with("/proc/self/status").and_return(true) File.stub!(:read).with("/proc/self/status").and_return("VxID: 2") @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "linux-vserver" @ohai[:virtualization][:role].should == "guest" end it "should not set virtualization if Linux-VServer isn't there" do File.should_receive(:exists?).at_least(:once).and_return(false) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization].should == {} end end describe "when we are checking for openvz" do it "should set openvz host if /proc/bc/0 exists" do File.should_receive(:exists?).with("/proc/bc/0").and_return(true) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "openvz" @ohai[:virtualization][:role].should == "host" end it "should set openvz guest if /proc/bc/0 doesn't exist and /proc/vz exists" do File.should_receive(:exists?).with("/proc/bc/0").and_return(false) File.should_receive(:exists?).with("/proc/vz").and_return(true) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization][:system].should == "openvz" @ohai[:virtualization][:role].should == "guest" end it "should not set virtualization if openvz isn't there" do File.should_receive(:exists?).with("/proc/bc/0").and_return(false) File.should_receive(:exists?).with("/proc/vz").and_return(false) @ohai._require_plugin("linux::virtualization") @ohai[:virtualization].should == {} end end it "should not set virtualization if no tests match" do @ohai._require_plugin("linux::virtualization") @ohai[:virtualization].should == {} end end ohai-6.14.0/spec/ohai/plugins/linux/cpu_spec.rb0000644000175000017500000001036111761755160020660 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux cpu plugin" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "linux" @mock_file = mock("/proc/cpuinfo") @mock_file.stub!(:each). and_yield("processor : 0"). and_yield("vendor_id : GenuineIntel"). and_yield("cpu family : 6"). and_yield("model : 23"). and_yield("model name : Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz"). and_yield("stepping : 6"). and_yield("cpu MHz : 1968.770"). and_yield("cache size : 64 KB"). and_yield("fdiv_bug : no"). and_yield("hlt_bug : no"). and_yield("f00f_bug : no"). and_yield("coma_bug : no"). and_yield("fpu : yes"). and_yield("fpu_exception : yes"). and_yield("cpuid level : 10"). and_yield("wp : yes"). and_yield("flags : fpu pse tsc msr mce cx8 sep mtrr pge cmov"). and_yield("bogomips : 2575.86"). and_yield("clflush size : 32") File.stub!(:open).with("/proc/cpuinfo").and_return(@mock_file) end it "should set cpu[:total] to 1" do @ohai._require_plugin("linux::cpu") @ohai[:cpu][:total].should == 1 end it "should set cpu[:real] to 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu][:real].should == 0 end it "should have a cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu].should have_key("0") end it "should have a vendor_id for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should have_key("vendor_id") @ohai[:cpu]["0"]["vendor_id"].should eql("GenuineIntel") end it "should have a family for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should have_key("family") @ohai[:cpu]["0"]["family"].should eql("6") end it "should have a model for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should have_key("model") @ohai[:cpu]["0"]["model"].should eql("23") end it "should have a stepping for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should have_key("stepping") @ohai[:cpu]["0"]["stepping"].should eql("6") end it "should not have a phyiscal_id for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should_not have_key("physical_id") end it "should not have a core_id for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should_not have_key("core_id") end it "should not have a cores for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should_not have_key("cores") end it "should have a model name for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should have_key("model_name") @ohai[:cpu]["0"]["model_name"].should eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz") end it "should have a mhz for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should have_key("mhz") @ohai[:cpu]["0"]["mhz"].should eql("1968.770") end it "should have a cache_size for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should have_key("cache_size") @ohai[:cpu]["0"]["cache_size"].should eql("64 KB") end it "should have flags for cpu 0" do @ohai._require_plugin("linux::cpu") @ohai[:cpu]["0"].should have_key("flags") @ohai[:cpu]["0"]["flags"].should == %w{fpu pse tsc msr mce cx8 sep mtrr pge cmov} end endohai-6.14.0/spec/ohai/plugins/linux/uptime_spec.rb0000644000175000017500000000406211761755160021375 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux plugin uptime" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai[:os] = "linux" @ohai._require_plugin("uptime") @mock_file = mock("/proc/uptime", { :gets => "18423 989" }) File.stub!(:open).with("/proc/uptime").and_return(@mock_file) end it "should check /proc/uptime for the uptime and idletime" do File.should_receive(:open).with("/proc/uptime").and_return(@mock_file) @ohai._require_plugin("linux::uptime") end it "should split the value of /proc uptime" do @mock_file.gets.should_receive(:split).with(" ").and_return(["18423", "989"]) @ohai._require_plugin("linux::uptime") end it "should set uptime_seconds to uptime" do @ohai._require_plugin("linux::uptime") @ohai[:uptime_seconds].should == 18423 end it "should set uptime to a human readable date" do @ohai._require_plugin("linux::uptime") @ohai[:uptime].should == "5 hours 07 minutes 03 seconds" end it "should set idletime_seconds to uptime" do @ohai._require_plugin("linux::uptime") @ohai[:idletime_seconds].should == 989 end it "should set idletime to a human readable date" do @ohai._require_plugin("linux::uptime") @ohai[:idletime].should == "16 minutes 29 seconds" end endohai-6.14.0/spec/ohai/plugins/linux/platform_spec.rb0000644000175000017500000004440611761755160021724 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux plugin platform" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) @ohai.extend(SimpleFromFile) @ohai[:os] = "linux" @ohai[:lsb] = Mash.new File.stub!(:exists?).with("/etc/debian_version").and_return(false) File.stub!(:exists?).with("/etc/redhat-release").and_return(false) File.stub!(:exists?).with("/etc/gentoo-release").and_return(false) File.stub!(:exists?).with("/etc/SuSE-release").and_return(false) File.stub!(:exists?).with("/etc/arch-release").and_return(false) File.stub!(:exists?).with("/etc/system-release").and_return(false) File.stub!(:exists?).with("/etc/slackware-version").and_return(false) File.stub!(:exists?).with("/etc/enterprise-release").and_return(false) File.stub!(:exists?).with("/etc/oracle-release").and_return(false) end it "should require the lsb plugin" do @ohai.should_receive(:require_plugin).with("linux::lsb").and_return(true) @ohai._require_plugin("linux::platform") end describe "on lsb compliant distributions" do before(:each) do @ohai[:lsb][:id] = "Ubuntu" @ohai[:lsb][:release] = "8.04" end it "should set platform to lowercased lsb[:id]" do @ohai._require_plugin("linux::platform") @ohai[:platform].should == "ubuntu" end it "should set platform_version to lsb[:release]" do @ohai._require_plugin("linux::platform") @ohai[:platform_version].should == "8.04" end it "should set platform to ubuntu and platform_family to debian [:lsb][:id] contains Ubuntu" do @ohai[:lsb][:id] = "Ubuntu" @ohai._require_plugin("linux::platform") @ohai[:platform].should == "ubuntu" @ohai[:platform_family].should == "debian" end it "should set platform to linuxmint and platform_family to debian [:lsb][:id] contains LinuxMint" do @ohai[:lsb][:id] = "LinuxMint" @ohai._require_plugin("linux::platform") @ohai[:platform].should == "linuxmint" @ohai[:platform_family].should == "debian" end it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do @ohai[:lsb][:id] = "Debian" @ohai._require_plugin("linux::platform") @ohai[:platform].should == "debian" @ohai[:platform_family].should == "debian" end it "should set platform to redhat and platform_family to rhel when [:lsb][:id] contains Redhat" do @ohai[:lsb][:id] = "RedHatEnterpriseServer" @ohai[:lsb][:release] = "5.7" @ohai._require_plugin("linux::platform") @ohai[:platform].should == "redhat" @ohai[:platform_family].should == "rhel" end it "should set platform to amazon and platform_family to rhel when [:lsb][:id] contains Amazon" do @ohai[:lsb][:id] = "AmazonAMI" @ohai[:lsb][:release] = "2011.09" @ohai._require_plugin("linux::platform") @ohai[:platform].should == "amazon" @ohai[:platform_family].should == "rhel" end it "should set platform to scientific when [:lsb][:id] contains ScientificSL" do @ohai[:lsb][:id] = "ScientificSL" @ohai[:lsb][:release] = "5.7" @ohai._require_plugin("linux::platform") @ohai[:platform].should == "scientific" end end describe "on debian" do before(:each) do @ohai.lsb = nil File.should_receive(:exists?).with("/etc/debian_version").and_return(true) end it "should check for the existance of debian_version" do @ohai._require_plugin("linux::platform") end it "should read the version from /etc/debian_version" do File.should_receive(:read).with("/etc/debian_version").and_return("5.0") @ohai._require_plugin("linux::platform") @ohai[:platform_version].should == "5.0" end it "should correctly strip any newlines" do File.should_receive(:read).with("/etc/debian_version").and_return("5.0\n") @ohai._require_plugin("linux::platform") @ohai[:platform_version].should == "5.0" end # Ubuntu has /etc/debian_version as well it "should detect Ubuntu as itself rather than debian" do @ohai[:lsb][:id] = "Ubuntu" @ohai[:lsb][:release] = "8.04" @ohai._require_plugin("linux::platform") @ohai[:platform].should == "ubuntu" end end describe "on slackware" do before(:each) do @ohai.lsb = nil File.should_receive(:exists?).with("/etc/slackware-version").and_return(true) end it "should set platform and platform_family to slackware" do File.should_receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "slackware" @ohai[:platform_family].should == "slackware" end end describe "on arch" do before(:each) do @ohai.lsb = nil File.should_receive(:exists?).with("/etc/arch-release").and_return(true) end it "should set platform to arch and platform_family to arch" do @ohai._require_plugin("linux::platform") @ohai[:platform].should == "arch" @ohai[:platform_family].should == "arch" end end describe "on gentoo" do before(:each) do @ohai.lsb = nil File.should_receive(:exists?).with("/etc/gentoo-release").and_return(true) end it "should set platform and platform_family to gentoo" do File.should_receive(:read).with("/etc/gentoo-release").and_return("Gentoo Base System release 1.20.1.1") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "gentoo" @ohai[:platform_family].should == "gentoo" end end describe "on redhat breeds" do describe "with lsb_release results" do it "should set the platform to redhat and platform_family to rhel even if the LSB name is something absurd but redhat like" do @ohai[:lsb][:id] = "RedHatEnterpriseServer" @ohai[:lsb][:release] = "6.1" @ohai._require_plugin("linux::platform") @ohai[:platform].should == "redhat" @ohai[:platform_version].should == "6.1" @ohai[:platform_family].should == "rhel" end it "should set the platform to centos and platform_family to rhel" do @ohai[:lsb][:id] = "CentOS" @ohai[:lsb][:release] = "5.4" @ohai._require_plugin("linux::platform") @ohai[:platform].should == "centos" @ohai[:platform_version].should == "5.4" @ohai[:platform_family].should == "rhel" end it "should set the platform_family to rhel if the LSB name is oracle-ish" do @ohai[:lsb][:id] = "EnterpriseEnterpriseServer" @ohai._require_plugin("linux::platform") @ohai[:platform_family].should == "rhel" end it "should set the platform_family to rhel if the LSB name is amazon-ish" do @ohai[:lsb][:id] = "Amazon" @ohai._require_plugin("linux::platform") @ohai[:platform_family].should == "rhel" end it "should set the platform_family to fedora if the LSB name is fedora-ish" do @ohai[:lsb][:id] = "Fedora" @ohai._require_plugin("linux::platform") @ohai[:platform_family].should == "fedora" end it "should set the platform_family to redhat if the LSB name is scientific-ish" do @ohai[:lsb][:id] = "Scientific" @ohai._require_plugin("linux::platform") @ohai[:platform_family].should == "rhel" end end describe "without lsb_release results" do before(:each) do @ohai.lsb = nil File.should_receive(:exists?).with("/etc/redhat-release").and_return(true) end it "should check for the existance of redhat-release" do @ohai._require_plugin("linux::platform") end it "should read the platform as centos and version as 5.3" do File.should_receive(:read).with("/etc/redhat-release").and_return("CentOS release 5.3") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "centos" end it "may be that someone munged Red Hat to be RedHat" do File.should_receive(:read).with("/etc/redhat-release").and_return("RedHat release 5.3") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "redhat" @ohai[:platform_version].should == "5.3" end it "should read the platform as redhat and version as 5.3" do File.should_receive(:read).with("/etc/redhat-release").and_return("Red Hat release 5.3") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "redhat" @ohai[:platform_version].should == "5.3" end it "should read the platform as fedora and version as 13 (rawhide)" do File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "fedora" @ohai[:platform_version].should == "13 (rawhide)" end it "should read the platform as fedora and version as 10" do File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 10") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "fedora" @ohai[:platform_version].should == "10" end it "should read the platform as fedora and version as 13 using to_i" do File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "fedora" @ohai[:platform_version].to_i.should == 13 end end end describe "on oracle enterprise linux" do describe "with lsb_results" do it "should read the platform as oracle and version as 5.7" do @ohai[:lsb][:id] = "EnterpriseEnterpriseServer" @ohai[:lsb][:release] = "5.7" File.stub!(:exists?).with("/etc/redhat-release").and_return(true) File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)") File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true) File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "oracle" @ohai[:platform_version].should == "5.7" end it "should read the platform as oracle and version as 6.1" do @ohai[:lsb][:id] = "OracleServer" @ohai[:lsb][:release] = "6.1" File.stub!(:exists?).with("/etc/redhat-release").and_return(true) File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)") File.should_receive(:exists?).with("/etc/oracle-release").and_return(true) File.should_receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "oracle" @ohai[:platform_version].should == "6.1" end end describe "without lsb_results" do before(:each) do @ohai.lsb = nil end it "should read the platform as oracle and version as 5" do File.stub!(:exists?).with("/etc/redhat-release").and_return(true) File.stub!(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)") File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true) File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "oracle" @ohai[:platform_version].should == "5" end it "should read the platform as oracle and version as 5.1" do File.stub!(:exists?).with("/etc/redhat-release").and_return(true) File.stub!(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)") File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true) File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "oracle" @ohai[:platform_version].should == "5.1" end it "should read the platform as oracle and version as 5.7" do File.stub!(:exists?).with("/etc/redhat-release").and_return(true) File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)") File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true) File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "oracle" @ohai[:platform_version].should == "5.7" end it "should read the platform as oracle and version as 6.0" do File.stub!(:exists?).with("/etc/redhat-release").and_return(true) File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)") File.should_receive(:exists?).with("/etc/oracle-release").and_return(true) File.should_receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "oracle" @ohai[:platform_version].should == "6.0" end it "should read the platform as oracle and version as 6.1" do File.stub!(:exists?).with("/etc/redhat-release").and_return(true) File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)") File.should_receive(:exists?).with("/etc/oracle-release").and_return(true) File.should_receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "oracle" @ohai[:platform_version].should == "6.1" end end end describe "on suse" do before(:each) do File.should_receive(:exists?).with("/etc/SuSE-release").and_return(true) end describe "with lsb_release results" do before(:each) do @ohai[:lsb][:id] = "SUSE LINUX" end it "should read the platform as suse" do @ohai[:lsb][:release] = "12.1" File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "suse" @ohai[:platform_version].should == "12.1" @ohai[:platform_family].should == "suse" end end describe "without lsb_release results" do before(:each) do @ohai.lsb = nil end it "should check for the existance of SuSE-release" do @ohai._require_plugin("linux::platform") end it "should set platform and platform_family to suse and bogus verion to 10.0" do File.should_receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "suse" @ohai[:platform_family].should == "suse" end it "should read the version as 10.1 for bogus SLES 10" do File.should_receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 10 (i586)\nVERSION = 10\nPATCHLEVEL = 1\n") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "suse" @ohai[:platform_version].should == "10.1" @ohai[:platform_family].should == "suse" end it "should read the version as 11.2" do File.should_receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "suse" @ohai[:platform_version].should == "11.2" @ohai[:platform_family].should == "suse" end it "[OHAI-272] should read the version as 11.3" do File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "suse" @ohai[:platform_version].should == "11.3" @ohai[:platform_family].should == "suse" end it "[OHAI-272] should read the version as 9.1" do File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "suse" @ohai[:platform_version].should == "9.1" @ohai[:platform_family].should == "suse" end it "[OHAI-272] should read the version as 11.4" do File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon") @ohai._require_plugin("linux::platform") @ohai[:platform].should == "suse" @ohai[:platform_version].should == "11.4" @ohai[:platform_family].should == "suse" end end end end ohai-6.14.0/spec/ohai/plugins/linux/filesystem_spec.rb0000644000175000017500000003317311761755160022263 0ustar tfheentfheen# # Author:: Matthew Kent () # Copyright:: Copyright (c) 2011 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux filesystem plugin" do before(:each) do @ohai = Ohai::System.new @ohai[:os] = "linux" @ohai.stub!(:require_plugin).and_return(true) @ohai.extend(SimpleFromFile) @ohai.stub!(:popen4).with("df -P").and_return(false) @ohai.stub!(:popen4).with("mount").and_return(false) @ohai.stub!(:popen4).with("blkid -s TYPE").and_return(false) @ohai.stub!(:popen4).with("blkid -s UUID").and_return(false) @ohai.stub!(:popen4).with("blkid -s LABEL").and_return(false) File.stub!(:exists?).with("/proc/mounts").and_return(false) end describe "when gathering filesystem usage data from df" do before(:each) do @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 @stdout.stub!(:each). and_yield("Filesystem 1024-blocks Used Available Capacity Mounted on"). and_yield("/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /"). and_yield("tmpfs 2030944 0 2030944 0% /lib/init/rw"). and_yield("udev 2025576 228 2025348 1% /dev"). and_yield("tmpfs 2030944 2960 2027984 1% /dev/shm"). and_yield("/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home"). and_yield("/dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special"). and_yield("/dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp"). and_yield("/dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr"). and_yield("/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var"). and_yield("/dev/md0 960492 36388 875312 4% /boot") end it "should run df -P" do @ohai.should_receive(:popen4).with("df -P").and_return(true) @ohai._require_plugin("linux::filesystem") end it "should set kb_size to value from df -P" do @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_size].should be == "97605057" end it "should set kb_used to value from df -P" do @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_used].should be == "53563253" end it "should set kb_available to value from df -P" do @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_available].should be == "44041805" end it "should set percent_used to value from df -P" do @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:percent_used].should be == "56%" end it "should set mount to value from df -P" do @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special" end end describe "when gathering mounted filesystem data from mount" do before(:each) do @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 @stdout.stub!(:each). and_yield("/dev/mapper/sys.vg-root.lv on / type ext4 (rw,noatime,errors=remount-ro)"). and_yield("tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)"). and_yield("proc on /proc type proc (rw,noexec,nosuid,nodev)"). and_yield("sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)"). and_yield("udev on /dev type tmpfs (rw,mode=0755)"). and_yield("tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)"). and_yield("devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)"). and_yield("/dev/mapper/sys.vg-home.lv on /home type xfs (rw,noatime)"). and_yield("/dev/mapper/sys.vg-special.lv on /special type xfs (ro,noatime)"). and_yield("/dev/mapper/sys.vg-tmp.lv on /tmp type ext4 (rw,noatime)"). and_yield("/dev/mapper/sys.vg-usr.lv on /usr type ext4 (rw,noatime)"). and_yield("/dev/mapper/sys.vg-var.lv on /var type ext4 (rw,noatime)"). and_yield("/dev/md0 on /boot type ext3 (rw,noatime,errors=remount-ro)"). and_yield("fusectl on /sys/fs/fuse/connections type fusectl (rw)"). and_yield("binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)") end it "should run mount" do @ohai.should_receive(:popen4).with("mount").and_return(true) @ohai._require_plugin("linux::filesystem") end it "should set mount to value from mount" do @ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special" end it "should set fs_type to value from mount" do @ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs" end it "should set mount_options to an array of values from mount" do @ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime" ] end end describe "when gathering filesystem type data from blkid" do before(:each) do @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 @stdout.stub!(:each). and_yield("/dev/sdb1: TYPE=\"linux_raid_member\" "). and_yield("/dev/sdb2: TYPE=\"linux_raid_member\" "). and_yield("/dev/sda1: TYPE=\"linux_raid_member\" "). and_yield("/dev/sda2: TYPE=\"linux_raid_member\" "). and_yield("/dev/md0: TYPE=\"ext3\" "). and_yield("/dev/md1: TYPE=\"LVM2_member\" "). and_yield("/dev/mapper/sys.vg-root.lv: TYPE=\"ext4\" "). and_yield("/dev/mapper/sys.vg-swap.lv: TYPE=\"swap\" "). and_yield("/dev/mapper/sys.vg-tmp.lv: TYPE=\"ext4\" "). and_yield("/dev/mapper/sys.vg-usr.lv: TYPE=\"ext4\" "). and_yield("/dev/mapper/sys.vg-var.lv: TYPE=\"ext4\" "). and_yield("/dev/mapper/sys.vg-home.lv: TYPE=\"xfs\" ") end it "should run blkid -s TYPE" do @ohai.should_receive(:popen4).with("blkid -s TYPE").and_return(true) @ohai._require_plugin("linux::filesystem") end it "should set kb_size to value from blkid -s TYPE" do @ohai.stub!(:popen4).with("blkid -s TYPE").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/md1"][:fs_type].should be == "LVM2_member" end end describe "when gathering filesystem uuid data from blkid" do before(:each) do @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 @stdout.stub!(:each). and_yield("/dev/sdb1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" "). and_yield("/dev/sdb2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" "). and_yield("/dev/sda1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" "). and_yield("/dev/sda2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" "). and_yield("/dev/md0: UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" "). and_yield("/dev/md1: UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" "). and_yield("/dev/mapper/sys.vg-root.lv: UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" "). and_yield("/dev/mapper/sys.vg-swap.lv: UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" "). and_yield("/dev/mapper/sys.vg-tmp.lv: UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" "). and_yield("/dev/mapper/sys.vg-usr.lv: UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" "). and_yield("/dev/mapper/sys.vg-var.lv: UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" "). and_yield("/dev/mapper/sys.vg-home.lv: UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" ") end it "should run blkid -s UUID" do @ohai.should_receive(:popen4).with("blkid -s UUID").and_return(true) @ohai._require_plugin("linux::filesystem") end it "should set kb_size to value from blkid -s UUID" do @ohai.stub!(:popen4).with("blkid -s UUID").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/sda2"][:uuid].should be == "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa" end end describe "when gathering filesystem label data from blkid" do before(:each) do @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = mock("STDOUT") @status = 0 @stdout.stub!(:each). and_yield("/dev/sda1: LABEL=\"fuego:0\" "). and_yield("/dev/sda2: LABEL=\"fuego:1\" "). and_yield("/dev/sdb1: LABEL=\"fuego:0\" "). and_yield("/dev/sdb2: LABEL=\"fuego:1\" "). and_yield("/dev/md0: LABEL=\"/boot\" "). and_yield("/dev/mapper/sys.vg-root.lv: LABEL=\"/\" "). and_yield("/dev/mapper/sys.vg-tmp.lv: LABEL=\"/tmp\" "). and_yield("/dev/mapper/sys.vg-usr.lv: LABEL=\"/usr\" "). and_yield("/dev/mapper/sys.vg-var.lv: LABEL=\"/var\" "). and_yield("/dev/mapper/sys.vg-home.lv: LABEL=\"/home\" ") end it "should run blkid -s LABEL" do @ohai.should_receive(:popen4).with("blkid -s LABEL").and_return(true) @ohai._require_plugin("linux::filesystem") end it "should set kb_size to value from blkid -s LABEL" do @ohai.stub!(:popen4).with("blkid -s LABEL").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/md0"][:label].should be == "/boot" end end describe "when gathering data from /proc/mounts" do before(:each) do File.stub!(:exists?).with("/proc/mounts").and_return(true) @mock_file = mock("/proc/mounts") @mock_file.stub!(:read_nonblock).and_return(@mock_file) @mock_file.stub!(:each_line). and_yield("rootfs / rootfs rw 0 0"). and_yield("none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0"). and_yield("none /proc proc rw,nosuid,nodev,noexec,relatime 0 0"). and_yield("none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0"). and_yield("none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0"). and_yield("/dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0"). and_yield("tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0"). and_yield("tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0"). and_yield("/dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0"). and_yield("/dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0"). and_yield("/dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0"). and_yield("/dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0"). and_yield("/dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0"). and_yield("/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0"). and_yield("fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0"). and_yield("binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0") File.stub!(:open).with("/proc/mounts").and_return(@mock_file) end it "should set mount to value from /proc/mounts" do @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special" end it "should set fs_type to value from /proc/mounts" do @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs" end it "should set mount_options to an array of values from /proc/mounts" do @ohai._require_plugin("linux::filesystem") @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime", "attr2", "noquota" ] end end end ohai-6.14.0/spec/ohai/plugins/passwd_spec.rb0000644000175000017500000000373311761755160020240 0ustar tfheentfheenrequire File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin etc" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) end PasswdEntry = Struct.new(:name, :uid, :gid, :dir, :shell, :gecos) GroupEntry = Struct.new(:name, :gid, :mem) it "should include a list of all users" do Etc.should_receive(:passwd).and_yield(PasswdEntry.new("root", 1, 1, '/root', '/bin/zsh', 'BOFH')). and_yield(PasswdEntry.new('www', 800, 800, '/var/www', '/bin/false', 'Serving the web since 1970')) @ohai._require_plugin("passwd") @ohai[:etc][:passwd]['root'].should == Mash.new(:shell => '/bin/zsh', :gecos => 'BOFH', :gid => 1, :uid => 1, :dir => '/root') @ohai[:etc][:passwd]['www'].should == Mash.new(:shell => '/bin/false', :gecos => 'Serving the web since 1970', :gid => 800, :uid => 800, :dir => '/var/www') end it "should set the current user" do Etc.should_receive(:getlogin).and_return('chef') @ohai._require_plugin("passwd") @ohai[:current_user].should == 'chef' end it "should set the available groups" do Etc.should_receive(:group).and_yield(GroupEntry.new("admin", 100, ['root', 'chef'])).and_yield(GroupEntry.new('www', 800, ['www', 'deploy'])) @ohai._require_plugin("passwd") @ohai[:etc][:group]['admin'].should == Mash.new(:gid => 100, :members => ['root', 'chef']) @ohai[:etc][:group]['www'].should == Mash.new(:gid => 800, :members => ['www', 'deploy']) end if "".respond_to?(:force_encoding) it "sets the encoding of strings to the default external encoding" do fields = ["root", 1, 1, '/root', '/bin/zsh', 'BOFH'] fields.each {|f| f.force_encoding(Encoding::ASCII_8BIT) if f.respond_to?(:force_encoding) } Etc.stub!(:passwd).and_yield(PasswdEntry.new(*fields)) @ohai._require_plugin("passwd") root = @ohai[:etc][:passwd]['root'] root['gecos'].encoding.should == Encoding.default_external end end end ohai-6.14.0/spec/ohai/plugins/eucalyptus_spec.rb0000644000175000017500000001066111761755160021133 0ustar tfheentfheen# # Author:: Tim Dysinger () # Author:: Christopher Brown (cb@opscode.com) # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'open-uri' describe Ohai::System, "plugin eucalyptus" do before(:each) do @ohai = Ohai::System.new @ohai.stub!(:require_plugin).and_return(true) end shared_examples_for "!eucalyptus" do it "should NOT attempt to fetch the eucalyptus metadata" do OpenURI.should_not_receive(:open) @ohai._require_plugin("eucalyptus") end end shared_examples_for "eucalyptus" do before(:each) do @http_client = mock("Net::HTTP client") @ohai.stub!(:http_client).and_return(@http_client) @http_client.should_receive(:get). with("/2008-02-01/meta-data/"). and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups")) @http_client.should_receive(:get). with("/2008-02-01/meta-data/instance_type"). and_return(mock("Net::HTTP Response", :body => "c1.medium")) @http_client.should_receive(:get). with("/2008-02-01/meta-data/ami_id"). and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934")) @http_client.should_receive(:get). with("/2008-02-01/meta-data/security-groups"). and_return(mock("Net::HTTP Response", :body => "group1\ngroup2")) @http_client.should_receive(:get). with("/2008-02-01/user-data/"). and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) end it "should recursively fetch all the eucalyptus metadata" do IO.stub!(:select).and_return([[],[1],[]]) t = mock("connection") t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS) Socket.stub!(:new).and_return(t) @ohai._require_plugin("eucalyptus") @ohai[:eucalyptus].should_not be_nil @ohai[:eucalyptus]['instance_type'].should == "c1.medium" @ohai[:eucalyptus]['ami_id'].should == "ami-5d2dc934" @ohai[:eucalyptus]['security_groups'].should eql ['group1', 'group2'] end end describe "with eucalyptus mac and metadata address connected" do it_should_behave_like "eucalyptus" before(:each) do IO.stub!(:select).and_return([[],[1],[]]) @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "d0:0d:95:47:6E:ED"=> { "family" => "lladdr" } } } } } end end describe "without eucalyptus mac and metadata address connected" do it_should_behave_like "!eucalyptus" before(:each) do @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } } end end describe "with eucalyptus cloud file" do it_should_behave_like "eucalyptus" before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(true) File.stub!(:read).with('/etc/chef/ohai/hints/eucalyptus.json').and_return('') File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(true) File.stub!(:read).with('C:\chef\ohai\hints/eucalyptus.json').and_return('') end end describe "without cloud file" do it_should_behave_like "!eucalyptus" before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false) File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false) end end describe "with ec2 cloud file" do it_should_behave_like "!eucalyptus" before(:each) do File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true) File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('') File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true) File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('') end end end ohai-6.14.0/spec/ohai/plugins/sigar/0000755000175000017500000000000011761755160016477 5ustar tfheentfheenohai-6.14.0/spec/ohai/plugins/sigar/network_route_spec.rb0000644000175000017500000001110211761755160022740 0ustar tfheentfheen# # Author:: Toomas Pelberg () # Copyright:: Copyright (c) 2011 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') sigar_available = begin require 'sigar' true rescue LoadError false end require 'ohai' describe Ohai::System, "Sigar network route plugin" do if sigar_available before(:each) do @ohai = Ohai::System.new @sigar = double("Sigar") @net_info_conf={ :default_gateway => "192.168.1.254", :default_gateway_interface => "eth0", :primary_dns => "192.168.1.254", :secondary_dns => "8.8.8.8", :host_name => "localhost" } net_info=double("Sigar::NetInfo") @net_info_conf.each_pair do |k,v| net_info.stub(k).and_return(v) end @net_route_conf={ :destination => "192.168.1.0", :gateway => "0.0.0.0", :mask => "255.255.255.0", :flags => 1, :refcnt => 0, :use => 0, :metric => 0, :mtu => 0, :window => 0, :irtt => 0, :ifname => "eth0" } net_route=double("Sigar::NetRoute") @net_route_conf.each_pair do |k,v| net_route.stub(k).and_return(v) end @net_interface_conf={ :flags => 2115, :destination => "192.168.1.1", :mtu => 1500, :type => "Ethernet", :hwaddr => "00:11:22:33:44:55:66", :address => "192.168.1.1", :broadcast => "192.168.1.255", :netmask => "255.255.255.0", :address6 => nil, :tx_queue_len => 1000, :prefix6_length => 0, } net_conf=double("Sigar::NetConf") @net_interface_conf.each_pair do |k,v| net_conf.stub(k).and_return(v) end @net_interface_stat={ :rx_bytes=>1369035618, :rx_dropped=>0, :rx_errors=>0, :rx_frame=>0, :rx_overruns=>0, :rx_packets=>7271669, :speed=>-1, :tx_bytes=>3482843666, :tx_carrier=>0, :tx_collisions=>0, :tx_dropped=>0, :tx_errors=>0, :tx_overruns=>0, :tx_packets=>4392794 } net_stat=double("Sigar::NetStat") @net_interface_stat.each_pair do |k,v| net_stat.stub(k).and_return(v) end @net_arp_conf={ :address => "192.168.1.5", :flags => 2, :hwaddr => "00:15:62:96:01:D0", :ifname => "eth0", :type => "ether", } net_arp=double("Sigar::NetArp") @net_arp_conf.each_pair do |k,v| net_arp.stub(k).and_return(v) end @sigar.stub(:fqdn).and_return("localhost.localdomain") @sigar.should_receive(:net_info).at_least(2).times.and_return(net_info) @sigar.should_receive(:net_interface_list).once.and_return(["eth0"]) @sigar.should_receive(:net_interface_config).with("eth0").and_return(net_conf) @sigar.should_receive(:net_interface_stat).with("eth0").and_return(net_stat) @sigar.should_receive(:arp_list).once.and_return([net_arp]) # Since we mock net_route_list here, flags never gets called @sigar.should_receive(:net_route_list).once.and_return([net_route]) Sigar.should_receive(:new).at_least(2).times.and_return(@sigar) @ohai.require_plugin("os") @ohai[:os]="sigar" @ohai.require_plugin("network") @ohai.require_plugin("sigar::network_route") end it "should set the routes" do @ohai[:network][:interfaces][:eth0].should have_key(:route) end it "should set the route details" do @net_route_conf.each_pair do |k,v| # Work around the above mocking of net_route_list skipping the call to flags() if k == :flags v="U" @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v end @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"].should have_key(k) @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k].should eql(v) end end else pending "Sigar not available, skipping sigar tests" end end ohai-6.14.0/spec/spec_helper.rb0000644000175000017500000000321111761755160015604 0ustar tfheentfheenrequire 'rspec' require 'mixlib/config' $:.unshift(File.dirname(__FILE__) + '/../lib') require 'ohai' Ohai::Config[:log_level] = :error def it_should_check_from(plugin, attribute, from, value) it "should set the #{attribute} to the value from '#{from}'" do @ohai._require_plugin(plugin) @ohai[attribute].should == value end end def it_should_check_from_mash(plugin, attribute, from, value) it "should get the #{plugin}[:#{attribute}] value from '#{from}'" do @ohai.should_receive(:from).with(from).and_return(value) @ohai._require_plugin(plugin) end it "should set the #{plugin}[:#{attribute}] to the value from '#{from}'" do @ohai._require_plugin(plugin) @ohai[plugin][attribute].should == value end end # the mash variable may be an array listing multiple levels of Mash hierarchy def it_should_check_from_deep_mash(plugin, mash, attribute, from, value) it "should get the #{mash.inspect}[:#{attribute}] value from '#{from}'" do @ohai.should_receive(:from).with(from).and_return(value) @ohai._require_plugin(plugin) end it "should set the #{mash.inspect}[:#{attribute}] to the value from '#{from}'" do @ohai._require_plugin(plugin) if mash.is_a?(String) @ohai[mash][attribute].should == value elsif mash.is_a?(Array) if mash.length == 2 @ohai[mash[0]][mash[1]][attribute].should == value elsif mash.length == 3 @ohai[mash[0]][mash[1]][mash[2]][attribute].should == value else return nil end else return nil end end end module SimpleFromFile def from_file(filename) self.instance_eval(IO.read(filename), filename, 1) end end ohai-6.14.0/README.rdoc0000644000175000017500000000574411761755160013657 0ustar tfheentfheen= ohai = DESCRIPTION: Ohai detects data about your operating system. It can be used standalone, but it's primary purpose is to provide node data to Chef. 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. Opscode 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 wiki: * http://wiki.opscode.com/display/chef/Ohai = DEVELOPMENT: Before working on the code, if you plan to contribute your changes, you need to read the Opscode Contributing document. * http://wiki.opscode.com/display/chef/How+to+Contribute You will also need to set up the repository with the appropriate branches. We document the process on the Chef Wiki. * http://wiki.opscode.com/display/chef/Working+with+git (Substitude 'ohai' for 'chef') Once your repository is set up, you can start working on the code. We do use BDD/TDD with RSpec, and soon Cucumber for integration/feature testing, so you'll need to get those installed. = ENVIRONMENT: In order to have a dev environment where you can work on Ohai, you'll need to install a few additional gems after setting up the Git repository. Install the following RubyGems. * rake * rspec * extlib * systemu * json gem install rake rspec extlib systemu json == Rake Tasks Ohai has some Rake tasks for doing various things. rake -T rake clobber_package # Remove package products rake gem # Build the gem file ohai-$VERSION.gem rake install # install the gem locally rake make_spec # create a gemspec file rake package # Build all the packages rake repackage # Force a rebuild of the package files rake spec # Run specs ($VERSION is the current version, from the GemSpec in Rakefile) == Spec Testing: We use RSpec for unit/spec tests. rake spec Because ohai gathers system information, and we don't know what kind of system we might be running on (yet), we're moving away from specs for integration testing and to cucumber. = LINKS: Source: * http://github.com/opscode/ohai/tree/master Tickets/Issues: * http://tickets.opscode.com/ (Use the OHAI project) Documentation: * http://wiki.opscode.com/display/chef/Ohai = LICENSE: Ohai - system information application Author:: Adam Jacob () Copyright:: Copyright (c) 2008 Opscode, Inc. License:: Apache License, Version 2.0 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ohai-6.14.0/metadata.yml0000644000175000017500000002652311761755160014352 0ustar tfheentfheen--- !ruby/object:Gem::Specification name: ohai version: !ruby/object:Gem::Version hash: 23 prerelease: segments: - 6 - 14 - 0 version: 6.14.0 platform: ruby authors: - Adam Jacob autorequire: bindir: bin cert_chain: [] date: 2012-05-30 00:00:00 Z dependencies: - !ruby/object:Gem::Dependency name: systemu prerelease: false requirement: &id001 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :runtime version_requirements: *id001 - !ruby/object:Gem::Dependency name: yajl-ruby prerelease: false requirement: &id002 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :runtime version_requirements: *id002 - !ruby/object:Gem::Dependency name: mixlib-cli prerelease: false requirement: &id003 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :runtime version_requirements: *id003 - !ruby/object:Gem::Dependency name: mixlib-config prerelease: false requirement: &id004 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :runtime version_requirements: *id004 - !ruby/object:Gem::Dependency name: mixlib-log prerelease: false requirement: &id005 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :runtime version_requirements: *id005 - !ruby/object:Gem::Dependency name: ipaddress prerelease: false requirement: &id006 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :runtime version_requirements: *id006 - !ruby/object:Gem::Dependency name: rspec-core prerelease: false requirement: &id007 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :development version_requirements: *id007 - !ruby/object:Gem::Dependency name: rspec-expectations prerelease: false requirement: &id008 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :development version_requirements: *id008 - !ruby/object:Gem::Dependency name: rspec-mocks prerelease: false requirement: &id009 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :development version_requirements: *id009 - !ruby/object:Gem::Dependency name: rspec_junit_formatter prerelease: false requirement: &id010 !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" type: :development version_requirements: *id010 description: Ohai profiles your system and emits JSON email: adam@opscode.com executables: - ohai extensions: [] extra_rdoc_files: [] files: - LICENSE - README.rdoc - Rakefile - docs/man/man1/ohai.1 - lib/ohai.rb - lib/ohai/plugins/languages.rb - lib/ohai/plugins/virtualization.rb - lib/ohai/plugins/dmi.rb - lib/ohai/plugins/passwd.rb - lib/ohai/plugins/ohai.rb - lib/ohai/plugins/php.rb - lib/ohai/plugins/ip_scopes.rb - lib/ohai/plugins/keys.rb - lib/ohai/plugins/dmi_common.rb - lib/ohai/plugins/rackspace.rb - lib/ohai/plugins/erlang.rb - lib/ohai/plugins/freebsd/virtualization.rb - lib/ohai/plugins/freebsd/memory.rb - lib/ohai/plugins/freebsd/hostname.rb - lib/ohai/plugins/freebsd/uptime.rb - lib/ohai/plugins/freebsd/ssh_host_key.rb - lib/ohai/plugins/freebsd/network.rb - lib/ohai/plugins/freebsd/kernel.rb - lib/ohai/plugins/freebsd/platform.rb - lib/ohai/plugins/freebsd/ps.rb - lib/ohai/plugins/freebsd/cpu.rb - lib/ohai/plugins/freebsd/filesystem.rb - lib/ohai/plugins/linux/virtualization.rb - lib/ohai/plugins/linux/lsb.rb - lib/ohai/plugins/linux/memory.rb - lib/ohai/plugins/linux/hostname.rb - lib/ohai/plugins/linux/uptime.rb - lib/ohai/plugins/linux/ssh_host_key.rb - lib/ohai/plugins/linux/block_device.rb - lib/ohai/plugins/linux/network.rb - lib/ohai/plugins/linux/kernel.rb - lib/ohai/plugins/linux/platform.rb - lib/ohai/plugins/linux/ps.rb - lib/ohai/plugins/linux/cpu.rb - lib/ohai/plugins/linux/filesystem.rb - lib/ohai/plugins/groovy.rb - lib/ohai/plugins/darwin/hostname.rb - lib/ohai/plugins/darwin/uptime.rb - lib/ohai/plugins/darwin/ssh_host_key.rb - lib/ohai/plugins/darwin/network.rb - lib/ohai/plugins/darwin/system_profiler.rb - lib/ohai/plugins/darwin/kernel.rb - lib/ohai/plugins/darwin/platform.rb - lib/ohai/plugins/darwin/ps.rb - lib/ohai/plugins/darwin/filesystem.rb - lib/ohai/plugins/chef.rb - lib/ohai/plugins/hostname.rb - lib/ohai/plugins/perl.rb - lib/ohai/plugins/uptime.rb - lib/ohai/plugins/ec2.rb - lib/ohai/plugins/network_listeners.rb - lib/ohai/plugins/hpux/memory.rb - lib/ohai/plugins/hpux/hostname.rb - lib/ohai/plugins/hpux/uptime.rb - lib/ohai/plugins/hpux/ssh_host_key.rb - lib/ohai/plugins/hpux/network.rb - lib/ohai/plugins/hpux/platform.rb - lib/ohai/plugins/hpux/ps.rb - lib/ohai/plugins/hpux/cpu.rb - lib/ohai/plugins/hpux/filesystem.rb - lib/ohai/plugins/mono.rb - lib/ohai/plugins/solaris2/virtualization.rb - lib/ohai/plugins/solaris2/dmi.rb - lib/ohai/plugins/solaris2/hostname.rb - lib/ohai/plugins/solaris2/uptime.rb - lib/ohai/plugins/solaris2/ssh_host_key.rb - lib/ohai/plugins/solaris2/network.rb - lib/ohai/plugins/solaris2/zpools.rb - lib/ohai/plugins/solaris2/kernel.rb - lib/ohai/plugins/solaris2/platform.rb - lib/ohai/plugins/solaris2/ps.rb - lib/ohai/plugins/solaris2/cpu.rb - lib/ohai/plugins/solaris2/filesystem.rb - lib/ohai/plugins/ohai_time.rb - lib/ohai/plugins/c.rb - lib/ohai/plugins/lua.rb - lib/ohai/plugins/openbsd/virtualization.rb - lib/ohai/plugins/openbsd/memory.rb - lib/ohai/plugins/openbsd/hostname.rb - lib/ohai/plugins/openbsd/uptime.rb - lib/ohai/plugins/openbsd/ssh_host_key.rb - lib/ohai/plugins/openbsd/network.rb - lib/ohai/plugins/openbsd/kernel.rb - lib/ohai/plugins/openbsd/platform.rb - lib/ohai/plugins/openbsd/ps.rb - lib/ohai/plugins/openbsd/cpu.rb - lib/ohai/plugins/openbsd/filesystem.rb - lib/ohai/plugins/python.rb - lib/ohai/plugins/network.rb - lib/ohai/plugins/kernel.rb - lib/ohai/plugins/cloud.rb - lib/ohai/plugins/java.rb - lib/ohai/plugins/platform.rb - lib/ohai/plugins/ruby.rb - lib/ohai/plugins/os.rb - lib/ohai/plugins/sigar/memory.rb - lib/ohai/plugins/sigar/hostname.rb - lib/ohai/plugins/sigar/uptime.rb - lib/ohai/plugins/sigar/network.rb - lib/ohai/plugins/sigar/network_route.rb - lib/ohai/plugins/sigar/platform.rb - lib/ohai/plugins/sigar/cpu.rb - lib/ohai/plugins/sigar/filesystem.rb - lib/ohai/plugins/command.rb - lib/ohai/plugins/windows/hostname.rb - lib/ohai/plugins/windows/uptime.rb - lib/ohai/plugins/windows/network.rb - lib/ohai/plugins/windows/kernel.rb - lib/ohai/plugins/windows/platform.rb - lib/ohai/plugins/windows/cpu.rb - lib/ohai/plugins/windows/filesystem.rb - lib/ohai/plugins/eucalyptus.rb - lib/ohai/plugins/netbsd/virtualization.rb - lib/ohai/plugins/netbsd/memory.rb - lib/ohai/plugins/netbsd/hostname.rb - lib/ohai/plugins/netbsd/uptime.rb - lib/ohai/plugins/netbsd/ssh_host_key.rb - lib/ohai/plugins/netbsd/network.rb - lib/ohai/plugins/netbsd/kernel.rb - lib/ohai/plugins/netbsd/platform.rb - lib/ohai/plugins/netbsd/ps.rb - lib/ohai/plugins/netbsd/cpu.rb - lib/ohai/plugins/netbsd/filesystem.rb - lib/ohai/plugins/aix/memory.rb - lib/ohai/plugins/aix/hostname.rb - lib/ohai/plugins/aix/uptime.rb - lib/ohai/plugins/aix/ssh_host_key.rb - lib/ohai/plugins/aix/network.rb - lib/ohai/plugins/aix/platform.rb - lib/ohai/plugins/aix/ps.rb - lib/ohai/plugins/aix/cpu.rb - lib/ohai/plugins/aix/filesystem.rb - lib/ohai/application.rb - lib/ohai/version.rb - lib/ohai/mash.rb - lib/ohai/exception.rb - lib/ohai/config.rb - lib/ohai/log.rb - lib/ohai/system.rb - lib/ohai/mixin/string.rb - lib/ohai/mixin/from_file.rb - lib/ohai/mixin/command.rb - lib/ohai/mixin/ec2_metadata.rb - spec/ohai/plugins/groovy_spec.rb - spec/ohai/plugins/lua_spec.rb - spec/ohai/plugins/ec2_spec.rb - spec/ohai/plugins/ruby_spec.rb - spec/ohai/plugins/fail_spec.rb - spec/ohai/plugins/rackspace_spec.rb - spec/ohai/plugins/freebsd/kernel_spec.rb - spec/ohai/plugins/freebsd/platform_spec.rb - spec/ohai/plugins/freebsd/hostname_spec.rb - spec/ohai/plugins/php_spec.rb - spec/ohai/plugins/linux/cpu_spec.rb - spec/ohai/plugins/linux/network_spec.rb - spec/ohai/plugins/linux/kernel_spec.rb - spec/ohai/plugins/linux/platform_spec.rb - spec/ohai/plugins/linux/uptime_spec.rb - spec/ohai/plugins/linux/virtualization_spec.rb - spec/ohai/plugins/linux/lsb_spec.rb - spec/ohai/plugins/linux/hostname_spec.rb - spec/ohai/plugins/linux/filesystem_spec.rb - spec/ohai/plugins/chef_spec.rb - spec/ohai/plugins/darwin/network_spec.rb - spec/ohai/plugins/darwin/kernel_spec.rb - spec/ohai/plugins/darwin/platform_spec.rb - spec/ohai/plugins/darwin/hostname_spec.rb - spec/ohai/plugins/python_spec.rb - spec/ohai/plugins/java_spec.rb - spec/ohai/plugins/kernel_spec.rb - spec/ohai/plugins/dmi_spec.rb - spec/ohai/plugins/mono_spec.rb - spec/ohai/plugins/solaris2/network_spec.rb - spec/ohai/plugins/solaris2/kernel_spec.rb - spec/ohai/plugins/solaris2/platform_spec.rb - spec/ohai/plugins/solaris2/virtualization_spec.rb - spec/ohai/plugins/solaris2/hostname_spec.rb - spec/ohai/plugins/openbsd/kernel_spec.rb - spec/ohai/plugins/openbsd/platform_spec.rb - spec/ohai/plugins/openbsd/hostname_spec.rb - spec/ohai/plugins/platform_spec.rb - spec/ohai/plugins/erlang_spec.rb - spec/ohai/plugins/perl_spec.rb - spec/ohai/plugins/c_spec.rb - spec/ohai/plugins/ohai_spec.rb - spec/ohai/plugins/sigar/network_route_spec.rb - spec/ohai/plugins/os_spec.rb - spec/ohai/plugins/passwd_spec.rb - spec/ohai/plugins/cloud_spec.rb - spec/ohai/plugins/eucalyptus_spec.rb - spec/ohai/plugins/netbsd/kernel_spec.rb - spec/ohai/plugins/netbsd/platform_spec.rb - spec/ohai/plugins/netbsd/hostname_spec.rb - spec/ohai/plugins/hostname_spec.rb - spec/ohai/plugins/ohai_time_spec.rb - spec/ohai/system_spec.rb - spec/ohai/mixin/command_spec.rb - spec/ohai/mixin/from_file_spec.rb - spec/spec_helper.rb - spec/spec.opts - spec/rcov.opts - spec/ohai_spec.rb - bin/ohai homepage: http://wiki.opscode.com/display/chef/Ohai licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" requirements: [] rubyforge_project: rubygems_version: 1.8.10 signing_key: specification_version: 3 summary: Ohai profiles your system and emits JSON test_files: [] ohai-6.14.0/LICENSE0000644000175000017500000002514211761755160013050 0ustar tfheentfheen Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ohai-6.14.0/Rakefile0000644000175000017500000000115111761755160013502 0ustar tfheentfheenrequire 'rubygems' require 'rake/gempackagetask' require 'rubygems/specification' require 'date' gemspec = eval(IO.read("ohai.gemspec")) Rake::GemPackageTask.new(gemspec).define desc "install the gem locally" task :install => [:package] do sh %{gem install pkg/#{ohai}-#{OHAI_VERSION}} end begin require 'rspec/core/rake_task' RSpec::Core::RakeTask.new do |t| t.pattern = 'spec/**/*_spec.rb' end rescue LoadError desc "rspec is not installed, this task is disabled" task :spec do abort "rspec is not installed. `(sudo) gem install rspec` to run unit tests" end end task :default => :spec ohai-6.14.0/docs/0000755000175000017500000000000011761755160012767 5ustar tfheentfheenohai-6.14.0/docs/man/0000755000175000017500000000000011761755160013542 5ustar tfheentfheenohai-6.14.0/docs/man/man1/0000755000175000017500000000000011761755160014376 5ustar tfheentfheenohai-6.14.0/docs/man/man1/ohai.10000644000175000017500000000110211761755160015372 0ustar tfheentfheen.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. .TH OHAI "1" "April 2009" "ohai" "User Commands" .SH NAME ohai \- collect system information .SH SYNOPSIS .B ohai [\fIOPTION\fR]... .SH DESCRIPTION Information about your system is collected and returned as multidimensional attributes in a JSON format. .TP \fB\-d\fR, \fB\-\-directory\fR NAME A directory to add to the Ohai search path .TP \fB\-f\fR, \fB\-\-file\fR NAME A file to run Ohai against .TP \fB\-l\fR, \fB\-\-loglevel\fR NAME Set log level for Ohai .TP \fB\-h\fR, \fB\-\-help\fR Show this message .IP ohai-6.14.0/bin/0000755000175000017500000000000011761755160012607 5ustar tfheentfheenohai-6.14.0/bin/ohai0000755000175000017500000000256511761755160013465 0ustar tfheentfheen#!/usr/bin/env ruby # # ./ohai - I'm in ur serverz, showin you the daters # # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # begin require 'rubygems' rescue LoadError # must be debian! ;) missing_rubygems = true end begin # if we're in a source code checkout, we want to run the code from that. # have to do this *after* rubygems is loaded. $:.unshift File.expand_path('../../lib', __FILE__) require 'ohai/application' rescue LoadError if missing_rubygems STDERR.puts "rubygems previously failed to load - is it installed?" end raise end if RUBY_PLATFORM =~ /mswin|mingw32|windows/ begin require 'ruby-wmi' rescue LoadError STDERR.puts "ruby-wmi failed to load - is it installed?" raise end end Ohai::Application.new.run ohai-6.14.0/lib/0000755000175000017500000000000011761755160012605 5ustar tfheentfheenohai-6.14.0/lib/ohai.rb0000644000175000017500000000135711761755160014060 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ohai/version' require 'ohai/config' require 'ohai/system' ohai-6.14.0/lib/ohai/0000755000175000017500000000000011761755160013525 5ustar tfheentfheenohai-6.14.0/lib/ohai/config.rb0000644000175000017500000000263011761755160015320 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'mixlib/config' module Ohai class Config extend Mixlib::Config # from chef/config.rb, should maybe be moved to mixlib-config? def self.platform_specific_path(path) if RUBY_PLATFORM =~ /mswin|mingw|windows/ # turns /etc/chef/client.rb into C:/chef/client.rb path = File.join(ENV['SYSTEMDRIVE'], path.split('/')[2..-1]) # ensure all forward slashes are backslashes path.gsub!(File::SEPARATOR, (File::ALT_SEPARATOR || '\\')) end path end log_level :info log_location STDOUT plugin_path [ File.expand_path(File.join(File.dirname(__FILE__), 'plugins'))] disabled_plugins [] hints_path [ platform_specific_path('/etc/chef/ohai/hints') ] end end ohai-6.14.0/lib/ohai/application.rb0000644000175000017500000000630311761755160016357 0ustar tfheentfheen# # Author:: Mathieu Sauve-Frankel # Copyright:: Copyright (c) 2009 Mathieu Sauve-Frankel. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'ohai' require 'ohai/log' require 'mixlib/cli' class Ohai::Application include Mixlib::CLI option :directory, :short => "-d DIRECTORY", :long => "--directory DIRECTORY", :description => "A directory to add to the Ohai search path" option :file, :short => "-f FILE", :long => "--file FILE", :description => "A file to run Ohai against" option :log_level, :short => "-l LEVEL", :long => "--log_level LEVEL", :description => "Set the log level (debug, info, warn, error, fatal)", :proc => lambda { |l| l.to_sym } option :log_location, :short => "-L LOGLOCATION", :long => "--logfile LOGLOCATION", :description => "Set the log file location, defaults to STDOUT - recommended for daemonizing", :proc => nil option :help, :short => "-h", :long => "--help", :description => "Show this message", :on => :tail, :boolean => true, :show_options => true, :exit => 0 option :version, :short => "-v", :long => "--version", :description => "Show chef version", :boolean => true, :proc => lambda {|v| puts "Ohai: #{::Ohai::VERSION}"}, :exit => 0 def initialize super # Always switch to a readable directory. Keeps subsequent Dir.chdir() {} # from failing due to permissions when launched as a less privileged user. Dir.chdir("/") end def run configure_ohai configure_logging run_application end def configure_ohai @attributes = parse_options Ohai::Config.merge!(config) if Ohai::Config[:directory] Ohai::Config[:plugin_path] << Ohai::Config[:directory] end end def configure_logging Ohai::Log.init(Ohai::Config[:log_location]) Ohai::Log.level = Ohai::Config[:log_level] end def run_application ohai = Ohai::System.new if Ohai::Config[:file] ohai.from_file(Ohai::Config[:file]) else ohai.all_plugins end if @attributes.length > 0 @attributes.each do |a| puts ohai.attributes_print(a) end else puts ohai.json_pretty_print end end class << self # Log a fatal error message to both STDERR and the Logger, exit the application def fatal!(msg, err = -1) STDERR.puts("FATAL: #{msg}") Chef::Log.fatal(msg) Process.exit err end def exit!(msg, err = -1) Chef::Log.debug(msg) Process.exit err end end end ohai-6.14.0/lib/ohai/version.rb0000644000175000017500000000141011761755160015533 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # module Ohai OHAI_ROOT = File.expand_path(File.dirname(__FILE__)) VERSION = '6.14.0' end ohai-6.14.0/lib/ohai/exception.rb0000644000175000017500000000137011761755160016051 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # module Ohai module Exceptions class Exec < RuntimeError; end end end ohai-6.14.0/lib/ohai/mixin/0000755000175000017500000000000011761755160014651 5ustar tfheentfheenohai-6.14.0/lib/ohai/mixin/string.rb0000644000175000017500000000230611761755160016505 0ustar tfheentfheen# # Author:: James Gartrell () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # class String # Add string function to handle WMI property conversion to json hash keys # Makes an underscored, lowercase form from the expression in the string. # underscore will also change ’::’ to ’/’ to convert namespaces to paths. # This should implement the same functionality as underscore method in # ActiveSupport::CoreExtensions::String::Inflections def wmi_underscore self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase end end ohai-6.14.0/lib/ohai/mixin/ec2_metadata.rb0000644000175000017500000000541011761755160017507 0ustar tfheentfheen# # Author:: Tim Dysinger () # Author:: Benjamin Black () # Author:: Christopher Brown () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'net/http' require 'socket' module Ohai module Mixin module Ec2Metadata EC2_METADATA_ADDR = "169.254.169.254" unless defined?(EC2_METADATA_ADDR) EC2_METADATA_URL = "/2008-02-01/meta-data" unless defined?(EC2_METADATA_URL) EC2_USERDATA_URL = "/2008-02-01/user-data" unless defined?(EC2_USERDATA_URL) EC2_ARRAY_VALUES = %w(security-groups) def can_metadata_connect?(addr, port, timeout=2) t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0) saddr = Socket.pack_sockaddr_in(port, addr) connected = false begin t.connect_nonblock(saddr) rescue Errno::EINPROGRESS r,w,e = IO::select(nil,[t],nil,timeout) if !w.nil? connected = true else begin t.connect_nonblock(saddr) rescue Errno::EISCONN t.close connected = true rescue SystemCallError end end rescue SystemCallError end Ohai::Log.debug("can_metadata_connect? == #{connected}") connected end def http_client Net::HTTP.start(EC2_METADATA_ADDR).tap {|h| h.read_timeout = 600} end def fetch_metadata(id='') metadata = Hash.new http_client.get("#{EC2_METADATA_URL}/#{id}").body.split("\n").each do |o| key = "#{id}#{o.gsub(/\=.*$/, '/')}" if key[-1..-1] != '/' metadata[key.gsub(/\-|\//, '_').to_sym] = if EC2_ARRAY_VALUES.include? key http_client.get("#{EC2_METADATA_URL}/#{key}").body.split("\n") else http_client.get("#{EC2_METADATA_URL}/#{key}").body end else fetch_metadata(key).each{|k,v| metadata[k] = v} end end metadata end def fetch_userdata() response = http_client.get("#{EC2_USERDATA_URL}/") response.code == "200" ? response.body : nil end end end end ohai-6.14.0/lib/ohai/mixin/command.rb0000644000175000017500000002667111761755160016630 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ohai/exception' require 'ohai/config' require 'ohai/log' require 'stringio' require 'tmpdir' require 'fcntl' require 'etc' require 'systemu' module Ohai module Mixin module Command def run_command(args={}) if args.has_key?(:creates) if File.exists?(args[:creates]) Ohai::Log.debug("Skipping #{args[:command]} - creates #{args[:creates]} exists.") return false end end stdout_string = nil stderr_string = nil args[:cwd] ||= Dir.tmpdir unless File.directory?(args[:cwd]) raise Ohai::Exceptions::Exec, "#{args[:cwd]} does not exist or is not a directory" end status = nil Dir.chdir(args[:cwd]) do status, stdout_string, stderr_string = run_command_backend(args[:command], args[:timeout]) # systemu returns 42 when it hits unexpected errors if status.exitstatus == 42 and stderr_string == "" stderr_string = "Failed to run: #{args[:command]}, assuming command not found" Ohai::Log.debug(stderr_string) end if stdout_string Ohai::Log.debug("---- Begin #{args[:command]} STDOUT ----") Ohai::Log.debug(stdout_string.strip) Ohai::Log.debug("---- End #{args[:command]} STDOUT ----") end if stderr_string Ohai::Log.debug("---- Begin #{args[:command]} STDERR ----") Ohai::Log.debug(stderr_string.strip) Ohai::Log.debug("---- End #{args[:command]} STDERR ----") end args[:returns] ||= 0 args[:no_status_check] ||= false if status.exitstatus != args[:returns] and not args[:no_status_check] raise Ohai::Exceptions::Exec, "#{args[:command_string]} returned #{status.exitstatus}, expected #{args[:returns]}" else Ohai::Log.debug("Ran #{args[:command_string]} (#{args[:command]}) returned #{status.exitstatus}") end end return status, stdout_string, stderr_string end module_function :run_command def run_command_unix(command, timeout) stderr_string, stdout_string, status = "", "", nil exec_processing_block = lambda do |pid, stdin, stdout, stderr| stdout_string, stderr_string = stdout.string.chomp, stderr.string.chomp end if timeout begin Timeout.timeout(timeout) do status = popen4(command, {}, &exec_processing_block) end rescue Timeout::Error => e Chef::Log.error("#{command} exceeded timeout #{timeout}") raise(e) end else status = popen4(command, {}, &exec_processing_block) end return status, stdout_string, stderr_string end def run_command_windows(command, timeout) if timeout begin systemu(command) rescue SystemExit => e raise rescue Timeout::Error => e Ohai::Log.error("#{command} exceeded timeout #{timeout}") raise(e) end else systemu(command) end end if RUBY_PLATFORM =~ /mswin|mingw32|windows/ alias :run_command_backend :run_command_windows else alias :run_command_backend :run_command_unix end # This is taken directly from Ara T Howard's Open4 library, and then # modified to suit the needs of Ohai. Any bugs here are most likely # my own, and not Ara's. # # The original appears in external/open4.rb in its unmodified form. # # Thanks Ara! def popen4(cmd, args={}, &b) ## Disable garbage collection to work around possible bug in MRI # Ruby 1.8 suffers from intermittent segfaults believed to be due to GC while IO.select # See OHAI-330 / CHEF-2916 / CHEF-1305 GC.disable # Waitlast - this is magic. # # Do we wait for the child process to die before we yield # to the block, or after? That is the magic of waitlast. # # By default, we are waiting before we yield the block. args[:waitlast] ||= false args[:user] ||= nil unless args[:user].kind_of?(Integer) args[:user] = Etc.getpwnam(args[:user]).uid if args[:user] end args[:group] ||= nil unless args[:group].kind_of?(Integer) args[:group] = Etc.getgrnam(args[:group]).gid if args[:group] end args[:environment] ||= {} # Default on C locale so parsing commands output can be done # independently of the node's default locale. # "LC_ALL" could be set to nil, in which case we also must ignore it. unless args[:environment].has_key?("LC_ALL") args[:environment]["LC_ALL"] = "C" end pw, pr, pe, ps = IO.pipe, IO.pipe, IO.pipe, IO.pipe verbose = $VERBOSE begin $VERBOSE = nil ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) cid = fork { Process.setsid pw.last.close STDIN.reopen pw.first pw.first.close pr.first.close STDOUT.reopen pr.last pr.last.close pe.first.close STDERR.reopen pe.last pe.last.close STDOUT.sync = STDERR.sync = true if args[:group] Process.egid = args[:group] Process.gid = args[:group] end if args[:user] Process.euid = args[:user] Process.uid = args[:user] end args[:environment].each do |key,value| ENV[key] = value end if args[:umask] umask = ((args[:umask].respond_to?(:oct) ? args[:umask].oct : args[:umask].to_i) & 007777) File.umask(umask) end begin if cmd.kind_of?(Array) exec(*cmd) else exec(cmd) end raise 'forty-two' rescue Exception => e Marshal.dump(e, ps.last) ps.last.flush end ps.last.close unless (ps.last.closed?) exit! } ensure $VERBOSE = verbose end [pw.first, pr.last, pe.last, ps.last].each{|fd| fd.close} begin e = Marshal.load ps.first raise(Exception === e ? e : "unknown failure!") rescue EOFError # If we get an EOF error, then the exec was successful 42 ensure ps.first.close end pw.last.sync = true pi = [pw.last, pr.first, pe.first] if b begin if args[:waitlast] b[cid, *pi] # send EOF so that if the child process is reading from STDIN # it will actually finish up and exit pi[0].close_write Process.waitpid2(cid).last else # This took some doing. # The trick here is to close STDIN # Then set our end of the childs pipes to be O_NONBLOCK # Then wait for the child to die, which means any IO it # wants to do must be done - it's dead. If it isn't, # it's because something totally skanky is happening, # and we don't care. o = StringIO.new e = StringIO.new #pi[0].close stdout = pi[1] stderr = pi[2] stdout.sync = true stderr.sync = true stdout.fcntl(Fcntl::F_SETFL, pi[1].fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK) stderr.fcntl(Fcntl::F_SETFL, pi[2].fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK) stdout_finished = false stderr_finished = false results = nil while !stdout_finished || !stderr_finished begin channels_to_watch = [] channels_to_watch << stdout if !stdout_finished channels_to_watch << stderr if !stderr_finished ready = IO.select(channels_to_watch, nil, nil, 1.0) rescue Errno::EAGAIN ensure results = Process.waitpid2(cid, Process::WNOHANG) if results stdout_finished = true stderr_finished = true end end if ready && ready.first.include?(stdout) line = results ? stdout.gets(nil) : stdout.gets if line o.write(line) else stdout_finished = true end end if ready && ready.first.include?(stderr) line = results ? stderr.gets(nil) : stderr.gets if line e.write(line) else stderr_finished = true end end end results = Process.waitpid2(cid) unless results o.rewind e.rewind # **OHAI-275** # The way we read from the pipes causes ruby to mark the strings # as ASCII-8BIT (i.e., binary), but the content should be encoded # as the default external encoding. For example, a command may # return data encoded as UTF-8, but the strings will be marked as # ASCII-8BIT. Later, when you attempt to print the values as # UTF-8, Ruby will try to convert them and fail, raising an # error. # # Ruby always marks strings as binary when read from IO in # incomplete chunks, since you may have split the data within a # multibyte char. In our case, we concat the chunks back # together, so any multibyte chars will be reassembled. # # Note that all of this applies only to Ruby 1.9, which we check # for by making sure that the Encoding class exists and strings # have encoding methods. if "".respond_to?(:force_encoding) && defined?(Encoding) o.string.force_encoding(Encoding.default_external) e.string.force_encoding(Encoding.default_external) end b[cid, pi[0], o, e] results.last end ensure pi.each{|fd| fd.close unless fd.closed?} end else [cid, pw.last, pr.first, pe.first] end rescue Errno::ENOENT raise Ohai::Exceptions::Exec, "command #{cmd} doesn't exist or is not in the PATH" ensure # we disabled GC entering GC.enable end module_function :popen4 end end end ohai-6.14.0/lib/ohai/mixin/from_file.rb0000644000175000017500000000226011761755160017140 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # module Ohai module Mixin module FromFile # Loads a given ruby file, and runs instance_eval against it in the context of the current # object. # # Raises an IOError if the file cannot be found, or is not readable. def from_file(filename) if File.exists?(filename) && File.readable?(filename) self.instance_eval(IO.read(filename), filename, 1) else raise IOError, "Cannot open or read #{filename}!" end end end end end ohai-6.14.0/lib/ohai/log.rb0000644000175000017500000000154511761755160014640 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ohai/config' require 'mixlib/log' module Ohai class Log extend Mixlib::Log init(Ohai::Config[:log_location]) level = Ohai::Config[:log_level] end end ohai-6.14.0/lib/ohai/mash.rb0000644000175000017500000001507311761755160015010 0ustar tfheentfheen# Copyright (c) 2009 Dan Kubb # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # --- # --- # Some portions of blank.rb and mash.rb are verbatim copies of software # licensed under the MIT license. That license is included below: # Copyright (c) 2005-2008 David Heinemeier Hansson # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # This class has dubious semantics and we only have it so that people can write # params[:key] instead of params['key']. class Mash < Hash # @param constructor # The default value for the mash. Defaults to an empty hash. # # @details [Alternatives] # If constructor is a Hash, a new mash will be created based on the keys of # the hash and no default value will be set. def initialize(constructor = {}) if constructor.is_a?(Hash) super() update(constructor) else super(constructor) end end # @param key The default value for the mash. Defaults to nil. # # @details [Alternatives] # If key is a Symbol and it is a key in the mash, then the default value will # be set to the value matching the key. def default(key = nil) if key.is_a?(Symbol) && include?(key = key.to_s) self[key] else super end end alias_method :regular_writer, :[]= unless method_defined?(:regular_writer) alias_method :regular_update, :update unless method_defined?(:regular_update) # @param key The key to set. # @param value # The value to set the key to. # # @see Mash#convert_key # @see Mash#convert_value def []=(key, value) regular_writer(convert_key(key), convert_value(value)) end # @param other_hash # A hash to update values in the mash with. The keys and the values will be # converted to Mash format. # # @return [Mash] The updated mash. def update(other_hash) other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } self end alias_method :merge!, :update # @param key The key to check for. This will be run through convert_key. # # @return [Boolean] True if the key exists in the mash. def key?(key) super(convert_key(key)) end # def include? def has_key? def member? alias_method :include?, :key? alias_method :has_key?, :key? alias_method :member?, :key? # @param key The key to fetch. This will be run through convert_key. # @param *extras Default value. # # @return [Object] The value at key or the default value. def fetch(key, *extras) super(convert_key(key), *extras) end # @param *indices # The keys to retrieve values for. These will be run through +convert_key+. # # @return [Array] The values at each of the provided keys def values_at(*indices) indices.collect {|key| self[convert_key(key)]} end # @param hash The hash to merge with the mash. # # @return [Mash] A new mash with the hash values merged in. def merge(hash) self.dup.update(hash) end # @param key # The key to delete from the mash.\ def delete(key) super(convert_key(key)) end # @param *rejected 1, :two => 2, :three => 3 }.except(:one) # #=> { "two" => 2, "three" => 3 } def except(*keys) super(*keys.map {|k| convert_key(k)}) end # Used to provide the same interface as Hash. # # @return [Mash] This mash unchanged. def stringify_keys!; self end # @return [Hash] The mash as a Hash with symbolized keys. def symbolize_keys h = Hash.new(default) each { |key, val| h[key.to_sym] = val } h end # @return [Hash] The mash as a Hash with string keys. def to_hash Hash.new(default).merge(self) end # @return [Mash] Convert a Hash into a Mash # The input Hash's default value is maintained def self.from_hash(hash) mash = Mash.new(hash) mash.default = hash.default mash end protected # @param key The key to convert. # # @param [Object] # The converted key. If the key was a symbol, it will be converted to a # string. # # @api private def convert_key(key) key.kind_of?(Symbol) ? key.to_s : key end # @param value The value to convert. # # @return [Object] # The converted value. A Hash or an Array of hashes, will be converted to # their Mash equivalents. # # @api private def convert_value(value) if value.class == Hash Mash.from_hash(value) elsif value.is_a?(Array) value.collect { |e| convert_value(e) } else value end end end ohai-6.14.0/lib/ohai/plugins/0000755000175000017500000000000011761755160015206 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/ruby.rb0000644000175000017500000000453411761755160016522 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages/ruby" require_plugin "languages" def run_ruby(command) cmd = "ruby -e \"require 'rbconfig'; #{command}\"" status, stdout, stderr = run_command(:no_status_check => true, :command => cmd) stdout.strip end languages[:ruby] = Mash.new values = { :platform => "RUBY_PLATFORM", :version => "RUBY_VERSION", :release_date => "RUBY_RELEASE_DATE", :target => "::Config::CONFIG['target']", :target_cpu => "::Config::CONFIG['target_cpu']", :target_vendor => "::Config::CONFIG['target_vendor']", :target_os => "::Config::CONFIG['target_os']", :host => "::Config::CONFIG['host']", :host_cpu => "::Config::CONFIG['host_cpu']", :host_os => "::Config::CONFIG['host_os']", :host_vendor => "::Config::CONFIG['host_vendor']", :bin_dir => "::Config::CONFIG['bindir']", :ruby_bin => "::File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name'])" } # Create a query string from above hash env_string = "" values.keys.each do |v| env_string << "#{v}=\#{#{values[v]}}," end # Query the system ruby result = run_ruby "puts %Q(#{env_string})" # Parse results to plugin hash result.split(',').each do |entry| key, value = entry.split('=') languages[:ruby][key.to_sym] = value || "" end # Perform one more (conditional) query bin_dir = languages[:ruby][:bin_dir] ruby_bin = languages[:ruby][:ruby_bin] gem_binaries = [ run_ruby("require 'rubygems'; puts ::Gem.default_exec_format % 'gem'"), "gem" ].map {|bin| ::File.join(bin_dir, bin)} gem_binary = gem_binaries.find {|bin| ::File.exists? bin } if gem_binary languages[:ruby][:gems_dir] = run_ruby "puts %x{#{ruby_bin} #{gem_binary} env gemdir}.chomp!" languages[:ruby][:gem_bin] = gem_binary end ohai-6.14.0/lib/ohai/plugins/python.rb0000644000175000017500000000223511761755160017056 0ustar tfheentfheen# # Author:: Thom May () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages/python" require_plugin "languages" output = nil python = Mash.new status, stdout, stderr = run_command(:no_status_check => true, :command => "python -c \"import sys; print sys.version\"") if status == 0 output = stdout.split python[:version] = output[0] if output.length >= 6 python[:builddate] = "%s %s %s %s" % [output[2],output[3],output[4],output[5].gsub!(/\)/,'')] end languages[:python] = python if python[:version] and python[:builddate] end ohai-6.14.0/lib/ohai/plugins/freebsd/0000755000175000017500000000000011761755160016620 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/freebsd/kernel.rb0000644000175000017500000000224111761755160020424 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "kernel" kernel[:os] = kernel[:name] kernel[:ident] = from("uname -i") kernel[:securelevel] = from_with_regex("sysctl kern.securelevel", /kern.securelevel: (.+)$/) kld = Mash.new popen4("/sbin/kldstat") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| # 1 7 0xc0400000 97f830 kernel if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/ kld[$5] = { :size => $4, :refcount => $2 } end end end kernel[:modules] = kld ohai-6.14.0/lib/ohai/plugins/freebsd/filesystem.rb0000644000175000017500000000316011761755160021331 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "filesystem" fs = Mash.new # Grab filesystem data from df popen4("df") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^Filesystem/ next when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ filesystem = $1 fs[filesystem] = Mash.new fs[filesystem][:kb_size] = $2 fs[filesystem][:kb_used] = $3 fs[filesystem][:kb_available] = $4 fs[filesystem][:percent_used] = $5 fs[filesystem][:mount] = $6 end end end # Grab mount information from mount popen4("mount -l") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/ filesystem = $1 fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:mount] = $2 fs[filesystem][:fs_type] = $3 fs[filesystem][:mount_options] = $4.split(/,\s*/) end end end # Set the filesystem data filesystem fs ohai-6.14.0/lib/ohai/plugins/freebsd/cpu.rb0000644000175000017500000000357211761755160017743 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2008 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "cpu" # all dmesg output for smp I can find only provides info about a single processor # identical processors is probably a hardware requirement so we'll duplicate data for each cpu # old examples: http://www.bnv-bamberg.de/home/ba3294/smp/rbuild/index.htm cpuinfo = Mash.new # /var/run/dmesg.boot #CPU: QEMU Virtual CPU version 0.9.1 (1862.02-MHz 686-class CPU) # Origin = "GenuineIntel" Id = 0x623 Stepping = 3 # Features=0x78bfbfd # Features2=0x80000001> File.open("/var/run/dmesg.boot").each do |line| case line when /CPU:\s+(.+) \(([\d.]+).+\)/ cpuinfo["model_name"] = $1 cpuinfo["mhz"] = $2 when /Origin = "(.+)"\s+Id = (.+)\s+Stepping = (.+)/ cpuinfo["vendor_id"] = $1 cpuinfo["stepping"] = $3 # These _should_ match /AMD Features2?/ lines as well when /Features=.+<(.+)>/ cpuinfo["flags"] = $1.downcase.split(',') # Features2=0x80000001> when /Features2=[a-f\dx]+<(.+)>/ cpuinfo["flags"].concat($1.downcase.split(',')) when /Logical CPUs per core: (\d+)/ cpuinfo["cores"] = $1 end end cpu cpuinfo cpu[:total] = from("sysctl -n hw.ncpu") ohai-6.14.0/lib/ohai/plugins/freebsd/memory.rb0000644000175000017500000000371011761755160020456 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "memory" memory Mash.new memory[:swap] = Mash.new # /usr/src/sys/sys/vmmeter.h memory[:page_size] = from("sysctl -n vm.stats.vm.v_page_size") memory[:page_count] = from("sysctl -n vm.stats.vm.v_page_count") memory[:total] = memory[:page_size].to_i * memory[:page_count].to_i memory[:free] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_free_count").to_i memory[:active] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_active_count").to_i memory[:inactive] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_inactive_count").to_i memory[:cache] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_cache_count").to_i memory[:wired] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_wire_count").to_i memory[:buffers] = from("sysctl -n vfs.bufspace") popen4("swapinfo") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| # Device 1K-blocks Used Avail Capacity # /dev/ad0s1b 253648 0 253648 0% if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/ mdev = $1 memory[:swap][mdev] = Mash.new memory[:swap][mdev][:total] = $2 memory[:swap][mdev][:used] = $3 memory[:swap][mdev][:free] = $4 memory[:swap][mdev][:percent_free] = $5 end end end ohai-6.14.0/lib/ohai/plugins/freebsd/ps.rb0000644000175000017500000000142111761755160017565 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "command/ps" require_plugin 'command' # ps -e requires procfs command[:ps] = 'ps -ax' ohai-6.14.0/lib/ohai/plugins/freebsd/network.rb0000644000175000017500000001075711761755160020650 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "network", "counters/network" from("route -n get default").split("\n").each do |line| if line =~ /(\w+): ([\w\.]+)/ case $1 when "gateway" network[:default_gateway] = $2 when "interface" network[:default_interface] = $2 end end end iface = Mash.new popen4("/sbin/ifconfig -a") do |pid, stdin, stdout, stderr| stdin.close cint = nil stdout.each do |line| if line =~ /^([0-9a-zA-Z\.]+):\s+/ cint = $1 iface[cint] = Mash.new if cint =~ /^(\w+)(\d+.*)/ iface[cint][:type] = $1 iface[cint][:number] = $2 end end # call the family lladdr to match linux for consistency if line =~ /\s+ether (.+?)\s/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "lladdr" } end if line =~ /\s+inet ([\d.]+) netmask ([\da-fx]+)\s*\w*\s*([\d.]*)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] # convert the netmask to decimal for consistency netmask = "#{$2[2,2].hex}.#{$2[4,2].hex}.#{$2[6,2].hex}.#{$2[8,2].hex}" if $3.empty? iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask } else # found a broadcast address iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask, "broadcast" => $3 } end end if line =~ /\s+inet6 ([a-f0-9\:]+)%?(\w*)\s+prefixlen\s+(\d+)\s*\w*\s*([\da-fx]*)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] if $4.empty? iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $3 } else # found a zone_id / scope iface[cint][:addresses][$1] = { "family" => "inet6", "zoneid" => $2, "prefixlen" => $3, "scopeid" => $4 } end end if line =~ /flags=\d+<(.+)>/ flags = $1.split(',') iface[cint][:flags] = flags if flags.length > 0 end if line =~ /metric: (\d+) mtu: (\d+)/ iface[cint][:metric] = $1 iface[cint][:mtu] = $2 end end end popen4("arp -an") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/ next unless iface[$3] # this should never happen iface[$3][:arp] = Mash.new unless iface[$3][:arp] iface[$3][:arp][$1] = $2.downcase end end end network["interfaces"] = iface net_counters = Mash.new # From netstat(1), not sure of the implications: # Show the state of all network interfaces or a single interface # which have been auto-configured (interfaces statically configured # into a system, but not located at boot time are not shown). popen4("netstat -ibdn") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| # Name Mtu Network Address Ipkts Ierrs Ibytes Opkts Oerrs Obytes Coll Drop # ed0 1500 54:52:00:68:92:85 333604 26 151905886 175472 0 24897542 0 905 # $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 if line =~ /^([\w\.\*]+)\s+\d+\s+\s+([\w:]*)\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ net_counters[$1] = Mash.new unless net_counters[$1] net_counters[$1]["rx"] = Mash.new unless net_counters[$1]["rx"] net_counters[$1]["tx"] = Mash.new unless net_counters[$1]["tx"] net_counters[$1]["rx"]["packets"] = $3 net_counters[$1]["rx"]["errors"] = $4 net_counters[$1]["rx"]["bytes"] = $5 net_counters[$1]["tx"]["packets"] = $6 net_counters[$1]["tx"]["errors"] = $7 net_counters[$1]["tx"]["bytes"] = $8 net_counters[$1]["tx"]["collisions"] = $9 net_counters[$1]["tx"]["dropped"] = $10 end end end counters[:network][:interfaces] = net_counters ohai-6.14.0/lib/ohai/plugins/freebsd/hostname.rb0000644000175000017500000000140111761755160020757 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "hostname", "fqdn" hostname from("hostname -s") fqdn from("hostname -f") ohai-6.14.0/lib/ohai/plugins/freebsd/uptime.rb0000644000175000017500000000205111761755160020446 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "uptime", "uptime_seconds" # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009 popen4("/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /kern.boottime:\D+(\d+)/ uptime_seconds Time.new.to_i - $1.to_i uptime self._seconds_to_human(uptime_seconds) end end end ohai-6.14.0/lib/ohai/plugins/freebsd/platform.rb0000644000175000017500000000143511761755160020774 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "platform", "platform_version" platform from("uname -s").downcase platform_version from("uname -r") ohai-6.14.0/lib/ohai/plugins/freebsd/virtualization.rb0000644000175000017500000000476311761755160022243 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "virtualization" virtualization Mash.new if from("sysctl -n security.jail.jailed").to_i == 1 virtualization[:system] = "jail" virtualization[:role] = "guest" end # XXX doesn't work when jail is there but not running (ezjail-admin stop) if from("jls -n \| wc -l").to_i >= 1 virtualization[:system] = "jail" virtualization[:role] = "host" end # KVM Host support for FreeBSD is in development # http://feanor.sssup.it/~fabio/freebsd/lkvm/ # Detect KVM/QEMU from cpu, report as KVM # hw.model: QEMU Virtual CPU version 0.9.1 if from("sysctl -n hw.model") =~ /QEMU Virtual CPU/ virtualization[:system] = "kvm" virtualization[:role] = "guest" end # http://www.dmo.ca/blog/detecting-virtualization-on-linux if File.exists?("/usr/local/sbin/dmidecode") popen4("dmidecode") do |pid, stdin, stdout, stderr| stdin.close found_virt_manufacturer = nil found_virt_product = nil stdout.each do |line| case line when /Manufacturer: Microsoft/ found_virt_manufacturer = "microsoft" when /Product Name: Virtual Machine/ found_virt_product = "microsoft" when /Version: 5.0/ if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft" virtualization[:system] = "virtualpc" virtualization[:role] = "guest" end when /Version: VS2005R2/ if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft" virtualization[:system] = "virtualserver" virtualization[:role] = "guest" end when /Manufacturer: VMware/ found_virt_manufacturer = "vmware" when /Product Name: VMware Virtual Platform/ if found_virt_manufacturer == "vmware" virtualization[:system] = "vmware" virtualization[:role] = "guest" end end end end end ohai-6.14.0/lib/ohai/plugins/freebsd/ssh_host_key.rb0000644000175000017500000000161611761755160021653 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "keys/ssh" require_plugin "keys" keys[:ssh] = Mash.new keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1] keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1] ohai-6.14.0/lib/ohai/plugins/perl.rb0000644000175000017500000000214011761755160016472 0ustar tfheentfheen# # Author:: Joshua Timberman () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages/perl" require_plugin "languages" output = nil perl = Mash.new status, stdout, stderr = run_command(:no_status_check => true, :command => "perl -V:version -V:archname") if status == 0 stdout.each_line do |line| case line when /^version=\'(.+)\';$/ perl[:version] = $1 when /^archname=\'(.+)\';$/ perl[:archname] = $1 end end end if status == 0 languages[:perl] = perl end ohai-6.14.0/lib/ohai/plugins/kernel.rb0000644000175000017500000000200111761755160017004 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "kernel" require_plugin 'ruby' kernel Mash.new case languages[:ruby][:host_os] when /mswin|mingw32|windows/ require_plugin "windows::kernel" else kernel[:name] = from("uname -s") kernel[:release] = from("uname -r") kernel[:version] = from("uname -v") kernel[:machine] = from("uname -m") kernel[:modules] = Mash.new end ohai-6.14.0/lib/ohai/plugins/windows/0000755000175000017500000000000011761755160016700 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/windows/kernel.rb0000644000175000017500000000520011761755160020502 0ustar tfheentfheen# # Author:: James Gartrell () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ruby-wmi' WIN32OLE.codepage = WIN32OLE::CP_UTF8 def machine_lookup(sys_type) return "i386" if sys_type.eql?("X86-based PC") return "x86_64" if sys_type.eql?("x64-based PC") sys_type end def os_lookup(sys_type) return "Unknown" if sys_type.to_s.eql?("0") return "Other" if sys_type.to_s.eql?("1") return "MSDOS" if sys_type.to_s.eql?("14") return "WIN3x" if sys_type.to_s.eql?("15") return "WIN95" if sys_type.to_s.eql?("16") return "WIN98" if sys_type.to_s.eql?("17") return "WINNT" if sys_type.to_s.eql?("18") return "WINCE" if sys_type.to_s.eql?("19") return nil end host = WMI::Win32_OperatingSystem.find(:first) kernel[:os_info] = Mash.new host.properties_.each do |p| kernel[:os_info][p.name.wmi_underscore.to_sym] = host.send(p.name) end kernel[:name] = "#{kernel[:os_info][:caption]}" kernel[:release] = "#{kernel[:os_info][:version]}" kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}" kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os] host = WMI::Win32_ComputerSystem.find(:first) kernel[:cs_info] = Mash.new host.properties_.each do |p| kernel[:cs_info][p.name.wmi_underscore.to_sym] = host.send(p.name) end kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}") kext = Mash.new pnp_drivers = Mash.new drivers = WMI::Win32_PnPSignedDriver.find(:all) drivers.each do |driver| pnp_drivers[driver.DeviceID] = Mash.new driver.properties_.each do |p| pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver.send(p.name) end if driver.DeviceName kext[driver.DeviceName] = pnp_drivers[driver.DeviceID] kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version] kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil end end kernel[:pnp_drivers] = pnp_drivers kernel[:modules] = kext ohai-6.14.0/lib/ohai/plugins/windows/filesystem.rb0000644000175000017500000000342211761755160021412 0ustar tfheentfheen# # Author:: James Gartrell () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ruby-wmi' fs = Mash.new ld_info = Mash.new # Grab filesystem data from WMI # Note: we should really be parsing Win32_Volume and Win32_Mapped drive disks = WMI::Win32_LogicalDisk.find(:all) disks.each do |disk| filesystem = disk.DeviceID fs[filesystem] = Mash.new ld_info[filesystem] = Mash.new disk.properties_.each do |p| ld_info[filesystem][p.name.wmi_underscore.to_sym] = disk.send(p.name) end fs[filesystem][:kb_size] = ld_info[filesystem][:size].to_i / 1000 fs[filesystem][:kb_available] = ld_info[filesystem][:free_space].to_i / 1000 fs[filesystem][:kb_used] = fs[filesystem][:kb_size].to_i - fs[filesystem][:kb_available].to_i fs[filesystem][:percent_used] = (fs[filesystem][:kb_size].to_i != 0 ? fs[filesystem][:kb_used].to_i * 100 / fs[filesystem][:kb_size].to_i : 0) fs[filesystem][:mount] = ld_info[filesystem][:name] fs[filesystem][:fs_type] = ld_info[filesystem][:file_system].downcase unless ld_info[filesystem][:file_system] == nil fs[filesystem][:volume_name] = ld_info[filesystem][:volume_name] end # Set the filesystem data filesystem fs ohai-6.14.0/lib/ohai/plugins/windows/cpu.rb0000644000175000017500000000311311761755160020012 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ruby-wmi' provides "cpu" cpuinfo = Mash.new cpu_number = 0 index = 0 WMI::Win32_Processor.find(:all).each do |processor| cpu_number += processor.numberofcores current_cpu = index.to_s index += 1 cpuinfo[current_cpu] = Mash.new cpuinfo[current_cpu]["vendor_id"] = processor.manufacturer cpuinfo[current_cpu]["family"] = processor.family.to_s cpuinfo[current_cpu]["model"] = processor.revision.to_s cpuinfo[current_cpu]["stepping"] = processor.stepping cpuinfo[current_cpu]["physical_id"] = processor.deviceid #cpuinfo[current_cpu]["core_id"] = XXX cpuinfo[current_cpu]["cores"] = processor.numberofcores cpuinfo[current_cpu]["model_name"] = processor.description cpuinfo[current_cpu]["mhz"] = processor.maxclockspeed.to_s cpuinfo[current_cpu]["cache_size"] = "#{processor.l2cachesize} KB" #cpuinfo[current_cpu]["flags"] = XXX end cpu cpuinfo cpu[:total] = cpu_number cpu[:real] = index ohai-6.14.0/lib/ohai/plugins/windows/network.rb0000644000175000017500000000775611761755160020735 0ustar tfheentfheen# # Author:: James Gartrell () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "network" require 'ruby-wmi' def encaps_lookup(encap) return "Ethernet" if encap.eql?("Ethernet 802.3") encap end iface = Mash.new iface_config = Mash.new iface_instance = Mash.new # http://msdn.microsoft.com/en-us/library/windows/desktop/aa394217%28v=vs.85%29.aspx adapters = WMI::Win32_NetworkAdapterConfiguration.find(:all) adapters.each do |adapter| i = adapter.Index iface_config[i] = Mash.new adapter.properties_.each do |p| iface_config[i][p.name.wmi_underscore.to_sym] = adapter.invoke(p.name) end end # http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx adapters = WMI::Win32_NetworkAdapter.find(:all) adapters.each do |adapter| i = adapter.Index iface_instance[i] = Mash.new adapter.properties_.each do |p| iface_instance[i][p.name.wmi_underscore.to_sym] = adapter.invoke(p.name) end end iface_instance.keys.each do |i| if iface_config[i][:ip_enabled] and iface_instance[i][:net_connection_id] cint = sprintf("0x%x", iface_instance[i][:interface_index] ? iface_instance[i][:interface_index] : iface_instance[i][:index] ).downcase iface[cint] = Mash.new iface[cint][:configuration] = iface_config[i] iface[cint][:instance] = iface_instance[i] iface[cint][:counters] = Mash.new iface[cint][:addresses] = Mash.new iface[cint][:configuration][:ip_address].each_index do |i| ip = iface[cint][:configuration][:ip_address][i] _ip = IPAddress("#{ip}/#{iface[cint][:configuration][:ip_subnet][i]}") iface[cint][:addresses][ip] = Mash.new( :prefixlen => _ip.prefix ) if _ip.ipv6? # inet6 address iface[cint][:addresses][ip][:family] = "inet6" iface[cint][:addresses][ip][:scope] = "Link" if ip =~ /^fe80/i else # should be an inet4 address iface[cint][:addresses][ip][:netmask] = _ip.netmask.to_s if iface[cint][:configuration][:ip_use_zero_broadcast] iface[cint][:addresses][ip][:broadcast] = _ip.network.to_s else iface[cint][:addresses][ip][:broadcast] = _ip.broadcast.to_s end iface[cint][:addresses][ip][:family] = "inet" end end # Apparently you can have more than one mac_address? Odd. [iface[cint][:configuration][:mac_address]].flatten.each do |mac_addr| iface[cint][:addresses][mac_addr] = { "family" => "lladdr" } end iface[cint][:mtu] = iface[cint][:configuration][:mtu] iface[cint][:type] = iface[cint][:instance][:adapter_type] iface[cint][:arp] = {} iface[cint][:encapsulation] = encaps_lookup(iface[cint][:instance][:adapter_type]) if iface[cint][:configuration][:default_ip_gateway] != nil and iface[cint][:configuration][:default_ip_gateway].size > 0 network[:default_gateway] = iface[cint][:configuration][:default_ip_gateway].first network[:default_interface] = cint end end end cint=nil status, stdout, stderr = run_command(:command => "arp -a") if status == 0 stdout.split("\n").each do |line| if line =~ /^Interface:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+[-]+\s+(0x\S+)/ cint = $2.downcase end next unless iface[cint] if line =~ /^\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-fA-F0-9\:-]+)/ iface[cint][:arp][$1] = $2.gsub("-",":").downcase end end end network["interfaces"] = iface ohai-6.14.0/lib/ohai/plugins/windows/hostname.rb0000644000175000017500000000200111761755160021034 0ustar tfheentfheen# # Author:: James Gartrell () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ruby-wmi' require 'socket' host = WMI::Win32_ComputerSystem.find(:first) hostname "#{host.Name}" info = Socket.gethostbyname(Socket.gethostname) if info.first =~ /.+?\.(.*)/ fqdn info.first else #host is not in dns. optionally use: #C:\WINDOWS\system32\drivers\etc\hosts fqdn Socket.gethostbyaddr(info.last).first end ohai-6.14.0/lib/ohai/plugins/windows/uptime.rb0000644000175000017500000000155211761755160020533 0ustar tfheentfheen# # Author:: Paul Mooring (paul@opscode.com) # Copyright:: Copyright (c) 2012 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ruby-wmi' provides "uptime", "uptime_seconds" uptime_seconds ::WMI::Win32_PerfFormattedData_PerfOS_System.find(:first).SystemUpTime.to_i uptime self._seconds_to_human(uptime_seconds) ohai-6.14.0/lib/ohai/plugins/windows/platform.rb0000644000175000017500000000207011761755160021050 0ustar tfheentfheen# # Author:: James Gartrell () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # After long discussion in IRC the "powers that be" have come to a concensus # that there is no other Windows platforms exist that were not based on the # Windows_NT kernel, so we herby decree that "windows" will refer to all # platforms built upon the Windows_NT kernel and have access to win32 or win64 # subsystems. platform os platform_version kernel['release'] platform_family "windows" ohai-6.14.0/lib/ohai/plugins/rackspace.rb0000644000175000017500000000427011761755160017472 0ustar tfheentfheen# # Author:: Cary Penniman () # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. provides "rackspace" require_plugin "kernel" require_plugin "network" # Checks for matching rackspace kernel name # # === Return # true:: If kernel name matches # false:: Otherwise def has_rackspace_kernel? kernel[:release].split('-').last.eql?("rscloud") end # Checks for matching rackspace arp mac # # === Return # true:: If mac address matches # false:: Otherwise def has_rackspace_mac? network[:interfaces].values.each do |iface| unless iface[:arp].nil? return true if iface[:arp].value?("00:00:0c:07:ac:01") or iface[:arp].value?("00:00:0c:9f:f0:01") end end false end # Identifies the rackspace cloud # # === Return # true:: If the rackspace cloud can be identified # false:: Otherwise def looks_like_rackspace? hint?('rackspace') || has_rackspace_mac? || has_rackspace_kernel? end # Names rackspace ip address # # === Parameters # name:: Use :public_ip or :private_ip # eth:: Interface name of public or private ip def get_ip_address(name, eth) network[:interfaces][eth][:addresses].each do |key, info| rackspace[name] = key if info['family'] == 'inet' end end # Adds rackspace Mash if looks_like_rackspace? rackspace Mash.new get_ip_address(:public_ip, :eth0) get_ip_address(:private_ip, :eth1) # public_ip + private_ip are deprecated in favor of public_ipv4 and local_ipv4 to standardize. rackspace[:public_ipv4] = rackspace[:public_ip] rackspace[:public_hostname] = "#{rackspace[:public_ip].gsub('.','-')}.static.cloud-ips.com" rackspace[:local_ipv4] = rackspace[:private_ip] rackspace[:local_hostname] = hostname end ohai-6.14.0/lib/ohai/plugins/openbsd/0000755000175000017500000000000011761755160016640 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/openbsd/kernel.rb0000644000175000017500000000222211761755160020443 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "kernel" kernel[:os] = kernel[:name] kernel[:securelevel] = from_with_regex("sysctl kern.securelevel", /kern.securelevel=(.+)$/) mod = Mash.new popen4("/usr/bin/modstat") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| # 1 7 0xc0400000 97f830 kernel if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/ kld[$5] = { :size => $4, :refcount => $2 } end end end kernel[:modules] = mod unless mod.empty? ohai-6.14.0/lib/ohai/plugins/openbsd/filesystem.rb0000644000175000017500000000317011761755160021352 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "filesystem" fs = Mash.new # Grab filesystem data from df popen4("df") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^Filesystem/ next when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ filesystem = $1 fs[filesystem] = Mash.new fs[filesystem]['kb_size'] = $2 fs[filesystem]['kb_used'] = $3 fs[filesystem]['kb_available'] = $4 fs[filesystem]['percent_used'] = $5 fs[filesystem]['mount'] = $6 end end end # Grab mount information from mount popen4("mount -l") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/ filesystem = $1 fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem]['mount'] = $2 fs[filesystem]['fs_type'] = $3 fs[filesystem]['mount-options'] = $4.split(/,\s*/) end end end # Set the filesystem data filesystem fs ohai-6.14.0/lib/ohai/plugins/openbsd/cpu.rb0000644000175000017500000000242011761755160017752 0ustar tfheentfheen# # Author:: Mathieu Sauve-Frankel # Copyright:: Copyright (c) 2009 Mathieu Sauve-Frankel # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides 'cpu' cpuinfo = Mash.new # OpenBSD provides most cpu information via sysctl, the only thing we need to # to scrape from dmesg.boot is the cpu feature list. # cpu0: FPU,V86,DE,PSE,TSC,MSR,MCE,CX8,SEP,MTRR,PGE,MCA,CMOV,PAT,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,TM,SBF,EST,TM2 File.open("/var/run/dmesg.boot").each do |line| case line when /cpu\d+:\s+([A-Z]+$|[A-Z]+,.*$)/ cpuinfo["flags"] = $1.downcase.split(',') end end cpuinfo[:model_name] = from("sysctl -n hw.model") cpuinfo[:total] = from("sysctl -n hw.ncpu") cpuinfo[:mhz] = from("sysctl -n hw.cpuspeed") cpu cpuinfo ohai-6.14.0/lib/ohai/plugins/openbsd/memory.rb0000644000175000017500000000625611761755160020506 0ustar tfheentfheen# # Author:: Mathieu Sauve-Frankel # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "memory" memory Mash.new memory[:swap] = Mash.new # $ vmstat -s # 4096 bytes per page # 514011 pages managed # 224519 pages free # 209339 pages active # 4647 pages inactive # 0 pages being paged out # 5 pages wired # 0 pages zeroed # 4 pages reserved for pagedaemon # 6 pages reserved for kernel # 262205 swap pages # 0 swap pages in use # 0 total anon's in system # 0 free anon's # 1192991609 page faults # 1369579301 traps # 814549706 interrupts # 771702498 cpu context switches # 208810590 fpu context switches # 492361360 software interrupts # 1161998825 syscalls # 0 pagein operations # 0 swap ins # 0 swap outs # 768352 forks # 16 forks where vmspace is shared # 1763 kernel map entries # 0 number of times the pagedaemon woke up # 0 revolutions of the clock hand # 0 pages freed by pagedaemon # 0 pages scanned by pagedaemon # 0 pages reactivated by pagedaemon # 0 busy pages found by pagedaemon # 1096393776 total name lookups # cache hits (37% pos + 2% neg) system 1% per-directory # deletions 0%, falsehits 6%, toolong 26% # 0 select collisions popen4("vmstat -s") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /(\d+) bytes per page/ memory[:page_size] = $1 when /(\d+) pages managed/ memory[:page_count] = $1 memory[:total] = memory[:page_size].to_i * memory[:page_count].to_i when /(\d+) pages free/ memory[:free] = memory[:page_size].to_i * $1.to_i when /(\d+) pages active/ memory[:active] = memory[:page_size].to_i * $1.to_i when /(\d+) pages inactive/ memory[:inactive] = memory[:page_size].to_i * $1.to_i when /(\d+) pages wired/ memory[:wired] = memory[:page_size].to_i * $1.to_i end end end popen4("swapctl -l") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| # Device 1024-blocks Used Avail Capacity Priority # swap_device 1048824 0 1048824 0% 0 if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/ mdev = $1 memory[:swap][mdev] = Mash.new memory[:swap][mdev][:total] = $2 memory[:swap][mdev][:used] = $3 memory[:swap][mdev][:free] = $4 memory[:swap][mdev][:percent_free] = $5 end end end ohai-6.14.0/lib/ohai/plugins/openbsd/ps.rb0000644000175000017500000000142111761755160017605 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "command/ps" require_plugin 'command' # ps -e requires procfs command[:ps] = 'ps -ax' ohai-6.14.0/lib/ohai/plugins/openbsd/network.rb0000644000175000017500000001036511761755160020663 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "network", "counters/network" from("route -n get default").split("\n").each do |line| if line =~ /(\w+): ([\w\.]+)/ case $1 when "gateway" network[:default_gateway] = $2 when "interface" network[:default_interface] = $2 end end end iface = Mash.new popen4("/sbin/ifconfig -a") do |pid, stdin, stdout, stderr| stdin.close cint = nil stdout.each do |line| if line =~ /^([0-9a-zA-Z\.]+):\s+/ cint = $1 iface[cint] = Mash.new if cint =~ /^(\w+)(\d+.*)/ iface[cint][:type] = $1 iface[cint][:number] = $2 end end # call the family lladdr to match linux for consistency if line =~ /\s+lladdr (.+?)\s/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "lladdr" } end if line =~ /\s+inet ([\d.]+) netmask ([\da-fx]+)\s*\w*\s*([\d.]*)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] # convert the netmask to decimal for consistency netmask = "#{$2[2,2].hex}.#{$2[4,2].hex}.#{$2[6,2].hex}.#{$2[8,2].hex}" if $3.empty? iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask } else # found a broadcast address iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask, "broadcast" => $3 } end end if line =~ /\s+inet6 ([a-f0-9\:]+)%?(\w*)\s+prefixlen\s+(\d+)\s*\w*\s*([\da-fx]*)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] if $4.empty? iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $3 } else #found a zone_id / scope iface[cint][:addresses][$1] = { "family" => "inet6", "zoneid" => $2, "prefixlen" => $3, "scopeid" => $4 } end end if line =~ /flags=\d+<(.+)>/ flags = $1.split(',') iface[cint][:flags] = flags if flags.length > 0 end if line =~ /metric: (\d+) mtu: (\d+)/ iface[cint][:metric] = $1 iface[cint][:mtu] = $2 end end end popen4("arp -an") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/ next unless iface[$3] # this should never happen iface[$3][:arp] = Mash.new unless iface[$3][:arp] iface[$3][:arp][$1] = $2.downcase end end end network["interfaces"] = iface net_counters = Mash.new # From netstat(1), not sure of the implications: # Show the state of all network interfaces or a single interface # which have been auto-configured (interfaces statically configured # into a system, but not located at boot time are not shown). popen4("netstat -idn") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| # Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll Drop # em0 1500 00:11:25:2d:90:be 3719557 0 3369969 0 0 0 # $1 $2 $3 $4 $5 $6 $7 $8 if line =~ /^([\w\.\*]+)\s+\d+\s+\s+([\w:]*)\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ cint = $1 net_counters[cint] = Mash.new unless net_counters[cint] net_counters[cint] = Mash.new unless net_counters[cint]["rx"] net_counters[cint] = Mash.new unless net_counters[cint]["tx"] net_counters[cint] = $3 net_counters[cint] = $4 net_counters[cint] = $5 net_counters[cint] = $6 net_counters[cint] = $7 net_counters[cint] = $8 end end end counters[:network][:interfaces] = net_counters ohai-6.14.0/lib/ohai/plugins/openbsd/hostname.rb0000644000175000017500000000137611761755160021012 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "hostname", "fqdn" hostname from("hostname -s") fqdn from("hostname") ohai-6.14.0/lib/ohai/plugins/openbsd/uptime.rb0000644000175000017500000000201411761755160020465 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "uptime", "uptime_seconds" # kern.boottime=Tue Nov 1 14:45:52 2011 popen4("/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /kern.boottime=(.+)/ uptime_seconds Time.new.to_i - Time.parse($1).to_i uptime self._seconds_to_human(uptime_seconds) end end end ohai-6.14.0/lib/ohai/plugins/openbsd/platform.rb0000644000175000017500000000143511761755160021014 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "platform", "platform_version" platform from("uname -s").downcase platform_version from("uname -r") ohai-6.14.0/lib/ohai/plugins/openbsd/virtualization.rb0000644000175000017500000000427111761755160022255 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "virtualization" virtualization Mash.new # KVM Host support for FreeBSD is in development # http://feanor.sssup.it/~fabio/freebsd/lkvm/ # Detect KVM/QEMU from cpu, report as KVM # hw.model: QEMU Virtual CPU version 0.9.1 if from("sysctl -n hw.model") =~ /QEMU Virtual CPU/ virtualization[:system] = "kvm" virtualization[:role] = "guest" end # http://www.dmo.ca/blog/detecting-virtualization-on-linux if File.exists?("/usr/local/sbin/dmidecode") popen4("dmidecode") do |pid, stdin, stdout, stderr| stdin.close found_virt_manufacturer = nil found_virt_product = nil stdout.each do |line| case line when /Manufacturer: Microsoft/ found_virt_manufacturer = "microsoft" when /Product Name: Virtual Machine/ found_virt_product = "microsoft" when /Version: 5.0/ if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft" virtualization[:system] = "virtualpc" virtualization[:role] = "guest" end when /Version: VS2005R2/ if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft" virtualization[:system] = "virtualserver" virtualization[:role] = "guest" end when /Manufacturer: VMware/ found_virt_manufacturer = "vmware" when /Product Name: VMware Virtual Platform/ if found_virt_manufacturer == "vmware" virtualization[:system] = "vmware" virtualization[:role] = "guest" end end end end end ohai-6.14.0/lib/ohai/plugins/openbsd/ssh_host_key.rb0000644000175000017500000000161611761755160021673 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "keys/ssh" require_plugin "keys" keys[:ssh] = Mash.new keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1] keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1] ohai-6.14.0/lib/ohai/plugins/eucalyptus.rb0000644000175000017500000000354111761755160017734 0ustar tfheentfheen# # Author:: Tim Dysinger () # Author:: Benjamin Black () # Author:: Christopher Brown () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. provides "eucalyptus" require 'ohai/mixin/ec2_metadata' require_plugin "hostname" require_plugin "kernel" require_plugin "network" extend Ohai::Mixin::Ec2Metadata def get_mac_address(addresses) detected_addresses = addresses.detect { |address, keypair| keypair == {"family"=>"lladdr"} } if detected_addresses return detected_addresses.first else return "" end end def has_euca_mac? network[:interfaces].values.each do |iface| has_mac = (get_mac_address(iface[:addresses]) =~ /^[dD]0:0[dD]:/) Ohai::Log.debug("has_euca_mac? == #{!!has_mac}") return true if has_mac end Ohai::Log.debug("has_euca_mac? == false") false end def looks_like_euca? # Try non-blocking connect so we don't "block" if # the Xen environment is *not* EC2 hint?('eucalyptus') || has_euca_mac? && can_metadata_connect?(EC2_METADATA_ADDR,80) end if looks_like_euca? Ohai::Log.debug("looks_like_euca? == true") eucalyptus Mash.new self.fetch_metadata.each {|k, v| eucalyptus[k] = v } eucalyptus[:userdata] = self.fetch_userdata else Ohai::Log.debug("looks_like_euca? == false") false end ohai-6.14.0/lib/ohai/plugins/chef.rb0000644000175000017500000000165011761755160016442 0ustar tfheentfheen# # Author:: Tollef Fog Heen # Copyright:: Copyright (c) 2010 Tollef Fog Heen # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'chef/version' provides "chef" self[:chef_packages] = Mash.new unless self[:chef_packages] self[:chef_packages][:chef] = Mash.new self[:chef_packages][:chef][:version] = Chef::VERSION self[:chef_packages][:chef][:chef_root] = Chef::CHEF_ROOT ohai-6.14.0/lib/ohai/plugins/erlang.rb0000644000175000017500000000231411761755160017003 0ustar tfheentfheen# # Author:: Joe Williams () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages/erlang" require_plugin "languages" output = nil erlang = Mash.new status, stdout, stderr = run_command(:no_status_check => true, :command => "erl +V") if status == 0 output = stderr.split if output.length >= 6 options = output[1] options.gsub!(/(\(|\))/, '') erlang[:version] = output[5] erlang[:options] = options.split(',') erlang[:emulator] = output[2].gsub!(/(\(|\))/, '') if erlang[:version] and erlang[:options] and erlang[:emulator] languages[:erlang] = erlang end end end ohai-6.14.0/lib/ohai/plugins/ohai.rb0000644000175000017500000000164011761755160016454 0ustar tfheentfheen# # Author:: Tollef Fog Heen # Copyright:: Copyright (c) 2010 Tollef Fog Heen # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "ohai" provides "ohai" self[:chef_packages] = Mash.new unless self[:chef_packages] self[:chef_packages][:ohai] = Mash.new self[:chef_packages][:ohai][:version] = Ohai::VERSION self[:chef_packages][:ohai][:ohai_root] = Ohai::OHAI_ROOT ohai-6.14.0/lib/ohai/plugins/cloud.rb0000644000175000017500000000557111761755160016651 0ustar tfheentfheen# # Author:: Cary Penniman () # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. provides "cloud" require_plugin "ec2" require_plugin "rackspace" require_plugin "eucalyptus" # Make top-level cloud hashes # def create_objects cloud Mash.new cloud[:public_ips] = Array.new cloud[:private_ips] = Array.new end # ---------------------------------------- # ec2 # ---------------------------------------- # Is current cloud ec2? # # === Return # true:: If ec2 Hash is defined # false:: Otherwise def on_ec2? ec2 != nil end # Fill cloud hash with ec2 values def get_ec2_values cloud[:public_ips] << ec2['public_ipv4'] cloud[:private_ips] << ec2['local_ipv4'] cloud[:public_ipv4] = ec2['public_ipv4'] cloud[:public_hostname] = ec2['public_hostname'] cloud[:local_ipv4] = ec2['local_ipv4'] cloud[:local_hostname] = ec2['local_hostname'] cloud[:provider] = "ec2" end # setup ec2 cloud if on_ec2? create_objects get_ec2_values end # ---------------------------------------- # rackspace # ---------------------------------------- # Is current cloud rackspace? # # === Return # true:: If rackspace Hash is defined # false:: Otherwise def on_rackspace? rackspace != nil end # Fill cloud hash with rackspace values def get_rackspace_values cloud[:public_ips] << rackspace['public_ip'] cloud[:private_ips] << rackspace['private_ip'] cloud[:public_ipv4] = rackspace['public_ipv4'] cloud[:public_hostname] = rackspace['public_hostname'] cloud[:local_ipv4] = rackspace['local_ipv4'] cloud[:local_hostname] = rackspace['local_hostname'] cloud[:provider] = "rackspace" end # setup rackspace cloud if on_rackspace? create_objects get_rackspace_values end # ---------------------------------------- # eucalyptus # ---------------------------------------- # Is current cloud eucalyptus? # # === Return # true:: If eucalyptus Hash is defined # false:: Otherwise def on_eucalyptus? eucalyptus != nil end def get_eucalyptus_values cloud[:public_ips] << eucalyptus['public_ipv4'] cloud[:private_ips] << eucalyptus['local_ipv4'] cloud[:public_ipv4] = eucalyptus['public_ipv4'] cloud[:public_hostname] = eucalyptus['public_hostname'] cloud[:local_ipv4] = eucalyptus['local_ipv4'] cloud[:local_hostname] = eucalyptus['local_hostname'] cloud[:provider] = "eucalyptus" end if on_eucalyptus? create_objects get_eucalyptus_values end ohai-6.14.0/lib/ohai/plugins/os.rb0000644000175000017500000000271611761755160016162 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "os", "os_version" require 'rbconfig' require_plugin 'kernel' case ::RbConfig::CONFIG['host_os'] when /aix(.+)$/ os "aix" when /darwin(.+)$/ os "darwin" when /hpux(.+)$/ os "hpux" when /linux/ os "linux" when /freebsd(.+)$/ os "freebsd" when /openbsd(.+)$/ os "openbsd" when /netbsd(.*)$/ os "netbsd" when /solaris2/ os "solaris2" when /mswin|mingw32|windows/ # After long discussion in IRC the "powers that be" have come to a concensus # that there is no other Windows platforms exist that were not based on the # Windows_NT kernel, so we herby decree that "windows" will refer to all # platforms built upon the Windows_NT kernel and have access to win32 or win64 # subsystems. os "windows" else os ::RbConfig::CONFIG['host_os'] end os_version kernel[:release] ohai-6.14.0/lib/ohai/plugins/ip_scopes.rb0000644000175000017500000000260511761755160017522 0ustar tfheentfheen# # Author:: James Harton () # Copyright:: Copyright (c) 2010 Sociable Limited. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. begin require 'ipaddr_extensions' provides "network_ip_scope", "privateaddress" require_plugin "hostname" require_plugin "network" network['interfaces'].keys.each do |ifName| next if network['interfaces'][ifName]['addresses'].nil? network['interfaces'][ifName]['addresses'].each do |address,attrs| begin attrs.merge! 'ip_scope' => address.to_ip.scope privateaddress address if address.to_ip.scope =~ /PRIVATE/ rescue ArgumentError # Just silently fail if we can't create an IP from the string. end end end rescue LoadError => e # our favourite gem is not installed. Boohoo. Ohai::Log.debug("ip_scopes: cannot load gem, plugin disabled: #{e}") end ohai-6.14.0/lib/ohai/plugins/lua.rb0000644000175000017500000000174411761755160016322 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2009 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages/lua" require_plugin "languages" output = nil lua = Mash.new status, stdout, stderr = run_command(:no_status_check => true, :command => "lua -v") if status == 0 output = stderr.split if output.length >= 1 lua[:version] = output[1] end languages[:lua] = lua if lua[:version] end ohai-6.14.0/lib/ohai/plugins/network_listeners.rb0000644000175000017500000000243211761755160021315 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2009 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'sigar' provides "network/listeners" require_plugin "network" flags = Sigar::NETCONN_TCP|Sigar::NETCONN_SERVER listeners = Mash.new sigar = Sigar.new sigar.net_connection_list(flags).each do |conn| port = conn.local_port addr = conn.local_address.to_s if addr == "0.0.0.0" || addr == "::" addr = "*" end listeners[port] = Mash.new listeners[port][:address] = addr begin pid = sigar.proc_port(conn.type, port) listeners[port][:pid] = pid listeners[port][:name] = sigar.proc_state(pid).name rescue end end network[:listeners] = Mash.new network[:listeners][:tcp] = listeners ohai-6.14.0/lib/ohai/plugins/aix/0000755000175000017500000000000011761755160015767 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/aix/filesystem.rb0000644000175000017500000000131611761755160020501 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::filesystem" ohai-6.14.0/lib/ohai/plugins/aix/cpu.rb0000644000175000017500000000130711761755160017104 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::cpu" ohai-6.14.0/lib/ohai/plugins/aix/memory.rb0000644000175000017500000000131211761755160017621 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::memory" ohai-6.14.0/lib/ohai/plugins/aix/ps.rb0000644000175000017500000000136211761755160016740 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "command/ps" require_plugin 'command' command[:ps] = 'ps -ef' ohai-6.14.0/lib/ohai/plugins/aix/network.rb0000644000175000017500000000131311761755160020003 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::network" ohai-6.14.0/lib/ohai/plugins/aix/hostname.rb0000644000175000017500000000131411761755160020131 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::hostname" ohai-6.14.0/lib/ohai/plugins/aix/uptime.rb0000644000175000017500000000131211761755160017614 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::uptime" ohai-6.14.0/lib/ohai/plugins/aix/platform.rb0000644000175000017500000000131411761755160020137 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::platform" ohai-6.14.0/lib/ohai/plugins/aix/ssh_host_key.rb0000644000175000017500000000161611761755160021022 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "keys/ssh" require_plugin "keys" keys[:ssh] = Mash.new keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1] keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1] ohai-6.14.0/lib/ohai/plugins/dmi.rb0000644000175000017500000001071311761755160016306 0ustar tfheentfheen# # Author:: Kurt Yoder (ktyopscode@yoderhome.com) # Copyright:: Copyright (c) 2010 Kurt Yoder # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "ohai/plugins/dmi_common" provides "dmi" # dmidecode does not return data without access to /dev/mem (or its equivalent) dmi Mash.new # all output lines should fall within one of these patterns handle_line = /^Handle (0x[0-9A-F]{4}), DMI type (\d+), (\d+) bytes/ type_line = /^([A-Z][a-zA-Z ]+)( Information)?/ blank_line = /^\s*$/ data_line = /^\t([^:]+):(?: (.*))?/ extended_data_line = /^\t\t(.+)/ # first lines may contain some interesting information: # # dmidecode 2.10 # SMBIOS 2.5 present. # 5 structures occupying 352 bytes. # Table at 0x000E1000. dmidecode_version_line = /^# dmidecode (\d+\.\d+)/ smbios_version_line = /^SMBIOS (\d+\.\d+) present\./ structures_line = /^(\d+) structures occupying (\d+) bytes\./ table_location_line = /^Table at (0x[0-9A-E]+)\./ dmi_record = nil field = nil popen4("dmidecode") do |pid, stdin, stdout, stderr| stdin.close # ==== EXAMPLE RECORD: ==== #Handle 0x0000, DMI type 0, 24 bytes #BIOS Information # Vendor: American Megatrends Inc. # Version: 080012 # ... similar lines trimmed # Characteristics: # ISA is supported # PCI is supported # ... similar lines trimmed stdout.each do |line| next if blank_line.match(line) if dmidecode_version = dmidecode_version_line.match(line) dmi[:dmidecode_version] = dmidecode_version[1] elsif smbios_version = smbios_version_line.match(line) dmi[:smbios_version] = smbios_version[1] elsif structures = structures_line.match(line) dmi[:structures] = Mash.new dmi[:structures][:count] = structures[1] dmi[:structures][:size] = structures[2] elsif table_location = table_location_line.match(line) dmi[:table_location] = table_location[1] elsif handle = handle_line.match(line) # Don't overcapture for now (OHAI-260) next unless DMI::IdToCapture.include?(handle[2].to_i) dmi_record = {:type => DMI.id_lookup(handle[2])} dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type]) dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records) dmi_record[:position] = dmi[dmi_record[:type]][:all_records].length dmi[dmi_record[:type]][:all_records].push(Mash.new) dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:record_id] = handle[1] dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = handle[2] field = nil elsif type = type_line.match(line) if dmi_record == nil Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = type[1] elsif data = data_line.match(line) if dmi_record == nil Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2] field = data[1] elsif extended_data = extended_data_line.match(line) if dmi_record == nil Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}") next end if field == nil Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}") next end # overwrite "raw" value with a new Mash dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == 'Mash' dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = nil else Ohai::Log.debug("unrecognized output line; discarding:\n#{line}") end end end DMI.convenience_keys(dmi) ohai-6.14.0/lib/ohai/plugins/php.rb0000644000175000017500000000205011761755160016317 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2009 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages/php" require_plugin "languages" output = nil php = Mash.new status, stdout, stderr = run_command(:no_status_check => true, :command => "php -v") if status == 0 output = stdout.split if output.length >= 6 php[:version] = output[1] php[:builddate] = "%s %s %s" % [output[4],output[5],output[6]] end languages[:php] = php if php[:version] end ohai-6.14.0/lib/ohai/plugins/keys.rb0000644000175000017500000000122611761755160016507 0ustar tfheentfheen# # Cookbook Name:: apache2 # Recipe:: default # # Copyright 2008, OpsCode, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "keys" keys Mash.newohai-6.14.0/lib/ohai/plugins/groovy.rb0000644000175000017500000000177211761755160017067 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2009 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages/groovy" require_plugin "languages" output = nil groovy = Mash.new status, stdout, stderr = run_command(:no_status_check => true, :command => "groovy -v") if status == 0 output = stdout.split if output.length >= 2 groovy[:version] = output[2] end languages[:groovy] = groovy if groovy[:version] end ohai-6.14.0/lib/ohai/plugins/mono.rb0000644000175000017500000000215311761755160016504 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2009 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages/mono" require_plugin "languages" output = nil mono = Mash.new status, stdout, stderr = run_command(:no_status_check => true, :command => "mono -V") if status == 0 output = stdout.split if output.length >= 4 mono[:version] = output[4] end if output.length >= 11 mono[:builddate] = "%s %s %s %s" % [output[6],output[7],output[8],output[11].gsub!(/\)/,'')] end languages[:mono] = mono if mono[:version] end ohai-6.14.0/lib/ohai/plugins/darwin/0000755000175000017500000000000011761755160016472 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/darwin/system_profiler.rb0000644000175000017500000000177111761755160022253 0ustar tfheentfheen# # Author:: Benjamin Black () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "system_profile" begin require 'plist' system_profile Array.new popen4("system_profiler -xml -detailLevel mini") do |pid, stdin, stdout, stderr| stdin.close Plist::parse_xml(stdout.read).each do |e| system_profile << e end end rescue LoadError => e Ohai::Log.debug("Can't load gem: #{e})") endohai-6.14.0/lib/ohai/plugins/darwin/kernel.rb0000644000175000017500000000221111761755160020273 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "kernel" kernel[:os] = kernel[:name] if from("sysctl -n hw.optional.x86_64").to_i == 1 kernel[:machine] = 'x86_64' end kext = Mash.new popen4("kextstat -k -l") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/ kext[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 } end end end kernel[:modules] = kext ohai-6.14.0/lib/ohai/plugins/darwin/filesystem.rb0000644000175000017500000000330611761755160021205 0ustar tfheentfheen# # Author:: Benjamin Black () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "filesystem" fs = Mash.new block_size = 0 popen4("df") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^Filesystem\s+(\d+)-/ block_size = $1.to_i next when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ filesystem = $1 fs[filesystem] = Mash.new fs[filesystem][:block_size] = block_size fs[filesystem][:kb_size] = $2.to_i / (1024 / block_size) fs[filesystem][:kb_used] = $3.to_i / (1024 / block_size) fs[filesystem][:kb_available] = $4.to_i / (1024 / block_size) fs[filesystem][:percent_used] = $5 fs[filesystem][:mount] = $6 end end end popen4("mount") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/ filesystem = $1 fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:mount] = $2 fs[filesystem][:fs_type] = $3 fs[filesystem][:mount_options] = $4.split(/,\s*/) end end end filesystem fsohai-6.14.0/lib/ohai/plugins/darwin/ps.rb0000644000175000017500000000136311761755160017444 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "command/ps" require_plugin 'command' command[:ps] = 'ps -ef'ohai-6.14.0/lib/ohai/plugins/darwin/network.rb0000644000175000017500000001604111761755160020512 0ustar tfheentfheen# # Author:: Benjamin Black () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "network", "counters/network" require 'scanf' from("route -n get default").split("\n").each do |line| if line =~ /(\w+): ([\w\.]+)/ case $1 when "gateway" network[:default_gateway] = $2 when "interface" network[:default_interface] = $2 end end end def parse_media(media_string) media = Hash.new line_array = media_string.split(' ') 0.upto(line_array.length - 1) do |i| unless line_array[i].eql?("none") if line_array[i + 1] =~ /^\<([a-zA-Z\-\,]+)\>$/ media[line_array[i]] = Hash.new unless media.has_key?(line_array[i]) if media[line_array[i]].has_key?("options") $1.split(",").each do |opt| media[line_array[i]]["options"] << opt unless media[line_array[i]]["options"].include?(opt) end else media[line_array[i]]["options"] = $1.split(",") end else if line_array[i].eql?("autoselect") media["autoselect"] = Hash.new unless media.has_key?("autoselect") media["autoselect"]["options"] = [] end end else media["none"] = { "options" => [] } end end media end def encaps_lookup(ifname) return "Loopback" if ifname.eql?("lo") return "1394" if ifname.eql?("fw") return "IPIP" if ifname.eql?("gif") return "6to4" if ifname.eql?("stf") return "dot1q" if ifname.eql?("vlan") "Unknown" end def scope_lookup(scope) return "Node" if scope.eql?("::1") return "Link" if scope.match(/^fe80\:/) return "Site" if scope.match(/^fec0\:/) "Global" end def excluded_setting?(setting) setting.match('_sw_cksum') end def locate_interface(ifaces, ifname, mac) return ifname unless ifaces[ifname].nil? # oh well, time to go hunting! return ifname.chop if ifname.match /\*$/ ifaces.keys.each do |ifc| ifaces[ifc][:addresses].keys.each do |addr| return ifc if addr.eql? mac end end nil end iface = Mash.new popen4("ifconfig -a") do |pid, stdin, stdout, stderr| stdin.close cint = nil stdout.each do |line| if line =~ /^([0-9a-zA-Z\.\:\-]+): \S+ mtu (\d+)$/ cint = $1 iface[cint] = Mash.new unless iface[cint]; iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:mtu] = $2 if line =~ /\sflags\=\d+\<((UP|BROADCAST|DEBUG|SMART|SIMPLEX|LOOPBACK|POINTOPOINT|NOTRAILERS|RUNNING|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC|,)+)\>\s/ flags = $1.split(',') else flags = Array.new end iface[cint][:flags] = flags.flatten if cint =~ /^(\w+)(\d+.*)/ iface[cint][:type] = $1 iface[cint][:number] = $2 iface[cint][:encapsulation] = encaps_lookup($1) end end if line =~ /^\s+ether ([0-9a-f\:]+)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "lladdr" } iface[cint][:encapsulation] = "Ethernet" end if line =~ /^\s+lladdr ([0-9a-f\:]+)\s/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "lladdr" } end if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask 0x(([0-9a-f]){1,8})\s*$/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf('%2x'*4)*"."} end if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask 0x(([0-9a-f]){1,8}) broadcast (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf('%2x'*4)*".", "broadcast" => $4 } end if line =~ /\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*) prefixlen (\d+)\s*/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $4 , "scope" => scope_lookup($1) } end if line =~ /\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*) prefixlen (\d+) scopeid 0x([a-f0-9]+)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $4 , "scope" => scope_lookup($1) } end if line =~ /^\s+media: ((\w+)|(\w+ [a-zA-Z0-9\-\<\>]+)) status: (\w+)/ iface[cint][:media] = Mash.new unless iface[cint][:media] iface[cint][:media][:selected] = parse_media($1) iface[cint][:status] = $4 end if line =~ /^\s+supported media: (.*)/ iface[cint][:media] = Mash.new unless iface[cint][:media] iface[cint][:media][:supported] = parse_media($1) end end end popen4("arp -an") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^\S+ \((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([a-zA-Z0-9\.\:\-]+).*\[(\w+)\]/ # MAC addr really should be normalized to include all the zeroes. next if iface[$3].nil? # this should never happen iface[$3][:arp] = Mash.new unless iface[$3][:arp] iface[$3][:arp][$1] = $2 end end end settings = Mash.new popen4("sysctl net") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^([a-zA-Z0-9\.\_]+)\: (.*)/ # should normalize names between platforms for the same settings. settings[$1] = $2 unless excluded_setting?($1) end end end network[:settings] = settings network[:interfaces] = iface net_counters = Mash.new popen4("netstat -i -d -l -b -n") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^([a-zA-Z0-9\.\:\-\*]+)\s+\d+\s+\<[a-zA-Z0-9\#]+\>\s+([a-f0-9\:]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ || line =~ /^([a-zA-Z0-9\.\:\-\*]+)\s+\d+\s+\<[a-zA-Z0-9\#]+\>(\s+)(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ ifname = locate_interface(iface, $1, $2) next if iface[ifname].nil? # this shouldn't happen, but just in case net_counters[ifname] = Mash.new unless net_counters[ifname] net_counters[ifname] = { :rx => { :bytes => $5, :packets => $3, :errors => $4, :drop => 0, :overrun => 0, :frame => 0, :compressed => 0, :multicast => 0 }, :tx => { :bytes => $8, :packets => $6, :errors => $7, :drop => 0, :overrun => 0, :collisions => $9, :carrier => 0, :compressed => 0 } } end end end counters[:network][:interfaces] = net_counters ohai-6.14.0/lib/ohai/plugins/darwin/hostname.rb0000644000175000017500000000137011761755160020636 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "fqdn", "hostname" hostname from("hostname -s") fqdn from("hostname")ohai-6.14.0/lib/ohai/plugins/darwin/uptime.rb0000644000175000017500000000205511761755160020324 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "uptime", "uptime_seconds" # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009 popen4("/usr/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /kern.boottime:\D+(\d+)/ uptime_seconds Time.new.to_i - $1.to_i uptime self._seconds_to_human(uptime_seconds) end end end ohai-6.14.0/lib/ohai/plugins/darwin/platform.rb0000644000175000017500000000221511761755160020643 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "platform", "platform_version", "platform_build", "platform_family" popen4("/usr/bin/sw_vers") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^ProductName:\s+(.+)$/ macname = $1 macname.downcase! macname.gsub!(" ", "_") platform macname when /^ProductVersion:\s+(.+)$/ platform_version $1 when /^BuildVersion:\s+(.+)$/ platform_build $1 end end end platform_family "mac_os_x" ohai-6.14.0/lib/ohai/plugins/darwin/ssh_host_key.rb0000644000175000017500000000160411761755160021522 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "keys/ssh" require_plugin "keys" keys[:ssh] = Mash.new keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh_host_dsa_key.pub").split[1] keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh_host_rsa_key.pub").split[1]ohai-6.14.0/lib/ohai/plugins/ec2.rb0000644000175000017500000000314311761755160016205 0ustar tfheentfheen# # Author:: Tim Dysinger () # Author:: Benjamin Black () # Author:: Christopher Brown () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. provides "ec2" require 'ohai/mixin/ec2_metadata' require_plugin "hostname" require_plugin "kernel" require_plugin "network" extend Ohai::Mixin::Ec2Metadata def has_ec2_mac? network[:interfaces].values.each do |iface| unless iface[:arp].nil? if iface[:arp].value?("fe:ff:ff:ff:ff:ff") Ohai::Log.debug("has_ec2_mac? == true") return true end end end Ohai::Log.debug("has_ec2_mac? == false") false end def looks_like_ec2? # Try non-blocking connect so we don't "block" if # the Xen environment is *not* EC2 hint?('ec2') || has_ec2_mac? && can_metadata_connect?(EC2_METADATA_ADDR,80) end if looks_like_ec2? Ohai::Log.debug("looks_like_ec2? == true") ec2 Mash.new fetch_metadata.each {|k, v| ec2[k] = v } ec2[:userdata] = self.fetch_userdata else Ohai::Log.debug("looks_like_ec2? == false") false end ohai-6.14.0/lib/ohai/plugins/network.rb0000644000175000017500000000610711761755160017230 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ipaddress' provides "network", "counters/network" network Mash.new unless network network[:interfaces] = Mash.new unless network[:interfaces] counters Mash.new unless counters counters[:network] = Mash.new unless counters[:network] ipaddress nil ip6address macaddress nil require_plugin "hostname" require_plugin "#{os}::network" # ipaddress and macaddress can be set from the #{os}::network plugin return unless ipaddress.nil? def find_ip_and_mac(addresses, match = nil) ip = nil; mac = nil; ip6 = nil addresses.keys.each do |addr| if match.nil? ip = addr if addresses[addr]["family"].eql?("inet") else ip = addr if addresses[addr]["family"].eql?("inet") && network_contains_address(match, addr, addresses[addr]) end ip6 = addr if addresses[addr]["family"].eql?("inet6") && addresses[addr]["scope"].eql?("Global") mac = addr if addresses[addr]["family"].eql?("lladdr") break if (ip and mac) end Ohai::Log.debug("Found IPv4 address #{ip} with MAC #{mac} #{match.nil? ? '' : 'matching address ' + match}") Ohai::Log.debug("Found IPv6 address #{ip6}") if ip6 [ip, mac, ip6] end def network_contains_address(address_to_match, network_ip, network_opts) if network_opts[:peer] network_opts[:peer] == address_to_match else network = IPAddress "#{network_ip}/#{network_opts[:netmask]}" host = IPAddress address_to_match network.include?(host) end end # If we have a default interface that has addresses, populate the short-cut attributes # 0.0.0.0 is not a valid gateway address in this case if network[:default_interface] and network[:default_gateway] and network[:default_gateway] != "0.0.0.0" and network["interfaces"][network[:default_interface]] and network["interfaces"][network[:default_interface]]["addresses"] Ohai::Log.debug("Using default interface for default ip and mac address") im = find_ip_and_mac(network["interfaces"][network[:default_interface]]["addresses"], network[:default_gateway]) ipaddress im.shift macaddress im.shift ip6address im.shift else network["interfaces"].keys.sort.each do |iface| if network["interfaces"][iface]["encapsulation"].eql?("Ethernet") Ohai::Log.debug("Picking ip and mac address from first Ethernet interface") im = find_ip_and_mac(network["interfaces"][iface]["addresses"]) ipaddress im.shift macaddress im.shift return if (ipaddress and macaddress) end end end ohai-6.14.0/lib/ohai/plugins/solaris2/0000755000175000017500000000000011761755160016744 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/solaris2/kernel.rb0000644000175000017500000000243111761755160020551 0ustar tfheentfheen# # Author:: Benjamin Black () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "kernel/os" kernel[:os] = from("uname -s") modules = Mash.new popen4("modinfo") do |pid, stdin, stdout, stderr| stdin.close # EXAMPLE: # Id Loadaddr Size Info Rev Module Name # 6 1180000 4623 1 1 specfs (filesystem for specfs) module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/ stdout.each do |line| if mod = module_description.match(line) modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]} end end end kernel[:modules] = modules ohai-6.14.0/lib/ohai/plugins/solaris2/filesystem.rb0000644000175000017500000000622211761755160021457 0ustar tfheentfheen# # Author:: Kurt Yoder (ktyopscode@yoderhome.com) # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "filesystem" fs = Mash.new # Grab filesystem data from df popen4("df -ka") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^Filesystem\s+kbytes/ next when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ filesystem = $1 fs[filesystem] = Mash.new fs[filesystem][:kb_size] = $2 fs[filesystem][:kb_used] = $3 fs[filesystem][:kb_available] = $4 fs[filesystem][:percent_used] = $5 fs[filesystem][:mount] = $6 end end end # Grab file system type from df (must be done separately) popen4("df -na") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| next unless (line =~ /^(.+?)\s*: (\S+)\s*$/) mount = $1 fs.each { |filesystem,fs_attributes| next unless (fs_attributes[:mount] == mount) fs[filesystem][:fs_type] = $2 } end end # Grab mount information from /bin/mount popen4("mount") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| next unless (line =~ /^(.+?) on (.+?) (.+?) on (.+?)$/) filesystem = $2 fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:mount] = $1 fs[filesystem][:mount_time] = $4 # $4 must come before "split", else it becomes nil fs[filesystem][:mount_options] = $3.split("/") end end # Grab any zfs data from "zfs get" zfs = Mash.new popen4("zfs get -p -H all") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| next unless (line =~ /^([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]+)$/) filesystem = $1 zfs[filesystem] = Mash.new unless zfs.has_key?(filesystem) zfs[filesystem][:values] = Mash.new unless zfs[filesystem].has_key?('values') zfs[filesystem][:sources] = Mash.new unless zfs[filesystem].has_key?('sources') zfs[filesystem][:values][$2] = $3 zfs[filesystem][:sources][$2] = $4.chomp end end zfs.each { |filesystem, attributes| fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:fs_type] = 'zfs' fs[filesystem][:mount] = attributes[:values][:mountpoint] if attributes[:values].has_key?('mountpoint') fs[filesystem][:zfs_values] = attributes[:values] fs[filesystem][:zfs_sources] = attributes[:sources] # find all zfs parents parents = filesystem.split('/') zfs_parents = [] (0 .. parents.length - 1).to_a.each { |parent_indexes| next_parent = parents[0 .. parent_indexes].join('/') zfs_parents.push(next_parent) } zfs_parents.pop fs[filesystem][:zfs_parents] = zfs_parents fs[filesystem][:zfs_zpool] = (zfs_parents.length == 0) } # Set the filesystem data filesystem fs ohai-6.14.0/lib/ohai/plugins/solaris2/cpu.rb0000644000175000017500000000313611761755160020063 0ustar tfheentfheen#$ psrinfo -v #Status of virtual processor 0 as of: 01/11/2009 23:31:55 # on-line since 05/29/2008 15:05:28. # The i386 processor operates at 2660 MHz, # and has an i387 compatible floating point processor. #Status of virtual processor 1 as of: 01/11/2009 23:31:55 # on-line since 05/29/2008 15:05:30. # The i386 processor operates at 2660 MHz, # and has an i387 compatible floating point processor. #Status of virtual processor 2 as of: 01/11/2009 23:31:55 # on-line since 05/29/2008 15:05:30. # The i386 processor operates at 2660 MHz, # and has an i387 compatible floating point processor. #Status of virtual processor 3 as of: 01/11/2009 23:31:55 # on-line since 05/29/2008 15:05:30. # The i386 processor operates at 2660 MHz, # and has an i387 compatible floating point processor. #Status of virtual processor 4 as of: 01/11/2009 23:31:55 # on-line since 05/29/2008 15:05:30. # The i386 processor operates at 2660 MHz, # and has an i387 compatible floating point processor. #Status of virtual processor 5 as of: 01/11/2009 23:31:55 # on-line since 05/29/2008 15:05:30. # The i386 processor operates at 2660 MHz, # and has an i387 compatible floating point processor. #Status of virtual processor 6 as of: 01/11/2009 23:31:55 # on-line since 05/29/2008 15:05:30. # The i386 processor operates at 2660 MHz, # and has an i387 compatible floating point processor. #Status of virtual processor 7 as of: 01/11/2009 23:31:55 # on-line since 05/29/2008 15:05:30. # The i386 processor operates at 2660 MHz, # and has an i387 compatible floating point processor. ohai-6.14.0/lib/ohai/plugins/solaris2/dmi.rb0000644000175000017500000001672111761755160020051 0ustar tfheentfheen# # Author:: Kurt Yoder (ktyopscode@yoderhome.com) # Copyright:: Copyright (c) 2010 Kurt Yoder # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "dmi" # if we already have a "dmi" with keys (presumably from dmidecode), don't try smbios # note that a single key just means dmidecode exited with its version if (dmi.class.to_s == 'Mash') and (dmi.keys.length > 1) Ohai::Log.debug('skipping smbios output, since DMI information has already been provided') return end dmi Mash.new # bad Solaris shows strings defined by system instead of SMB IDs # this is what the *real* IDs are: # pulled from http://src.opensolaris.org/source/xref/nwam/nwam1/usr/src/uts/common/sys/smbios.h smb_to_id = { 'SMB_TYPE_BIOS' => 0, # BIOS information (R) 'SMB_TYPE_SYSTEM' => 1, # system information (R) 'SMB_TYPE_BASEBOARD' => 2, # base board 'SMB_TYPE_CHASSIS' => 3, # system enclosure or chassis (R) 'SMB_TYPE_PROCESSOR' => 4, # processor (R) 'SMB_TYPE_MEMCTL' => 5, # memory controller (O) 'SMB_TYPE_MEMMOD' => 6, # memory module (O) 'SMB_TYPE_CACHE' => 7, # processor cache (R) 'SMB_TYPE_PORT' => 8, # port connector 'SMB_TYPE_SLOT' => 9, # upgradeable system slot (R) 'SMB_TYPE_OBDEVS' => 10, # on-board devices 'SMB_TYPE_OEMSTR' => 11, # OEM string table 'SMB_TYPE_SYSCONFSTR' => 12, # system configuration string table 'SMB_TYPE_LANG' => 13, # BIOS language information 'SMB_TYPE_GROUP' => 14, # group associations 'SMB_TYPE_EVENTLOG' => 15, # system event log 'SMB_TYPE_MEMARRAY' => 16, # physical memory array (R) 'SMB_TYPE_MEMDEVICE' => 17, # memory device (R) 'SMB_TYPE_MEMERR32' => 18, # 32-bit memory error information 'SMB_TYPE_MEMARRAYMAP' => 19, # memory array mapped address (R) 'SMB_TYPE_MEMDEVICEMAP' => 20, # memory device mapped address (R) 'SMB_TYPE_POINTDEV' => 21, # built-in pointing device 'SMB_TYPE_BATTERY' => 22, # portable battery 'SMB_TYPE_RESET' => 23, # system reset settings 'SMB_TYPE_SECURITY' => 24, # hardware security settings 'SMB_TYPE_POWERCTL' => 25, # system power controls 'SMB_TYPE_VPROBE' => 26, # voltage probe 'SMB_TYPE_COOLDEV' => 27, # cooling device 'SMB_TYPE_TPROBE' => 28, # temperature probe 'SMB_TYPE_IPROBE' => 29, # current probe 'SMB_TYPE_OOBRA' => 30, # out-of-band remote access facility 'SMB_TYPE_BIS' => 31, # boot integrity services 'SMB_TYPE_BOOT' => 32, # system boot status (R) 'SMB_TYPE_MEMERR64' => 33, # 64-bit memory error information 'SMB_TYPE_MGMTDEV' => 34, # management device 'SMB_TYPE_MGMTDEVCP' => 35, # management device component 'SMB_TYPE_MGMTDEVDATA' => 36, # management device threshold data 'SMB_TYPE_MEMCHAN' => 37, # memory channel 'SMB_TYPE_IPMIDEV' => 38, # IPMI device information 'SMB_TYPE_POWERSUP' => 39, # system power supply 'SMB_TYPE_INACTIVE' => 126, # inactive table entry 'SMB_TYPE_EOT' => 127, # end of table 'SMB_TYPE_OEM_LO' => 128, # start of OEM-specific type range 'SUN_OEM_EXT_PROCESSOR' => 132, # processor extended info 'SUN_OEM_PCIEXRC' => 138, # PCIE RootComplex/RootPort info 'SUN_OEM_EXT_MEMARRAY' => 144, # phys memory array extended info 'SUN_OEM_EXT_MEMDEVICE' => 145, # memory device extended info 'SMB_TYPE_OEM_HI' => 256, # end of OEM-specific type range } # all output lines should fall within one of these patterns header_type_line = /^ID\s+SIZE\s+TYPE/ header_information_line = /^(\d+)\s+(\d+)\s+(\S+)\s+\(([^\)]+)\)/ blank_line = /^\s*$/ data_key_value_line = /^ ([^:]+): (.*)/ data_key_only_line = /^ (\S.*)(:\s*)?$/ extended_data_line = /^\t(\S+) \((.+)\)/ dmi_record = nil field = nil popen4("smbios") do |pid, stdin, stdout, stderr| stdin.close # ==== EXAMPLE: ==== # ID SIZE TYPE # 0 40 SMB_TYPE_BIOS (BIOS information) # # Vendor: HP # Version String: 2.16 # ... similar lines trimmed # Characteristics: 0x7fc9da80 # SMB_BIOSFL_PCI (PCI is supported) # ... similar lines trimmed # note the second level of indentation is via a *tab* stdout.each do |raw_line| next if header_type_line.match(raw_line) next if blank_line.match(raw_line) # remove/replace any characters that don't fall inside permissible ASCII range, or whitespace line = raw_line.gsub(/[^\x20-\x7E\n\t\r]/, '.') if (line != raw_line) Ohai::Log.debug("converted characters from line:\n#{raw_line}") end if header_information = header_information_line.match(line) dmi_record = {} # look up SMB ID if smb_to_id.has_key?(header_information[3]) dmi_record[:type] = DMI.id_lookup(smb_to_id[header_information[3]]) else dmi_record[:type] = header_information[3].downcase Ohai::Log.debug("unrecognized header type; falling back to #{dmi_record[:type]}") end dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type]) dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records) dmi_record[:position] = dmi[dmi_record[:type]][:all_records].length dmi[dmi_record[:type]][:all_records].push(Mash.new) dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:record_id] = header_information[1] dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = header_information[2] dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = header_information[4] field = nil elsif data = data_key_value_line.match(line) if dmi_record == nil Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2] field = data[1] elsif data = data_key_only_line.match(line) if dmi_record == nil Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = '' field = data[1] elsif extended_data = extended_data_line.match(line) if dmi_record == nil Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}") next end if field == nil Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}") next end # overwrite "raw" value with a new Mash dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == 'Mash' dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = extended_data[2] else Ohai::Log.debug("unrecognized output line; discarding:\n#{line}") end end end DMI.convenience_keys(dmi) ohai-6.14.0/lib/ohai/plugins/solaris2/ps.rb0000644000175000017500000000136111761755160017714 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "command/ps" require_plugin 'command' command[:ps] = 'ps -ef'ohai-6.14.0/lib/ohai/plugins/solaris2/zpools.rb0000644000175000017500000000426611761755160020627 0ustar tfheentfheen# # Author:: Jason J. W. Williams (williamsjj@digitar.com) # Copyright:: Copyright (c) 2011 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "zpools" pools = Mash.new # Grab ZFS zpools overall health and attributes popen4("zpool list -H -o name,size,alloc,free,cap,dedup,health,version") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^([-_0-9A-Za-z]*)\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+(\d+%)\s+([.0-9]+x)\s+([-_0-9A-Za-z]+)\s+(\d+)$/ pools[$1] = Mash.new pools[$1][:pool_size] = $2 pools[$1][:pool_allocated] = $3 pools[$1][:pool_free] = $4 pools[$1][:capacity_used] = $5 pools[$1][:dedup_factor] = $6 pools[$1][:health] = $7 pools[$1][:zpool_version] = $8 end end end # Grab individual health for devices in the zpools for pool in pools.keys pools[pool][:devices] = Mash.new # Run "zpool status" as non-root user (adm) so that # the command won't try to open() each device which can # hang the command if any of the disks are bad. popen4("su adm -c \"zpool status #{pool}\"") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^\s+(c[-_a-zA-Z0-9]+)\s+([-_a-zA-Z0-9]+)\s+(\d+)\s+(\d+)\s+(\d+)$/ pools[pool][:devices][$1] = Mash.new pools[pool][:devices][$1][:state] = $2 pools[pool][:devices][$1][:errors] = Mash.new pools[pool][:devices][$1][:errors][:read] = $3 pools[pool][:devices][$1][:errors][:write] = $4 pools[pool][:devices][$1][:errors][:checksum] = $5 end end end end # Set the zpools data zpools poolsohai-6.14.0/lib/ohai/plugins/solaris2/network.rb0000644000175000017500000001401711761755160020765 0ustar tfheentfheen# # Author:: Benjamin Black () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # EXAMPLE SOLARIS IFCONFIG OUTPUT; CURRENTLY, ONLY SIMPLE STUFF IS SUPPORTED (E.G., NO TUNNELS) # DEAR SUN: YOU GET AN F FOR YOUR IFCONFIG #lo0:3: flags=2001000849 mtu 8232 index 1 # inet 127.0.0.1 netmask ff000000 #e1000g0:3: flags=201000843 mtu 1500 index 3 # inet 72.2.115.28 netmask ffffff80 broadcast 72.2.115.127 #e1000g2:1: flags=201000843 mtu 1500 index 4 # inet 10.2.115.28 netmask ffffff80 broadcast 10.2.115.127 # inet6 2001:0db8:3c4d:55:a00:20ff:fe8e:f3ad/64 #ip.tun0: flags=2200851 mtu 1480 index 3 # inet tunnel src 109.146.85.57 tunnel dst 109.146.85.212 # tunnel security settings --> use 'ipsecconf -ln -i ip.tun1' # tunnel hop limit 60 # inet6 fe80::6d92:5539/10 --> fe80::6d92:55d4 #ip.tun0:1: flags=2200851 mtu 1480 index 3 # inet6 2::45/128 --> 2::46 #lo0: flags=1000849 mtu 8232 index 1 # inet 127.0.0.1 netmask ff000000 #eri0: flags=1004843 mtu 1500 \ #index 2 # inet 172.17.128.208 netmask ffffff00 broadcast 172.17.128.255 #ip6.tun0: flags=10008d1 \ #mtu 1460 # index 3 # inet6 tunnel src fe80::1 tunnel dst fe80::2 # tunnel security settings --> use 'ipsecconf -ln -i ip.tun1' # tunnel hop limit 60 tunnel encapsulation limit 4 # inet 10.0.0.208 --> 10.0.0.210 netmask ff000000 #qfe1: flags=2000841 mtu 1500 index 3 # usesrc vni0 # inet6 fe80::203:baff:fe17:4be0/10 # ether 0:3:ba:17:4b:e0 #vni0: flags=2002210041 mtu 0 # index 5 # srcof qfe1 # inet6 fe80::203:baff:fe17:4444/128 provides "network" require 'scanf' def encaps_lookup(ifname) return "Ethernet" if ifname.eql?("e1000g") return "Ethernet" if ifname.eql?("eri") return "Loopback" if ifname.eql?("lo") "Unknown" end def arpname_to_ifname(iface, arpname) iface.keys.each do |ifn| return ifn if ifn.split(':')[0].eql?(arpname) end nil end iface = Mash.new popen4("ifconfig -a") do |pid, stdin, stdout, stderr| stdin.close cint = nil stdout.each do |line| if line =~ /^([0-9a-zA-Z\.\:\-]+): \S+ mtu (\d+) index (\d+)/ cint = $1 iface[cint] = Mash.new unless iface[cint] iface[cint][:mtu] = $2 iface[cint][:index] = $3 if line =~ / flags\=\d+\<((ADDRCONF|ANYCAST|BROADCAST|CoS|DEPRECATED|DHCP|DUPLICATE|FAILED|FIXEDMTU|INACTIVE|LOOPBACK|MIP|MULTI_BCAST|MULTICAST|NOARP|NOFAILOVER|NOLOCAL|NONUD|NORTEXCH|NOXMIT|OFFLINE|POINTOPOINT|PREFERRED|PRIVATE|ROUTER|RUNNING|STANDBY|TEMPORARY|UNNUMBERED|UP|VIRTUAL|XRESOLV|IPv4|IPv6|,)+)\>\s/ flags = $1.split(',') else flags = Array.new end iface[cint][:flags] = flags.flatten if cint =~ /^(\w+)(\d+.*)/ iface[cint][:type] = $1 iface[cint][:number] = $2 iface[cint][:encapsulation] = encaps_lookup($1) end end if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask (([0-9a-f]){1,8})\s*$/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf('%2x'*4)*"."} end if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask (([0-9a-f]){1,8}) broadcast (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf('%2x'*4)*".", "broadcast" => $4 } end if line =~ /\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*)\/(\d+)\s*$/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $4 } end end end popen4("arp -an") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /([0-9a-zA-Z]+)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\w+)\s+([a-zA-Z0-9\.\:\-]+)/ next unless iface[arpname_to_ifname(iface, $1)] # this should never happen, except on solaris because sun hates you. iface[arpname_to_ifname(iface, $1)][:arp] = Mash.new unless iface[arpname_to_ifname(iface, $1)][:arp] iface[arpname_to_ifname(iface, $1)][:arp][$2] = $5 end end end iface.keys.each do |ifn| iaddr = nil if iface[ifn][:encapsulation].eql?("Ethernet") iface[ifn][:addresses].keys.each do |addr| if iface[ifn][:addresses][addr]["family"].eql?("inet") iaddr = addr break end end if iface[ifn][:arp] iface[ifn][:arp].keys.each do |addr| if addr.eql?(iaddr) iface[ifn][:addresses][iface[ifn][:arp][iaddr]] = { "family" => "lladdr" } break end end end end end network[:interfaces] = iface popen4("route -n get default") do |pid, stdin, stdout, stderr| stdin.close route_get = stdout.read matches = /interface: (\S+)/.match(route_get) if matches Ohai::Log.debug("found gateway device: #{$1}") network[:default_interface] = matches[1] end matches = /gateway: (\S+)/.match(route_get) if matches Ohai::Log.debug("found gateway: #{$1}") network[:default_gateway] = matches[1] end end ohai-6.14.0/lib/ohai/plugins/solaris2/hostname.rb0000644000175000017500000000213411761755160021107 0ustar tfheentfheen# # Author:: Benjamin Black () # Author:: Daniel DeLeo # Copyright:: Copyright (c) 2008 Opscode, Inc. # Copyright:: Copyright (c) 2009 Daniel DeLeo # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'socket' provides "hostname", "fqdn" hostname from("hostname") fqdn_lookup = Socket.getaddrinfo(hostname, nil, nil, nil, nil, Socket::AI_CANONNAME).first[2] if fqdn_lookup.split('.').length > 1 # we recieved an fqdn fqdn fqdn_lookup else # default to assembling one fqdn(from("hostname") + "." + from("domainname")) end ohai-6.14.0/lib/ohai/plugins/solaris2/uptime.rb0000644000175000017500000000232511761755160020576 0ustar tfheentfheen# # Author:: Kurt Yoder () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'date' # It would be far better if we could include sys/uptime from sys-uptime RubyGem # It would also be good if we could pull idle time; how do we do this on Solaris? provides "uptime", "uptime_seconds" # Example output: # $ who -b # . system boot Jul 9 17:51 popen4('who -b') do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /.* boot (.+)/ uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i uptime self._seconds_to_human(uptime_seconds) break end end end ohai-6.14.0/lib/ohai/plugins/solaris2/platform.rb0000644000175000017500000000324011761755160021114 0ustar tfheentfheen# # Author:: Benjamin Black () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "platform", "platform_version", "platform_build" if File.exists?("/sbin/uname") uname_exec = "/sbin/uname" else uname_exec = "uname" end popen4("#{uname_exec} -X") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^Release =\s+(.+)$/ platform_version $1 when /^KernelID =\s+(.+)$/ platform_build $1 end end end File.open("/etc/release") do |file| while line = file.gets case line when /^\s*(OmniOS).*r(\d+).*$/ platform "omnios" platform_version $2 when /^\s*(OpenIndiana).*oi_(\d+).*$/ platform "openindiana" platform_version $2 when /^\s*(OpenSolaris).*snv_(\d+).*$/ platform "opensolaris" platform_version $2 when /^\s*(Oracle Solaris) (\d+)\s.*$/ platform "solaris2" when /^\s*(Solaris)\s.*$/ platform "solaris2" when /^\s*(NexentaCore)\s.*$/ platform "nexentacore" when /^\s*(SmartOS)\s.*$/ platform "smartos" end end end ohai-6.14.0/lib/ohai/plugins/solaris2/virtualization.rb0000644000175000017500000000511211761755160022354 0ustar tfheentfheen# # Author:: Sean Walbran () # Author:: Kurt Yoder () # Copyright:: Copyright (c) 2009 Opscode, Inc. # Copyright:: Copyright (c) 2010 Kurt Yoder # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "virtualization" virtualization Mash.new # Detect KVM/QEMU from cpuinfo, report as KVM psrinfo_path="/usr/sbin/psrinfo" if File.exists?(psrinfo_path) popen4(psrinfo_path + " -pv") do |pid, stdin, stdout, stderr| stdin.close psr_info = stdout.read if psr_info =~ /QEMU Virtual CPU/ virtualization[:system] = "kvm" virtualization[:role] = "guest" end end end # http://www.dmo.ca/blog/detecting-virtualization-on-linux smbios_path="/usr/sbin/smbios" if File.exists?(smbios_path) popen4(smbios_path) do |pid, stdin, stdout, stderr| stdin.close dmi_info = stdout.read case dmi_info when /Manufacturer: Microsoft/ if dmi_info =~ /Product: Virtual Machine/ virtualization[:system] = "virtualpc" virtualization[:role] = "guest" end when /Manufacturer: VMware/ if dmi_info =~ /Product: VMware Virtual Platform/ virtualization[:system] = "vmware" virtualization[:role] = "guest" end else nil end end end if File.executable?('/usr/sbin/zoneadm') zones = Mash.new popen4("zoneadm list -pc") do |pid, stdin, stdout, stderr| stdin.close stdout.each{ |line| info = line.chomp.split(/:/) zones[info[1]] = { 'id' => info[0], 'state' => info[2], 'root' => info[3], 'uuid' => info[4], 'brand' => info[5], 'ip' => info[6], } } if (zones.length == 1) first_zone = zones.keys[0] unless( first_zone == 'global') virtualization[:system] = 'zone' virtualization[:role] = 'guest' virtualization[:guest_uuid] = zones[first_zone]['uuid'] end elsif (zones.length > 1) virtualization[:system] = 'zone' virtualization[:role] = 'host' virtualization[:guests] = zones end end end ohai-6.14.0/lib/ohai/plugins/solaris2/ssh_host_key.rb0000644000175000017500000000161611761755160021777 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "keys/ssh" require_plugin "keys" keys[:ssh] = Mash.new keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1] keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1] ohai-6.14.0/lib/ohai/plugins/netbsd/0000755000175000017500000000000011761755160016465 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/netbsd/kernel.rb0000644000175000017500000000222011761755160020266 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "kernel" kernel[:os] = kernel[:name] kernel[:securelevel] = from_with_regex("sysctl kern.securelevel", /kern.securelevel=(.+)$/) mod = Mash.new popen4("/usr/bin/modstat") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| # 1 7 0xc0400000 97f830 kernel if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/ kld[$5] = { :size => $4, :refcount => $2 } end end end kernel[:modules] = mod unless mod.empty? ohai-6.14.0/lib/ohai/plugins/netbsd/filesystem.rb0000644000175000017500000000317011761755160021177 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "filesystem" fs = Mash.new # Grab filesystem data from df popen4("df") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^Filesystem/ next when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ filesystem = $1 fs[filesystem] = Mash.new fs[filesystem]['kb_size'] = $2 fs[filesystem]['kb_used'] = $3 fs[filesystem]['kb_available'] = $4 fs[filesystem]['percent_used'] = $5 fs[filesystem]['mount'] = $6 end end end # Grab mount information from mount popen4("mount -l") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/ filesystem = $1 fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem]['mount'] = $2 fs[filesystem]['fs_type'] = $3 fs[filesystem]['mount-options'] = $4.split(/,\s*/) end end end # Set the filesystem data filesystem fs ohai-6.14.0/lib/ohai/plugins/netbsd/cpu.rb0000644000175000017500000000262011761755160017601 0ustar tfheentfheen# # Author:: Mathieu Sauve-Frankel # Copyright:: Copyright (c) 2009 Mathieu Sauve-Frankel # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides 'cpu' cpuinfo = Mash.new # NetBSD provides some cpu information via sysctl, and a little via dmesg.boot # unlike OpenBSD and FreeBSD, NetBSD does not provide information about the # available instruction set # cpu0 at mainbus0 apid 0: Intel 686-class, 2134MHz, id 0x6f6 File.open("/var/run/dmesg.boot").each do |line| case line when /cpu[\d\w\s]+:\s([\w\s\-]+),\s+(\w+),/ cpuinfo[:model_name] = $1 cpuinfo[:mhz] = $2.gsub(/mhz/i, "") end end flags = [] popen4("dmidecode") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^\s+([A-Z\d-]+)\s+\([\w\s-]+\)$/ flags << $1.downcase end end end cpuinfo[:flags] = flags unless flags.empty? cpu cpuinfo ohai-6.14.0/lib/ohai/plugins/netbsd/memory.rb0000644000175000017500000000625211761755160020327 0ustar tfheentfheen# # Author:: Mathieu Sauve-Frankel # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "memory" memory Mash.new memory[:swap] = Mash.new # $ vmstat -s # 4096 bytes per page # 514011 pages managed # 224519 pages free # 209339 pages active # 4647 pages inactive # 0 pages being paged out # 5 pages wired # 0 pages zeroed # 4 pages reserved for pagedaemon # 6 pages reserved for kernel # 262205 swap pages # 0 swap pages in use # 0 total anon's in system # 0 free anon's # 1192991609 page faults # 1369579301 traps # 814549706 interrupts # 771702498 cpu context switches # 208810590 fpu context switches # 492361360 software interrupts # 1161998825 syscalls # 0 pagein operations # 0 swap ins # 0 swap outs # 768352 forks # 16 forks where vmspace is shared # 1763 kernel map entries # 0 number of times the pagedaemon woke up # 0 revolutions of the clock hand # 0 pages freed by pagedaemon # 0 pages scanned by pagedaemon # 0 pages reactivated by pagedaemon # 0 busy pages found by pagedaemon # 1096393776 total name lookups # cache hits (37% pos + 2% neg) system 1% per-directory # deletions 0%, falsehits 6%, toolong 26% # 0 select collisions popen4("vmstat -s") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /(\d+) bytes per page/ memory[:page_size] = $1 when /(\d+) pages managed/ memory[:page_count] = $1 memory[:total] = memory[:page_size].to_i * memory[:page_count].to_i when /(\d+) pages free/ memory[:free] = memory[:page_size].to_i * $1.to_i when /(\d+) pages active/ memory[:active] = memory[:page_size].to_i * $1.to_i when /(\d+) pages inactive/ memory[:inactive] = memory[:page_size].to_i * $1.to_i when /(\d+) pages wired/ memory[:wired] = memory[:page_size].to_i * $1.to_i end end end popen4("swapctl -l") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| # Device 1024-blocks Used Avail Capacity Priority # swap_device 1048824 0 1048824 0% 0 if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/ mdev = $1 memory[:swap][mdev] = Mash.new memory[:swap][mdev][:total] = $2 memory[:swap][mdev][:used] = $3 memory[:swap][mdev][:free] = $4 memory[:swap][mdev][:percent_free] = $5 end end end ohai-6.14.0/lib/ohai/plugins/netbsd/ps.rb0000644000175000017500000000141711761755160017437 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "command/ps" require_plugin 'command' # ps -e requires procfs command[:ps] = 'ps -ax' ohai-6.14.0/lib/ohai/plugins/netbsd/network.rb0000644000175000017500000001036611761755160020511 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "network", "counters/network" from("route -n get default").split("\n").each do |line| if line =~ /(\w+): ([\w\.]+)/ case $1 when "gateway" network[:default_gateway] = $2 when "interface" network[:default_interface] = $2 end end end iface = Mash.new popen4("/sbin/ifconfig -a") do |pid, stdin, stdout, stderr| stdin.close cint = nil stdout.each do |line| if line =~ /^([0-9a-zA-Z\.]+):\s+/ cint = $1 iface[cint] = Mash.new if cint =~ /^(\w+)(\d+.*)/ iface[cint][:type] = $1 iface[cint][:number] = $2 end end # call the family lladdr to match linux for consistency if line =~ /\s+address: (.+?)\s/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "lladdr" } end if line =~ /\s+inet ([\d.]+) netmask ([\da-fx]+)\s*\w*\s*([\d.]*)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] # convert the netmask to decimal for consistency netmask = "#{$2[2,2].hex}.#{$2[4,2].hex}.#{$2[6,2].hex}.#{$2[8,2].hex}" if $3.empty? iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask } else # found a broadcast address iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask, "broadcast" => $3 } end end if line =~ /\s+inet6 ([a-f0-9\:]+)%?(\w*)\s+prefixlen\s+(\d+)\s*\w*\s*([\da-fx]*)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] if $4.empty? iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $3 } else #found a zone_id / scope iface[cint][:addresses][$1] = { "family" => "inet6", "zoneid" => $2, "prefixlen" => $3, "scopeid" => $4 } end end if line =~ /flags=\d+<(.+)>/ flags = $1.split(',') iface[cint][:flags] = flags if flags.length > 0 end if line =~ /metric: (\d+) mtu: (\d+)/ iface[cint][:metric] = $1 iface[cint][:mtu] = $2 end end end popen4("arp -an") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/ next unless iface[$3] # this should never happen iface[$3][:arp] = Mash.new unless iface[$3][:arp] iface[$3][:arp][$1] = $2.downcase end end end network["interfaces"] = iface net_counters = Mash.new # From netstat(1), not sure of the implications: # Show the state of all network interfaces or a single interface # which have been auto-configured (interfaces statically configured # into a system, but not located at boot time are not shown). popen4("netstat -idn") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| # Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll Drop # em0 1500 00:11:25:2d:90:be 3719557 0 3369969 0 0 0 # $1 $2 $3 $4 $5 $6 $7 $8 if line =~ /^([\w\.\*]+)\s+\d+\s+\s+([\w:]*)\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ cint = $1 net_counters[cint] = Mash.new unless net_counters[cint] net_counters[cint] = Mash.new unless net_counters[cint]["rx"] net_counters[cint] = Mash.new unless net_counters[cint]["tx"] net_counters[cint] = $3 net_counters[cint] = $4 net_counters[cint] = $5 net_counters[cint] = $6 net_counters[cint] = $7 net_counters[cint] = $8 end end end counters[:network][:interfaces] = net_counters ohai-6.14.0/lib/ohai/plugins/netbsd/hostname.rb0000644000175000017500000000137611761755160020637 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "hostname", "fqdn" hostname from("hostname -s") fqdn from("hostname") ohai-6.14.0/lib/ohai/plugins/netbsd/uptime.rb0000644000175000017500000000205011761755160020312 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "uptime", "uptime_seconds" # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009 popen4("/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /kern.boottime:\D+(\d+)/ uptime_seconds Time.new.to_i - $1.to_i uptime self._seconds_to_human(uptime_seconds) end end end ohai-6.14.0/lib/ohai/plugins/netbsd/platform.rb0000644000175000017500000000143411761755160020640 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "platform", "platform_version" platform from("uname -s").downcase platform_version from("uname -r") ohai-6.14.0/lib/ohai/plugins/netbsd/virtualization.rb0000644000175000017500000000426511761755160022105 0ustar tfheentfheen# # Author:: Bryan McLellan (btm@loftninjas.org) # Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "virtualization" virtualization Mash.new # KVM Host support for FreeBSD is in development # http://feanor.sssup.it/~fabio/freebsd/lkvm/ # Detect KVM/QEMU from cpu, report as KVM # hw.model: QEMU Virtual CPU version 0.9.1 if from("sysctl -n hw.model") =~ /QEMU Virtual CPU/ virtualization[:system] = "kvm" virtualization[:role] = "guest" end # http://www.dmo.ca/blog/detecting-virtualization-on-linux if File.exists?("/usr/pkg/sbin/dmidecode") popen4("dmidecode") do |pid, stdin, stdout, stderr| stdin.close found_virt_manufacturer = nil found_virt_product = nil stdout.each do |line| case line when /Manufacturer: Microsoft/ found_virt_manufacturer = "microsoft" when /Product Name: Virtual Machine/ found_virt_product = "microsoft" when /Version: 5.0/ if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft" virtualization[:system] = "virtualpc" virtualization[:role] = "guest" end when /Version: VS2005R2/ if found_virt_manufacturer == "microsoft" && found_virt_product == "microsoft" virtualization[:system] = "virtualserver" virtualization[:role] = "guest" end when /Manufacturer: VMware/ found_virt_manufacturer = "vmware" when /Product Name: VMware Virtual Platform/ if found_virt_manufacturer == "vmware" virtualization[:system] = "vmware" virtualization[:role] = "guest" end end end end end ohai-6.14.0/lib/ohai/plugins/netbsd/ssh_host_key.rb0000644000175000017500000000161611761755160021520 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "keys/ssh" require_plugin "keys" keys[:ssh] = Mash.new keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1] keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1] ohai-6.14.0/lib/ohai/plugins/hostname.rb0000644000175000017500000000150111761755160017346 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "fqdn", "domain" require_plugin "#{os}::hostname" # Domain is everything after the first dot if fqdn fqdn =~ /.+?\.(.*)/ domain $1 endohai-6.14.0/lib/ohai/plugins/linux/0000755000175000017500000000000011761755160016345 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/linux/lsb.rb0000644000175000017500000000325711761755160017461 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "lsb" lsb Mash.new if File.exists?("/etc/lsb-release") File.open("/etc/lsb-release").each do |line| case line when /^DISTRIB_ID=["']?(.+?)["']?$/ lsb[:id] = $1 when /^DISTRIB_RELEASE=["']?(.+?)["']?$/ lsb[:release] = $1 when /^DISTRIB_CODENAME=["']?(.+?)["']?$/ lsb[:codename] = $1 when /^DISTRIB_DESCRIPTION=["']?(.+?)["']?$/ lsb[:description] = $1 end end elsif File.exists?("/usr/bin/lsb_release") # Fedora/Redhat, requires redhat-lsb package popen4("lsb_release -a") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^Distributor ID:\s+(.+)$/ lsb[:id] = $1 when /^Description:\s+(.+)$/ lsb[:description] = $1 when /^Release:\s+(.+)$/ lsb[:release] = $1 when /^Codename:\s+(.+)$/ lsb[:codename] = $1 else lsb[:id] = line end end end else Ohai::Log.debug("Skipping LSB, cannot find /etc/lsb-release or /usr/bin/lsb_release") end ohai-6.14.0/lib/ohai/plugins/linux/kernel.rb0000644000175000017500000000172511761755160020157 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "kernel" kernel[:os] = from("uname -o") kext = Mash.new popen4("env lsmod") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/ kext[$1] = { :size => $2, :refcount => $3 } end end end kernel[:modules] = kext ohai-6.14.0/lib/ohai/plugins/linux/block_device.rb0000644000175000017500000000251711761755160021310 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "block_device" if File.exists?("/sys/block") block = Mash.new Dir["/sys/block/*"].each do |block_device_dir| dir = File.basename(block_device_dir) block[dir] = Mash.new %w{size removable}.each do |check| if File.exists?("/sys/block/#{dir}/#{check}") File.open("/sys/block/#{dir}/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip } end end %w{model rev state timeout vendor}.each do |check| if File.exists?("/sys/block/#{dir}/device/#{check}") File.open("/sys/block/#{dir}/device/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip } end end end block_device block end ohai-6.14.0/lib/ohai/plugins/linux/filesystem.rb0000644000175000017500000000577511761755160021074 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "filesystem" fs = Mash.new # Grab filesystem data from df popen4("df -P") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| case line when /^Filesystem\s+1024-blocks/ next when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ filesystem = $1 fs[filesystem] = Mash.new fs[filesystem][:kb_size] = $2 fs[filesystem][:kb_used] = $3 fs[filesystem][:kb_available] = $4 fs[filesystem][:percent_used] = $5 fs[filesystem][:mount] = $6 end end end # Grab mount information from /bin/mount popen4("mount") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/ filesystem = $1 fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:mount] = $2 fs[filesystem][:fs_type] = $3 fs[filesystem][:mount_options] = $4.split(",") end end end # Gather more filesystem types via libuuid, even devices that's aren't mounted popen4("blkid -s TYPE") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^(\S+): TYPE="(\S+)"/ filesystem = $1 fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:fs_type] = $2 end end end # Gather device UUIDs via libuuid popen4("blkid -s UUID") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^(\S+): UUID="(\S+)"/ filesystem = $1 fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:uuid] = $2 end end end # Gather device labels via libuuid popen4("blkid -s LABEL") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^(\S+): LABEL="(\S+)"/ filesystem = $1 fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:label] = $2 end end end # Grab any missing mount information from /proc/mounts if File.exists?('/proc/mounts') File.open('/proc/mounts').read_nonblock(4096).each_line do |line| if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/ filesystem = $1 next if fs.has_key?(filesystem) fs[filesystem] = Mash.new fs[filesystem][:mount] = $2 fs[filesystem][:fs_type] = $3 fs[filesystem][:mount_options] = $4.split(",") end end end # Set the filesystem data filesystem fs ohai-6.14.0/lib/ohai/plugins/linux/cpu.rb0000644000175000017500000000341111761755160017460 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "cpu" cpuinfo = Mash.new real_cpu = Mash.new cpu_number = 0 current_cpu = nil File.open("/proc/cpuinfo").each do |line| case line when /processor\s+:\s(.+)/ cpuinfo[$1] = Mash.new current_cpu = $1 cpu_number += 1 when /vendor_id\s+:\s(.+)/ cpuinfo[current_cpu]["vendor_id"] = $1 when /cpu family\s+:\s(.+)/ cpuinfo[current_cpu]["family"] = $1 when /model\s+:\s(.+)/ cpuinfo[current_cpu]["model"] = $1 when /stepping\s+:\s(.+)/ cpuinfo[current_cpu]["stepping"] = $1 when /physical id\s+:\s(.+)/ cpuinfo[current_cpu]["physical_id"] = $1 real_cpu[$1] = true when /core id\s+:\s(.+)/ cpuinfo[current_cpu]["core_id"] = $1 when /cpu cores\s+:\s(.+)/ cpuinfo[current_cpu]["cores"] = $1 when /model name\s+:\s(.+)/ cpuinfo[current_cpu]["model_name"] = $1 when /cpu MHz\s+:\s(.+)/ cpuinfo[current_cpu]["mhz"] = $1 when /cache size\s+:\s(.+)/ cpuinfo[current_cpu]["cache_size"] = $1 when /flags\s+:\s(.+)/ cpuinfo[current_cpu]["flags"] = $1.split(' ') end end cpu cpuinfo cpu[:total] = cpu_number cpu[:real] = real_cpu.keys.lengthohai-6.14.0/lib/ohai/plugins/linux/memory.rb0000644000175000017500000000544311761755160020210 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "memory" memory Mash.new memory[:swap] = Mash.new File.open("/proc/meminfo").each do |line| case line when /^MemTotal:\s+(\d+) (.+)$/ memory[:total] = "#{$1}#{$2}" when /^MemFree:\s+(\d+) (.+)$/ memory[:free] = "#{$1}#{$2}" when /^Buffers:\s+(\d+) (.+)$/ memory[:buffers] = "#{$1}#{$2}" when /^Cached:\s+(\d+) (.+)$/ memory[:cached] = "#{$1}#{$2}" when /^Active:\s+(\d+) (.+)$/ memory[:active] = "#{$1}#{$2}" when /^Inactive:\s+(\d+) (.+)$/ memory[:inactive] = "#{$1}#{$2}" when /^HighTotal:\s+(\d+) (.+)$/ memory[:high_total] = "#{$1}#{$2}" when /^HighFree:\s+(\d+) (.+)$/ memory[:high_free] = "#{$1}#{$2}" when /^LowTotal:\s+(\d+) (.+)$/ memory[:low_total] = "#{$1}#{$2}" when /^LowFree:\s+(\d+) (.+)$/ memory[:low_free] = "#{$1}#{$2}" when /^Dirty:\s+(\d+) (.+)$/ memory[:dirty] = "#{$1}#{$2}" when /^Writeback:\s+(\d+) (.+)$/ memory[:writeback] = "#{$1}#{$2}" when /^AnonPages:\s+(\d+) (.+)$/ memory[:anon_pages] = "#{$1}#{$2}" when /^Mapped:\s+(\d+) (.+)$/ memory[:mapped] = "#{$1}#{$2}" when /^Slab:\s+(\d+) (.+)$/ memory[:slab] = "#{$1}#{$2}" when /^SReclaimable:\s+(\d+) (.+)$/ memory[:slab_reclaimable] = "#{$1}#{$2}" when /^SUnreclaim:\s+(\d+) (.+)$/ memory[:slab_unreclaim] = "#{$1}#{$2}" when /^PageTables:\s+(\d+) (.+)$/ memory[:page_tables] = "#{$1}#{$2}" when /^NFS_Unstable:\s+(\d+) (.+)$/ memory[:nfs_unstable] = "#{$1}#{$2}" when /^Bounce:\s+(\d+) (.+)$/ memory[:bounce] = "#{$1}#{$2}" when /^CommitLimit:\s+(\d+) (.+)$/ memory[:commit_limit] = "#{$1}#{$2}" when /^Committed_AS:\s+(\d+) (.+)$/ memory[:committed_as] = "#{$1}#{$2}" when /^VmallocTotal:\s+(\d+) (.+)$/ memory[:vmalloc_total] = "#{$1}#{$2}" when /^VmallocUsed:\s+(\d+) (.+)$/ memory[:vmalloc_used] = "#{$1}#{$2}" when /^VmallocChunk:\s+(\d+) (.+)$/ memory[:vmalloc_chunk] = "#{$1}#{$2}" when /^SwapCached:\s+(\d+) (.+)$/ memory[:swap][:cached] = "#{$1}#{$2}" when /^SwapTotal:\s+(\d+) (.+)$/ memory[:swap][:total] = "#{$1}#{$2}" when /^SwapFree:\s+(\d+) (.+)$/ memory[:swap][:free] = "#{$1}#{$2}" end end ohai-6.14.0/lib/ohai/plugins/linux/ps.rb0000644000175000017500000000136411761755160017320 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "command/ps" require_plugin 'command' command[:ps] = 'ps -ef' ohai-6.14.0/lib/ohai/plugins/linux/network.rb0000644000175000017500000003620111761755160020365 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ipaddr' provides "network", "counters/network" def encaps_lookup(encap) return "Loopback" if encap.eql?("Local Loopback") || encap.eql?("loopback") return "PPP" if encap.eql?("Point-to-Point Protocol") return "SLIP" if encap.eql?("Serial Line IP") return "VJSLIP" if encap.eql?("VJ Serial Line IP") return "IPIP" if encap.eql?("IPIP Tunnel") return "6to4" if encap.eql?("IPv6-in-IPv4") return "Ethernet" if encap.eql?("ether") encap end iface = Mash.new net_counters = Mash.new # Match the lead line for an interface from iproute2 # 3: eth0.11@eth0: mtu 1500 qdisc noqueue state UP # The '@eth0:' portion doesn't exist on primary interfaces and thus is optional in the regex IPROUTE_INT_REGEX = /^(\d+): ([0-9a-zA-Z@:\.\-_]*?)(@[0-9a-zA-Z]+|):\s/ if File.exist?("/sbin/ip") # families to get default routes from families = [ { :name => "inet", :default_route => "0.0.0.0/0", :default_prefix => :default, :neighbour_attribute => :arp }, { :name => "inet6", :default_route => "::/0", :default_prefix => :default_inet6, :neighbour_attribute => :neighbour_inet6 } ] popen4("ip addr") do |pid, stdin, stdout, stderr| stdin.close cint = nil stdout.each do |line| if line =~ IPROUTE_INT_REGEX cint = $2 iface[cint] = Mash.new if cint =~ /^(\w+)(\d+.*)/ iface[cint][:type] = $1 iface[cint][:number] = $2 end if line =~ /mtu (\d+)/ iface[cint][:mtu] = $1 end flags = line.scan(/(UP|BROADCAST|DEBUG|LOOPBACK|POINTTOPOINT|NOTRAILERS|LOWER_UP|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC)/) if flags.length > 1 iface[cint][:flags] = flags.flatten.uniq end end if line =~ /link\/(\w+) ([\da-f\:]+) / iface[cint][:encapsulation] = encaps_lookup($1) unless $2 == "00:00:00:00:00:00" iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$2.upcase] = { "family" => "lladdr" } end end if line =~ /inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/(\d{1,2}))?/ tmp_addr, tmp_prefix = $1, $3 tmp_prefix ||= "32" original_int = nil # Are we a formerly aliased interface? if line =~ /#{cint}:(\d+)$/ sub_int = $1 alias_int = "#{cint}:#{sub_int}" original_int = cint cint = alias_int end iface[cint] = Mash.new unless iface[cint] # Create the fake alias interface if needed iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix } iface[cint][:addresses][tmp_addr][:netmask] = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s if line =~ /peer (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:addresses][tmp_addr][:peer] = $1 end if line =~ /brd (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:addresses][tmp_addr][:broadcast] = $1 end if line =~ /scope (\w+)/ iface[cint][:addresses][tmp_addr][:scope] = ($1.eql?("host") ? "Node" : $1.capitalize) end # If we found we were an an alias interface, restore cint to its original value cint = original_int unless original_int.nil? end if line =~ /inet6 ([a-f0-9\:]+)\/(\d+) scope (\w+)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] tmp_addr = $1 iface[cint][:addresses][tmp_addr] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("host") ? "Node" : $3.capitalize) } end end end popen4("ip -d -s link") do |pid, stdin, stdout, stderr| stdin.close tmp_int = nil on_rx = true stdout.each do |line| if line =~ IPROUTE_INT_REGEX tmp_int = $2 net_counters[tmp_int] = Mash.new unless net_counters[tmp_int] end if line =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ int = on_rx ? :rx : :tx net_counters[tmp_int][int] = Mash.new unless net_counters[tmp_int][int] net_counters[tmp_int][int][:bytes] = $1 net_counters[tmp_int][int][:packets] = $2 net_counters[tmp_int][int][:errors] = $3 net_counters[tmp_int][int][:drop] = $4 if(int == :rx) net_counters[tmp_int][int][:overrun] = $5 else net_counters[tmp_int][int][:carrier] = $5 net_counters[tmp_int][int][:collisions] = $6 end on_rx = !on_rx end if line =~ /qlen (\d+)/ net_counters[tmp_int][:tx] = Mash.new unless net_counters[tmp_int][:tx] net_counters[tmp_int][:tx][:queuelen] = $1 end if line =~ /vlan id (\d+)/ tmp_id = $1 iface[tmp_int][:vlan] = Mash.new unless iface[tmp_int][:vlan] iface[tmp_int][:vlan][:id] = tmp_id vlan_flags = line.scan(/(REORDER_HDR|GVRP|LOOSE_BINDING)/) if vlan_flags.length > 0 iface[tmp_int][:vlan][:flags] = vlan_flags.flatten.uniq end end if line =~ /state (\w+)/ iface[tmp_int]['state'] = $1.downcase end end end families.each do |family| neigh_attr = family[:neighbour_attribute] default_prefix = family[:default_prefix] popen4("ip -f #{family[:name]} neigh show") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^([a-f0-9\:\.]+)\s+dev\s+([^\s]+)\s+lladdr\s+([a-fA-F0-9\:]+)/ unless iface[$2] Ohai::Log.warn("neighbour list has entries for unknown interface #{iface[$2]}") next end iface[$2][neigh_attr] = Mash.new unless iface[$2][neigh_attr] iface[$2][neigh_attr][$1] = $3.downcase end end end # checking the routing tables # why ? # 1) to set the default gateway and default interfaces attributes # 2) on some occasions, the best way to select node[:ipaddress] is to look at # the routing table source field. # 3) and since we're at it, let's populate some :routes attributes # (going to do that for both inet and inet6 addresses) popen4("ip -f #{family[:name]} route show") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^([^\s]+)\s(.*)$/ route_dest = $1 route_ending = $2 # if route_ending =~ /\bdev\s+([^\s]+)\b/ route_int = $1 else Ohai::Log.debug("Skipping route entry without a device: '#{line}'") next end unless iface[route_int] Ohai::Log.debug("Skipping previously unseen interface from 'ip route show': #{route_int}") next end route_entry = Mash.new( :destination => route_dest, :family => family[:name] ) %w[via scope metric proto src].each do |k| route_entry[k] = $1 if route_ending =~ /\b#{k}\s+([^\s]+)\b/ end # a sanity check, especially for Linux-VServer, OpenVZ and LXC: # don't report the route entry if the src address isn't set on the node next if route_entry[:src] and not iface[route_int][:addresses].has_key? route_entry[:src] iface[route_int][:routes] = Array.new unless iface[route_int][:routes] iface[route_int][:routes] << route_entry end end end # now looking at the routes to set the default attributes # for information, default routes can be of this form : # - default via 10.0.2.4 dev br0 # - default dev br0 scope link # - default via 10.0.3.1 dev eth1 src 10.0.3.2 metric 10 # - default via 10.0.4.1 dev eth2 src 10.0.4.2 metric 20 # using a temporary var to hold routes and their interface name routes = iface.collect do |i,iv| iv[:routes].collect do |r| r.merge(:dev=>i) if r[:family] == family[:name] end.compact if iv[:routes] end.compact.flatten # using a temporary var to hold the default route # in case there are more than 1 default route, sort it by its metric # and return the first one # (metric value when unspecified is 0) default_route = routes.select do |r| r[:destination] == "default" end.sort do |x,y| (x[:metric].nil? ? 0 : x[:metric].to_i) <=> (y[:metric].nil? ? 0 : y[:metric].to_i) end.first if default_route.nil? or default_route.empty? Ohai::Log.debug("Unable to determine default #{family[:name]} interface") else network["#{default_prefix}_interface"] = default_route[:dev] Ohai::Log.debug("#{default_prefix}_interface set to #{default_route[:dev]}") # setting gateway to 0.0.0.0 or :: if the default route is a link level one network["#{default_prefix}_gateway"] = default_route[:via] ? default_route[:via] : family[:default_route].chomp("/0") Ohai::Log.debug("#{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}") # since we're at it, let's populate {ip,mac,ip6}address with the best values # using the source field when it's specified : # 1) in the default route # 2) in the route entry used to reach the default gateway route = routes.select do |r| # selecting routes r[:src] and # it has a src field iface[r[:dev]] and # the iface exists iface[r[:dev]][:addresses].has_key? r[:src] and # the src ip is set on the node iface[r[:dev]][:addresses][r[:src]][:scope].downcase != "link" and # this isn't a link level addresse ( r[:destination] == "default" or ( default_route[:via] and # the default route has a gateway IPAddress(r[:destination]).include? IPAddress(default_route[:via]) # the route matches the gateway ) ) end.sort_by do |r| # sorting the selected routes: # - getting default routes first # - then sort by metric # - then by prefixlen [ r[:destination] == "default" ? 0 : 1, r[:metric].nil? ? 0 : r[:metric].to_i, # for some reason IPAddress doesn't accept "::/0", it doesn't like prefix==0 # just a quick workaround: use 0 if IPAddress fails begin IPAddress( r[:destination] == "default" ? family[:default_route] : r[:destination] ).prefix rescue 0 end ] end.first unless route.nil? or route.empty? if family[:name] == "inet" ipaddress route[:src] macaddress iface[route[:dev]][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless iface[route[:dev]][:flags].include? "NOARP" else ip6address route[:src] end end end end else begin route_result = from("route -n \| grep -m 1 ^0.0.0.0").split(/[ \t]+/) network[:default_gateway], network[:default_interface] = route_result.values_at(1,7) rescue Ohai::Exceptions::Exec Ohai::Log.debug("Unable to determine default interface") end popen4("ifconfig -a") do |pid, stdin, stdout, stderr| stdin.close cint = nil stdout.each do |line| tmp_addr = nil # dev_valid_name in the kernel only excludes slashes, nulls, spaces # http://git.kernel.org/?p=linux/kernel/git/stable/linux-stable.git;a=blob;f=net/core/dev.c#l851 if line =~ /^([0-9a-zA-Z@\.\:\-_]+)\s+/ cint = $1 iface[cint] = Mash.new if cint =~ /^(\w+)(\d+.*)/ iface[cint][:type] = $1 iface[cint][:number] = $2 end end if line =~ /Link encap:(Local Loopback)/ || line =~ /Link encap:(.+?)\s/ iface[cint][:encapsulation] = encaps_lookup($1) end if line =~ /HWaddr (.+?)\s/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "lladdr" } end if line =~ /inet addr:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "inet" } tmp_addr = $1 end if line =~ /inet6 addr: ([a-f0-9\:]+)\/(\d+) Scope:(\w+)/ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("Host") ? "Node" : $3) } end if line =~ /Bcast:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:addresses][tmp_addr]["broadcast"] = $1 end if line =~ /Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:addresses][tmp_addr]["netmask"] = $1 end flags = line.scan(/(UP|BROADCAST|DEBUG|LOOPBACK|POINTTOPOINT|NOTRAILERS|RUNNING|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC)\s/) if flags.length > 1 iface[cint][:flags] = flags.flatten end if line =~ /MTU:(\d+)/ iface[cint][:mtu] = $1 end if line =~ /P-t-P:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ iface[cint][:peer] = $1 end if line =~ /RX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) frame:(\d+)/ net_counters[cint] = Mash.new unless net_counters[cint] net_counters[cint][:rx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "frame" => $5 } end if line =~ /TX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) carrier:(\d+)/ net_counters[cint][:tx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "carrier" => $5 } end if line =~ /collisions:(\d+)/ net_counters[cint][:tx]["collisions"] = $1 end if line =~ /txqueuelen:(\d+)/ net_counters[cint][:tx]["queuelen"] = $1 end if line =~ /RX bytes:(\d+) \((\d+?\.\d+ .+?)\)/ net_counters[cint][:rx]["bytes"] = $1 end if line =~ /TX bytes:(\d+) \((\d+?\.\d+ .+?)\)/ net_counters[cint][:tx]["bytes"] = $1 end end end popen4("arp -an") do |pid, stdin, stdout, stderr| stdin.close stdout.each do |line| if line =~ /^\S+ \((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) \[(\w+)\] on ([0-9a-zA-Z\.\:\-]+)/ next unless iface[$4] # this should never happen iface[$4][:arp] = Mash.new unless iface[$4][:arp] iface[$4][:arp][$1] = $2.downcase end end end end counters[:network][:interfaces] = net_counters network["interfaces"] = iface ohai-6.14.0/lib/ohai/plugins/linux/hostname.rb0000644000175000017500000000154111761755160020511 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "hostname", "fqdn" hostname from("hostname -s") begin fqdn from("hostname --fqdn") rescue Ohai::Log.debug("hostname -f returned an error, probably no domain is set") end ohai-6.14.0/lib/ohai/plugins/linux/uptime.rb0000644000175000017500000000170211761755160020175 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "uptime", "idletime", "uptime_seconds", "idletime_seconds" uptime, idletime = File.open("/proc/uptime").gets.split(" ") uptime_seconds uptime.to_i uptime self._seconds_to_human(uptime.to_i) idletime_seconds idletime.to_i idletime self._seconds_to_human(idletime.to_i) ohai-6.14.0/lib/ohai/plugins/linux/platform.rb0000644000175000017500000000740711761755160020526 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # def get_redhatish_platform(contents) contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase end def get_redhatish_version(contents) contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1] end provides "platform", "platform_version", "platform_family" require_plugin 'linux::lsb' # platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching if File.exists?("/etc/oracle-release") contents = File.read("/etc/oracle-release").chomp platform "oracle" platform_version get_redhatish_version(contents) elsif File.exists?("/etc/enterprise-release") contents = File.read("/etc/enterprise-release").chomp platform "oracle" platform_version get_redhatish_version(contents) elsif File.exists?("/etc/debian_version") # Ubuntu and Debian both have /etc/debian_version # Ubuntu should always have a working lsb, debian does not by default if lsb[:id] =~ /Ubuntu/i platform "ubuntu" platform_version lsb[:release] else platform "debian" platform_version File.read("/etc/debian_version").chomp end elsif File.exists?("/etc/redhat-release") contents = File.read("/etc/redhat-release").chomp platform get_redhatish_platform(contents) platform_version get_redhatish_version(contents) elsif File.exists?("/etc/system-release") contents = File.read("/etc/system-release").chomp platform get_redhatish_platform(contents) platform_version get_redhatish_version(contents) elsif File.exists?('/etc/gentoo-release') platform "gentoo" platform_version File.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join elsif File.exists?('/etc/SuSE-release') platform "suse" platform_version File.read("/etc/SuSE-release").scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".") platform_version File.read("/etc/SuSE-release").scan(/VERSION = ([\d\.]{2,})/).flatten.join(".") if platform_version == "" elsif File.exists?('/etc/slackware-version') platform "slackware" platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join elsif File.exists?('/etc/arch-release') platform "arch" # no way to determine platform_version in a rolling release distribution # kernel release will be used - ex. 2.6.32-ARCH elsif lsb[:id] =~ /RedHat/i platform "redhat" platform_version lsb[:release] elsif lsb[:id] =~ /Amazon/i platform "amazon" platform_version lsb[:release] elsif lsb[:id] =~ /ScientificSL/i platform "scientific" platform_version lsb[:release] elsif lsb[:id] # LSB can provide odd data that changes between releases, so we currently fall back on it rather than dealing with its subtleties platform lsb[:id].downcase platform_version lsb[:release] end case platform when /debian/, /ubuntu/, /linuxmint/ platform_family "debian" when /fedora/ platform_family "fedora" when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/ platform_family "rhel" when /suse/ platform_family "suse" when /gentoo/ platform_family "gentoo" when /slackware/ platform_family "slackware" when /arch/ platform_family "arch" end ohai-6.14.0/lib/ohai/plugins/linux/virtualization.rb0000644000175000017500000000750711761755160021767 0ustar tfheentfheen# # Author:: Thom May () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "virtualization" virtualization Mash.new # if it is possible to detect paravirt vs hardware virt, it should be put in # virtualization[:mechanism] ## Xen # /proc/xen is an empty dir for EL6 + Linode Guests if File.exists?("/proc/xen") virtualization[:system] = "xen" # Assume guest virtualization[:role] = "guest" # This file should exist on most Xen systems, normally empty for guests if File.exists?("/proc/xen/capabilities") if File.read("/proc/xen/capabilities") =~ /control_d/i virtualization[:role] = "host" end end end # Xen Notes: # - cpuid of guests, if we could get it, would also be a clue # - may be able to determine if under paravirt from /dev/xen/evtchn (See OHAI-253) # - EL6 guests carry a 'hypervisor' cpu flag # - Additional edge cases likely should not change the above assumptions # but rather be additive - btm # Detect from kernel module if File.exists?("/proc/modules") modules = File.read("/proc/modules") if modules =~ /^kvm/ virtualization[:system] = "kvm" virtualization[:role] = "host" elsif modules =~ /^vboxdrv/ virtualization[:system] = "vbox" virtualization[:role] = "host" elsif modules =~ /^vboxguest/ virtualization[:system] = "vbox" virtualization[:role] = "guest" end end # Detect KVM/QEMU from cpuinfo, report as KVM # We could pick KVM from 'Booting paravirtualized kernel on KVM' in dmesg # 2.6.27-9-server (intrepid) has this / 2.6.18-6-amd64 (etch) does not # It would be great if we could read pv_info in the kernel # Wait for reply to: http://article.gmane.org/gmane.comp.emulators.kvm.devel/27885 if File.exists?("/proc/cpuinfo") if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU/ virtualization[:system] = "kvm" virtualization[:role] = "guest" end end # Detect OpenVZ / Virtuozzo. # http://wiki.openvz.org/BC_proc_entries if File.exists?("/proc/bc/0") virtualization[:system] = "openvz" virtualization[:role] = "host" elsif File.exists?("/proc/vz") virtualization[:system] = "openvz" virtualization[:role] = "guest" end # http://www.dmo.ca/blog/detecting-virtualization-on-linux if File.exists?("/usr/sbin/dmidecode") popen4("dmidecode") do |pid, stdin, stdout, stderr| stdin.close dmi_info = stdout.read case dmi_info when /Manufacturer: Microsoft/ if dmi_info =~ /Product Name: Virtual Machine/ virtualization[:system] = "virtualpc" virtualization[:role] = "guest" end when /Manufacturer: VMware/ if dmi_info =~ /Product Name: VMware Virtual Platform/ virtualization[:system] = "vmware" virtualization[:role] = "guest" end when /Manufacturer: Xen/ if dmi_info =~ /Product Name: HVM domU/ virtualization[:system] = "xen" virtualization[:role] = "guest" end else nil end end end # Detect Linux-VServer if File.exists?("/proc/self/status") proc_self_status = File.read("/proc/self/status") vxid = proc_self_status.match(/^(s_context|VxID): (\d+)$/) if vxid and vxid[2] virtualization[:system] = "linux-vserver" if vxid[2] == "0" virtualization[:role] = "host" else virtualization[:role] = "guest" end end end ohai-6.14.0/lib/ohai/plugins/linux/ssh_host_key.rb0000644000175000017500000000161611761755160021400 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "keys/ssh" require_plugin "keys" keys[:ssh] = Mash.new keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1] keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1] ohai-6.14.0/lib/ohai/plugins/passwd.rb0000644000175000017500000000144711761755160017042 0ustar tfheentfheenprovides 'etc', 'current_user' require 'etc' def fix_encoding(str) str.force_encoding(Encoding.default_external) if str.respond_to?(:force_encoding) str end unless etc etc Mash.new etc[:passwd] = Mash.new etc[:group] = Mash.new Etc.passwd do |entry| user_passwd_entry = Mash.new(:dir => entry.dir, :gid => entry.gid, :uid => entry.uid, :shell => entry.shell, :gecos => entry.gecos) user_passwd_entry.each_value {|v| fix_encoding(v)} etc[:passwd][fix_encoding(entry.name)] = user_passwd_entry end Etc.group do |entry| group_entry = Mash.new(:gid => entry.gid, :members => entry.mem.map {|u| fix_encoding(u)}) etc[:group][fix_encoding(entry.name)] = group_entry end end unless current_user current_user fix_encoding(Etc.getlogin) end ohai-6.14.0/lib/ohai/plugins/ohai_time.rb0000644000175000017500000000133011761755160017466 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "ohai_time" ohai_time Time.now.to_fohai-6.14.0/lib/ohai/plugins/dmi_common.rb0000644000175000017500000000766211761755160017667 0ustar tfheentfheen# # Author:: Kurt Yoder (ktyopscode@yoderhome.com) # Copyright:: Copyright (c) 2010 Kurt Yoder # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # module DMI # List of IDs and what they translate to # from 'man 8 dmidecode' # all-lowercase, all non-alphanumeric converted to '_' # 128-255 are 'oem_data_[id]' # Everything else is 'unknown' IdToDescription = { 0 => 'bios', 1 => 'system', 2 => 'base_board', 3 => 'chassis', 4 => 'processor', 5 => 'memory_controller', 6 => 'memory_module', 7 => 'cache', 8 => 'port_connector', 9 => 'system_slots', 10 => 'on_board_devices', 11 => 'oem_strings', 12 => 'system_configuration_options', 13 => 'bios_language', 14 => 'group_associations', 15 => 'system_event_log', 16 => 'physical_memory_array', 17 => 'memory_device', 18 => '32_bit_memory_error', 19 => 'memory_array_mapped_address', 20 => 'memory_device_mapped_address', 21 => 'built_in_pointing_device', 22 => 'portable_battery', 23 => 'system_reset', 24 => 'hardware_security', 25 => 'system_power_controls', 26 => 'voltage_probe', 27 => 'cooling_device', 28 => 'temperature_probe', 29 => 'electrical_current_probe', 30 => 'out_of_band_remote_access', 31 => 'boot_integrity_services', 32 => 'system_boot', 33 => '64_bit_memory_error', 34 => 'management_device', 35 => 'management_device_component', 36 => 'management_device_threshold_data', 37 => 'memory_channel', 38 => 'ipmi_device', 39 => 'power_supply', 126 => 'disabled_entries', 127 => 'end_of_table_marker', } # list of IDs to collect, otherwise we generate pages of hashes about cache chip size and whatnot # See OHAI-260. When we can give the user a choice, this will be a default. IdToCapture = [ 0, 1, 2, 3, 4, 6, 11 ] # look up DMI ID def DMI.id_lookup(id) begin id = id.to_i if (id >= 128) and (id <= 255) id = "oem_data_#{id}" elsif DMI::IdToDescription.has_key?(id) id = DMI::IdToDescription[id] else Ohai::Log.debug("unrecognized header id; falling back to 'unknown'") id = 'unknown' end rescue Ohai::Log.debug("failed to look up id #{id}, returning unchanged") id end end # create simplified convenience access keys for each record type # for single occurrences of one type, copy to top level all fields and values # for multiple occurrences of same type, copy to top level all fields and values that are common to all records def DMI.convenience_keys(dmi) dmi.each{ |type, records| in_common = Mash.new next unless records.class.to_s == 'Mash' next unless records.has_key?('all_records') records[:all_records].each{ |record| record.each{ |field, value| next if value.class.to_s == 'Mash' next if field.to_s == 'application_identifier' next if field.to_s == 'size' next if field.to_s == 'record_id' translated = field.downcase.gsub(/[^a-z0-9]/, '_') if in_common.has_key?(translated) in_common[translated] = nil unless in_common[translated] == value else in_common[translated] = value end } } in_common.each{ |field, value| next if value == nil dmi[type][field] = value } } end end ohai-6.14.0/lib/ohai/plugins/sigar/0000755000175000017500000000000011761755160016313 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/sigar/network_route.rb0000644000175000017500000000311111761755160021543 0ustar tfheentfheen# # Author:: Toomas Pelberg () # Copyright:: Copyright (c) 2011 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "sigar" require_plugin "network" provides "network" def flags(flags) f = "" if (flags & Sigar::RTF_UP) != 0 f += "U" end if (flags & Sigar::RTF_GATEWAY) != 0 f += "G" end if (flags & Sigar::RTF_HOST) != 0 f += "H" end f end # From sigar: include/sigar.h sigar_net_route_t SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname] sigar=Sigar.new sigar.net_route_list.each do |route| next unless network[:interfaces][route.ifname] # this should never happen network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route] route_data={} SIGAR_ROUTE_METHODS.each do |m| if(m == :flags) route_data[m]=flags(route.send(m)) else route_data[m]=route.send(m) end end network[:interfaces][route.ifname][:route][route.destination] = route_data end ohai-6.14.0/lib/ohai/plugins/sigar/filesystem.rb0000644000175000017500000000265511761755160021034 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "filesystem" require "sigar" fs = Mash.new sigar = Sigar.new sigar.file_system_list.each do |fsys| filesystem = fsys.dev_name fs[filesystem] = Mash.new fs[filesystem][:mount] = fsys.dir_name fs[filesystem][:fs_type] = fsys.sys_type_name fs[filesystem][:mount_options] = fsys.options begin usage = sigar.file_system_usage(fsys.dir_name) fs[filesystem][:kb_size] = (usage.total / 1024).to_s fs[filesystem][:kb_used] = ((usage.total - usage.free) / 1024).to_s fs[filesystem][:kb_available] = (usage.free / 1024).to_s fs[filesystem][:percent_used] = (usage.use_percent * 100).to_s + '%' rescue SystemExit => e raise rescue Exception => e #e.g. floppy or cdrom drive end end # Set the filesystem data filesystem fs ohai-6.14.0/lib/ohai/plugins/sigar/cpu.rb0000644000175000017500000000220611761755160017427 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "sigar" sigar = Sigar.new provides "cpu" cpuinfo = Mash.new ix = 0 sigar.cpu_info_list.each do |info| current_cpu = ix.to_s ix += 1 cpuinfo[current_cpu] = Mash.new cpuinfo[current_cpu]["vendor_id"] = info.vendor cpuinfo[current_cpu]["model"] = info.model cpuinfo[current_cpu]["mhz"] = info.mhz.to_s cpuinfo[current_cpu]["cache_size"] = info.cache_size.to_s cpuinfo[:total] = info.total_cores cpuinfo[:real] = info.total_sockets end cpu cpuinfo ohai-6.14.0/lib/ohai/plugins/sigar/memory.rb0000644000175000017500000000213711761755160020153 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "sigar" sigar = Sigar.new provides "memory" memory Mash.new memory[:swap] = Mash.new mem = sigar.mem swap = sigar.swap memory[:total] = (mem.total / 1024).to_s + "kB" memory[:free] = (mem.free / 1024).to_s + "kB" memory[:used] = (mem.used / 1024).to_s + "kB" memory[:swap][:total] = (swap.total / 1024).to_s + "kB" memory[:swap][:free] = (swap.free / 1024).to_s + "kB" memory[:swap][:used] = (swap.used / 1024).to_s + "kB" ohai-6.14.0/lib/ohai/plugins/sigar/network.rb0000644000175000017500000000763611761755160020345 0ustar tfheentfheen# # Author:: Matthew Kent () # Copyright:: Copyright (c) 2009 Matthew Kent # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #http://github.com/mdkent/ohai/commit/92f51aa18b6add9682510a87dcf94835ea72b04d require "sigar" sigar = Sigar.new provides "network", "counters/network" ninfo = sigar.net_info network[:default_interface] = ninfo.default_gateway_interface network[:default_gateway] = ninfo.default_gateway def encaps_lookup(encap) return "Loopback" if encap.eql?("Local Loopback") return "PPP" if encap.eql?("Point-to-Point Protocol") return "SLIP" if encap.eql?("Serial Line IP") return "VJSLIP" if encap.eql?("VJ Serial Line IP") return "IPIP" if encap.eql?("IPIP Tunnel") return "6to4" if encap.eql?("IPv6-in-IPv4") encap end iface = Mash.new net_counters = Mash.new sigar.net_interface_list.each do |cint| iface[cint] = Mash.new if cint =~ /^(\w+)(\d+.*)/ iface[cint][:type] = $1 iface[cint][:number] = $2 end ifconfig = sigar.net_interface_config(cint) iface[cint][:encapsulation] = encaps_lookup(ifconfig.type) iface[cint][:addresses] = Mash.new # Backwards compat: loopback has no hwaddr if (ifconfig.flags & Sigar::IFF_LOOPBACK) == 0 iface[cint][:addresses][ifconfig.hwaddr] = { "family" => "lladdr" } end if ifconfig.address != "0.0.0.0" iface[cint][:addresses][ifconfig.address] = { "family" => "inet" } # Backwards compat: no broadcast on tunnel or loopback dev if (((ifconfig.flags & Sigar::IFF_POINTOPOINT) == 0) && ((ifconfig.flags & Sigar::IFF_LOOPBACK) == 0)) iface[cint][:addresses][ifconfig.address]["broadcast"] = ifconfig.broadcast end iface[cint][:addresses][ifconfig.address]["netmask"] = ifconfig.netmask end iface[cint][:flags] = Sigar.net_interface_flags_to_s(ifconfig.flags).split(' ') iface[cint][:mtu] = ifconfig.mtu.to_s iface[cint][:queuelen] = ifconfig.tx_queue_len.to_s if ifconfig.prefix6_length != 0 iface[cint][:addresses][ifconfig.address6] = { "family" => "inet6" } iface[cint][:addresses][ifconfig.address6]["prefixlen"] = ifconfig.prefix6_length.to_s iface[cint][:addresses][ifconfig.address6]["scope"] = Sigar.net_scope_to_s(ifconfig.scope6) end net_counters[cint] = Mash.new unless net_counters[cint] if (!cint.include?(":")) ifstat = sigar.net_interface_stat(cint) net_counters[cint][:rx] = { "packets" => ifstat.rx_packets.to_s, "errors" => ifstat.rx_errors.to_s, "drop" => ifstat.rx_dropped.to_s, "overrun" => ifstat.rx_overruns.to_s, "frame" => ifstat.rx_frame.to_s, "bytes" => ifstat.rx_bytes.to_s } net_counters[cint][:tx] = { "packets" => ifstat.tx_packets.to_s, "errors" => ifstat.tx_errors.to_s, "drop" => ifstat.tx_dropped.to_s, "overrun" => ifstat.tx_overruns.to_s, "carrier" => ifstat.tx_carrier.to_s, "collisions" => ifstat.tx_collisions.to_s, "bytes" => ifstat.tx_bytes.to_s } end end begin sigar.arp_list.each do |arp| next unless iface[arp.ifname] # this should never happen iface[arp.ifname][:arp] = Mash.new unless iface[arp.ifname][:arp] iface[arp.ifname][:arp][arp.address] = arp.hwaddr end rescue #64-bit AIX for example requires 64-bit caller end counters[:network][:interfaces] = net_counters network["interfaces"] = iface ohai-6.14.0/lib/ohai/plugins/sigar/hostname.rb0000644000175000017500000000144011761755160020455 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'sigar' provides "hostname", "fqdn" sigar = Sigar.new hostname sigar.net_info.host_name fqdn sigar.fqdn ohai-6.14.0/lib/ohai/plugins/sigar/uptime.rb0000644000175000017500000000153611761755160020150 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "sigar" sigar = Sigar.new provides "uptime", "uptime_seconds" uptime = sigar.uptime.uptime uptime_seconds uptime.to_i * 1000 uptime self._seconds_to_human(uptime.to_i) ohai-6.14.0/lib/ohai/plugins/sigar/platform.rb0000644000175000017500000000146711761755160020474 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require "sigar" provides "platform", "platform_version" sys = Sigar.new.sys_info platform sys.name.downcase platform_version sys.version ohai-6.14.0/lib/ohai/plugins/uptime.rb0000644000175000017500000000252711761755160017044 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # def _seconds_to_human(seconds) days = seconds.to_i / 86400 seconds -= 86400 * days hours = seconds.to_i / 3600 seconds -= 3600 * hours minutes = seconds.to_i / 60 seconds -= 60 * minutes if days > 1 return sprintf("%d days %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds) elsif days == 1 return sprintf("%d day %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds) elsif hours > 0 return sprintf("%d hours %02d minutes %02d seconds", hours, minutes, seconds) elsif minutes > 0 return sprintf("%d minutes %02d seconds", minutes, seconds) else return sprintf("%02d seconds", seconds) end end ohai-6.14.0/lib/ohai/plugins/platform.rb0000644000175000017500000000166411761755160017366 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "platform", "platform_version", "platform_family" require_plugin "#{os}::platform" platform os unless attribute?("platform") platform_version os_version unless attribute?("platform_version") platform_family platform unless attribute?("platform_family") ohai-6.14.0/lib/ohai/plugins/c.rb0000644000175000017500000000612311761755160015757 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'rbconfig' provides "languages/c" require_plugin "languages" c = Mash.new #gcc status, stdout, stderr = run_command(:no_status_check => true, :command => "gcc -v") if status == 0 description = stderr.split($/).last output = description.split if output.length >= 3 c[:gcc] = Mash.new c[:gcc][:version] = output[2] c[:gcc][:description] = description end end #glibc ["/lib/libc.so.6", "/lib64/libc.so.6"].each do |glibc| status, stdout, stderr = run_command(:no_status_check => true, :command => glibc) if status == 0 description = stdout.split($/).first if description =~ /(\d+\.\d+\.?\d*)/ c[:glibc] = Mash.new c[:glibc][:version] = $1 c[:glibc][:description] = description end break end end #ms cl status, stdout, stderr = run_command(:no_status_check => true, :command => "cl /?") if status == 0 description = stderr.split($/).first if description =~ /Compiler Version ([\d\.]+)/ c[:cl] = Mash.new c[:cl][:version] = $1 c[:cl][:description] = description end end #ms vs status, stdout, stderr = run_command(:no_status_check => true, :command => "devenv.com /?") if status == 0 lines = stdout.split($/) description = lines[0].length == 0 ? lines[1] : lines[0] if description =~ /Visual Studio Version ([\d\.]+)/ c[:vs] = Mash.new c[:vs][:version] = $1.chop c[:vs][:description] = description end end #ibm xlc status, stdout, stderr = run_command(:no_status_check => true, :command => "xlc -qversion") if status == 0 or (status >> 8) == 249 description = stdout.split($/).first if description =~ /V(\d+\.\d+)/ c[:xlc] = Mash.new c[:xlc][:version] = $1 c[:xlc][:description] = description.strip end end #sun pro status, stdout, stderr = run_command(:no_status_check => true, :command => "cc -V -flags") if status == 0 output = stderr.split if stderr =~ /^cc: Sun C/ && output.size >= 4 c[:sunpro] = Mash.new c[:sunpro][:version] = output[3] c[:sunpro][:description] = stderr.chomp end end #hpux cc status, stdout, stderr = run_command(:no_status_check => true, :command => "what /opt/ansic/bin/cc") if status == 0 description = stdout.split($/).select { |line| line =~ /HP C Compiler/ }.first if description output = description.split c[:hpcc] = Mash.new c[:hpcc][:version] = output[1] if output.size >= 1 c[:hpcc][:description] = description.strip end end languages[:c] = c if c.keys.length > 0 ohai-6.14.0/lib/ohai/plugins/command.rb0000644000175000017500000000131711761755160017153 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "command" command Mash.newohai-6.14.0/lib/ohai/plugins/java.rb0000644000175000017500000000274111761755160016460 0ustar tfheentfheen# # Author:: Benjamin Black () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages/java" require_plugin "languages" java = Mash.new status, stdout, stderr = nil if RUBY_PLATFORM.downcase.include?("darwin") if system("/usr/libexec/java_home 2&>1 >/dev/null") status, stdout, stderr = run_command(:no_status_check => true, :command => "java -version") end else status, stdout, stderr = run_command(:no_status_check => true, :command => "java -version") end if status == 0 stderr.split("\n").each do |line| case line when /java version \"([0-9\.\_]+)\"/ java[:version] = $1 when /^(.+Runtime Environment.*) \((build )?(.+)\)$/ java[:runtime] = { "name" => $1, "build" => $3 } when /^(.+ (Client|Server) VM) \(build (.+)\)$/ java[:hotspot] = { "name" => $1, "build" => $3 } end end languages[:java] = java if java[:version] end ohai-6.14.0/lib/ohai/plugins/hpux/0000755000175000017500000000000011761755160016172 5ustar tfheentfheenohai-6.14.0/lib/ohai/plugins/hpux/filesystem.rb0000644000175000017500000000131611761755160020704 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::filesystem" ohai-6.14.0/lib/ohai/plugins/hpux/cpu.rb0000644000175000017500000000130711761755160017307 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::cpu" ohai-6.14.0/lib/ohai/plugins/hpux/memory.rb0000644000175000017500000000131211761755160020024 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::memory" ohai-6.14.0/lib/ohai/plugins/hpux/ps.rb0000644000175000017500000000136211761755160017143 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "command/ps" require_plugin 'command' command[:ps] = 'ps -ef' ohai-6.14.0/lib/ohai/plugins/hpux/network.rb0000644000175000017500000000131311761755160020206 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::network" ohai-6.14.0/lib/ohai/plugins/hpux/hostname.rb0000644000175000017500000000131411761755160020334 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::hostname" ohai-6.14.0/lib/ohai/plugins/hpux/uptime.rb0000644000175000017500000000131211761755160020017 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::uptime" ohai-6.14.0/lib/ohai/plugins/hpux/platform.rb0000644000175000017500000000131411761755160020342 0ustar tfheentfheen# # Author:: Doug MacEachern # Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_plugin "sigar::platform" ohai-6.14.0/lib/ohai/plugins/hpux/ssh_host_key.rb0000644000175000017500000000162611761755160021226 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "keys/ssh" require_plugin "keys" keys[:ssh] = Mash.new keys[:ssh][:host_dsa_public] = IO.read("/opt/ssh/etc/ssh_host_dsa_key.pub").split[1] keys[:ssh][:host_rsa_public] = IO.read("/opt/ssh/etc/ssh_host_rsa_key.pub").split[1] ohai-6.14.0/lib/ohai/plugins/languages.rb0000644000175000017500000000132411761755160017501 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "languages" languages Mash.new ohai-6.14.0/lib/ohai/plugins/virtualization.rb0000644000175000017500000000724111761755160020623 0ustar tfheentfheen# # Author:: Benjamin Black () # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # provides "virtualization" require_plugin "#{os}::virtualization" unless virtualization.nil? || !(virtualization[:role].eql?("host")) begin require 'libvirt' require 'hpricot' emu = (virtualization[:system].eql?('kvm') ? 'qemu' : virtualization[:system]) virtualization[:libvirt_version] = Libvirt::version(emu)[0].to_s virtconn = Libvirt::open_read_only("#{emu}:///system") virtualization[:uri] = virtconn.uri virtualization[:capabilities] = Mash.new virtualization[:capabilities][:xml_desc] = (virtconn.capabilities.split("\n").collect {|line| line.strip}).join #xdoc = Hpricot virtualization[:capabilities][:xml_desc] virtualization[:nodeinfo] = Mash.new ni = virtconn.node_get_info ['cores','cpus','memory','mhz','model','nodes','sockets','threads'].each {|a| virtualization[:nodeinfo][a] = ni.send(a)} virtualization[:domains] = Mash.new virtconn.list_domains.each do |d| dv = virtconn.lookup_domain_by_id d virtualization[:domains][dv.name] = Mash.new virtualization[:domains][dv.name][:id] = d virtualization[:domains][dv.name][:xml_desc] = (dv.xml_desc.split("\n").collect {|line| line.strip}).join ['os_type','uuid'].each {|a| virtualization[:domains][dv.name][a] = dv.send(a)} ['cpu_time','max_mem','memory','nr_virt_cpu','state'].each {|a| virtualization[:domains][dv.name][a] = dv.info.send(a)} #xdoc = Hpricot virtualization[:domains][dv.name][:xml_desc] end virtualization[:networks] = Mash.new virtconn.list_networks.each do |n| nv = virtconn.lookup_network_by_name n virtualization[:networks][n] = Mash.new virtualization[:networks][n][:xml_desc] = (nv.xml_desc.split("\n").collect {|line| line.strip}).join ['bridge_name','uuid'].each {|a| virtualization[:networks][n][a] = nv.send(a)} #xdoc = Hpricot virtualization[:networks][n][:xml_desc] end virtualization[:storage] = Mash.new virtconn.list_storage_pools.each do |pool| sp = virtconn.lookup_storage_pool_by_name pool virtualization[:storage][pool] = Mash.new virtualization[:storage][pool][:xml_desc] = (sp.xml_desc.split("\n").collect {|line| line.strip}).join ['autostart','uuid'].each {|a| virtualization[:storage][pool][a] = sp.send(a)} ['allocation','available','capacity','state'].each {|a| virtualization[:storage][pool][a] = sp.info.send(a)} #xdoc = Hpricot virtualization[:storage][pool][:xml_desc] virtualization[:storage][pool][:volumes] = Mash.new sp.list_volumes.each do |v| virtualization[:storage][pool][:volumes][v] = Mash.new sv = sp.lookup_volume_by_name pool ['key','name','path'].each {|a| virtualization[:storage][pool][:volumes][v][a] = sv.send(a)} ['allocation','capacity','type'].each {|a| virtualization[:storage][pool][:volumes][v][a] = sv.info.send(a)} end end virtconn.close rescue LoadError => e Ohai::Log.debug("Can't load gem: #{e}. virtualization plugin is disabled.") end end ohai-6.14.0/lib/ohai/system.rb0000644000175000017500000001643311761755160015405 0ustar tfheentfheen# # Author:: Adam Jacob () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'ohai/mash' require 'ohai/log' require 'ohai/mixin/from_file' require 'ohai/mixin/command' require 'ohai/mixin/string' require 'yajl' module Ohai class System attr_accessor :data, :seen_plugins, :hints include Ohai::Mixin::FromFile include Ohai::Mixin::Command def initialize @data = Mash.new @seen_plugins = Hash.new @providers = Mash.new @plugin_path = "" @hints = Hash.new end def [](key) @data[key] end def []=(key, value) @data[key] = value end def each(&block) @data.each do |key, value| block.call(key, value) end end def attribute?(name) @data.has_key?(name) end def set(name, *value) set_attribute(name, *value) end def from(cmd) status, stdout, stderr = run_command(:command => cmd) return "" if stdout.nil? || stdout.empty? stdout.strip end def provides(*paths) paths.each do |path| parts = path.split('/') h = @providers unless parts.length == 0 parts.shift if parts[0].length == 0 parts.each do |part| h[part] ||= Mash.new h = h[part] end end h[:_providers] ||= [] h[:_providers] << @plugin_path end end # Set the value equal to the stdout of the command, plus run through a regex - the first piece of match data is the value. def from_with_regex(cmd, *regex_list) regex_list.flatten.each do |regex| status, stdout, stderr = run_command(:command => cmd) return "" if stdout.nil? || stdout.empty? stdout.chomp!.strip md = stdout.match(regex) return md[1] end end def set_attribute(name, *values) @data[name] = Array18(*values) @data[name] end def get_attribute(name) @data[name] end def hint?(name) @json_parser ||= Yajl::Parser.new return @hints[name] if @hints[name] Ohai::Config[:hints_path].each do |path| filename = File.join(path, "#{name}.json") if File.exist?(filename) begin hash = @json_parser.parse(File.read(filename)) @hints[name] = hash || Hash.new # hint should exist because the file did, even if it didn't contain anything rescue Yajl::ParseError => e Ohai::Log.error("Could not parse hint file at #{filename}: #{e.message}") end end end @hints[name] end def all_plugins require_plugin('os') Ohai::Config[:plugin_path].each do |path| [ Dir[File.join(path, '*')], Dir[File.join(path, @data[:os], '**', '*')] ].flatten.each do |file| file_regex = Regexp.new("#{path}#{File::SEPARATOR}(.+).rb$") md = file_regex.match(file) if md plugin_name = md[1].gsub(File::SEPARATOR, "::") require_plugin(plugin_name) unless @seen_plugins.has_key?(plugin_name) end end end unless RUBY_PLATFORM =~ /mswin|mingw32|windows/ # Catch any errant children who need to be reaped begin true while Process.wait(-1, Process::WNOHANG) rescue Errno::ECHILD end end true end def collect_providers(providers) refreshments = [] if providers.is_a?(Mash) providers.keys.each do |provider| if provider.eql?("_providers") refreshments << providers[provider] else refreshments << collect_providers(providers[provider]) end end else refreshments << providers end refreshments.flatten.uniq end def refresh_plugins(path = '/') parts = path.split('/') if parts.length == 0 h = @providers else parts.shift if parts[0].length == 0 h = @providers parts.each do |part| break unless h.has_key?(part) h = h[part] end end refreshments = collect_providers(h) Ohai::Log.debug("Refreshing plugins: #{refreshments.join(", ")}") # remove the hints cache @hints = Hash.new refreshments.each do |r| @seen_plugins.delete(r) if @seen_plugins.has_key?(r) end refreshments.each do |r| require_plugin(r) unless @seen_plugins.has_key?(r) end end def require_plugin(plugin_name, force=false) unless force return true if @seen_plugins[plugin_name] end if Ohai::Config[:disabled_plugins].include?(plugin_name) Ohai::Log.debug("Skipping disabled plugin #{plugin_name}") return false end @plugin_path = plugin_name filename = "#{plugin_name.gsub("::", File::SEPARATOR)}.rb" Ohai::Config[:plugin_path].each do |path| check_path = File.expand_path(File.join(path, filename)) begin @seen_plugins[plugin_name] = true Ohai::Log.debug("Loading plugin #{plugin_name}") from_file(check_path) return true rescue Errno::ENOENT => e Ohai::Log.debug("No #{plugin_name} at #{check_path}") rescue SystemExit, Interrupt raise rescue Exception,Errno::ENOENT => e Ohai::Log.debug("Plugin #{plugin_name} threw exception #{e.inspect} #{e.backtrace.join("\n")}") end end end # Sneaky! Lets us stub out require_plugin when testing plugins, but still # call the real require_plugin to kick the whole thing off. alias :_require_plugin :require_plugin # Serialize this object as a hash def to_json Yajl::Encoder.new.encode(@data) end # Pretty Print this object as JSON def json_pretty_print(item=nil) Yajl::Encoder.new(:pretty => true).encode(item || @data) end def attributes_print(a) data = @data a.split("/").each do |part| data = data[part] end raise ArgumentError, "I cannot find an attribute named #{a}!" if data.nil? case a when Hash,Mash,Array json_pretty_print(data) when String if data.respond_to?(:lines) json_pretty_print(data.lines.to_a) else json_pretty_print(data.to_a) end else raise ArgumentError, "I can only generate JSON for Hashes, Mashes, Arrays and Strings. You fed me a #{data.class}!" end end def method_missing(name, *args) return get_attribute(name) if args.length == 0 set_attribute(name, *args) end private def Array18(*args) return nil if args.empty? return args.first if args.length == 1 return *args end end end