ohai 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/Rakefile +3 -3
  2. data/bin/ohai +14 -4
  3. data/docs/man/man1/ohai.1 +23 -0
  4. data/lib/ohai.rb +1 -1
  5. data/lib/ohai/application.rb +8 -0
  6. data/lib/ohai/plugins/chef.rb +23 -0
  7. data/lib/ohai/plugins/groovy.rb +35 -0
  8. data/lib/ohai/plugins/java.rb +6 -3
  9. data/lib/ohai/plugins/kernel.rb +1 -1
  10. data/lib/ohai/plugins/linux/network.rb +1 -1
  11. data/lib/ohai/plugins/linux/platform.rb +1 -1
  12. data/lib/ohai/plugins/lua.rb +34 -0
  13. data/lib/ohai/plugins/mono.rb +37 -0
  14. data/lib/ohai/plugins/network_listeners.rb +47 -0
  15. data/lib/ohai/plugins/ohai.rb +23 -0
  16. data/lib/ohai/plugins/os.rb +5 -4
  17. data/lib/ohai/plugins/perl.rb +5 -3
  18. data/lib/ohai/plugins/php.rb +36 -0
  19. data/lib/ohai/plugins/rackspace.rb +14 -4
  20. data/lib/ohai/plugins/windows/filesystem.rb +0 -0
  21. data/lib/ohai/system.rb +14 -9
  22. data/spec/ohai/mixin/command_spec.rb +1 -1
  23. data/spec/ohai/mixin/from_file_spec.rb +1 -1
  24. data/spec/ohai/plugins/chef_spec.rb +38 -0
  25. data/spec/ohai/plugins/cloud_spec.rb +3 -1
  26. data/spec/ohai/plugins/darwin/hostname_spec.rb +1 -1
  27. data/spec/ohai/plugins/darwin/kernel_spec.rb +1 -1
  28. data/spec/ohai/plugins/darwin/platform_spec.rb +1 -1
  29. data/spec/ohai/plugins/dmi_spec.rb +1 -1
  30. data/spec/ohai/plugins/ec2_spec.rb +1 -1
  31. data/spec/ohai/plugins/erlang_spec.rb +1 -1
  32. data/spec/ohai/plugins/freebsd/hostname_spec.rb +1 -1
  33. data/spec/ohai/plugins/freebsd/kernel_spec.rb +1 -1
  34. data/spec/ohai/plugins/freebsd/platform_spec.rb +1 -1
  35. data/spec/ohai/plugins/groovy_spec.rb +53 -0
  36. data/spec/ohai/plugins/hostname_spec.rb +1 -1
  37. data/spec/ohai/plugins/java_spec.rb +1 -1
  38. data/spec/ohai/plugins/kernel_spec.rb +1 -1
  39. data/spec/ohai/plugins/linux/cpu_spec.rb +1 -1
  40. data/spec/ohai/plugins/linux/hostname_spec.rb +1 -1
  41. data/spec/ohai/plugins/linux/kernel_spec.rb +1 -1
  42. data/spec/ohai/plugins/linux/lsb_spec.rb +1 -1
  43. data/spec/ohai/plugins/linux/platform_spec.rb +32 -1
  44. data/spec/ohai/plugins/linux/uptime_spec.rb +1 -1
  45. data/spec/ohai/plugins/linux/virtualization_spec.rb +1 -1
  46. data/spec/ohai/plugins/lua_spec.rb +53 -0
  47. data/spec/ohai/plugins/mono_spec.rb +53 -0
  48. data/spec/ohai/plugins/netbsd/hostname_spec.rb +1 -1
  49. data/spec/ohai/plugins/netbsd/kernel_spec.rb +1 -1
  50. data/spec/ohai/plugins/netbsd/platform_spec.rb +1 -1
  51. data/spec/ohai/plugins/ohai_spec.rb +33 -0
  52. data/spec/ohai/plugins/ohai_time_spec.rb +1 -1
  53. data/spec/ohai/plugins/openbsd/hostname_spec.rb +1 -1
  54. data/spec/ohai/plugins/openbsd/kernel_spec.rb +1 -1
  55. data/spec/ohai/plugins/openbsd/platform_spec.rb +1 -1
  56. data/spec/ohai/plugins/os_spec.rb +9 -3
  57. data/spec/ohai/plugins/passwd_spec.rb +1 -1
  58. data/spec/ohai/plugins/perl_spec.rb +3 -3
  59. data/spec/ohai/plugins/php_spec.rb +52 -0
  60. data/spec/ohai/plugins/platform_spec.rb +1 -1
  61. data/spec/ohai/plugins/python_spec.rb +1 -1
  62. data/spec/ohai/plugins/rackspace_spec.rb +1 -1
  63. data/spec/ohai/plugins/ruby_spec.rb +1 -1
  64. data/spec/ohai/plugins/solaris2/hostname_spec.rb +1 -1
  65. data/spec/ohai/plugins/solaris2/kernel_spec.rb +1 -1
  66. data/spec/ohai/plugins/solaris2/network_spec.rb +1 -1
  67. data/spec/ohai/system_spec.rb +1 -1
  68. data/spec/ohai_spec.rb +1 -1
  69. data/spec/spec_helper.rb +0 -5
  70. metadata +32 -7
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'date'
5
5
  require 'spec/rake/spectask'
6
6
 
7
7
  GEM = "ohai"
8
- GEM_VERSION = "0.5.0"
8
+ GEM_VERSION = "0.5.2"
9
9
  AUTHOR = "Adam Jacob"
10
10
  EMAIL = "adam@opscode.com"
11
11
  HOMEPAGE = "http://wiki.opscode.com/display/ohai"
@@ -22,7 +22,7 @@ spec = Gem::Specification.new do |s|
22
22
  s.email = EMAIL
23
23
  s.homepage = HOMEPAGE
24
24
 
25
- s.add_dependency "json"
25
+ s.add_dependency "json", "<= 1.4.2"
26
26
  s.add_dependency "extlib"
27
27
  s.add_dependency "systemu"
28
28
  s.add_dependency "mixlib-cli"
@@ -33,7 +33,7 @@ spec = Gem::Specification.new do |s|
33
33
 
34
34
  s.require_path = 'lib'
35
35
  s.autorequire = GEM
36
- s.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{extras,lib,spec}/**/*")
36
+ s.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{docs,lib,spec}/**/*")
37
37
  end
38
38
 
39
39
  task :default => :spec
data/bin/ohai CHANGED
@@ -9,9 +9,9 @@
9
9
  # Licensed under the Apache License, Version 2.0 (the "License");
10
10
  # you may not use this file except in compliance with the License.
11
11
  # You may obtain a copy of the License at
12
- #
12
+ #
13
13
  # http://www.apache.org/licenses/LICENSE-2.0
14
- #
14
+ #
15
15
  # Unless required by applicable law or agreed to in writing, software
16
16
  # distributed under the License is distributed on an "AS IS" BASIS,
17
17
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,16 +25,26 @@ $: << File.join(File.dirname(__FILE__), "..", "lib")
25
25
  begin
26
26
  require 'rubygems'
27
27
  rescue LoadError
28
- # must be debian! ;)
28
+ # must be debian! ;)
29
29
  missing_rubygems = true
30
30
  end
31
31
  begin
32
32
  require 'ohai/application'
33
33
  rescue LoadError
34
- if missing_rubygems
34
+ if missing_rubygems
35
35
  STDERR.puts "rubygems previously failed to load - is it installed?"
36
36
  end
37
37
 
38
38
  raise
39
39
  end
40
+
41
+ if RUBY_PLATFORM =~ /mswin|mingw32|windows/
42
+ begin
43
+ require 'ruby-wmi'
44
+ rescue LoadError
45
+ STDERR.puts "ruby-wmi failed to load - is it installed?"
46
+ raise
47
+ end
48
+ end
49
+
40
50
  Ohai::Application.new.run
@@ -0,0 +1,23 @@
1
+ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36.
2
+ .TH OHAI "1" "April 2009" "ohai" "User Commands"
3
+ .SH NAME
4
+ ohai \- collect system information
5
+ .SH SYNOPSIS
6
+ .B ohai
7
+ [\fIOPTION\fR]...
8
+ .SH DESCRIPTION
9
+ Information about your system is collected and returned as multidimensional
10
+ attributes in a JSON format.
11
+ .TP
12
+ \fB\-d\fR, \fB\-\-directory\fR NAME
13
+ A directory to add to the Ohai search path
14
+ .TP
15
+ \fB\-f\fR, \fB\-\-file\fR NAME
16
+ A file to run Ohai against
17
+ .TP
18
+ \fB\-l\fR, \fB\-\-loglevel\fR NAME
19
+ Set log level for Ohai
20
+ .TP
21
+ \fB\-h\fR, \fB\-\-help\fR
22
+ Show this message
23
+ .IP
@@ -23,5 +23,5 @@ require 'ohai/config'
23
23
  require 'ohai/system'
24
24
 
25
25
  module Ohai
26
- VERSION = '0.5.0'
26
+ VERSION = '0.5.2'
27
27
  end
@@ -61,6 +61,14 @@ class Ohai::Application
61
61
  :proc => lambda {|v| puts "Ohai: #{::Ohai::VERSION}"},
62
62
  :exit => 0
63
63
 
64
+ def initialize
65
+ super
66
+
67
+ # Always switch to a readable directory. Keeps subsequent Dir.chdir() {}
68
+ # from failing due to permissions when launched as a less privileged user.
69
+ Dir.chdir("/")
70
+ end
71
+
64
72
  def run
65
73
  configure_ohai
66
74
  configure_logging
@@ -0,0 +1,23 @@
1
+ #
2
+ # Author:: Tollef Fog Heen <tfheen@err.no>
3
+ # Copyright:: Copyright (c) 2010 Tollef Fog Heen
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef'
20
+ provides "chef"
21
+
22
+ chef Mash.new
23
+ chef[:version] = Chef::VERSION
@@ -0,0 +1,35 @@
1
+ #
2
+ # Author:: Doug MacEachern <dougm@vmware.com>
3
+ # Copyright:: Copyright (c) 2009 VMware, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ provides "languages/groovy"
20
+
21
+ require_plugin "languages"
22
+
23
+ output = nil
24
+
25
+ groovy = Mash.new
26
+
27
+ status, stdout, stderr = run_command(:no_status_check => true, :command => "groovy -v")
28
+ if status == 0
29
+ output = stdout.split
30
+ if output.length >= 2
31
+ groovy[:version] = output[2]
32
+ end
33
+ languages[:groovy] = groovy if groovy[:version]
34
+ end
35
+
@@ -26,9 +26,12 @@ status, stdout, stderr = run_command(:no_status_check => true, :command => "java
26
26
  if status == 0
27
27
  stderr.split("\n").each do |line|
28
28
  case line
29
- when /java version \"([0-9\.\_]+)\"/: java[:version] = $1
30
- when /^(.+Runtime Environment.*) \(build (.+)\)$/: java[:runtime] = { "name" => $1, "build" => $2 }
31
- when /^(.+ Client VM) \(build (.+)\)$/: java[:hotspot] = { "name" => $1, "build" => $2 }
29
+ when /java version \"([0-9\.\_]+)\"/
30
+ java[:version] = $1
31
+ when /^(.+Runtime Environment.*) \(build (.+)\)$/
32
+ java[:runtime] = { "name" => $1, "build" => $2 }
33
+ when /^(.+ Client VM) \(build (.+)\)$/
34
+ java[:hotspot] = { "name" => $1, "build" => $2 }
32
35
  end
33
36
  end
34
37
 
@@ -22,7 +22,7 @@ require_plugin 'ruby'
22
22
 
23
23
  kernel Mash.new
24
24
  case languages[:ruby][:host_os]
25
- when /mswin/
25
+ when /mswin|mingw32|windows/
26
26
  require_plugin "windows::kernel"
27
27
  else
28
28
  kernel[:name] = from("uname -s")
@@ -18,7 +18,7 @@
18
18
 
19
19
  provides "network", "counters/network"
20
20
 
21
- network[:default_interface] = from("route -n \| grep ^0.0.0.0 \| awk \'{print \$8\}\'")
21
+ network[:default_interface] = from("route -n \| grep -m 1 ^0.0.0.0 \| awk \'{print \$8\}\'")
22
22
 
23
23
  def encaps_lookup(encap)
24
24
  return "Loopback" if encap.eql?("Local Loopback")
@@ -42,7 +42,7 @@ elsif File.exists?('/etc/gentoo-release')
42
42
  platform_version IO.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join
43
43
  elsif File.exists?('/etc/SuSE-release')
44
44
  platform "suse"
45
- platform_version IO.read('/etc/SuSE-release').scan(/\d+\.\d+/)[0]
45
+ platform_version File.read("/etc/SuSE-release").scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
46
46
  elsif File.exists?('/etc/arch-release')
47
47
  platform "arch"
48
48
  # no way to determine platform_version in a rolling release distribution
@@ -0,0 +1,34 @@
1
+ #
2
+ # Author:: Doug MacEachern <dougm@vmware.com>
3
+ # Copyright:: Copyright (c) 2009 VMware, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ provides "languages/lua"
20
+
21
+ require_plugin "languages"
22
+
23
+ output = nil
24
+
25
+ lua = Mash.new
26
+
27
+ status, stdout, stderr = run_command(:no_status_check => true, :command => "lua -v")
28
+ if status == 0
29
+ output = stderr.split
30
+ if output.length >= 1
31
+ lua[:version] = output[1]
32
+ end
33
+ languages[:lua] = lua if lua[:version]
34
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Doug MacEachern <dougm@vmware.com>
3
+ # Copyright:: Copyright (c) 2009 VMware, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ provides "languages/mono"
20
+
21
+ require_plugin "languages"
22
+
23
+ output = nil
24
+
25
+ mono = Mash.new
26
+
27
+ status, stdout, stderr = run_command(:no_status_check => true, :command => "mono -V")
28
+ if status == 0
29
+ output = stdout.split
30
+ if output.length >= 4
31
+ mono[:version] = output[4]
32
+ end
33
+ if output.length >= 11
34
+ mono[:builddate] = "%s %s %s %s" % [output[6],output[7],output[8],output[11].gsub!(/\)/,'')]
35
+ end
36
+ languages[:mono] = mono if mono[:version]
37
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ # Author:: Doug MacEachern <dougm@vmware.com>
3
+ # Copyright:: Copyright (c) 2009 VMware, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'sigar'
20
+
21
+ provides "network/listeners"
22
+
23
+ require_plugin "network"
24
+
25
+ flags = Sigar::NETCONN_TCP|Sigar::NETCONN_SERVER
26
+
27
+ listeners = Mash.new
28
+
29
+ sigar = Sigar.new
30
+ sigar.net_connection_list(flags).each do |conn|
31
+ port = conn.local_port
32
+ addr = conn.local_address.to_s
33
+ if addr == "0.0.0.0" || addr == "::"
34
+ addr = "*"
35
+ end
36
+ listeners[port] = Mash.new
37
+ listeners[port][:address] = addr
38
+ begin
39
+ pid = sigar.proc_port(conn.type, port)
40
+ listeners[port][:pid] = pid
41
+ listeners[port][:name] = sigar.proc_state(pid).name
42
+ rescue
43
+ end
44
+ end
45
+
46
+ network[:listeners] = Mash.new
47
+ network[:listeners][:tcp] = listeners
@@ -0,0 +1,23 @@
1
+ #
2
+ # Author:: Tollef Fog Heen <tfheen@err.no>
3
+ # Copyright:: Copyright (c) 2010 Tollef Fog Heen
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "ohai"
20
+ provides "ohai"
21
+
22
+ ohai Mash.new
23
+ ohai[:version] = Ohai::VERSION
@@ -18,10 +18,11 @@
18
18
 
19
19
  provides "os", "os_version"
20
20
 
21
- require_plugin 'ruby'
21
+ require 'rbconfig'
22
+
22
23
  require_plugin 'kernel'
23
24
 
24
- case languages[:ruby][:host_os]
25
+ case ::Config::CONFIG['host_os']
25
26
  when /darwin(.+)$/
26
27
  os "darwin"
27
28
  when /linux/
@@ -34,7 +35,7 @@ when /netbsd(.+)$/
34
35
  os "netbsd"
35
36
  when /solaris2\.([\d]+)/
36
37
  os "solaris2"
37
- when /mswin/
38
+ when /mswin|mingw32|windows/
38
39
  # After long discussion in IRC the "powers that be" have come to a concensus
39
40
  # that there is no other Windows platforms exist that were not based on the
40
41
  # Windows_NT kernel, so we herby decree that "windows" will refer to all
@@ -42,7 +43,7 @@ when /mswin/
42
43
  # subsystems.
43
44
  os "windows"
44
45
  else
45
- os languages[:ruby][:host_os]
46
+ os ::Config::CONFIG['host_os']
46
47
  end
47
48
 
48
49
  os_version kernel[:release]
@@ -24,10 +24,12 @@ output = nil
24
24
  perl = Mash.new
25
25
  status = popen4("perl -V:version -V:archname") do |pid, stdin, stdout, stderr|
26
26
  stdin.close
27
- stdout.each do |line|
27
+ stdout.each_line do |line|
28
28
  case line
29
- when /^version=\'(.+)\';$/: perl[:version] = $1
30
- when /^archname=\'(.+)\';$/: perl[:archname] = $1
29
+ when /^version=\'(.+)\';$/
30
+ perl[:version] = $1
31
+ when /^archname=\'(.+)\';$/
32
+ perl[:archname] = $1
31
33
  end
32
34
  end
33
35
  end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Author:: Doug MacEachern <dougm@vmware.com>
3
+ # Copyright:: Copyright (c) 2009 VMware, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ provides "languages/php"
20
+
21
+ require_plugin "languages"
22
+
23
+ output = nil
24
+
25
+ php = Mash.new
26
+
27
+ status, stdout, stderr = run_command(:no_status_check => true, :command => "php -v")
28
+ if status == 0
29
+ output = stdout.split
30
+ if output.length >= 6
31
+ php[:version] = output[1]
32
+ php[:builddate] = "%s %s %s" % [output[4],output[5],output[6]]
33
+ end
34
+ languages[:php] = php if php[:version]
35
+ end
36
+