rackamole 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- require 'pony'
1
+ require 'mail'
2
2
  require 'erubis'
3
3
 
4
4
  module Rackamole::Alert
@@ -22,22 +22,21 @@ module Rackamole::Alert
22
22
  # args :: The gathered information from the mole.
23
23
  #
24
24
  def self.deliver_alert( logger, options, args )
25
- @options = options
26
- opts = options[:email]
27
- params = opts.clone
28
- params[:to] = opts[:to].join( ", " )
29
- params[:subject] = "RackAmole <#{alert_type( args )}> #{request_time?( args )} on #{args[:app_name]}.#{args[:host]} for user #{args[:user_name]}"
25
+ @options = options
26
+ @args = args
27
+ tmpl = File.join( template_root, %w[alert.erb] )
28
+ template = Erubis::Eruby.new( IO.read( tmpl ), :trim => true )
29
+ body = template.result( binding )
30
+ subject = "Rackamole <#{alert_type( args )}> #{request_time?( args )}on #{args[:app_name]}.#{args[:host]} for user #{args[:user_name]}"
30
31
 
31
- @args = args
32
-
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
- output
32
+ mail = Mail.new do
33
+ from options[:email][:from]
34
+ to options[:email][:to]
35
+ subject subject
36
+ body body
37
+ end
38
+ mail.deliver!
39
+ mail
41
40
  rescue => boom
42
41
  boom.backtrace.each { |l| logger.error l }
43
42
  logger.error( "Rackamole email alert failed with error `#{boom}" )
@@ -45,7 +44,6 @@ module Rackamole::Alert
45
44
 
46
45
  def self.section( title )
47
46
  buff = []
48
- # buff << "-"*80
49
47
  buff << "-"*40
50
48
  buff << "o #{title.capitalize}\n"
51
49
  buff << self.send( title.downcase )
@@ -103,7 +101,7 @@ module Rackamole::Alert
103
101
  when Rackamole.perf
104
102
  buff << "#{spew( :request_time )}/#{@options[:perf_threshold]}"
105
103
  end
106
- buff << spew( :url ) << spew( :path ) << spew( :status )
104
+ buff << spew( :user_name) << spew( :url ) << spew( :path ) << spew( :status )
107
105
  buff << spew( :method ) << spew( :request_time ) << spew( :ip )
108
106
  buff.join( "\n" )
109
107
  end
@@ -116,7 +114,7 @@ module Rackamole::Alert
116
114
 
117
115
  # Dump request time if any...
118
116
  def self.request_time?( args )
119
- args[:type] == Rackamole.perf ? ("%5.2f" % args[:request_time] ) : ''
117
+ args[:type] == Rackamole.perf ? ("%5.2f " % args[:request_time] ) : ''
120
118
  end
121
119
 
122
120
  # Identify the type of alert...
@@ -130,22 +128,5 @@ module Rackamole::Alert
130
128
  "Fault"
131
129
  end
132
130
  end
133
-
134
- # # Dump args...
135
- # def self.dump( buff, env, level=0 )
136
- # env.each_pair do |k,value|
137
- # if value.respond_to?(:each_pair)
138
- # buff << "%s %-#{40-level}s" % [' '*level,k]
139
- # dump( buff, env[k], level+1 )
140
- # elsif value.instance_of?(Array)
141
- # buff << "%s %-#{40-level}s" % [' '*level,k]
142
- # value.each do |v|
143
- # buff << "%s %-#{40-(level+1)}s" % [' '*(level+1),v]
144
- # end
145
- # else
146
- # buff << "%s %-#{40-level}s %s" % [ ' '*level, k, value.inspect ]
147
- # end
148
- # end
149
- # end
150
131
  end
151
132
  end
@@ -169,7 +169,7 @@ module Rack
169
169
  unless duplicated?( env, attrs )
170
170
  # send email alert ?
171
171
  if alertable?( :email, attrs[:type] )
172
- logger.debug ">>> Sending out email on mole type #{attrs[:type]} to #{options[:email][:to].join( ", ")}"
172
+ logger.debug ">>> Sending out email on mole type #{attrs[:type]} from #{options[:email][:from]} to #{options[:email][:to].join( ", ")}"
173
173
  Rackamole::Alert::Emole.deliver_alert( logger, options, attrs )
174
174
  end
175
175
 
@@ -15,7 +15,18 @@ module Rackamole
15
15
  #
16
16
  # Setup rackamole to use the mongodb store as follows:
17
17
  #
18
- # config.middleware.use Rack::Mole, { :store => Rackamole::Store::MongoDb.new }
18
+ # config.middleware.use Rack::Mole, {
19
+ # :store => Rackamole::Store::MongoDb.new(
20
+ # :db_name => 'mole_blee_development_mdb',
21
+ # :username => 'fernand',
22
+ # :password => 'letmein',
23
+ # )
24
+ # }
25
+ #
26
+ # === NOTE
27
+ #
28
+ # To use in conjunction with Wackamole your db_name must follow
29
+ # the convention "mole_[app_name]_[environment]_mdb".
19
30
  #
20
31
  # === Options
21
32
  #
data/lib/rackamole.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Rackamole
2
2
 
3
3
  # :stopdoc:
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.4'
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # :startdoc:
@@ -6,12 +6,10 @@ describe Rackamole::Alert::Emole do
6
6
  @from = "fernand"
7
7
  @to = %w[fernand bobo blee]
8
8
 
9
- @expected = TMail::Mail.new
10
- @expected.set_content_type 'text', 'plain', { 'charset' => 'utf-8' }
11
- @expected.mime_version = '1.0'
12
- @expected.from = @from
13
- @expected.to = @to
14
-
9
+ Mail.defaults do
10
+ delivery_method :test
11
+ end
12
+
15
13
  @options = { :email => { :from => @from, :to => @to }, :perf_threshold => 10 }
16
14
 
17
15
  @args = OrderedHash.new
@@ -56,29 +54,33 @@ describe Rackamole::Alert::Emole do
56
54
  describe "#alert" do
57
55
 
58
56
  it "should send a feature email correctly" do
59
- # @expected.subject = "[M()le] (Feature) -Test@Fred- for user Fernand"
60
- @expected.body = feature_body
61
- # puts Rackamole::Alert::Emole.deliver_alert( nil, @options, @args )
62
- Rackamole::Alert::Emole.deliver_alert( nil, @options, @args ).should == @expected.body_port.to_s
57
+ alert = Rackamole::Alert::Emole.deliver_alert( nil, @options, @args )
58
+ alert.body.should == feature_body
59
+ alert.subject.should == "Rackamole <Feature> on Test.Fred for user Fernand"
60
+ alert.from.should == ["fernand"]
61
+ alert.to.should == ["fernand", 'bobo', 'blee']
63
62
  end
64
63
 
65
64
  it "should send a perf email correctly" do
66
65
  @args[:type] = Rackamole.perf
67
66
  @args[:request_time] = 15.2
68
- # @expected.subject = "[M()le] (Performance:10.0) -Test@Fred- for user Fernand"
69
- @expected.body = perf_body
70
- # puts Rackamole::Alert::Emole.deliver_alert( nil, @options, @args )
71
- Rackamole::Alert::Emole.deliver_alert( nil, @options, @args ).should == @expected.body_port.to_s
67
+
68
+ alert = Rackamole::Alert::Emole.deliver_alert( nil, @options, @args )
69
+ alert.body.to_s.should == perf_body
70
+ alert.subject.should == "Rackamole <Performance> 15.20 on Test.Fred for user Fernand"
71
+ alert.from.should == ["fernand"]
72
+ alert.to.should == ["fernand", 'bobo', 'blee']
72
73
  end
73
74
 
74
75
  it "should send a fault email correctly" do
75
76
  @args[:type] = Rackamole.fault
76
77
  @args[:fault] = 'Oh Snap!'
77
78
  @args[:stack] = ['fred', 'blee']
78
- # @expected.subject = "[M()le] (Fault) -Test@Fred- for user Fernand"
79
- @expected.body = fault_body
80
- # puts Rackamole::Alert::Emole.deliver_alert( nil, @options, @args )
81
- Rackamole::Alert::Emole.deliver_alert( nil, @options, @args ).should == @expected.body_port.to_s
79
+ alert = Rackamole::Alert::Emole.deliver_alert( nil, @options, @args )
80
+ alert.body.to_s.should == fault_body
81
+ alert.subject.should == "Rackamole <Fault> on Test.Fred for user Fernand"
82
+ alert.from.should == ["fernand"]
83
+ alert.to.should == ["fernand", 'bobo', 'blee']
82
84
  end
83
85
  end
84
86
 
@@ -89,6 +91,7 @@ Feature alert on application Test on host Fred
89
91
  ----------------------------------------
90
92
  o What
91
93
 
94
+ user_name: Fernand
92
95
  url: http://bumblebeetuna/fred/blee
93
96
  path: /fred/blee
94
97
  status: 200
@@ -158,6 +161,7 @@ Performance alert on application Test on host Fred
158
161
  o What
159
162
 
160
163
  request_time: 15.2/10
164
+ user_name: Fernand
161
165
  url: http://bumblebeetuna/fred/blee
162
166
  path: /fred/blee
163
167
  status: 200
@@ -231,6 +235,7 @@ o What
231
235
  : fred
232
236
  : blee
233
237
 
238
+ user_name: Fernand
234
239
  url: http://bumblebeetuna/fred/blee
235
240
  path: /fred/blee
236
241
  status: 200
@@ -185,7 +185,7 @@ describe Rackamole::Store::MongoDb do
185
185
  :username => 'fred',
186
186
  :password => 'hoy',
187
187
  :logger => Rackamole::Logger.new( :file_name => $stdout, :log_level => 'info' ) )
188
- }.should raise_error( /Authentication failed/ )
188
+ }.should raise_error( /Failed to authenticate user 'fred'/ )
189
189
  end
190
190
  end
191
191
  end
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.3.3
4
+ version: 0.3.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-02-27 00:00:00 -07:00
12
+ date: 2010-03-17 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency