kurchatov 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +111 -0
  7. data/Rakefile +1 -0
  8. data/Vagrantfile +16 -0
  9. data/bin/kurchatov +6 -0
  10. data/examples/check_file_contains.rb +14 -0
  11. data/examples/count_proc.rb +14 -0
  12. data/examples/cpu.rb +29 -0
  13. data/examples/disk.rb +56 -0
  14. data/examples/disk_stat.rb +28 -0
  15. data/examples/dns_check.rb +5 -0
  16. data/examples/exim.rb +12 -0
  17. data/examples/file_age.rb +11 -0
  18. data/examples/find_files.rb +21 -0
  19. data/examples/http.rb +25 -0
  20. data/examples/iptables.rb +27 -0
  21. data/examples/la.rb +10 -0
  22. data/examples/mdadm.rb +43 -0
  23. data/examples/megacli.rb +12 -0
  24. data/examples/memory.rb +28 -0
  25. data/examples/net.rb +25 -0
  26. data/examples/net_stat.rb +25 -0
  27. data/examples/nfs.rb +9 -0
  28. data/examples/nginx.rb +22 -0
  29. data/examples/nginx_500.rb +48 -0
  30. data/examples/ntp.rb +15 -0
  31. data/examples/openfiles.rb +6 -0
  32. data/examples/pgsql.rb +67 -0
  33. data/examples/ping_icmp.rb +12 -0
  34. data/examples/ping_tcp.rb +14 -0
  35. data/examples/proc_mem.rb +24 -0
  36. data/examples/process_usage.rb +15 -0
  37. data/examples/rabbitmq.rb +16 -0
  38. data/examples/runit.rb +47 -0
  39. data/examples/sidekiq.rb +21 -0
  40. data/examples/sidekiq_queue_state.rb +9 -0
  41. data/examples/status_file.rb +14 -0
  42. data/examples/tw_cli.rb +17 -0
  43. data/examples/uptime.rb +14 -0
  44. data/kurchatov.gemspec +28 -0
  45. data/lib/kurchatov/application.rb +154 -0
  46. data/lib/kurchatov/config.rb +14 -0
  47. data/lib/kurchatov/log.rb +9 -0
  48. data/lib/kurchatov/mashie.rb +152 -0
  49. data/lib/kurchatov/mixin/command.rb +31 -0
  50. data/lib/kurchatov/mixin/event.rb +63 -0
  51. data/lib/kurchatov/mixin/http.rb +21 -0
  52. data/lib/kurchatov/mixin/init.rb +6 -0
  53. data/lib/kurchatov/mixin/ohai.rb +22 -0
  54. data/lib/kurchatov/mixin/queue.rb +14 -0
  55. data/lib/kurchatov/monitor.rb +62 -0
  56. data/lib/kurchatov/plugin/config.rb +68 -0
  57. data/lib/kurchatov/plugin/dsl.rb +81 -0
  58. data/lib/kurchatov/plugin/riemann.rb +54 -0
  59. data/lib/kurchatov/plugin.rb +15 -0
  60. data/lib/kurchatov/queue.rb +28 -0
  61. data/lib/kurchatov/responders/http.rb +36 -0
  62. data/lib/kurchatov/responders/init.rb +3 -0
  63. data/lib/kurchatov/responders/riemann.rb +46 -0
  64. data/lib/kurchatov/responders/udp.rb +32 -0
  65. data/lib/kurchatov/riemann/client.rb +49 -0
  66. data/lib/kurchatov/riemann/event.rb +42 -0
  67. data/lib/kurchatov/riemann/message.rb +18 -0
  68. data/lib/kurchatov/version.rb +3 -0
  69. data/lib/kurchatov.rb +3 -0
  70. data/lib/ohai/plugins/darwin/hostname.rb +22 -0
  71. data/lib/ohai/plugins/darwin/platform.rb +38 -0
  72. data/lib/ohai/plugins/hostname.rb +27 -0
  73. data/lib/ohai/plugins/linux/hostname.rb +26 -0
  74. data/lib/ohai/plugins/linux/platform.rb +113 -0
  75. data/lib/ohai/plugins/linux/virtualization.rb +125 -0
  76. data/lib/ohai/plugins/os.rb +53 -0
  77. data/lib/ohai/plugins/platform.rb +28 -0
  78. data/lib/ohai/plugins/virtualization.rb +86 -0
  79. data/lib/ohai/plugins/windows/hostname.rb +33 -0
  80. data/lib/ohai/plugins/windows/platform.rb +27 -0
  81. data/tests/run.sh +55 -0
  82. metadata +209 -0
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require "kurchatov/riemann/client"
4
+ require "kurchatov/mixin/queue"
5
+
6
+ module Kurchatov
7
+ module Responders
8
+ class Riemann < Kurchatov::Plugin
9
+
10
+ include Kurchatov::Mixin::Queue
11
+
12
+ FLUSH_INTERVAL = 0.5
13
+
14
+ def initialize(conn)
15
+ @hosts = conn
16
+ @riemanns = Array.new
17
+ end
18
+
19
+ def run
20
+ make_clients
21
+ loop { flush; sleep FLUSH_INTERVAL }
22
+ end
23
+
24
+ private
25
+
26
+ def make_clients
27
+ @riemanns.clear
28
+ @hosts.each do |host|
29
+ riemann, port = host.split(':')
30
+ @riemanns << Kurchatov::Riemann::Client.new(:host => riemann, :port => port)
31
+ @name = @riemanns.map { |c| "riemann client [#{c.host}:#{c.port}]" }.join(' , ')
32
+ end
33
+ end
34
+
35
+ def flush
36
+ @events_to_send ||= events.all
37
+ unless @events_to_send.empty?
38
+ @riemanns.each {|riemann| riemann << @events_to_send }
39
+ Log.debug("Sended events via #{@name.inspect}: #{@events_to_send}")
40
+ end
41
+ @events_to_send = nil
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,32 @@
1
+ module Kurchatov
2
+ module Responders
3
+ class Udp < Kurchatov::Plugin
4
+
5
+ include Kurchatov::Mixin::Event
6
+ include Kurchatov::Mixin::Queue
7
+
8
+ def initialize(conn)
9
+ @host, @port = conn.split(':')
10
+ @name = "udp responder #{@host}:#{@port}"
11
+ end
12
+
13
+
14
+ def run
15
+ Socket.udp_server_loop(@host, @port) do |data, src|
16
+ process(data, src)
17
+ end
18
+ end
19
+
20
+ def process(data,src)
21
+ begin
22
+ event << JSON.parse(data)
23
+ src.reply "sended\n\n"
24
+ rescue => e
25
+ src.reply "failed to send: #{data.inspect}\n"
26
+ Log.error("Failed parse #{data.inspect}, #{e.class}: #{e}\n #{e.backtrace.join("\n")}")
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ require "timeout"
2
+ require "socket"
3
+ require "beefcake"
4
+ require "kurchatov/riemann/event"
5
+ require "kurchatov/riemann/message"
6
+
7
+ module Kurchatov
8
+ module Riemann
9
+ class Client
10
+
11
+ attr_accessor :host, :port
12
+
13
+ CONNECT_TIMEOUT = 5
14
+ SEND_TIMEOUT = 5
15
+ RIEMANN_PORT = 5555
16
+
17
+ def initialize(opts = {})
18
+ @host = opts[:host]
19
+ @port = opts[:port] || RIEMANN_PORT
20
+ @mutex = Mutex.new
21
+ end
22
+
23
+ def <<(events)
24
+ events = events.map {|e| Event.new(e) }
25
+ message = Message.new(:events => events)
26
+ with_connection do |socket|
27
+ x = message.encode_with_length
28
+ Timeout::timeout(SEND_TIMEOUT) {
29
+ socket.write(x)
30
+ socket.flush
31
+ }
32
+ end
33
+ end
34
+
35
+ def with_connection
36
+ @mutex.synchronize do
37
+ yield(@socket || connect)
38
+ end
39
+ end
40
+
41
+ def connect
42
+ Timeout::timeout(CONNECT_TIMEOUT) {
43
+ @socket ||= TCPSocket.new(@host, @port)
44
+ }
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,42 @@
1
+ module Kurchatov
2
+ module Riemann
3
+ class Event
4
+ include Beefcake::Message
5
+ optional :time, :int64, 1
6
+ optional :state, :string, 2
7
+ optional :service, :string, 3
8
+ optional :host, :string, 4
9
+ optional :description, :string, 5
10
+ repeated :tags, :string, 7
11
+ optional :ttl, :float, 8
12
+ optional :metric_sint64, :sint64, 13
13
+ optional :metric_d, :double, 14
14
+ optional :metric_f, :float, 15
15
+
16
+ def initialize(hash = nil)
17
+ if hash
18
+ super(hash)
19
+ self.metric = hash[:metric] if hash[:metric]
20
+ else
21
+ super
22
+ end
23
+ @time ||= Time.now.to_i
24
+ end
25
+
26
+ def metric
27
+ metric_d || metric_sint64 || metric_f
28
+ end
29
+
30
+ def metric=(m)
31
+ if Integer === m and (-(2**63)...2**63) === m
32
+ self.metric_sint64 = m
33
+ self.metric_f = m.to_f
34
+ else
35
+ self.metric_d = m.to_f
36
+ self.metric_f = m.to_f
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ module Kurchatov
2
+ module Riemann
3
+ class Message
4
+ include Beefcake::Message
5
+
6
+ optional :ok, :bool, 2
7
+ optional :error, :string, 3
8
+ repeated :events, Event, 6
9
+
10
+ def encode_with_length
11
+ buffer = ''
12
+ encoded = encode buffer
13
+ "#{[encoded.length].pack('N')}#{encoded}"
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Kurchatov
2
+ VERSION = "0.0.1"
3
+ end
data/lib/kurchatov.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "kurchatov/version"
2
+
3
+ module Kurchatov; end
@@ -0,0 +1,22 @@
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 "fqdn", "hostname"
20
+
21
+ hostname from("hostname -s")
22
+ fqdn from("hostname")
@@ -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 "platform", "platform_version", "platform_build", "platform_family"
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
37
+
38
+ platform_family "mac_os_x"
@@ -0,0 +1,27 @@
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 "fqdn", "domain"
20
+
21
+ require_plugin "#{os}::hostname"
22
+
23
+ # Domain is everything after the first dot
24
+ if fqdn
25
+ fqdn =~ /.+?\.(.*)/
26
+ domain $1
27
+ end
@@ -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,113 @@
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
+ def get_redhatish_platform(contents)
20
+ contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
21
+ end
22
+
23
+ def get_redhatish_version(contents)
24
+ contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1]
25
+ end
26
+
27
+ provides "platform", "platform_version", "platform_family"
28
+
29
+ require_plugin 'linux::lsb'
30
+
31
+ # platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching
32
+ if File.exists?("/etc/oracle-release")
33
+ contents = File.read("/etc/oracle-release").chomp
34
+ platform "oracle"
35
+ platform_version get_redhatish_version(contents)
36
+ elsif File.exists?("/etc/enterprise-release")
37
+ contents = File.read("/etc/enterprise-release").chomp
38
+ platform "oracle"
39
+ platform_version get_redhatish_version(contents)
40
+ elsif File.exists?("/etc/debian_version")
41
+ # Ubuntu and Debian both have /etc/debian_version
42
+ # Ubuntu should always have a working lsb, debian does not by default
43
+ if lsb[:id] =~ /Ubuntu/i
44
+ platform "ubuntu"
45
+ platform_version lsb[:release]
46
+ elsif lsb[:id] =~ /LinuxMint/i
47
+ platform "linuxmint"
48
+ platform_version lsb[:release]
49
+ else
50
+ if File.exists?("/usr/bin/raspi-config")
51
+ platform "raspbian"
52
+ else
53
+ platform "debian"
54
+ end
55
+ platform_version File.read("/etc/debian_version").chomp
56
+ end
57
+ elsif File.exists?("/etc/redhat-release")
58
+ contents = File.read("/etc/redhat-release").chomp
59
+ platform get_redhatish_platform(contents)
60
+ platform_version get_redhatish_version(contents)
61
+ elsif File.exists?("/etc/system-release")
62
+ contents = File.read("/etc/system-release").chomp
63
+ platform get_redhatish_platform(contents)
64
+ platform_version get_redhatish_version(contents)
65
+ elsif File.exists?('/etc/gentoo-release')
66
+ platform "gentoo"
67
+ platform_version File.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join
68
+ elsif File.exists?('/etc/SuSE-release')
69
+ platform "suse"
70
+ suse_release = File.read("/etc/SuSE-release")
71
+ platform_version suse_release.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
72
+ platform_version suse_release.scan(/VERSION = ([\d\.]{2,})/).flatten.join(".") if platform_version == ""
73
+ elsif File.exists?('/etc/slackware-version')
74
+ platform "slackware"
75
+ platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join
76
+ elsif File.exists?('/etc/arch-release')
77
+ platform "arch"
78
+ # no way to determine platform_version in a rolling release distribution
79
+ # kernel release will be used - ex. 2.6.32-ARCH
80
+ elsif lsb[:id] =~ /RedHat/i
81
+ platform "redhat"
82
+ platform_version lsb[:release]
83
+ elsif lsb[:id] =~ /Amazon/i
84
+ platform "amazon"
85
+ platform_version lsb[:release]
86
+ elsif lsb[:id] =~ /ScientificSL/i
87
+ platform "scientific"
88
+ platform_version lsb[:release]
89
+ elsif lsb[:id] =~ /XenServer/i
90
+ platform "xenserver"
91
+ platform_version lsb[:release]
92
+ elsif lsb[:id] # LSB can provide odd data that changes between releases, so we currently fall back on it rather than dealing with its subtleties
93
+ platform lsb[:id].downcase
94
+ platform_version lsb[:release]
95
+ end
96
+
97
+
98
+ case platform
99
+ when /debian/, /ubuntu/, /linuxmint/, /raspbian/
100
+ platform_family "debian"
101
+ when /fedora/
102
+ platform_family "fedora"
103
+ when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/, /xenserver/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
104
+ platform_family "rhel"
105
+ when /suse/
106
+ platform_family "suse"
107
+ when /gentoo/
108
+ platform_family "gentoo"
109
+ when /slackware/
110
+ platform_family "slackware"
111
+ when /arch/
112
+ platform_family "arch"
113
+ end
@@ -0,0 +1,125 @@
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
+
26
+ ## Xen
27
+ # /proc/xen is an empty dir for EL6 + Linode Guests
28
+ if File.exists?("/proc/xen")
29
+ virtualization[:system] = "xen"
30
+ # Assume guest
31
+ virtualization[:role] = "guest"
32
+
33
+ # This file should exist on most Xen systems, normally empty for guests
34
+ if File.exists?("/proc/xen/capabilities")
35
+ if File.read("/proc/xen/capabilities") =~ /control_d/i
36
+ virtualization[:role] = "host"
37
+ end
38
+ end
39
+ end
40
+
41
+ # Xen Notes:
42
+ # - cpuid of guests, if we could get it, would also be a clue
43
+ # - may be able to determine if under paravirt from /dev/xen/evtchn (See OHAI-253)
44
+ # - EL6 guests carry a 'hypervisor' cpu flag
45
+ # - Additional edge cases likely should not change the above assumptions
46
+ # but rather be additive - btm
47
+
48
+ # Detect from kernel module
49
+ if File.exists?("/proc/modules")
50
+ modules = File.read("/proc/modules")
51
+ if modules =~ /^kvm/
52
+ virtualization[:system] = "kvm"
53
+ virtualization[:role] = "host"
54
+ elsif modules =~ /^vboxdrv/
55
+ virtualization[:system] = "vbox"
56
+ virtualization[:role] = "host"
57
+ elsif modules =~ /^vboxguest/
58
+ virtualization[:system] = "vbox"
59
+ virtualization[:role] = "guest"
60
+ end
61
+ end
62
+
63
+ # Detect KVM/QEMU from cpuinfo, report as KVM
64
+ # We could pick KVM from 'Booting paravirtualized kernel on KVM' in dmesg
65
+ # 2.6.27-9-server (intrepid) has this / 2.6.18-6-amd64 (etch) does not
66
+ # It would be great if we could read pv_info in the kernel
67
+ # Wait for reply to: http://article.gmane.org/gmane.comp.emulators.kvm.devel/27885
68
+ if File.exists?("/proc/cpuinfo")
69
+ if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU/
70
+ virtualization[:system] = "kvm"
71
+ virtualization[:role] = "guest"
72
+ end
73
+ end
74
+
75
+ # Detect OpenVZ / Virtuozzo.
76
+ # http://wiki.openvz.org/BC_proc_entries
77
+ if File.exists?("/proc/bc/0")
78
+ virtualization[:system] = "openvz"
79
+ virtualization[:role] = "host"
80
+ elsif File.exists?("/proc/vz")
81
+ virtualization[:system] = "openvz"
82
+ virtualization[:role] = "guest"
83
+ end
84
+
85
+ # http://www.dmo.ca/blog/detecting-virtualization-on-linux
86
+ if File.exists?("/usr/sbin/dmidecode")
87
+ popen4("dmidecode") do |pid, stdin, stdout, stderr|
88
+ stdin.close
89
+ dmi_info = stdout.read
90
+ case dmi_info
91
+ when /Manufacturer: Microsoft/
92
+ if dmi_info =~ /Product Name: Virtual Machine/
93
+ virtualization[:system] = "virtualpc"
94
+ virtualization[:role] = "guest"
95
+ end
96
+ when /Manufacturer: VMware/
97
+ if dmi_info =~ /Product Name: VMware Virtual Platform/
98
+ virtualization[:system] = "vmware"
99
+ virtualization[:role] = "guest"
100
+ end
101
+ when /Manufacturer: Xen/
102
+ if dmi_info =~ /Product Name: HVM domU/
103
+ virtualization[:system] = "xen"
104
+ virtualization[:role] = "guest"
105
+ end
106
+ else
107
+ nil
108
+ end
109
+
110
+ end
111
+ end
112
+
113
+ # Detect Linux-VServer
114
+ if File.exists?("/proc/self/status")
115
+ proc_self_status = File.read("/proc/self/status")
116
+ vxid = proc_self_status.match(/^(s_context|VxID): (\d+)$/)
117
+ if vxid and vxid[2]
118
+ virtualization[:system] = "linux-vserver"
119
+ if vxid[2] == "0"
120
+ virtualization[:role] = "host"
121
+ else
122
+ virtualization[:role] = "guest"
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,53 @@
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 "os", "os_version"
20
+
21
+ require 'rbconfig'
22
+
23
+ require_plugin 'kernel'
24
+
25
+ case ::RbConfig::CONFIG['host_os']
26
+ when /aix(.+)$/
27
+ os "aix"
28
+ when /darwin(.+)$/
29
+ os "darwin"
30
+ when /hpux(.+)$/
31
+ os "hpux"
32
+ when /linux/
33
+ os "linux"
34
+ when /freebsd(.+)$/
35
+ os "freebsd"
36
+ when /openbsd(.+)$/
37
+ os "openbsd"
38
+ when /netbsd(.*)$/
39
+ os "netbsd"
40
+ when /solaris2/
41
+ os "solaris2"
42
+ when /mswin|mingw32|windows/
43
+ # After long discussion in IRC the "powers that be" have come to a concensus
44
+ # that there is no other Windows platforms exist that were not based on the
45
+ # Windows_NT kernel, so we herby decree that "windows" will refer to all
46
+ # platforms built upon the Windows_NT kernel and have access to win32 or win64
47
+ # subsystems.
48
+ os "windows"
49
+ else
50
+ os ::RbConfig::CONFIG['host_os']
51
+ end
52
+
53
+ os_version kernel[:release]
@@ -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 "platform", "platform_version", "platform_family"
20
+
21
+ require_plugin "#{os}::platform"
22
+
23
+ platform os unless attribute?("platform")
24
+
25
+ platform_version os_version unless attribute?("platform_version")
26
+
27
+ platform_family platform unless attribute?("platform_family")
28
+