Object
Send an email notification for particular moled feature. An email will be sent based on the configuration :email defined on the Rack::Mole component. This option must specify the to and from addresses and the conditions that will trigger the email defined by alert_on for the type of moled features to track via email. The notification will be sent via Mail, so you will need to make sure it is properly configured for your domain. NOTE: This is just a notification mechanism. All moled event will be either logged or persisted in the db regardless.
| options | Mole options. The :email key minimaly contains :from for the from address. Must be a valid domain. |
:: And a :to, n array of email addresses for recipients to be notified.
| args | The gathered information from the mole. |
# File lib/rackamole/alert/emole.rb, line 24
24: def self.deliver_alert( logger, options, args )
25: @options = options
26: @args = args
27: tmpl = File.join( template_root, ]alert.erb] )
28: template = Erubis::Eruby.new( IO.read( tmpl ), :trim => true )
29: body = template.result( binding )
30: timing = request_time( args ) if args[:type] == Rackamole.perf
31: subject = "Rackamole <#{alert_type( args )}>#{timing ? " #{timing} " : ' '}on #{args[:app_name]}.#{args[:host]} for user #{args[:user_name]}"
32:
33: mail = Mail.new do
34: from options[:email][:from]
35: to options[:email][:to]
36: subject subject
37: body body
38: end
39: mail.deliver!
40: mail
41: rescue => boom
42: logger.error( "Rackamole email alert failed with error `#{boom}" )
43: boom.backtrace.each { |l| logger.error l }
44: end
# File lib/rackamole/alert/emole.rb, line 88
88: def self._spew( buff, sep, indent, key, value, silent )
89: if value.is_a?( Hash )
90: buff << "#{indent}#{humanize( key )}:" unless silent
91: value.each_pair{ |k,v| _spew( buff, sep, indent+" ", k, v, false ) }
92: elsif value.is_a?( Array )
93: buff << "#{indent}#{humanize( key )}:" unless silent
94: value.each { |s| _spew( buff, sep, indent+" ", '', s, false ) }
95: else
96: buff << "#{indent}#{humanize( key )}: #{value}"
97: end
98: end
Identify the type of alert...
# File lib/rackamole/alert/emole.rb, line 129
129: def self.alert_type( args )
130: case args[:type]
131: when Rackamole.feature
132: "Feature"
133: when Rackamole.perf
134: "Performance"
135: when Rackamole.fault
136: "Fault"
137: end
138: end
# File lib/rackamole/alert/emole.rb, line 58
58: def self.args
59: @args
60: end
# File lib/rackamole/alert/emole.rb, line 119
119: def self.browser() [ spew( :browser, true ) ]; end
# File lib/rackamole/alert/emole.rb, line 116
116: def self.client() [ spew( :machine, true ) ]; end
# File lib/rackamole/alert/emole.rb, line 66
66: def self.feature_type
67: case args[:type]
68: when Rackamole.feature
69: "Feature"
70: when Rackamole.perf
71: "Performance"
72: when Rackamole.fault
73: "Fault"
74: end
75: end
# File lib/rackamole/alert/emole.rb, line 120
120: def self.headers() [ spew( :headers, true ) ]; end
# File lib/rackamole/alert/emole.rb, line 62
62: def self.humanize( key )
63: key
64: end
# File lib/rackamole/alert/emole.rb, line 117
117: def self.params() [ spew( :params, true ) ]; end
Dump request time if any...
# File lib/rackamole/alert/emole.rb, line 123
123: def self.request_time( args )
124: return '' unless args[:request_time]
125: "%1.2f" % args[:request_time]
126: end
# File lib/rackamole/alert/emole.rb, line 115
115: def self.server() [ spew( :host ), spew( :software ), spew( :ruby_version ) ]; end
# File lib/rackamole/alert/emole.rb, line 118
118: def self.session() [ spew( :session, true ) ]; end
Format args and spit out into buffer
# File lib/rackamole/alert/emole.rb, line 78
78: def self.spew( key, silent=false )
79: buff = []
80: value = args[key]
81:
82: value = request_time( args ) if key == :request_time
83:
84: _spew( buff, '--', (silent ? '' : ' '), key, value, silent )
85: buff.join( "\n" )
86: end
What just happened?
# File lib/rackamole/alert/emole.rb, line 101
101: def self.what
102: buff = []
103: case args[:type]
104: when Rackamole.fault
105: buff << spew( :fault ) << spew( :stack ) + "\n"
106: when Rackamole.perf
107: buff << "#{spew( :request_time )} [#{@options[:perf_threshold]}]"
108: end
109: buff << spew( :user_name) << spew( :url ) << spew( :path ) << spew( :status )
110: buff << spew( :method )
111: buff << spew( :request_time ) unless args[:type] == Rackamole.perf
112: buff << spew( :ip )
113: buff.join( "\n" )
114: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.