ohai 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.rdoc +98 -0
- data/Rakefile +61 -0
- data/bin/ohai +24 -0
- data/lib/ohai.rb +27 -0
- data/lib/ohai/application.rb +113 -0
- data/lib/ohai/config.rb +29 -0
- data/lib/ohai/exception.rb +23 -0
- data/lib/ohai/log.rb +26 -0
- data/lib/ohai/mixin/command.rb +208 -0
- data/lib/ohai/mixin/from_file.rb +36 -0
- data/lib/ohai/mixin/string.rb +29 -0
- data/lib/ohai/plugins/command.rb +21 -0
- data/lib/ohai/plugins/darwin/filesystem.rb +57 -0
- data/lib/ohai/plugins/darwin/hostname.rb +22 -0
- data/lib/ohai/plugins/darwin/kernel.rb +37 -0
- data/lib/ohai/plugins/darwin/network.rb +187 -0
- data/lib/ohai/plugins/darwin/platform.rb +36 -0
- data/lib/ohai/plugins/darwin/ps.rb +23 -0
- data/lib/ohai/plugins/darwin/ssh_host_key.rb +25 -0
- data/lib/ohai/plugins/darwin/system_profiler.rb +33 -0
- data/lib/ohai/plugins/darwin/uptime.rb +32 -0
- data/lib/ohai/plugins/dmi.rb +59 -0
- data/lib/ohai/plugins/ec2.rb +100 -0
- data/lib/ohai/plugins/erlang.rb +40 -0
- data/lib/ohai/plugins/freebsd/cpu.rb +52 -0
- data/lib/ohai/plugins/freebsd/filesystem.rb +57 -0
- data/lib/ohai/plugins/freebsd/hostname.rb +22 -0
- data/lib/ohai/plugins/freebsd/kernel.rb +37 -0
- data/lib/ohai/plugins/freebsd/memory.rb +50 -0
- data/lib/ohai/plugins/freebsd/network.rb +112 -0
- data/lib/ohai/plugins/freebsd/platform.rb +23 -0
- data/lib/ohai/plugins/freebsd/ps.rb +24 -0
- data/lib/ohai/plugins/freebsd/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/freebsd/uptime.rb +32 -0
- data/lib/ohai/plugins/freebsd/virtualization.rb +66 -0
- data/lib/ohai/plugins/hostname.rb +27 -0
- data/lib/ohai/plugins/java.rb +36 -0
- data/lib/ohai/plugins/kernel.rb +33 -0
- data/lib/ohai/plugins/keys.rb +22 -0
- data/lib/ohai/plugins/languages.rb +21 -0
- data/lib/ohai/plugins/linux/block_device.rb +38 -0
- data/lib/ohai/plugins/linux/cpu.rb +60 -0
- data/lib/ohai/plugins/linux/filesystem.rb +57 -0
- data/lib/ohai/plugins/linux/hostname.rb +26 -0
- data/lib/ohai/plugins/linux/kernel.rb +33 -0
- data/lib/ohai/plugins/linux/lsb.rb +38 -0
- data/lib/ohai/plugins/linux/memory.rb +83 -0
- data/lib/ohai/plugins/linux/network.rb +112 -0
- data/lib/ohai/plugins/linux/platform.rb +43 -0
- data/lib/ohai/plugins/linux/ps.rb +23 -0
- data/lib/ohai/plugins/linux/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/linux/uptime.rb +28 -0
- data/lib/ohai/plugins/linux/virtualization.rb +77 -0
- data/lib/ohai/plugins/netbsd/cpu.rb +48 -0
- data/lib/ohai/plugins/netbsd/filesystem.rb +57 -0
- data/lib/ohai/plugins/netbsd/hostname.rb +22 -0
- data/lib/ohai/plugins/netbsd/kernel.rb +35 -0
- data/lib/ohai/plugins/netbsd/memory.rb +98 -0
- data/lib/ohai/plugins/netbsd/network.rb +111 -0
- data/lib/ohai/plugins/netbsd/platform.rb +22 -0
- data/lib/ohai/plugins/netbsd/ps.rb +24 -0
- data/lib/ohai/plugins/netbsd/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/netbsd/uptime.rb +31 -0
- data/lib/ohai/plugins/netbsd/virtualization.rb +65 -0
- data/lib/ohai/plugins/network.rb +52 -0
- data/lib/ohai/plugins/ohai_time.rb +21 -0
- data/lib/ohai/plugins/openbsd/cpu.rb +38 -0
- data/lib/ohai/plugins/openbsd/filesystem.rb +57 -0
- data/lib/ohai/plugins/openbsd/hostname.rb +22 -0
- data/lib/ohai/plugins/openbsd/kernel.rb +35 -0
- data/lib/ohai/plugins/openbsd/memory.rb +98 -0
- data/lib/ohai/plugins/openbsd/network.rb +111 -0
- data/lib/ohai/plugins/openbsd/platform.rb +23 -0
- data/lib/ohai/plugins/openbsd/ps.rb +24 -0
- data/lib/ohai/plugins/openbsd/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/openbsd/uptime.rb +32 -0
- data/lib/ohai/plugins/openbsd/virtualization.rb +66 -0
- data/lib/ohai/plugins/os.rb +48 -0
- data/lib/ohai/plugins/perl.rb +37 -0
- data/lib/ohai/plugins/platform.rb +25 -0
- data/lib/ohai/plugins/python.rb +37 -0
- data/lib/ohai/plugins/ruby.rb +39 -0
- data/lib/ohai/plugins/solaris2/cpu.rb +33 -0
- data/lib/ohai/plugins/solaris2/hostname.rb +25 -0
- data/lib/ohai/plugins/solaris2/kernel.rb +40 -0
- data/lib/ohai/plugins/solaris2/network.rb +141 -0
- data/lib/ohai/plugins/solaris2/platform.rb +33 -0
- data/lib/ohai/plugins/solaris2/ps.rb +23 -0
- data/lib/ohai/plugins/solaris2/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/uptime.rb +42 -0
- data/lib/ohai/plugins/virtualization.rb +86 -0
- data/lib/ohai/plugins/windows/filesystem.rb +44 -0
- data/lib/ohai/plugins/windows/hostname.rb +25 -0
- data/lib/ohai/plugins/windows/kernel.rb +75 -0
- data/lib/ohai/plugins/windows/network.rb +114 -0
- data/lib/ohai/plugins/windows/platform.rb +26 -0
- data/lib/ohai/system.rb +241 -0
- data/spec/ohai/mixin/command_spec.rb +37 -0
- data/spec/ohai/mixin/from_file_spec.rb +53 -0
- data/spec/ohai/plugins/darwin/hostname_spec.rb +34 -0
- data/spec/ohai/plugins/darwin/kernel_spec.rb +46 -0
- data/spec/ohai/plugins/darwin/platform_spec.rb +67 -0
- data/spec/ohai/plugins/dmi_spec.rb +73 -0
- data/spec/ohai/plugins/ec2_spec.rb +81 -0
- data/spec/ohai/plugins/erlang_spec.rb +63 -0
- data/spec/ohai/plugins/freebsd/hostname_spec.rb +34 -0
- data/spec/ohai/plugins/freebsd/kernel_spec.rb +37 -0
- data/spec/ohai/plugins/freebsd/platform_spec.rb +40 -0
- data/spec/ohai/plugins/hostname_spec.rb +39 -0
- data/spec/ohai/plugins/java_spec.rb +70 -0
- data/spec/ohai/plugins/kernel_spec.rb +43 -0
- data/spec/ohai/plugins/linux/cpu_spec.rb +128 -0
- data/spec/ohai/plugins/linux/hostname_spec.rb +52 -0
- data/spec/ohai/plugins/linux/kernel_spec.rb +31 -0
- data/spec/ohai/plugins/linux/lsb_spec.rb +60 -0
- data/spec/ohai/plugins/linux/platform_spec.rb +81 -0
- data/spec/ohai/plugins/linux/uptime_spec.rb +61 -0
- data/spec/ohai/plugins/linux/virtualization_spec.rb +131 -0
- data/spec/ohai/plugins/netbsd/hostname_spec.rb +34 -0
- data/spec/ohai/plugins/netbsd/kernel_spec.rb +36 -0
- data/spec/ohai/plugins/netbsd/platform_spec.rb +40 -0
- data/spec/ohai/plugins/ohai_time_spec.rb +46 -0
- data/spec/ohai/plugins/openbsd/hostname_spec.rb +34 -0
- data/spec/ohai/plugins/openbsd/kernel_spec.rb +37 -0
- data/spec/ohai/plugins/openbsd/platform_spec.rb +40 -0
- data/spec/ohai/plugins/os_spec.rb +69 -0
- data/spec/ohai/plugins/perl_spec.rb +89 -0
- data/spec/ohai/plugins/platform_spec.rb +56 -0
- data/spec/ohai/plugins/python_spec.rb +53 -0
- data/spec/ohai/plugins/ruby_spec.rb +51 -0
- data/spec/ohai/plugins/solaris2/hostname_spec.rb +43 -0
- data/spec/ohai/plugins/solaris2/kernel_spec.rb +164 -0
- data/spec/ohai/system_spec.rb +130 -0
- data/spec/ohai_spec.rb +27 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +68 -0
- metadata +240 -0
@@ -0,0 +1,37 @@
|
|
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 "kernel"
|
20
|
+
|
21
|
+
kernel[:os] = kernel[:name]
|
22
|
+
|
23
|
+
if from("sysctl -n hw.optional.x86_64").to_i == 1
|
24
|
+
kernel[:machine] = 'x86_64'
|
25
|
+
end
|
26
|
+
|
27
|
+
kext = Mash.new
|
28
|
+
popen4("kextstat -k -l") do |pid, stdin, stdout, stderr|
|
29
|
+
stdin.close
|
30
|
+
stdout.each do |line|
|
31
|
+
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\.]+)\)/
|
32
|
+
kext[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
kernel[:modules] = kext
|
@@ -0,0 +1,187 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Benjamin Black (<bb@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
|
+
require 'scanf'
|
22
|
+
|
23
|
+
network[:default_interface] = from("route -n get default \| grep interface: \| awk \'/: / \{print \$2\}\'")
|
24
|
+
|
25
|
+
def parse_media(media_string)
|
26
|
+
media = Hash.new
|
27
|
+
line_array = media_string.split(' ')
|
28
|
+
|
29
|
+
0.upto(line_array.length - 1) do |i|
|
30
|
+
unless line_array[i].eql?("none")
|
31
|
+
|
32
|
+
if line_array[i + 1] =~ /^\<([a-zA-Z\-\,]+)\>$/
|
33
|
+
media[line_array[i]] = Hash.new unless media.has_key?(line_array[i])
|
34
|
+
if media[line_array[i]].has_key?("options")
|
35
|
+
$1.split(",").each do |opt|
|
36
|
+
media[line_array[i]]["options"] << opt unless media[line_array[i]]["options"].include?(opt)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
media[line_array[i]]["options"] = $1.split(",")
|
40
|
+
end
|
41
|
+
else
|
42
|
+
if line_array[i].eql?("autoselect")
|
43
|
+
media["autoselect"] = Hash.new unless media.has_key?("autoselect")
|
44
|
+
media["autoselect"]["options"] = []
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
media["none"] = { "options" => [] }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
media
|
53
|
+
end
|
54
|
+
|
55
|
+
def encaps_lookup(ifname)
|
56
|
+
return "Loopback" if ifname.eql?("lo")
|
57
|
+
return "1394" if ifname.eql?("fw")
|
58
|
+
return "IPIP" if ifname.eql?("gif")
|
59
|
+
return "6to4" if ifname.eql?("stf")
|
60
|
+
return "dot1q" if ifname.eql?("vlan")
|
61
|
+
"Unknown"
|
62
|
+
end
|
63
|
+
|
64
|
+
def scope_lookup(scope)
|
65
|
+
return "Link" if scope.match(/^fe80\:/)
|
66
|
+
return "Site" if scope.match(/^fec0\:/)
|
67
|
+
"Global"
|
68
|
+
end
|
69
|
+
|
70
|
+
def excluded_setting?(setting)
|
71
|
+
setting.match('_sw_cksum')
|
72
|
+
end
|
73
|
+
|
74
|
+
def locate_interface(ifaces, ifname, mac)
|
75
|
+
return ifname unless ifaces[ifname].nil?
|
76
|
+
# oh well, time to go hunting!
|
77
|
+
return ifname.chop if ifname.match /\*$/
|
78
|
+
ifaces.keys.each do |ifc|
|
79
|
+
ifaces[ifc][:addresses].keys.each do |addr|
|
80
|
+
return ifc if addr.eql? mac
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
iface = Mash.new
|
88
|
+
popen4("ifconfig -a") do |pid, stdin, stdout, stderr|
|
89
|
+
stdin.close
|
90
|
+
cint = nil
|
91
|
+
stdout.each do |line|
|
92
|
+
if line =~ /^([0-9a-zA-Z\.\:\-]+): \S+ mtu (\d+)$/
|
93
|
+
cint = $1
|
94
|
+
iface[cint] = Mash.new unless iface[cint]; iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
95
|
+
iface[cint][:mtu] = $2
|
96
|
+
if line =~ /\sflags\=\d+\<((UP|BROADCAST|DEBUG|SMART|SIMPLEX|LOOPBACK|POINTOPOINT|NOTRAILERS|RUNNING|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC|,)+)\>\s/
|
97
|
+
flags = $1.split(',')
|
98
|
+
else
|
99
|
+
flags = Array.new
|
100
|
+
end
|
101
|
+
iface[cint][:flags] = flags.flatten
|
102
|
+
if cint =~ /^(\w+)(\d+.*)/
|
103
|
+
iface[cint][:type] = $1
|
104
|
+
iface[cint][:number] = $2
|
105
|
+
iface[cint][:encapsulation] = encaps_lookup($1)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
if line =~ /^\s+ether ([0-9a-f\:]+)\s/
|
109
|
+
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
110
|
+
iface[cint][:addresses][$1] = { "family" => "lladdr" }
|
111
|
+
iface[cint][:encapsulation] = "Ethernet"
|
112
|
+
end
|
113
|
+
if line =~ /^\s+lladdr ([0-9a-f\:]+)\s/
|
114
|
+
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
115
|
+
iface[cint][:addresses][$1] = { "family" => "lladdr" }
|
116
|
+
end
|
117
|
+
if line =~ /\s+inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) netmask 0x(([0-9a-f]){1,8})\s*$/
|
118
|
+
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
119
|
+
iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf('%2x'*4)*"."}
|
120
|
+
end
|
121
|
+
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})/
|
122
|
+
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
123
|
+
iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf('%2x'*4)*".", "broadcast" => $4 }
|
124
|
+
end
|
125
|
+
if line =~ /\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*) prefixlen (\d+)\s*$/
|
126
|
+
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
127
|
+
iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $4 , "scope" => "Node" }
|
128
|
+
end
|
129
|
+
if line =~ /\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*) prefixlen (\d+) scopeid 0x([a-f0-9]+)/
|
130
|
+
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
131
|
+
iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $4 , "scope" => scope_lookup($1) }
|
132
|
+
end
|
133
|
+
if line =~ /^\s+media: ((\w+)|(\w+ [a-zA-Z0-9\-\<\>]+)) status: (\w+)/
|
134
|
+
iface[cint][:media] = Mash.new unless iface[cint][:media]
|
135
|
+
iface[cint][:media][:selected] = parse_media($1)
|
136
|
+
iface[cint][:status] = $4
|
137
|
+
end
|
138
|
+
if line =~ /^\s+supported media: (.*)/
|
139
|
+
iface[cint][:media] = Mash.new unless iface[cint][:media]
|
140
|
+
iface[cint][:media][:supported] = parse_media($1)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
popen4("arp -an") do |pid, stdin, stdout, stderr|
|
146
|
+
stdin.close
|
147
|
+
stdout.each do |line|
|
148
|
+
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+)\]/
|
149
|
+
# MAC addr really should be normalized to include all the zeroes.
|
150
|
+
next if iface[$3].nil? # this should never happen
|
151
|
+
iface[$3][:arp] = Mash.new unless iface[$3][:arp]
|
152
|
+
iface[$3][:arp][$1] = $2
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
settings = Mash.new
|
158
|
+
popen4("sysctl net") do |pid, stdin, stdout, stderr|
|
159
|
+
stdin.close
|
160
|
+
stdout.each do |line|
|
161
|
+
if line =~ /^([a-zA-Z0-9\.\_]+)\: (.*)/
|
162
|
+
# should normalize names between platforms for the same settings.
|
163
|
+
settings[$1] = $2 unless excluded_setting?($1)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
network[:settings] = settings
|
169
|
+
network[:interfaces] = iface
|
170
|
+
|
171
|
+
net_counters = Mash.new
|
172
|
+
popen4("netstat -i -d -l -b -n") do |pid, stdin, stdout, stderr|
|
173
|
+
stdin.close
|
174
|
+
stdout.each do |line|
|
175
|
+
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+)/ ||
|
176
|
+
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+)/
|
177
|
+
ifname = locate_interface(iface, $1, $2)
|
178
|
+
next if iface[ifname].nil? # this shouldn't happen, but just in case
|
179
|
+
net_counters[ifname] = Mash.new unless net_counters[ifname]
|
180
|
+
net_counters[ifname] = { :rx => { :bytes => $5, :packets => $3, :errors => $4, :drop => 0, :overrun => 0, :frame => 0, :compressed => 0, :multicast => 0 },
|
181
|
+
:tx => { :bytes => $8, :packets => $6, :errors => $7, :drop => 0, :overrun => 0, :collisions => $9, :carrier => 0, :compressed => 0 }
|
182
|
+
}
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
counters[:network][:interfaces] = net_counters
|
@@ -0,0 +1,36 @@
|
|
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", "platform_build"
|
20
|
+
|
21
|
+
popen4("/usr/bin/sw_vers") do |pid, stdin, stdout, stderr|
|
22
|
+
stdin.close
|
23
|
+
stdout.each do |line|
|
24
|
+
case line
|
25
|
+
when /^ProductName:\s+(.+)$/
|
26
|
+
macname = $1
|
27
|
+
macname.downcase!
|
28
|
+
macname.gsub!(" ", "_")
|
29
|
+
platform macname
|
30
|
+
when /^ProductVersion:\s+(.+)$/
|
31
|
+
platform_version $1
|
32
|
+
when /^BuildVersion:\s+(.+)$/
|
33
|
+
platform_build $1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
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,25 @@
|
|
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
|
+
keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh_host_dsa_key.pub").split[1]
|
25
|
+
keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh_host_rsa_key.pub").split[1]
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Benjamin Black (<bb@opscode.com>)
|
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 "system_profile"
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'plist'
|
23
|
+
|
24
|
+
system_profile Array.new
|
25
|
+
popen4("system_profiler -xml -detailLevel mini") do |pid, stdin, stdout, stderr|
|
26
|
+
stdin.close
|
27
|
+
Plist::parse_xml(stdout.read).each do |e|
|
28
|
+
system_profile << e
|
29
|
+
end
|
30
|
+
end
|
31
|
+
rescue LoadError => e
|
32
|
+
Ohai::Log.debug("Can't load gem: #{e})")
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan McLellan (btm@loftninjas.org)
|
3
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
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", "uptime_seconds"
|
20
|
+
|
21
|
+
# kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009
|
22
|
+
|
23
|
+
popen4("/usr/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr|
|
24
|
+
stdin.close
|
25
|
+
stdout.each do |line|
|
26
|
+
if line =~ /kern.boottime:\D+(\d+)/
|
27
|
+
uptime_seconds Time.new.to_i - $1.to_i
|
28
|
+
uptime self._seconds_to_human(uptime_seconds)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan McLellan (btm@loftninjas.org)
|
3
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
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 "dmi"
|
20
|
+
|
21
|
+
# dmidecode does not return data without access to /dev/mem (or its equivalent)
|
22
|
+
|
23
|
+
dmi Mash.new
|
24
|
+
dmi[:version] = from("dmidecode --version")
|
25
|
+
|
26
|
+
dmi[:bios] = Mash.new
|
27
|
+
dmi[:bios][:vendor] = from("dmidecode -s bios-vendor")
|
28
|
+
dmi[:bios][:version] = from("dmidecode -s bios-version")
|
29
|
+
dmi[:bios][:release_date] = from("dmidecode -s bios-release-date")
|
30
|
+
|
31
|
+
dmi[:system] = Mash.new
|
32
|
+
dmi[:system][:manufacturer] = from("dmidecode -s system-manufacturer")
|
33
|
+
dmi[:system][:product_name] = from("dmidecode -s system-product-name")
|
34
|
+
dmi[:system][:version] = from("dmidecode -s system-version")
|
35
|
+
dmi[:system][:serial_number] = from("dmidecode -s system-serial-number")
|
36
|
+
|
37
|
+
dmi[:baseboard] = Mash.new
|
38
|
+
dmi[:baseboard][:manufacturer] = from("dmidecode -s baseboard-manufacturer")
|
39
|
+
dmi[:baseboard][:product_name] = from("dmidecode -s baseboard-product-name")
|
40
|
+
dmi[:baseboard][:version] = from("dmidecode -s baseboard-version")
|
41
|
+
dmi[:baseboard][:serial_number] = from("dmidecode -s baseboard-serial-number")
|
42
|
+
dmi[:baseboard][:asset_tag] = from("dmidecode -s baseboard-asset-tag")
|
43
|
+
|
44
|
+
dmi[:chassis] = Mash.new
|
45
|
+
dmi[:chassis][:manufacturer] = from("dmidecode -s chassis-manufacturer")
|
46
|
+
dmi[:chassis][:version] = from("dmidecode -s chassis-version")
|
47
|
+
dmi[:chassis][:serial_number] = from("dmidecode -s chassis-serial-number")
|
48
|
+
dmi[:chassis][:asset_tag] = from("dmidecode -s chassis-asset-tag")
|
49
|
+
|
50
|
+
dmi[:processor] = Mash.new
|
51
|
+
dmi[:processor][:manufacturer] = from("dmidecode -s processor-manufacturer")
|
52
|
+
dmi[:processor][:version] = from("dmidecode -s processor-version")
|
53
|
+
|
54
|
+
if dmi[:version].to_f >= 2.8
|
55
|
+
dmi[:chassis][:type] = from("dmidecode -s chassis-type")
|
56
|
+
dmi[:system][:uuid] = from("dmidecode -s system-uuid")
|
57
|
+
dmi[:processor][:family] = from("dmidecode -s processor-family")
|
58
|
+
dmi[:processor][:frequency] = from("dmidecode -s processor-frequency")
|
59
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Tim Dysinger (<tim@dysinger.net>)
|
3
|
+
# Author:: Benjamin Black (<bb@opscode.com>)
|
4
|
+
# Author:: Christopher Brown (<cb@opscode.com>)
|
5
|
+
# Copyright:: Copyright (c) 2009 Opscode, Inc.
|
6
|
+
# License:: Apache License, Version 2.0
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
|
20
|
+
provides "ec2"
|
21
|
+
|
22
|
+
require 'open-uri'
|
23
|
+
require 'socket'
|
24
|
+
|
25
|
+
require_plugin "hostname"
|
26
|
+
require_plugin "kernel"
|
27
|
+
require_plugin "network"
|
28
|
+
|
29
|
+
EC2_METADATA_ADDR = "169.254.169.254" unless defined?(EC2_METADATA_ADDR)
|
30
|
+
EC2_METADATA_URL = "http://#{EC2_METADATA_ADDR}/2008-02-01/meta-data" unless defined?(EC2_METADATA_URL)
|
31
|
+
EC2_USERDATA_URL = "http://#{EC2_METADATA_ADDR}/2008-02-01/user-data" unless defined?(EC2_USERDATA_URL)
|
32
|
+
|
33
|
+
def can_metadata_connect?(addr, port, timeout=2)
|
34
|
+
t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0)
|
35
|
+
saddr = Socket.pack_sockaddr_in(port, addr)
|
36
|
+
connected = false
|
37
|
+
|
38
|
+
begin
|
39
|
+
t.connect_nonblock(saddr)
|
40
|
+
rescue Errno::EINPROGRESS
|
41
|
+
r,w,e = IO::select(nil,[t],nil,timeout)
|
42
|
+
if !w.nil?
|
43
|
+
connected = true
|
44
|
+
else
|
45
|
+
begin
|
46
|
+
t.connect_nonblock(saddr)
|
47
|
+
rescue Errno::EISCONN
|
48
|
+
t.close
|
49
|
+
connected = true
|
50
|
+
rescue SystemCallError
|
51
|
+
end
|
52
|
+
end
|
53
|
+
rescue SystemCallError
|
54
|
+
end
|
55
|
+
|
56
|
+
connected
|
57
|
+
end
|
58
|
+
|
59
|
+
def has_ec2_mac?
|
60
|
+
network[:interfaces].values.each do |iface|
|
61
|
+
unless iface[:arp].nil?
|
62
|
+
return true if iface[:arp].value?("fe:ff:ff:ff:ff:ff")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
def metadata(id='')
|
69
|
+
OpenURI.open_uri("#{EC2_METADATA_URL}/#{id}").read.split("\n").each do |o|
|
70
|
+
key = "#{id}#{o.gsub(/\=.*$/, '/')}"
|
71
|
+
if key[-1..-1] != '/'
|
72
|
+
ec2[key.gsub(/\-|\//, '_').to_sym] =
|
73
|
+
OpenURI.open_uri("#{EC2_METADATA_URL}/#{key}").read
|
74
|
+
else
|
75
|
+
metadata(key)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def userdata()
|
81
|
+
ec2[:userdata] = nil
|
82
|
+
# assumes the only expected error is the 404 if there's no user-data
|
83
|
+
begin
|
84
|
+
ec2[:userdata] = OpenURI.open_uri("#{EC2_USERDATA_URL}/").read
|
85
|
+
rescue OpenURI::HTTPError
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def looks_like_ec2?
|
90
|
+
# Try non-blocking connect so we don't "block" if
|
91
|
+
# the Xen environment is *not* EC2
|
92
|
+
has_ec2_mac? && can_metadata_connect?(EC2_METADATA_ADDR,80)
|
93
|
+
end
|
94
|
+
|
95
|
+
if looks_like_ec2?
|
96
|
+
ec2 Mash.new
|
97
|
+
self.metadata
|
98
|
+
self.userdata
|
99
|
+
end
|
100
|
+
|