rightscale-ohai 0.3.3.1
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 +59 -0
- data/bin/ohai +78 -0
- data/lib/ohai/config.rb +118 -0
- data/lib/ohai/exception.rb +23 -0
- data/lib/ohai/log/formatter.rb +57 -0
- data/lib/ohai/log.rb +89 -0
- data/lib/ohai/mixin/command.rb +203 -0
- data/lib/ohai/mixin/from_file.rb +36 -0
- data/lib/ohai/mixin/string.rb +29 -0
- data/lib/ohai/plugins/cloud.rb +35 -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/network.rb +52 -0
- data/lib/ohai/plugins/ohai_time.rb +21 -0
- data/lib/ohai/plugins/os.rb +43 -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/rightscale.rb +53 -0
- data/lib/ohai/plugins/ruby.rb +37 -0
- data/lib/ohai/plugins/solaris2/cpu.rb +33 -0
- data/lib/ohai/plugins/solaris2/hostname.rb +22 -0
- data/lib/ohai/plugins/solaris2/kernel.rb +21 -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 +226 -0
- data/lib/ohai.rb +27 -0
- data/spec/ohai/log/log_formatter_spec.rb +50 -0
- data/spec/ohai/log_spec.rb +63 -0
- data/spec/ohai/mixin/from_file_spec.rb +53 -0
- data/spec/ohai/plugins/cloud_spec.rb +64 -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 +77 -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/ohai_time_spec.rb +46 -0
- data/spec/ohai/plugins/os_spec.rb +58 -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/rightscale_spec.rb +71 -0
- data/spec/ohai/plugins/ruby_spec.rb +51 -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 +66 -0
- metadata +209 -0
@@ -0,0 +1,60 @@
|
|
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 "cpu"
|
20
|
+
|
21
|
+
cpuinfo = Mash.new
|
22
|
+
real_cpu = Mash.new
|
23
|
+
cpu_number = 0
|
24
|
+
current_cpu = nil
|
25
|
+
|
26
|
+
File.open("/proc/cpuinfo").each do |line|
|
27
|
+
case line
|
28
|
+
when /processor\s+:\s(.+)/
|
29
|
+
cpuinfo[$1] = Mash.new
|
30
|
+
current_cpu = $1
|
31
|
+
cpu_number += 1
|
32
|
+
when /vendor_id\s+:\s(.+)/
|
33
|
+
cpuinfo[current_cpu]["vendor_id"] = $1
|
34
|
+
when /cpu family\s+:\s(.+)/
|
35
|
+
cpuinfo[current_cpu]["family"] = $1
|
36
|
+
when /model\s+:\s(.+)/
|
37
|
+
cpuinfo[current_cpu]["model"] = $1
|
38
|
+
when /stepping\s+:\s(.+)/
|
39
|
+
cpuinfo[current_cpu]["stepping"] = $1
|
40
|
+
when /physical id\s+:\s(.+)/
|
41
|
+
cpuinfo[current_cpu]["physical_id"] = $1
|
42
|
+
real_cpu[$1] = true
|
43
|
+
when /core id\s+:\s(.+)/
|
44
|
+
cpuinfo[current_cpu]["core_id"] = $1
|
45
|
+
when /cpu cores\s+:\s(.+)/
|
46
|
+
cpuinfo[current_cpu]["cores"] = $1
|
47
|
+
when /model name\s+:\s(.+)/
|
48
|
+
cpuinfo[current_cpu]["model_name"] = $1
|
49
|
+
when /cpu MHz\s+:\s(.+)/
|
50
|
+
cpuinfo[current_cpu]["mhz"] = $1
|
51
|
+
when /cache size\s+:\s(.+)/
|
52
|
+
cpuinfo[current_cpu]["cache_size"] = $1
|
53
|
+
when /flags\s+:\s(.+)/
|
54
|
+
cpuinfo[current_cpu]["flags"] = $1.split(' ')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
cpu cpuinfo
|
59
|
+
cpu[:total] = cpu_number
|
60
|
+
cpu[:real] = real_cpu.keys.length
|
@@ -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 -P") do |pid, stdin, stdout, stderr|
|
25
|
+
stdin.close
|
26
|
+
stdout.each do |line|
|
27
|
+
case line
|
28
|
+
when /^Filesystem\s+1024-blocks/
|
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 /bin/mount
|
43
|
+
popen4("mount -l") do |pid, stdin, stdout, stderr|
|
44
|
+
stdin.close
|
45
|
+
stdout.each do |line|
|
46
|
+
if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/
|
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(",")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Set the filesystem data
|
57
|
+
filesystem fs
|
@@ -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 "hostname", "fqdn"
|
20
|
+
|
21
|
+
hostname from("hostname -s")
|
22
|
+
begin
|
23
|
+
fqdn from("hostname --fqdn")
|
24
|
+
rescue
|
25
|
+
Ohai::Log.debug("hostname -f returned an error, probably no domain is set")
|
26
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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] = from("uname -o")
|
22
|
+
|
23
|
+
kext = Mash.new
|
24
|
+
popen4("env lsmod") do |pid, stdin, stdout, stderr|
|
25
|
+
stdin.close
|
26
|
+
stdout.each do |line|
|
27
|
+
if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
|
28
|
+
kext[$1] = { :size => $2, :refcount => $3 }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
kernel[:modules] = kext
|
@@ -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
|