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,40 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Joe Williams (<joe@joetify.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 "languages/erlang"
|
20
|
+
|
21
|
+
require_plugin "languages"
|
22
|
+
|
23
|
+
output = nil
|
24
|
+
|
25
|
+
erlang = Mash.new
|
26
|
+
status, stdout, stderr = run_command(:no_status_check => true, :command => "erl +V")
|
27
|
+
|
28
|
+
if status == 0
|
29
|
+
output = stderr.split
|
30
|
+
if output.length >= 6
|
31
|
+
options = output[1]
|
32
|
+
options.gsub!(/(\(|\))/, '')
|
33
|
+
erlang[:version] = output[5]
|
34
|
+
erlang[:options] = options.split(',')
|
35
|
+
erlang[:emulator] = output[2].gsub!(/(\(|\))/, '')
|
36
|
+
if erlang[:version] and erlang[:options] and erlang[:emulator]
|
37
|
+
languages[:erlang] = erlang
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan McLellan (btm@loftninjas.org)
|
3
|
+
# Copyright:: Copyright (c) 2008 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 "cpu"
|
20
|
+
|
21
|
+
# all dmesg output for smp I can find only provides info about a single processor
|
22
|
+
# identical processors is probably a hardware requirement so we'll duplicate data for each cpu
|
23
|
+
# old examples: http://www.bnv-bamberg.de/home/ba3294/smp/rbuild/index.htm
|
24
|
+
cpuinfo = Mash.new
|
25
|
+
|
26
|
+
# /var/run/dmesg.boot
|
27
|
+
#CPU: QEMU Virtual CPU version 0.9.1 (1862.02-MHz 686-class CPU)
|
28
|
+
# Origin = "GenuineIntel" Id = 0x623 Stepping = 3
|
29
|
+
# Features=0x78bfbfd<FPU,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,MMX,FXSR,SSE,SSE2>
|
30
|
+
# Features2=0x80000001<SSE3,<b31>>
|
31
|
+
|
32
|
+
File.open("/var/run/dmesg.boot").each do |line|
|
33
|
+
case line
|
34
|
+
when /CPU:\s+(.+) \(([\d.]+).+\)/
|
35
|
+
cpuinfo["model_name"] = $1
|
36
|
+
cpuinfo["mhz"] = $2
|
37
|
+
when /Origin = "(.+)"\s+Id = (.+)\s+Stepping = (.+)/
|
38
|
+
cpuinfo["vendor_id"] = $1
|
39
|
+
cpuinfo["stepping"] = $3
|
40
|
+
# These _should_ match /AMD Features2?/ lines as well
|
41
|
+
when /Features=.+<(.+)>/
|
42
|
+
cpuinfo["flags"] = $1.downcase.split(',')
|
43
|
+
# Features2=0x80000001<SSE3,<b31>>
|
44
|
+
when /Features2=[a-f\dx]+<(.+)>/
|
45
|
+
cpuinfo["flags"].concat($1.downcase.split(','))
|
46
|
+
when /Logical CPUs per core: (\d+)/
|
47
|
+
cpuinfo["cores"] = $1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
cpu cpuinfo
|
52
|
+
cpu[:total] = from("sysctl -n hw.ncpu")
|
@@ -0,0 +1,57 @@
|
|
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 "filesystem"
|
20
|
+
|
21
|
+
fs = Mash.new
|
22
|
+
|
23
|
+
# Grab filesystem data from df
|
24
|
+
popen4("df") do |pid, stdin, stdout, stderr|
|
25
|
+
stdin.close
|
26
|
+
stdout.each do |line|
|
27
|
+
case line
|
28
|
+
when /^Filesystem/
|
29
|
+
next
|
30
|
+
when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
|
31
|
+
filesystem = $1
|
32
|
+
fs[filesystem] = Mash.new
|
33
|
+
fs[filesystem][:kb_size] = $2
|
34
|
+
fs[filesystem][:kb_used] = $3
|
35
|
+
fs[filesystem][:kb_available] = $4
|
36
|
+
fs[filesystem][:percent_used] = $5
|
37
|
+
fs[filesystem][:mount] = $6
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Grab mount information from mount
|
43
|
+
popen4("mount -l") do |pid, stdin, stdout, stderr|
|
44
|
+
stdin.close
|
45
|
+
stdout.each do |line|
|
46
|
+
if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
|
47
|
+
filesystem = $1
|
48
|
+
fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
|
49
|
+
fs[filesystem][:mount] = $2
|
50
|
+
fs[filesystem][:fs_type] = $3
|
51
|
+
fs[filesystem][:mount_options] = $4.split(/,\s*/)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Set the filesystem data
|
57
|
+
filesystem fs
|
@@ -0,0 +1,22 @@
|
|
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 "hostname", "fqdn"
|
20
|
+
|
21
|
+
hostname from("hostname -s")
|
22
|
+
fqdn from("hostname -f")
|
@@ -0,0 +1,37 @@
|
|
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 "kernel"
|
20
|
+
|
21
|
+
kernel[:os] = kernel[:name]
|
22
|
+
kernel[:ident] = from("uname -i")
|
23
|
+
kernel[:securelevel] = from_with_regex("sysctl kern.securelevel", /kern.securelevel: (.+)$/)
|
24
|
+
|
25
|
+
kld = Mash.new
|
26
|
+
popen4("/sbin/kldstat") do |pid, stdin, stdout, stderr|
|
27
|
+
stdin.close
|
28
|
+
stdout.each do |line|
|
29
|
+
# 1 7 0xc0400000 97f830 kernel
|
30
|
+
if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
|
31
|
+
kld[$5] = { :size => $4, :refcount => $2 }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
kernel[:modules] = kld
|
37
|
+
|
@@ -0,0 +1,50 @@
|
|
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 "memory"
|
20
|
+
|
21
|
+
memory Mash.new
|
22
|
+
memory[:swap] = Mash.new
|
23
|
+
|
24
|
+
# /usr/src/sys/sys/vmmeter.h
|
25
|
+
memory[:page_size] = from("sysctl -n vm.stats.vm.v_page_size")
|
26
|
+
memory[:page_count] = from("sysctl -n vm.stats.vm.v_page_count")
|
27
|
+
memory[:total] = memory[:page_size].to_i * memory[:page_count].to_i
|
28
|
+
memory[:free] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_free_count").to_i
|
29
|
+
memory[:active] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_active_count").to_i
|
30
|
+
memory[:inactive] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_inactive_count").to_i
|
31
|
+
memory[:cache] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_cache_count").to_i
|
32
|
+
memory[:wired] = memory[:page_size].to_i * from("sysctl -n vm.stats.vm.v_wire_count").to_i
|
33
|
+
memory[:buffers] = from("sysctl -n vfs.bufspace")
|
34
|
+
|
35
|
+
popen4("swapinfo") do |pid, stdin, stdout, stderr|
|
36
|
+
stdin.close
|
37
|
+
stdout.each do |line|
|
38
|
+
# Device 1K-blocks Used Avail Capacity
|
39
|
+
# /dev/ad0s1b 253648 0 253648 0%
|
40
|
+
if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/
|
41
|
+
mdev = $1
|
42
|
+
memory[:swap][mdev] = Mash.new
|
43
|
+
memory[:swap][mdev][:total] = $2
|
44
|
+
memory[:swap][mdev][:used] = $3
|
45
|
+
memory[:swap][mdev][:free] = $4
|
46
|
+
memory[:swap][mdev][:percent_free] = $5
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,112 @@
|
|
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 "network", "counters/network"
|
20
|
+
|
21
|
+
network[:default_interface] = from("route -n get default \| grep interface: \| awk \'/: / \{print \$2\}\'")
|
22
|
+
|
23
|
+
iface = Mash.new
|
24
|
+
popen4("/sbin/ifconfig -a") do |pid, stdin, stdout, stderr|
|
25
|
+
stdin.close
|
26
|
+
cint = nil
|
27
|
+
stdout.each do |line|
|
28
|
+
if line =~ /^([0-9a-zA-Z\.]+):\s+/
|
29
|
+
cint = $1
|
30
|
+
iface[cint] = Mash.new
|
31
|
+
if cint =~ /^(\w+)(\d+.*)/
|
32
|
+
iface[cint][:type] = $1
|
33
|
+
iface[cint][:number] = $2
|
34
|
+
end
|
35
|
+
end
|
36
|
+
# call the family lladdr to match linux for consistency
|
37
|
+
if line =~ /\s+ether (.+?)\s/
|
38
|
+
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
39
|
+
iface[cint][:addresses][$1] = { "family" => "lladdr" }
|
40
|
+
end
|
41
|
+
if line =~ /\s+inet ([\d.]+) netmask ([\da-fx]+)\s*\w*\s*([\d.]*)/
|
42
|
+
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
43
|
+
# convert the netmask to decimal for consistency
|
44
|
+
netmask = "#{$2[2,2].hex}.#{$2[4,2].hex}.#{$2[6,2].hex}.#{$2[8,2].hex}"
|
45
|
+
if $3.empty?
|
46
|
+
iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask }
|
47
|
+
else
|
48
|
+
# found a broadcast address
|
49
|
+
iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask, "broadcast" => $3 }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if line =~ /\s+inet6 ([a-f0-9\:]+)%?(\w*)\s+prefixlen\s+(\d+)\s*\w*\s*([\da-fx]*)/
|
53
|
+
iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
|
54
|
+
if $4.empty?
|
55
|
+
iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $3 }
|
56
|
+
else
|
57
|
+
# found a zone_id / scope
|
58
|
+
iface[cint][:addresses][$1] = { "family" => "inet6", "zoneid" => $2, "prefixlen" => $3, "scopeid" => $4 }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
if line =~ /flags=\d+<(.+)>/
|
62
|
+
flags = $1.split(',')
|
63
|
+
iface[cint][:flags] = flags if flags.length > 0
|
64
|
+
end
|
65
|
+
if line =~ /metric: (\d+) mtu: (\d+)/
|
66
|
+
iface[cint][:metric] = $1
|
67
|
+
iface[cint][:mtu] = $2
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
popen4("arp -an") do |pid, stdin, stdout, stderr|
|
73
|
+
stdin.close
|
74
|
+
stdout.each do |line|
|
75
|
+
if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
|
76
|
+
next unless iface[$3] # this should never happen
|
77
|
+
iface[$3][:arp] = Mash.new unless iface[$3][:arp]
|
78
|
+
iface[$3][:arp][$1] = $2.downcase
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
network["interfaces"] = iface
|
84
|
+
|
85
|
+
net_counters = Mash.new
|
86
|
+
# From netstat(1), not sure of the implications:
|
87
|
+
# Show the state of all network interfaces or a single interface
|
88
|
+
# which have been auto-configured (interfaces statically configured
|
89
|
+
# into a system, but not located at boot time are not shown).
|
90
|
+
popen4("netstat -ibdn") do |pid, stdin, stdout, stderr|
|
91
|
+
stdin.close
|
92
|
+
stdout.each do |line|
|
93
|
+
# Name Mtu Network Address Ipkts Ierrs Ibytes Opkts Oerrs Obytes Coll Drop
|
94
|
+
# ed0 1500 <Link#1> 54:52:00:68:92:85 333604 26 151905886 175472 0 24897542 0 905
|
95
|
+
# $1 $2 $3 $4 $5 $6 $7 $8 $9 $10
|
96
|
+
if line =~ /^([\w\.\*]+)\s+\d+\s+<Link#\d+>\s+([\w:]*)\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/
|
97
|
+
net_counters[$1] = Mash.new unless net_counters[$1]
|
98
|
+
net_counters[$1]["rx"] = Mash.new unless net_counters[$1]["rx"]
|
99
|
+
net_counters[$1]["tx"] = Mash.new unless net_counters[$1]["tx"]
|
100
|
+
net_counters[$1]["rx"]["packets"] = $3
|
101
|
+
net_counters[$1]["rx"]["errors"] = $4
|
102
|
+
net_counters[$1]["rx"]["bytes"] = $5
|
103
|
+
net_counters[$1]["tx"]["packets"] = $6
|
104
|
+
net_counters[$1]["tx"]["errors"] = $7
|
105
|
+
net_counters[$1]["tx"]["bytes"] = $8
|
106
|
+
net_counters[$1]["tx"]["collisions"] = $9
|
107
|
+
net_counters[$1]["tx"]["dropped"] = $10
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
counters[:network][:interfaces] = net_counters
|
@@ -0,0 +1,23 @@
|
|
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 "platform", "platform_version"
|
20
|
+
|
21
|
+
platform from("uname -s").downcase
|
22
|
+
platform_version from("uname -r")
|
23
|
+
|
@@ -0,0 +1,24 @@
|
|
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 "command/ps"
|
20
|
+
|
21
|
+
require_plugin 'command'
|
22
|
+
|
23
|
+
# ps -e requires procfs
|
24
|
+
command[:ps] = 'ps -ax'
|
@@ -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]
|