slashport 0.15.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/Rakefile +35 -0
  2. data/app/controllers/application.rb +2 -0
  3. data/app/controllers/cfg.rb +8 -0
  4. data/app/controllers/exceptions.rb +13 -0
  5. data/app/controllers/var.rb +27 -0
  6. data/app/controllers/vardoc.rb +7 -0
  7. data/app/helpers/cfg_helper.rb +5 -0
  8. data/app/helpers/global_helpers.rb +5 -0
  9. data/app/helpers/var_helper.rb +5 -0
  10. data/app/helpers/vardoc_helper.rb +5 -0
  11. data/app/models/base/attribute.rb +13 -0
  12. data/app/models/base/component.rb +206 -0
  13. data/app/models/base/exec.rb +40 -0
  14. data/app/models/base/registry.rb +4 -0
  15. data/app/models/base/tuple.rb +31 -0
  16. data/app/models/components/linuxhost.rb +125 -0
  17. data/app/models/components/linuxprocess.rb +55 -0
  18. data/app/models/components/mysql.rb +110 -0
  19. data/app/models/components/puppet.rb +20 -0
  20. data/app/views/cfg/index.html.erb +1 -0
  21. data/app/views/exceptions/not_acceptable.html.erb +63 -0
  22. data/app/views/exceptions/not_found.html.erb +47 -0
  23. data/app/views/layout/application.html.erb +12 -0
  24. data/app/views/var/index.json.erb +1 -0
  25. data/app/views/var/index.pp.erb +10 -0
  26. data/app/views/var/index.text.erb +18 -0
  27. data/app/views/vardoc/index.html.erb +1 -0
  28. data/autotest/discover.rb +1 -0
  29. data/autotest/merb.rb +149 -0
  30. data/autotest/merb_rspec.rb +165 -0
  31. data/bin/slashport +130 -0
  32. data/bin/slashportfetch +103 -0
  33. data/config/environments/development.rb +15 -0
  34. data/config/environments/production.rb +10 -0
  35. data/config/environments/rake.rb +11 -0
  36. data/config/environments/staging.rb +10 -0
  37. data/config/environments/test.rb +12 -0
  38. data/config/init.rb +26 -0
  39. data/config/rack.rb +11 -0
  40. data/config/router.rb +41 -0
  41. data/config/test.conf +2 -0
  42. data/doc/rdoc/generators/merb_generator.rb +1362 -0
  43. data/doc/rdoc/generators/template/merb/api_grease.js +640 -0
  44. data/doc/rdoc/generators/template/merb/index.html.erb +37 -0
  45. data/doc/rdoc/generators/template/merb/merb.css +252 -0
  46. data/doc/rdoc/generators/template/merb/merb.rb +351 -0
  47. data/doc/rdoc/generators/template/merb/merb_doc_styles.css +492 -0
  48. data/doc/rdoc/generators/template/merb/prototype.js +2515 -0
  49. data/lib/slashport.rb +93 -0
  50. data/public/favicon.ico +0 -0
  51. data/public/images/merb.jpg +0 -0
  52. data/public/javascripts/application.js +1 -0
  53. data/public/merb.fcgi +22 -0
  54. data/public/robots.txt +5 -0
  55. data/public/stylesheets/master.css +119 -0
  56. data/spec/requests/cfg_spec.rb +7 -0
  57. data/spec/requests/config_spec.rb +7 -0
  58. data/spec/requests/configdoc_spec.rb +7 -0
  59. data/spec/requests/var_spec.rb +7 -0
  60. data/spec/requests/vardoc_spec.rb +7 -0
  61. data/spec/spec.opts +0 -0
  62. data/spec/spec_helper.rb +20 -0
  63. metadata +156 -0
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+
3
+ class SlashPort::Component::LinuxProcess < SlashPort::Component
4
+ def self.add_process(name, &pid_method)
5
+ define_method(name.to_sym) do
6
+ pid = pid_method.call().to_i
7
+ query_process(pid)
8
+ end
9
+
10
+ attribute :name => name,
11
+ :handler => name.to_sym,
12
+ :doc => "Process data for #{name}"
13
+ end
14
+
15
+ def query_process(pid)
16
+ procinfo = ProcessInfo.new(pid)
17
+ limits = procinfo.get_limits
18
+ tuple = SlashPort::Tuple.new
19
+ puts limits.inspect
20
+ tuple.data["max_open_files"] = limits["open files"]
21
+ tuple.data["open_files"] = procinfo.open_files
22
+ return tuple
23
+ end
24
+
25
+ end # class SlashPort::Component
26
+
27
+
28
+ class ProcessInfo
29
+ def initialize(pid)
30
+ @pid = pid
31
+ end
32
+
33
+ def procpath(path)
34
+ return "/proc/#{@pid}/#{path}"
35
+ end
36
+
37
+ def get_limits
38
+ linere = /^Max (.*?) +\S+ +(\S+)(?: +\S+\s*)?$/
39
+ limits = Hash.new
40
+ File.open(procpath("limits")).each do |line|
41
+ line.chomp!
42
+ next if line =~ /^Limit/
43
+ puts line
44
+ match = linere.match(line)
45
+ next if match == nil
46
+ limits[match.captures[0]] = match.captures[1]
47
+ end
48
+ return limits
49
+ end
50
+
51
+ def open_files
52
+ return Dir.glob(procpath("fd/*")).length
53
+ end
54
+
55
+ end
@@ -0,0 +1,110 @@
1
+ require 'rubygems'
2
+ require 'sequel'
3
+
4
+ class SlashPort::Component
5
+ class Mysql < SlashPort::Component
6
+ attr_accessor :host
7
+ attr_accessor :user
8
+ attr_accessor :password
9
+
10
+ attribute :name => "master-status",
11
+ :handler => :MasterStatus,
12
+ :doc => "Shows the master status of this mysql server"
13
+
14
+ attribute :name => "slave-status",
15
+ :handler => :SlaveStatus,
16
+ :doc => "Shows the slave status of this mysql server"
17
+
18
+ attribute :name => "stats",
19
+ :handler => :MysqlStats,
20
+ :doc => "Stats from 'show status' in mysql."
21
+
22
+ attribute :name => "connection",
23
+ :handler => :MysqlOK,
24
+ :doc => "Reports whether we can send queries successfully to mysql."
25
+
26
+ #multiconfig "settings", :ConfigGetVariables, <<-doc
27
+ #Output of 'show variables'
28
+ #doc
29
+
30
+ def initialize
31
+ super
32
+ begin
33
+ @db = Sequel.connect("mysql://slashport@localhost")
34
+ rescue Sequel::AdapterNotFound => e
35
+ puts "Disabling #{self.class.label} component: missing mysql Sequel adapter: #{e.inspect}"
36
+ self.class.disable
37
+ end
38
+ end
39
+
40
+ def MysqlOK
41
+ tuple = SlashPort::Tuple.new
42
+ begin
43
+ # dummy query just to test our connection
44
+ @db["show variables like 'x'"].map
45
+ tuple.data["healthy"] = 1
46
+ rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError
47
+ tuple.data["healthy"] = 0
48
+ end
49
+ return tuple
50
+ end # end MysqlOK
51
+
52
+ def MasterStatus
53
+ data = []
54
+ tuple = SlashPort::Tuple.new
55
+ begin
56
+ result = @db["show master status"].map[0]
57
+ result.each do |key, val|
58
+ tuple.data[key.to_s.downcase] = val
59
+ end
60
+ data << tuple
61
+ rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError
62
+ return nil
63
+ end
64
+ return data
65
+ end # end MasterStatus
66
+
67
+ def SlaveStatus
68
+ tuple = SlashPort::Tuple.new
69
+ begin
70
+ result = @db["show slave status"].map[0]
71
+ ret = Hash.new
72
+ if result == nil
73
+ # this host is not a slave
74
+ tuple.data["is-slave"] = false
75
+ else
76
+ result.each do |key, val|
77
+ tuple.data[key.to_s.downcase] = val
78
+ end
79
+ end
80
+ rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError
81
+ return nil
82
+ end
83
+ return tuple
84
+ end # end MasterStatus
85
+
86
+ def MysqlStats
87
+ tuple = SlashPort::Tuple.new
88
+ begin
89
+ result = @db["show global status"]
90
+ result.map do |row|
91
+ value = row[:Value]
92
+ # use actual value if Float fails.
93
+ tuple.data[row[:Variable_name].downcase] = (Float(value) rescue value)
94
+ end
95
+ rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError
96
+ return nil
97
+ end
98
+ return tuple
99
+ end # end MysqlStats
100
+
101
+ def ConfigGetVariables
102
+ result = @db["show variables"]
103
+ data = Hash.new
104
+ result.map do |row|
105
+ data[row[:Variable_name]] = row[:Value]
106
+ end
107
+ return data
108
+ end # def ConfigGetVariables
109
+ end
110
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+
3
+ class SlashPort::Component
4
+ class Puppet < SlashPort::Component
5
+ attribute :name => "freshness",
6
+ :handler => :freshness,
7
+ :doc => "Freshness according to puppet's localconfig.yaml"
8
+
9
+ def freshness
10
+ begin
11
+ tuple = SlashPort::Tuple.new
12
+ age = Time.now - File.stat("/var/puppet/state/state.yaml").mtime
13
+ tuple.data["freshness"] = age.to_f
14
+ return tuple
15
+ rescue Errno::ENOENT
16
+ return nil
17
+ end
18
+ end # def freshness
19
+ end # class Puppet
20
+ end # class SlashPort::Component
@@ -0,0 +1 @@
1
+ You're in index of the Cfg controller.
@@ -0,0 +1,63 @@
1
+ <div id="container">
2
+ <div id="header-container">
3
+ <img src="/images/merb.jpg" />
4
+ <!-- <h1>Mongrel + Erb</h1> -->
5
+ <h2>pocket rocket web framework</h2>
6
+ <hr />
7
+ </div>
8
+
9
+ <div id="left-container">
10
+ <h3>Exception:</h3>
11
+ <p><%= request.exceptions.first.message %></p>
12
+ </div>
13
+
14
+ <div id="main-container">
15
+ <h3>Why am I seeing this page?</h3>
16
+ <p>Merb couldn't find an appropriate content_type to return,
17
+ based on what you said was available via provides() and
18
+ what the client requested.</p>
19
+
20
+ <h3>How to add a mime-type</h3>
21
+ <pre><code>
22
+ Merb.add_mime_type :pdf, :to_pdf, %w[application/pdf], &quot;Content-Encoding&quot; =&gt; &quot;gzip&quot;
23
+ </code></pre>
24
+ <h3>What this means is:</h3>
25
+ <ul>
26
+ <li>Add a mime-type for :pdf</li>
27
+ <li>Register the method for converting objects to PDF as <code>#to_pdf</code>.</li>
28
+ <li>Register the incoming mime-type "Accept" header as <code>application/pdf</code>.</li>
29
+ <li>Specify a new header for PDF types so it will set <code>Content-Encoding</code> to gzip.</li>
30
+ </ul>
31
+
32
+ <h3>You can then do:</h3>
33
+ <pre><code>
34
+ class Foo &lt; Application
35
+ provides :pdf
36
+ end
37
+ </code></pre>
38
+
39
+ <h3>Where can I find help?</h3>
40
+ <p>If you have any questions or if you can't figure something out, please take a
41
+ look at our <a href="http://merbivore.com/"> project page</a>,
42
+ feel free to come chat at irc.freenode.net, channel #merb,
43
+ or post to <a href="http://groups.google.com/group/merb">merb mailing list</a>
44
+ on Google Groups.</p>
45
+
46
+ <h3>What if I've found a bug?</h3>
47
+ <p>If you want to file a bug or make your own contribution to Merb,
48
+ feel free to register and create a ticket at our
49
+ <a href="http://merb.lighthouseapp.com/">project development page</a>
50
+ on Lighthouse.</p>
51
+
52
+ <h3>How do I edit this page?</h3>
53
+ <p>You can change what people see when this happens by editing <tt>app/views/exceptions/not_acceptable.html.erb</tt>.</p>
54
+
55
+ </div>
56
+
57
+ <div id="footer-container">
58
+ <hr />
59
+ <div class="left"></div>
60
+ <div class="right">&copy; 2008 the merb dev team</div>
61
+ <p>&nbsp;</p>
62
+ </div>
63
+ </div>
@@ -0,0 +1,47 @@
1
+ <div id="container">
2
+ <div id="header-container">
3
+ <img src="/images/merb.jpg" />
4
+ <!-- <h1>Mongrel + Erb</h1> -->
5
+ <h2>pocket rocket web framework</h2>
6
+ <hr />
7
+ </div>
8
+
9
+ <div id="left-container">
10
+ <h3>Exception:</h3>
11
+ <p><%= request.exceptions.first.message %></p>
12
+ </div>
13
+
14
+ <div id="main-container">
15
+ <h3>Welcome to Merb!</h3>
16
+ <p>Merb is a light-weight MVC framework written in Ruby. We hope you enjoy it.</p>
17
+
18
+ <h3>Where can I find help?</h3>
19
+ <p>If you have any questions or if you can't figure something out, please take a
20
+ look at our <a href="http://merbivore.com/"> project page</a>,
21
+ feel free to come chat at irc.freenode.net, channel #merb,
22
+ or post to <a href="http://groups.google.com/group/merb">merb mailing list</a>
23
+ on Google Groups.</p>
24
+
25
+ <h3>What if I've found a bug?</h3>
26
+ <p>If you want to file a bug or make your own contribution to Merb,
27
+ feel free to register and create a ticket at our
28
+ <a href="http://merb.lighthouseapp.com/">project development page</a>
29
+ on Lighthouse.</p>
30
+
31
+ <h3>How do I edit this page?</h3>
32
+ <p>You're seeing this page because you need to edit the following files:
33
+ <ul>
34
+ <li>config/router.rb <strong><em>(recommended)</em></strong></li>
35
+ <li>app/views/exceptions/not_found.html.erb <strong><em>(recommended)</em></strong></li>
36
+ <li>app/views/layout/application.html.erb <strong><em>(change this layout)</em></strong></li>
37
+ </ul>
38
+ </p>
39
+ </div>
40
+
41
+ <div id="footer-container">
42
+ <hr />
43
+ <div class="left"></div>
44
+ <div class="right">&copy; 2008 the merb dev team</div>
45
+ <p>&nbsp;</p>
46
+ </div>
47
+ </div>
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
3
+ <head>
4
+ <title>Fresh Merb App</title>
5
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6
+ <link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8" />
7
+ </head>
8
+ <body>
9
+ <%#= message[:notice] %>
10
+ <%= catch_content :for_layout %>
11
+ </body>
12
+ </html>
@@ -0,0 +1 @@
1
+ <%= @attributes.to_json %>
@@ -0,0 +1,10 @@
1
+ <%
2
+ require "pp"
3
+ require "stringio"
4
+
5
+ sio = StringIO.new
6
+ PP.pp(@attributes, sio)
7
+ sio.rewind
8
+ output = sio.read
9
+ %>
10
+ <%= output %>
@@ -0,0 +1,18 @@
1
+ <%
2
+ data = []
3
+ @attributes.each do |tuple|
4
+ # component, section - first
5
+ keys = ["component", "section"]
6
+ # the other keys next, sorted by key
7
+ keys += tuple.labels.keys.select { |k| !keys.include?(k) }.sort
8
+
9
+ labelstr = keys.collect { |k| "#{k}=#{tuple.labels[k]}" }.join(",")
10
+
11
+ # for each datum in our tuple, output one line.
12
+ # This gives us "label1=value1,label2=...,data1=value1" for
13
+ tuple.data.each do |key,value|
14
+ data << "#{labelstr},#{key}=#{value}"
15
+ end
16
+ end
17
+ -%>
18
+ <%= data.sort.join("\n") %>
@@ -0,0 +1 @@
1
+ You're in index of the Vardoc controller.
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "merb" }
@@ -0,0 +1,149 @@
1
+ # Adapted from Autotest::Rails
2
+ require 'autotest'
3
+
4
+ class Autotest::Merb < Autotest
5
+
6
+ # +model_tests_dir+:: the directory to find model-centric tests
7
+ # +controller_tests_dir+:: the directory to find controller-centric tests
8
+ # +view_tests_dir+:: the directory to find view-centric tests
9
+ # +fixtures_dir+:: the directory to find fixtures in
10
+ attr_accessor :model_tests_dir, :controller_tests_dir, :view_tests_dir, :fixtures_dir
11
+
12
+ def initialize
13
+ super
14
+
15
+ initialize_test_layout
16
+
17
+ # Ignore any happenings in these directories
18
+ add_exception %r%^\./(?:doc|log|public|tmp)%
19
+
20
+ # Ignore any mappings that Autotest may have already set up
21
+ clear_mappings
22
+
23
+ # Any changes to a file in the root of the 'lib' directory will run any
24
+ # model test with a corresponding name.
25
+ add_mapping %r%^lib\/.*\.rb% do |filename, _|
26
+ files_matching Regexp.new(["^#{model_test_for(filename)}$"])
27
+ end
28
+
29
+ # Any changes to a fixture will run corresponding view, controller and
30
+ # model tests
31
+ add_mapping %r%^#{fixtures_dir}/(.*)s.yml% do |_, m|
32
+ [
33
+ model_test_for(m[1]),
34
+ controller_test_for(m[1]),
35
+ view_test_for(m[1])
36
+ ]
37
+ end
38
+
39
+ # Any change to a test or test will cause it to be run
40
+ add_mapping %r%^test/(unit|models|integration|controllers|views|functional)/.*rb$% do |filename, _|
41
+ filename
42
+ end
43
+
44
+ # Any change to a model will cause it's corresponding test to be run
45
+ add_mapping %r%^app/models/(.*)\.rb$% do |_, m|
46
+ model_test_for(m[1])
47
+ end
48
+
49
+ # Any change to the global helper will result in all view and controller
50
+ # tests being run
51
+ add_mapping %r%^app/helpers/global_helpers.rb% do
52
+ files_matching %r%^test/(views|functional|controllers)/.*_test\.rb$%
53
+ end
54
+
55
+ # Any change to a helper will run it's corresponding view and controller
56
+ # tests, unless the helper is the global helper. Changes to the global
57
+ # helper run all view and controller tests.
58
+ add_mapping %r%^app/helpers/(.*)_helper(s)?.rb% do |_, m|
59
+ if m[1] == "global" then
60
+ files_matching %r%^test/(views|functional|controllers)/.*_test\.rb$%
61
+ else
62
+ [
63
+ view_test_for(m[1]),
64
+ controller_test_for(m[1])
65
+ ]
66
+ end
67
+ end
68
+
69
+ # Changes to views result in their corresponding view and controller test
70
+ # being run
71
+ add_mapping %r%^app/views/(.*)/% do |_, m|
72
+ [
73
+ view_test_for(m[1]),
74
+ controller_test_for(m[1])
75
+ ]
76
+ end
77
+
78
+ # Changes to a controller result in its corresponding test being run. If
79
+ # the controller is the exception or application controller, all
80
+ # controller tests are run.
81
+ add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
82
+ if ["application", "exception"].include?(m[1])
83
+ files_matching %r%^test/(controllers|views|functional)/.*_test\.rb$%
84
+ else
85
+ controller_test_for(m[1])
86
+ end
87
+ end
88
+
89
+ # If a change is made to the router, run all controller and view tests
90
+ add_mapping %r%^config/router.rb$% do # FIX
91
+ files_matching %r%^test/(controllers|views|functional)/.*_test\.rb$%
92
+ end
93
+
94
+ # If any of the major files governing the environment are altered, run
95
+ # everything
96
+ add_mapping %r%^test/test_helper.rb|config/(init|rack|environments/test.rb|database.yml)% do # FIX
97
+ files_matching %r%^test/(unit|models|controllers|views|functional)/.*_test\.rb$%
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ # Determines the paths we can expect tests or specs to reside, as well as
104
+ # corresponding fixtures.
105
+ def initialize_test_layout
106
+ self.model_tests_dir = "test/unit"
107
+ self.controller_tests_dir = "test/functional"
108
+ self.view_tests_dir = "test/views"
109
+ self.fixtures_dir = "test/fixtures"
110
+ end
111
+
112
+ # Given a filename and the test type, this method will return the
113
+ # corresponding test's or spec's name.
114
+ #
115
+ # ==== Arguments
116
+ # +filename+<String>:: the file name of the model, view, or controller
117
+ # +kind_of_test+<Symbol>:: the type of test we that we should run
118
+ #
119
+ # ==== Returns
120
+ # String:: the name of the corresponding test or spec
121
+ #
122
+ # ==== Example
123
+ #
124
+ # > test_for("user", :model)
125
+ # => "user_test.rb"
126
+ # > test_for("login", :controller)
127
+ # => "login_controller_test.rb"
128
+ # > test_for("form", :view)
129
+ # => "form_view_spec.rb" # If you're running a RSpec-like suite
130
+ def test_for(filename, kind_of_test)
131
+ name = [filename]
132
+ name << kind_of_test.to_s if kind_of_test == :view
133
+ name << "test"
134
+ return name.join("_") + ".rb"
135
+ end
136
+
137
+ def model_test_for(filename)
138
+ [model_tests_dir, test_for(filename, :model)].join("/")
139
+ end
140
+
141
+ def controller_test_for(filename)
142
+ [controller_tests_dir, test_for(filename, :controller)].join("/")
143
+ end
144
+
145
+ def view_test_for(filename)
146
+ [view_tests_dir, test_for(filename, :view)].join("/")
147
+ end
148
+
149
+ end