lib/rackamole/alert/emole.rb in rackamole-0.3.5 vs lib/rackamole/alert/emole.rb in rackamole-0.3.6
- old
+ new
@@ -25,23 +25,24 @@
@options = options
@args = args
tmpl = File.join( template_root, %w[alert.erb] )
template = Erubis::Eruby.new( IO.read( tmpl ), :trim => true )
body = template.result( binding )
- subject = "Rackamole <#{alert_type( args )}> #{request_time?( args )}on #{args[:app_name]}.#{args[:host]} for user #{args[:user_name]}"
+ timing = request_time( args ) if args[:type] == Rackamole.perf
+ subject = "Rackamole <#{alert_type( args )}>#{timing ? " #{timing} " : ' '}on #{args[:app_name]}.#{args[:host]} for user #{args[:user_name]}"
mail = Mail.new do
from options[:email][:from]
to options[:email][:to]
subject subject
body body
end
mail.deliver!
mail
- rescue => boom
+ rescue => boom
+ logger.error( "Rackamole email alert failed with error `#{boom}" )
boom.backtrace.each { |l| logger.error l }
- logger.error( "Rackamole email alert failed with error `#{boom}" )
end
def self.section( title )
buff = []
buff << "-"*40
@@ -76,12 +77,12 @@
# Format args and spit out into buffer
def self.spew( key, silent=false )
buff = []
value = args[key]
- value = request_time?( args ) if key == :request_time
-
+ value = request_time( args ) if key == :request_time
+
_spew( buff, '--', (silent ? '' : ' '), key, value, silent )
buff.join( "\n" )
end
def self._spew( buff, sep, indent, key, value, silent )
@@ -101,25 +102,28 @@
buff = []
case args[:type]
when Rackamole.fault
buff << spew( :fault ) << spew( :stack ) + "\n"
when Rackamole.perf
- buff << "#{spew( :request_time )}/#{@options[:perf_threshold]}"
+ buff << "#{spew( :request_time )} [#{@options[:perf_threshold]}]"
end
buff << spew( :user_name) << spew( :url ) << spew( :path ) << spew( :status )
- buff << spew( :method ) << spew( :request_time ) << spew( :ip )
+ buff << spew( :method )
+ buff << spew( :request_time ) unless args[:type] == Rackamole.perf
+ buff << spew( :ip )
buff.join( "\n" )
end
def self.server() [ spew( :host ), spew( :software ), spew( :ruby_version ) ]; end
def self.client() [ spew( :machine, true ) ]; end
def self.params() [ spew( :params, true ) ]; end
def self.session() [ spew( :session, true ) ]; end
def self.browser() [ spew( :browser, true ) ]; end
def self.headers() [ spew( :headers, true ) ]; end
# Dump request time if any...
- def self.request_time?( args )
- args[:request_time] ? ("%5.2f " % args[:request_time] ) : ''
+ def self.request_time( args )
+ return '' unless args[:request_time]
+ "%1.2f" % args[:request_time]
end
# Identify the type of alert...
def self.alert_type( args )
case args[:type]
\ No newline at end of file