rackamole 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +4 -1
- data/README.rdoc +2 -1
- data/Rakefile +2 -1
- data/a.rb +18 -0
- data/lib/rackamole.rb +1 -1
- data/lib/rackamole/alert/emole.rb +29 -18
- data/lib/rackamole/alert/templates/alert.erb +9 -0
- data/lib/rackamole/alert/twitt.rb +4 -3
- data/lib/rackamole/mole.rb +4 -3
- data/spec/rackamole/alert/emole_spec.rb +6 -6
- data/spec/rackamole/mole_spec.rb +7 -6
- data/spec/spec_helper.rb +3 -0
- metadata +17 -6
- data/lib/rackamole/alert/templates/rackamole/alert/emole/alert.erb +0 -9
data/HISTORY
CHANGED
@@ -19,4 +19,7 @@
|
|
19
19
|
0.2.3
|
20
20
|
* Bug fixes
|
21
21
|
* Fixed issue where session or param key falls under the format a.b.c which causes
|
22
|
-
validation problems in mongoDB. Thanks Rafael!
|
22
|
+
validation problems in mongoDB. Thanks Rafael!
|
23
|
+
|
24
|
+
0.2.4
|
25
|
+
* Breaking off action_mailer dependencies. Now leveraging Pony for sending out email alerts.
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
data/a.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pony'
|
3
|
+
|
4
|
+
# :to => ['fernand.galiana@gmail.com', 'fernand@collectiveintellect.com'],
|
5
|
+
|
6
|
+
result = Pony.mail(
|
7
|
+
:from => 'fernand@collectiveintellect.com',
|
8
|
+
:to => 'fernand.galiana@gmail.com, fernand@collectiveintellect.com',
|
9
|
+
:subject => 'test4',
|
10
|
+
:body => "Hello World",
|
11
|
+
:via => :smtp,
|
12
|
+
:smtp => { :host => "exchange@collectiveintellect.com", :port => 25, : }
|
13
|
+
# :user => 'fernand@collectiveintellect.com',
|
14
|
+
# :password => '$mistral1',
|
15
|
+
# :auth => :plain
|
16
|
+
)
|
17
|
+
|
18
|
+
puts result.inspect
|
data/lib/rackamole.rb
CHANGED
@@ -1,45 +1,56 @@
|
|
1
|
-
require '
|
1
|
+
require 'pony'
|
2
|
+
require 'erubis'
|
2
3
|
|
3
4
|
module Rackamole::Alert
|
4
|
-
class Emole
|
5
|
-
|
5
|
+
class Emole
|
6
|
+
|
7
|
+
# retrieves erb template dir
|
8
|
+
def self.template_root() @template_root ||= File.join( File.dirname(__FILE__), %w[templates] ); end
|
6
9
|
|
7
10
|
# Send an email notification for particular moled feature. An email will
|
8
11
|
# be sent based on the two configuration :emails and :mail_on defined on the
|
9
12
|
# Rack::Mole component. These specify the to and from addresses and the conditions
|
10
13
|
# that will trigger the email, currently :enabled and :features for the type of
|
11
|
-
# moled features to track via email. The notification will be sent via
|
14
|
+
# moled features to track via email. The notification will be sent via Pony,
|
12
15
|
# so you will need to make sure it is properly configured for your domain.
|
13
16
|
# NOTE: This is just a notification mechanism. All moled event will be either logged
|
14
17
|
# or persisted in the db regardless.
|
15
18
|
#
|
16
19
|
# === Parameters:
|
17
|
-
#
|
18
|
-
#
|
20
|
+
# options :: Hash minimaly containing :from for the from address. Must be a valid domain.
|
21
|
+
# :: And a :to, n array of email addresses for recipients to be notified.
|
19
22
|
# args :: The gathered information from the mole.
|
20
23
|
#
|
21
|
-
def
|
22
|
-
|
24
|
+
def self.deliver_alert( options, args )
|
25
|
+
params = options.clone
|
26
|
+
params[:to] = options[:to].join( ", " )
|
27
|
+
params[:subject] = "[M()le] (#{alert_type( args )}#{request_time?( args )}) -#{args[:app_name]}@#{args[:host]}- for user #{args[:user_name]}"
|
23
28
|
|
24
|
-
|
29
|
+
content = []
|
30
|
+
dump( content, args, 0 )
|
31
|
+
content = content.join( "\n" )
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
tmpl = File.join( template_root, %w[alert.erb] )
|
34
|
+
template = Erubis::Eruby.new( IO.read( tmpl ), :trim => true )
|
35
|
+
|
36
|
+
output = template.result( binding )
|
37
|
+
params[:body] = output
|
38
|
+
|
39
|
+
Pony.mail( params )
|
40
|
+
|
41
|
+
output
|
31
42
|
end
|
32
|
-
|
43
|
+
|
33
44
|
# =========================================================================
|
34
45
|
private
|
35
46
|
|
36
47
|
# Dump request time if any...
|
37
|
-
def request_time?( args )
|
48
|
+
def self.request_time?( args )
|
38
49
|
args[:type] == Rackamole.perf ? ":#{args[:request_time]}" : ''
|
39
50
|
end
|
40
51
|
|
41
52
|
# Identify the type of alert...
|
42
|
-
def alert_type( args )
|
53
|
+
def self.alert_type( args )
|
43
54
|
case args[:type]
|
44
55
|
when Rackamole.feature : "Feature"
|
45
56
|
when Rackamole.perf : "Performance"
|
@@ -48,7 +59,7 @@ module Rackamole::Alert
|
|
48
59
|
end
|
49
60
|
|
50
61
|
# Dump args...
|
51
|
-
def dump( buff, env, level=0 )
|
62
|
+
def self.dump( buff, env, level=0 )
|
52
63
|
env.each_pair do |k,value|
|
53
64
|
if value.respond_to?(:each_pair)
|
54
65
|
buff << "%s %-#{40-level}s" % [' '*level,k]
|
@@ -83,11 +83,12 @@ module Rackamole::Alert
|
|
83
83
|
("%4.2f" % time).to_f
|
84
84
|
end
|
85
85
|
|
86
|
-
# Truncate for twitt max size
|
86
|
+
# Truncate for twitt max size
|
87
|
+
# BOZO !! This will be hosed if not 1.9 for multibyte chars
|
87
88
|
def truncate(text, length = 140, truncate_string = "...")
|
88
89
|
return "" if text.nil?
|
89
|
-
l = length - truncate_string.
|
90
|
-
text.
|
90
|
+
l = length - truncate_string.size
|
91
|
+
text.size > length ? (text[0...l] + truncate_string).to_s : text
|
91
92
|
end
|
92
93
|
end
|
93
94
|
end
|
data/lib/rackamole/mole.rb
CHANGED
@@ -53,8 +53,9 @@ module Rack
|
|
53
53
|
# ==== BOZO! currently there is not support for throttling or monitoring these alerts.
|
54
54
|
# ==
|
55
55
|
# :email :: The mole can be configured to send out emails bases on interesting mole features.
|
56
|
-
# This feature uses
|
57
|
-
# and :alert_on options to indicate which mole type your wish to be alerted on.
|
56
|
+
# This feature uses Pony to send out the email. You must specify a hash with the following keys :from, :to
|
57
|
+
# and :alert_on options to indicate which mole type your wish to be alerted on.
|
58
|
+
# See Pony docs for custom options for your emails
|
58
59
|
# ==
|
59
60
|
# :email => { :from => 'fred@acme.com', :to => ['blee@acme.com', 'doh@acme.com'], :alert_on => [Rackamole.perf, Rackamole.fault] }
|
60
61
|
# ==
|
@@ -153,7 +154,7 @@ module Rack
|
|
153
154
|
# send email alert ?
|
154
155
|
if alertable?( :email, attrs[:type] )
|
155
156
|
logger.debug ">>> Sending out email on mole type #{attrs[:type]} to #{options[:email][:to].join( ", ")}"
|
156
|
-
Rackamole::Alert::Emole.deliver_alert( options[:email]
|
157
|
+
Rackamole::Alert::Emole.deliver_alert( options[:email], attrs )
|
157
158
|
end
|
158
159
|
|
159
160
|
# send twitter alert ?
|
@@ -22,17 +22,17 @@ describe Rackamole::Alert::Emole do
|
|
22
22
|
describe "#alert" do
|
23
23
|
|
24
24
|
it "should send a feature email correctly" do
|
25
|
-
@expected.subject = "[M()le] (Feature) -Test@Fred- for user Fernand"
|
25
|
+
# @expected.subject = "[M()le] (Feature) -Test@Fred- for user Fernand"
|
26
26
|
@expected.body = feature_body
|
27
|
-
Rackamole::Alert::Emole.
|
27
|
+
Rackamole::Alert::Emole.deliver_alert( {:from => @from, :to => @to}, @args ).should == @expected.body_port.to_s
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should send a perf email correctly" do
|
31
31
|
@args[:type] = Rackamole.perf
|
32
32
|
@args[:request_time] = 10.0
|
33
|
-
@expected.subject = "[M()le] (Performance:10.0) -Test@Fred- for user Fernand"
|
33
|
+
# @expected.subject = "[M()le] (Performance:10.0) -Test@Fred- for user Fernand"
|
34
34
|
@expected.body = perf_body
|
35
|
-
Rackamole::Alert::Emole.
|
35
|
+
Rackamole::Alert::Emole.deliver_alert( {:from => @from, :to => @to }, @args ).should == @expected.body_port.to_s
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should send a fault email correctly" do
|
@@ -40,9 +40,9 @@ describe Rackamole::Alert::Emole do
|
|
40
40
|
@args[:fault] = 'Oh Snap!'
|
41
41
|
@args[:stack] = ['fred', 'blee']
|
42
42
|
@args[:params] = { :id => 10 }
|
43
|
-
@expected.subject = "[M()le] (Fault) -Test@Fred- for user Fernand"
|
43
|
+
# @expected.subject = "[M()le] (Fault) -Test@Fred- for user Fernand"
|
44
44
|
@expected.body = fault_body
|
45
|
-
Rackamole::Alert::Emole.
|
45
|
+
Rackamole::Alert::Emole.deliver_alert( { :from => @from, :to => @to }, @args ).should == @expected.body_port.to_s
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
data/spec/rackamole/mole_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
+
require 'action_controller'
|
2
3
|
|
3
4
|
describe Rack::Mole do
|
4
5
|
include Rack::Test::Methods
|
@@ -65,7 +66,7 @@ describe Rack::Mole do
|
|
65
66
|
get "/", nil, @test_env
|
66
67
|
rescue
|
67
68
|
last_request.env['mole.stash'].should_not be_nil
|
68
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
69
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" )
|
69
70
|
fault.should_not be_nil
|
70
71
|
fault.count.should == 1
|
71
72
|
end
|
@@ -78,7 +79,7 @@ describe Rack::Mole do
|
|
78
79
|
get "/", nil, env
|
79
80
|
rescue
|
80
81
|
last_request.env['mole.stash'].should_not be_nil
|
81
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
82
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" )
|
82
83
|
fault.should_not be_nil
|
83
84
|
fault.count.should == i+1
|
84
85
|
env = last_request.env
|
@@ -92,9 +93,9 @@ describe Rack::Mole do
|
|
92
93
|
begin
|
93
94
|
env['PATH_INFO'] = "/#{i}"
|
94
95
|
get "/#{i}", nil, env
|
95
|
-
rescue
|
96
|
+
rescue => boom
|
96
97
|
last_request.env['mole.stash'].should_not be_nil
|
97
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
98
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" )
|
98
99
|
fault.should_not be_nil
|
99
100
|
fault.count.should == i+1
|
100
101
|
env = last_request.env
|
@@ -155,7 +156,7 @@ describe Rack::Mole do
|
|
155
156
|
rescue
|
156
157
|
@test_store.mole_result[:stack].should have(4).items
|
157
158
|
last_request.env['mole.stash'].should_not be_nil
|
158
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
159
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" )
|
159
160
|
fault.should_not be_nil
|
160
161
|
fault.count.should == 1
|
161
162
|
end
|
@@ -194,7 +195,7 @@ describe Rack::Mole do
|
|
194
195
|
@test_store.mole_result[:stack].should have(4).items
|
195
196
|
@test_store.mole_result[:fault].should == 'Oh snap!'
|
196
197
|
last_request.env['mole.stash'].should_not be_nil
|
197
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
198
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:190" )
|
198
199
|
fault.should_not be_nil
|
199
200
|
fault.count.should == 1
|
200
201
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rackamole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernand Galiana
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-09 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -73,14 +73,24 @@ dependencies:
|
|
73
73
|
version: 0.3.0
|
74
74
|
version:
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: erubis
|
77
77
|
type: :runtime
|
78
78
|
version_requirement:
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: 2.
|
83
|
+
version: 2.6.0
|
84
|
+
version:
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: pony
|
87
|
+
type: :runtime
|
88
|
+
version_requirement:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0.6"
|
84
94
|
version:
|
85
95
|
- !ruby/object:Gem::Dependency
|
86
96
|
name: bones
|
@@ -111,13 +121,14 @@ extensions: []
|
|
111
121
|
extra_rdoc_files:
|
112
122
|
- README.rdoc
|
113
123
|
- aaa.txt
|
114
|
-
- lib/rackamole/alert/templates/
|
124
|
+
- lib/rackamole/alert/templates/alert.erb
|
115
125
|
- samples/rails/moled/public/robots.txt
|
116
126
|
files:
|
117
127
|
- ...
|
118
128
|
- HISTORY
|
119
129
|
- README.rdoc
|
120
130
|
- Rakefile
|
131
|
+
- a.rb
|
121
132
|
- aaa.txt
|
122
133
|
- images/mole_logo.png
|
123
134
|
- images/mole_logo.psd
|
@@ -125,7 +136,7 @@ files:
|
|
125
136
|
- images/mole_logo_small.psd
|
126
137
|
- lib/rackamole.rb
|
127
138
|
- lib/rackamole/alert/emole.rb
|
128
|
-
- lib/rackamole/alert/templates/
|
139
|
+
- lib/rackamole/alert/templates/alert.erb
|
129
140
|
- lib/rackamole/alert/twitt.rb
|
130
141
|
- lib/rackamole/interceptor.rb
|
131
142
|
- lib/rackamole/logger.rb
|