ohai 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +98 -0
  3. data/Rakefile +61 -0
  4. data/bin/ohai +24 -0
  5. data/lib/ohai.rb +27 -0
  6. data/lib/ohai/application.rb +113 -0
  7. data/lib/ohai/config.rb +29 -0
  8. data/lib/ohai/exception.rb +23 -0
  9. data/lib/ohai/log.rb +26 -0
  10. data/lib/ohai/mixin/command.rb +208 -0
  11. data/lib/ohai/mixin/from_file.rb +36 -0
  12. data/lib/ohai/mixin/string.rb +29 -0
  13. data/lib/ohai/plugins/command.rb +21 -0
  14. data/lib/ohai/plugins/darwin/filesystem.rb +57 -0
  15. data/lib/ohai/plugins/darwin/hostname.rb +22 -0
  16. data/lib/ohai/plugins/darwin/kernel.rb +37 -0
  17. data/lib/ohai/plugins/darwin/network.rb +187 -0
  18. data/lib/ohai/plugins/darwin/platform.rb +36 -0
  19. data/lib/ohai/plugins/darwin/ps.rb +23 -0
  20. data/lib/ohai/plugins/darwin/ssh_host_key.rb +25 -0
  21. data/lib/ohai/plugins/darwin/system_profiler.rb +33 -0
  22. data/lib/ohai/plugins/darwin/uptime.rb +32 -0
  23. data/lib/ohai/plugins/dmi.rb +59 -0
  24. data/lib/ohai/plugins/ec2.rb +100 -0
  25. data/lib/ohai/plugins/erlang.rb +40 -0
  26. data/lib/ohai/plugins/freebsd/cpu.rb +52 -0
  27. data/lib/ohai/plugins/freebsd/filesystem.rb +57 -0
  28. data/lib/ohai/plugins/freebsd/hostname.rb +22 -0
  29. data/lib/ohai/plugins/freebsd/kernel.rb +37 -0
  30. data/lib/ohai/plugins/freebsd/memory.rb +50 -0
  31. data/lib/ohai/plugins/freebsd/network.rb +112 -0
  32. data/lib/ohai/plugins/freebsd/platform.rb +23 -0
  33. data/lib/ohai/plugins/freebsd/ps.rb +24 -0
  34. data/lib/ohai/plugins/freebsd/ssh_host_key.rb +26 -0
  35. data/lib/ohai/plugins/freebsd/uptime.rb +32 -0
  36. data/lib/ohai/plugins/freebsd/virtualization.rb +66 -0
  37. data/lib/ohai/plugins/hostname.rb +27 -0
  38. data/lib/ohai/plugins/java.rb +36 -0
  39. data/lib/ohai/plugins/kernel.rb +33 -0
  40. data/lib/ohai/plugins/keys.rb +22 -0
  41. data/lib/ohai/plugins/languages.rb +21 -0
  42. data/lib/ohai/plugins/linux/block_device.rb +38 -0
  43. data/lib/ohai/plugins/linux/cpu.rb +60 -0
  44. data/lib/ohai/plugins/linux/filesystem.rb +57 -0
  45. data/lib/ohai/plugins/linux/hostname.rb +26 -0
  46. data/lib/ohai/plugins/linux/kernel.rb +33 -0
  47. data/lib/ohai/plugins/linux/lsb.rb +38 -0
  48. data/lib/ohai/plugins/linux/memory.rb +83 -0
  49. data/lib/ohai/plugins/linux/network.rb +112 -0
  50. data/lib/ohai/plugins/linux/platform.rb +43 -0
  51. data/lib/ohai/plugins/linux/ps.rb +23 -0
  52. data/lib/ohai/plugins/linux/ssh_host_key.rb +26 -0
  53. data/lib/ohai/plugins/linux/uptime.rb +28 -0
  54. data/lib/ohai/plugins/linux/virtualization.rb +77 -0
  55. data/lib/ohai/plugins/netbsd/cpu.rb +48 -0
  56. data/lib/ohai/plugins/netbsd/filesystem.rb +57 -0
  57. data/lib/ohai/plugins/netbsd/hostname.rb +22 -0
  58. data/lib/ohai/plugins/netbsd/kernel.rb +35 -0
  59. data/lib/ohai/plugins/netbsd/memory.rb +98 -0
  60. data/lib/ohai/plugins/netbsd/network.rb +111 -0
  61. data/lib/ohai/plugins/netbsd/platform.rb +22 -0
  62. data/lib/ohai/plugins/netbsd/ps.rb +24 -0
  63. data/lib/ohai/plugins/netbsd/ssh_host_key.rb +26 -0
  64. data/lib/ohai/plugins/netbsd/uptime.rb +31 -0
  65. data/lib/ohai/plugins/netbsd/virtualization.rb +65 -0
  66. data/lib/ohai/plugins/network.rb +52 -0
  67. data/lib/ohai/plugins/ohai_time.rb +21 -0
  68. data/lib/ohai/plugins/openbsd/cpu.rb +38 -0
  69. data/lib/ohai/plugins/openbsd/filesystem.rb +57 -0
  70. data/lib/ohai/plugins/openbsd/hostname.rb +22 -0
  71. data/lib/ohai/plugins/openbsd/kernel.rb +35 -0
  72. data/lib/ohai/plugins/openbsd/memory.rb +98 -0
  73. data/lib/ohai/plugins/openbsd/network.rb +111 -0
  74. data/lib/ohai/plugins/openbsd/platform.rb +23 -0
  75. data/lib/ohai/plugins/openbsd/ps.rb +24 -0
  76. data/lib/ohai/plugins/openbsd/ssh_host_key.rb +26 -0
  77. data/lib/ohai/plugins/openbsd/uptime.rb +32 -0
  78. data/lib/ohai/plugins/openbsd/virtualization.rb +66 -0
  79. data/lib/ohai/plugins/os.rb +48 -0
  80. data/lib/ohai/plugins/perl.rb +37 -0
  81. data/lib/ohai/plugins/platform.rb +25 -0
  82. data/lib/ohai/plugins/python.rb +37 -0
  83. data/lib/ohai/plugins/ruby.rb +39 -0
  84. data/lib/ohai/plugins/solaris2/cpu.rb +33 -0
  85. data/lib/ohai/plugins/solaris2/hostname.rb +25 -0
  86. data/lib/ohai/plugins/solaris2/kernel.rb +40 -0
  87. data/lib/ohai/plugins/solaris2/network.rb +141 -0
  88. data/lib/ohai/plugins/solaris2/platform.rb +33 -0
  89. data/lib/ohai/plugins/solaris2/ps.rb +23 -0
  90. data/lib/ohai/plugins/solaris2/ssh_host_key.rb +26 -0
  91. data/lib/ohai/plugins/uptime.rb +42 -0
  92. data/lib/ohai/plugins/virtualization.rb +86 -0
  93. data/lib/ohai/plugins/windows/filesystem.rb +44 -0
  94. data/lib/ohai/plugins/windows/hostname.rb +25 -0
  95. data/lib/ohai/plugins/windows/kernel.rb +75 -0
  96. data/lib/ohai/plugins/windows/network.rb +114 -0
  97. data/lib/ohai/plugins/windows/platform.rb +26 -0
  98. data/lib/ohai/system.rb +241 -0
  99. data/spec/ohai/mixin/command_spec.rb +37 -0
  100. data/spec/ohai/mixin/from_file_spec.rb +53 -0
  101. data/spec/ohai/plugins/darwin/hostname_spec.rb +34 -0
  102. data/spec/ohai/plugins/darwin/kernel_spec.rb +46 -0
  103. data/spec/ohai/plugins/darwin/platform_spec.rb +67 -0
  104. data/spec/ohai/plugins/dmi_spec.rb +73 -0
  105. data/spec/ohai/plugins/ec2_spec.rb +81 -0
  106. data/spec/ohai/plugins/erlang_spec.rb +63 -0
  107. data/spec/ohai/plugins/freebsd/hostname_spec.rb +34 -0
  108. data/spec/ohai/plugins/freebsd/kernel_spec.rb +37 -0
  109. data/spec/ohai/plugins/freebsd/platform_spec.rb +40 -0
  110. data/spec/ohai/plugins/hostname_spec.rb +39 -0
  111. data/spec/ohai/plugins/java_spec.rb +70 -0
  112. data/spec/ohai/plugins/kernel_spec.rb +43 -0
  113. data/spec/ohai/plugins/linux/cpu_spec.rb +128 -0
  114. data/spec/ohai/plugins/linux/hostname_spec.rb +52 -0
  115. data/spec/ohai/plugins/linux/kernel_spec.rb +31 -0
  116. data/spec/ohai/plugins/linux/lsb_spec.rb +60 -0
  117. data/spec/ohai/plugins/linux/platform_spec.rb +81 -0
  118. data/spec/ohai/plugins/linux/uptime_spec.rb +61 -0
  119. data/spec/ohai/plugins/linux/virtualization_spec.rb +131 -0
  120. data/spec/ohai/plugins/netbsd/hostname_spec.rb +34 -0
  121. data/spec/ohai/plugins/netbsd/kernel_spec.rb +36 -0
  122. data/spec/ohai/plugins/netbsd/platform_spec.rb +40 -0
  123. data/spec/ohai/plugins/ohai_time_spec.rb +46 -0
  124. data/spec/ohai/plugins/openbsd/hostname_spec.rb +34 -0
  125. data/spec/ohai/plugins/openbsd/kernel_spec.rb +37 -0
  126. data/spec/ohai/plugins/openbsd/platform_spec.rb +40 -0
  127. data/spec/ohai/plugins/os_spec.rb +69 -0
  128. data/spec/ohai/plugins/perl_spec.rb +89 -0
  129. data/spec/ohai/plugins/platform_spec.rb +56 -0
  130. data/spec/ohai/plugins/python_spec.rb +53 -0
  131. data/spec/ohai/plugins/ruby_spec.rb +51 -0
  132. data/spec/ohai/plugins/solaris2/hostname_spec.rb +43 -0
  133. data/spec/ohai/plugins/solaris2/kernel_spec.rb +164 -0
  134. data/spec/ohai/system_spec.rb +130 -0
  135. data/spec/ohai_spec.rb +27 -0
  136. data/spec/rcov.opts +2 -0
  137. data/spec/spec.opts +2 -0
  138. data/spec/spec_helper.rb +68 -0
  139. metadata +240 -0
@@ -0,0 +1,38 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, 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 "lsb"
20
+
21
+ lsb Mash.new
22
+
23
+ begin
24
+ File.open("/etc/lsb-release").each do |line|
25
+ case line
26
+ when /^DISTRIB_ID=(.+)$/
27
+ lsb[:id] = $1
28
+ when /^DISTRIB_RELEASE=(.+)$/
29
+ lsb[:release] = $1
30
+ when /^DISTRIB_CODENAME=(.+)$/
31
+ lsb[:codename] = $1
32
+ when /^DISTRIB_DESCRIPTION=(.+)$/
33
+ lsb[:description] = $1
34
+ end
35
+ end
36
+ rescue
37
+ Ohai::Log.debug("Skipping LSB, cannot find /etc/lsb-release")
38
+ end
@@ -0,0 +1,83 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, 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 "memory"
20
+
21
+ memory Mash.new
22
+ memory[:swap] = Mash.new
23
+
24
+ File.open("/proc/meminfo").each do |line|
25
+ case line
26
+ when /^MemTotal:\s+(\d+) (.+)$/
27
+ memory[:total] = "#{$1}#{$2}"
28
+ when /^MemFree:\s+(\d+) (.+)$/
29
+ memory[:free] = "#{$1}#{$2}"
30
+ when /^Buffers:\s+(\d+) (.+)$/
31
+ memory[:buffers] = "#{$1}#{$2}"
32
+ when /^Cached:\s+(\d+) (.+)$/
33
+ memory[:cached] = "#{$1}#{$2}"
34
+ when /^Active:\s+(\d+) (.+)$/
35
+ memory[:active] = "#{$1}#{$2}"
36
+ when /^Inactive:\s+(\d+) (.+)$/
37
+ memory[:inactive] = "#{$1}#{$2}"
38
+ when /^HighTotal:\s+(\d+) (.+)$/
39
+ memory[:high_total] = "#{$1}#{$2}"
40
+ when /^HighFree:\s+(\d+) (.+)$/
41
+ memory[:high_free] = "#{$1}#{$2}"
42
+ when /^LowTotal:\s+(\d+) (.+)$/
43
+ memory[:low_total] = "#{$1}#{$2}"
44
+ when /^LowFree:\s+(\d+) (.+)$/
45
+ memory[:low_free] = "#{$1}#{$2}"
46
+ when /^Dirty:\s+(\d+) (.+)$/
47
+ memory[:dirty] = "#{$1}#{$2}"
48
+ when /^Writeback:\s+(\d+) (.+)$/
49
+ memory[:writeback] = "#{$1}#{$2}"
50
+ when /^AnonPages:\s+(\d+) (.+)$/
51
+ memory[:anon_pages] = "#{$1}#{$2}"
52
+ when /^Mapped:\s+(\d+) (.+)$/
53
+ memory[:mapped] = "#{$1}#{$2}"
54
+ when /^Slab:\s+(\d+) (.+)$/
55
+ memory[:slab] = "#{$1}#{$2}"
56
+ when /^SReclaimable:\s+(\d+) (.+)$/
57
+ memory[:slab_reclaimable] = "#{$1}#{$2}"
58
+ when /^SUnreclaim:\s+(\d+) (.+)$/
59
+ memory[:slab_unreclaim] = "#{$1}#{$2}"
60
+ when /^PageTables:\s+(\d+) (.+)$/
61
+ memory[:page_tables] = "#{$1}#{$2}"
62
+ when /^NFS_Unstable:\s+(\d+) (.+)$/
63
+ memory[:nfs_unstable] = "#{$1}#{$2}"
64
+ when /^Bounce:\s+(\d+) (.+)$/
65
+ memory[:bounce] = "#{$1}#{$2}"
66
+ when /^CommitLimit:\s+(\d+) (.+)$/
67
+ memory[:commit_limit] = "#{$1}#{$2}"
68
+ when /^Committed_AS:\s+(\d+) (.+)$/
69
+ memory[:committed_as] = "#{$1}#{$2}"
70
+ when /^VmallocTotal:\s+(\d+) (.+)$/
71
+ memory[:vmalloc_total] = "#{$1}#{$2}"
72
+ when /^VmallocUsed:\s+(\d+) (.+)$/
73
+ memory[:vmalloc_used] = "#{$1}#{$2}"
74
+ when /^VmallocChunk:\s+(\d+) (.+)$/
75
+ memory[:vmalloc_chunk] = "#{$1}#{$2}"
76
+ when /^SwapCached:\s+(\d+) (.+)$/
77
+ memory[:swap][:cached] = "#{$1}#{$2}"
78
+ when /^SwapTotal:\s+(\d+) (.+)$/
79
+ memory[:swap][:total] = "#{$1}#{$2}"
80
+ when /^SwapFree:\s+(\d+) (.+)$/
81
+ memory[:swap][:free] = "#{$1}#{$2}"
82
+ end
83
+ end
@@ -0,0 +1,112 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, 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 "network", "counters/network"
20
+
21
+ network[:default_interface] = from("route -n \| grep ^0.0.0.0 \| awk \'{print \$8\}\'")
22
+
23
+ def encaps_lookup(encap)
24
+ return "Loopback" if encap.eql?("Local Loopback")
25
+ return "PPP" if encap.eql?("Point-to-Point Protocol")
26
+ return "SLIP" if encap.eql?("Serial Line IP")
27
+ return "VJSLIP" if encap.eql?("VJ Serial Line IP")
28
+ return "IPIP" if encap.eql?("IPIP Tunnel")
29
+ return "6to4" if encap.eql?("IPv6-in-IPv4")
30
+ encap
31
+ end
32
+
33
+ iface = Mash.new
34
+ net_counters = Mash.new
35
+ popen4("ifconfig -a") do |pid, stdin, stdout, stderr|
36
+ stdin.close
37
+ cint = nil
38
+ stdout.each do |line|
39
+ tmp_addr = nil
40
+ if line =~ /^([0-9a-zA-Z\.\:\-]+)\s+/
41
+ cint = $1
42
+ iface[cint] = Mash.new
43
+ if cint =~ /^(\w+)(\d+.*)/
44
+ iface[cint][:type] = $1
45
+ iface[cint][:number] = $2
46
+ end
47
+ end
48
+ if line =~ /Link encap:(Local Loopback)/ || line =~ /Link encap:(.+?)\s/
49
+ iface[cint][:encapsulation] = encaps_lookup($1)
50
+ end
51
+ if line =~ /HWaddr (.+?)\s/
52
+ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
53
+ iface[cint][:addresses][$1] = { "family" => "lladdr" }
54
+ end
55
+ if line =~ /inet addr:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
56
+ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
57
+ iface[cint][:addresses][$1] = { "family" => "inet" }
58
+ tmp_addr = $1
59
+ end
60
+ if line =~ /inet6 addr: ([a-f0-9\:]+)\/(\d+) Scope:(\w+)/
61
+ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
62
+ iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("Host") ? "Node" : $3) }
63
+ end
64
+ if line =~ /Bcast:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
65
+ iface[cint][:addresses][tmp_addr]["broadcast"] = $1
66
+ end
67
+ if line =~ /Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
68
+ iface[cint][:addresses][tmp_addr]["netmask"] = $1
69
+ end
70
+ flags = line.scan(/(UP|BROADCAST|DEBUG|LOOPBACK|POINTTOPOINT|NOTRAILERS|RUNNING|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC)\s/)
71
+ if flags.length > 1
72
+ iface[cint][:flags] = flags.flatten
73
+ end
74
+ if line =~ /MTU:(\d+)/
75
+ iface[cint][:mtu] = $1
76
+ end
77
+ if line =~ /RX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) frame:(\d+)/
78
+ net_counters[cint] = Mash.new unless net_counters[cint]
79
+ net_counters[cint][:rx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "frame" => $5 }
80
+ end
81
+ if line =~ /TX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) carrier:(\d+)/
82
+ net_counters[cint][:tx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "carrier" => $5 }
83
+ end
84
+ if line =~ /collisions:(\d+)/
85
+ net_counters[cint][:tx]["collisions"] = $1
86
+ end
87
+ if line =~ /txqueuelen:(\d+)/
88
+ net_counters[cint][:tx]["queuelen"] = $1
89
+ end
90
+ if line =~ /RX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
91
+ net_counters[cint][:rx]["bytes"] = $1
92
+ end
93
+ if line =~ /TX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
94
+ net_counters[cint][:tx]["bytes"] = $1
95
+ end
96
+ end
97
+ end
98
+
99
+ popen4("arp -an") do |pid, stdin, stdout, stderr|
100
+ stdin.close
101
+ stdout.each do |line|
102
+ 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\.\:\-]+)/
103
+ next unless iface[$4] # this should never happen
104
+ iface[$4][:arp] = Mash.new unless iface[$4][:arp]
105
+ iface[$4][:arp][$1] = $2.downcase
106
+ end
107
+ end
108
+ end
109
+
110
+ counters[:network][:interfaces] = net_counters
111
+
112
+ network["interfaces"] = iface
@@ -0,0 +1,43 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, 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 "platform", "platform_version"
20
+
21
+ require_plugin 'linux::lsb'
22
+
23
+ if lsb[:id]
24
+ platform lsb[:id].downcase
25
+ platform_version lsb[:release]
26
+ elsif File.exists?("/etc/debian_version")
27
+ platform "debian"
28
+ platform_version File.read("/etc/debian_version").chomp
29
+ elsif File.exists?("/etc/redhat-release")
30
+ platform "redhat"
31
+ File.open("/etc/redhat-release").each do |line|
32
+ platform "centos" if line =~ /centos/i
33
+ case line
34
+ when /\(Rawhide\)/
35
+ platform_version "rawhide"
36
+ when /release ([\d\.]+)/
37
+ platform_version $1
38
+ end
39
+ end
40
+ elsif File.exists?('/etc/gentoo-release')
41
+ platform "gentoo"
42
+ platform_version IO.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join
43
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, 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 "command/ps"
20
+
21
+ require_plugin 'command'
22
+
23
+ command[:ps] = 'ps -ef'
@@ -0,0 +1,26 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, 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 "keys/ssh"
20
+
21
+ require_plugin "keys"
22
+
23
+ keys[:ssh] = Mash.new
24
+
25
+ keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1]
26
+ keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1]
@@ -0,0 +1,28 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, 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 "uptime", "idletime", "uptime_seconds", "idletime_seconds"
20
+
21
+ uptime, idletime = File.open("/proc/uptime").gets.split(" ")
22
+ uptime_seconds uptime.to_i
23
+ uptime self._seconds_to_human(uptime.to_i)
24
+ idletime_seconds idletime.to_i
25
+ idletime self._seconds_to_human(idletime.to_i)
26
+
27
+
28
+
@@ -0,0 +1,77 @@
1
+ #
2
+ # Author:: Thom May (<thom@clearairturbulence.org>)
3
+ # Copyright:: Copyright (c) 2009 Opscode, 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 "virtualization"
20
+
21
+ virtualization Mash.new
22
+
23
+ # if it is possible to detect paravirt vs hardware virt, it should be put in
24
+ # virtualization[:mechanism]
25
+ if File.exists?("/proc/xen/capabilities") && File.read("/proc/xen/capabilities") =~ /control_d/i
26
+ virtualization[:emulator] = "xen"
27
+ virtualization[:role] = "host"
28
+ elsif File.exists?("/proc/sys/xen/independent_wallclock")
29
+ virtualization[:emulator] = "xen"
30
+ virtualization[:role] = "guest"
31
+ end
32
+
33
+ # Detect KVM hosts by kernel module
34
+ if File.exists?("/proc/modules")
35
+ if File.read("/proc/modules") =~ /^kvm/
36
+ virtualization[:emulator] = "kvm"
37
+ virtualization[:role] = "host"
38
+ end
39
+ end
40
+
41
+ # Detect KVM/QEMU from cpuinfo, report as KVM
42
+ # We could pick KVM from 'Booting paravirtualized kernel on KVM' in dmesg
43
+ # 2.6.27-9-server (intrepid) has this / 2.6.18-6-amd64 (etch) does not
44
+ # It would be great if we could read pv_info in the kernel
45
+ # Wait for reply to: http://article.gmane.org/gmane.comp.emulators.kvm.devel/27885
46
+ if File.exists?("/proc/cpuinfo")
47
+ if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU/
48
+ virtualization[:emulator] = "kvm"
49
+ virtualization[:role] = "guest"
50
+ end
51
+ end
52
+
53
+ # http://www.dmo.ca/blog/detecting-virtualization-on-linux
54
+ if File.exists?("/usr/sbin/dmidecode")
55
+ popen4("dmidecode") do |pid, stdin, stdout, stderr|
56
+ stdin.close
57
+ found_virt_manufacturer = nil
58
+ stdout.each do |line|
59
+ case line
60
+ when /Manufacturer: Microsoft/
61
+ found_virt_manufacturer = "virtualpc"
62
+ when / Product Name: Virtual Machine/
63
+ if found_virt_manufacturer == "virtualpc"
64
+ virtualization[:emulator] = "virtualpc"
65
+ virtualization[:role] = "guest"
66
+ end
67
+ when /Manufacturer: VMware/
68
+ found_virt_manufacturer = "vmware"
69
+ when /Product Name: VMware Virtual Platform/
70
+ if found_virt_manufacturer == "vmware"
71
+ virtualization[:emulator] = "vmware"
72
+ virtualization[:role] = "guest"
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # Author:: Mathieu Sauve-Frankel <msf@kisoku.net>
3
+ # Copyright:: Copyright (c) 2009 Mathieu Sauve-Frankel
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 'cpu'
20
+
21
+ cpuinfo = Mash.new
22
+
23
+ # NetBSD provides some cpu information via sysctl, and a little via dmesg.boot
24
+ # unlike OpenBSD and FreeBSD, NetBSD does not provide information about the
25
+ # available instruction set
26
+ # cpu0 at mainbus0 apid 0: Intel 686-class, 2134MHz, id 0x6f6
27
+
28
+ File.open("/var/run/dmesg.boot").each do |line|
29
+ case line
30
+ when /cpu[\d\w\s]+:\s([\w\s\-]+),\s+(\w+),/
31
+ cpuinfo[:model_name] = $1
32
+ cpuinfo[:mhz] = $2.gsub(/mhz/i, "")
33
+ end
34
+ end
35
+
36
+ flags = []
37
+ popen4("dmidecode") do |pid, stdin, stdout, stderr|
38
+ stdin.close
39
+ stdout.each do |line|
40
+ if line =~ /^\s+([A-Z\d-]+)\s+\([\w\s-]+\)$/
41
+ flags << $1.downcase
42
+ end
43
+ end
44
+ end
45
+
46
+ cpuinfo[:flags] = flags unless flags.empty?
47
+
48
+ cpu cpuinfo