exception_notification 2.3.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +27 -86
- data/lib/exception_notifier.rb +31 -0
- data/lib/exception_notifier/notifier.rb +83 -0
- data/lib/exception_notifier/views/exception_notifier/_backtrace.text.erb +1 -0
- data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +8 -0
- data/lib/exception_notifier/views/exception_notifier/_request.text.erb +4 -0
- data/lib/exception_notifier/views/exception_notifier/_session.text.erb +2 -0
- data/{views/exception_notifier/_title.rhtml → lib/exception_notifier/views/exception_notifier/_title.text.erb} +1 -1
- data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +13 -0
- metadata +27 -20
- data/lib/exception_notification.rb +0 -7
- data/lib/exception_notification/consider_local.rb +0 -31
- data/lib/exception_notification/notifiable.rb +0 -66
- data/lib/exception_notification/notifier.rb +0 -75
- data/lib/exception_notification/notifier_helper.rb +0 -67
- data/views/exception_notifier/_backtrace.rhtml +0 -1
- data/views/exception_notifier/_environment.rhtml +0 -7
- data/views/exception_notifier/_inspect_model.rhtml +0 -16
- data/views/exception_notifier/_request.rhtml +0 -4
- data/views/exception_notifier/_session.rhtml +0 -2
- data/views/exception_notifier/exception_notification.rhtml +0 -6
data/README
CHANGED
@@ -13,71 +13,12 @@ environment, and also gives a backtrace of the exception.
|
|
13
13
|
|
14
14
|
== Usage
|
15
15
|
|
16
|
-
|
17
|
-
to generate error emails (typically ApplicationController):
|
16
|
+
As of Rails 3 ExceptionNotifier is used as a rack middleware
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
Then, specify the email recipients in your environment:
|
25
|
-
|
26
|
-
ExceptionNotification::Notifier.exception_recipients = %w(joe@schmoe.com bill@schmoe.com)
|
27
|
-
|
28
|
-
And that's it! The defaults take care of the rest.
|
29
|
-
|
30
|
-
== Configuration
|
31
|
-
|
32
|
-
You can tweak other values to your liking, as well. In your environment file,
|
33
|
-
just set any or all of the following values:
|
34
|
-
|
35
|
-
# defaults to exception.notifier@default.com
|
36
|
-
ExceptionNotification::Notifier.sender_address =
|
37
|
-
%("Application Error" <app.error@myapp.com>)
|
38
|
-
|
39
|
-
# defaults to "[ERROR] "
|
40
|
-
ExceptionNotification::Notifier.email_prefix = "[APP] "
|
41
|
-
|
42
|
-
Even if you have mixed into ApplicationController you can skip notification in
|
43
|
-
some controllers by
|
44
|
-
|
45
|
-
class MyController < ApplicationController
|
46
|
-
skip_exception_notifications
|
47
|
-
end
|
48
|
-
|
49
|
-
== Deprecated local_request? overriding
|
50
|
-
|
51
|
-
Email notifications will only occur when the IP address is determined not to
|
52
|
-
be local. You can specify certain addresses to always be local so that you'll
|
53
|
-
get a detailed error instead of the generic error page. You do this in your
|
54
|
-
controller (or even per-controller):
|
55
|
-
|
56
|
-
consider_local "64.72.18.143", "14.17.21.25"
|
57
|
-
|
58
|
-
You can specify subnet masks as well, so that all matching addresses are
|
59
|
-
considered local:
|
60
|
-
|
61
|
-
consider_local "64.72.18.143/24"
|
62
|
-
|
63
|
-
The address "127.0.0.1" is always considered local. If you want to completely
|
64
|
-
reset the list of all addresses (for instance, if you wanted "127.0.0.1" to
|
65
|
-
NOT be considered local), you can simply do, somewhere in your controller:
|
66
|
-
|
67
|
-
local_addresses.clear
|
68
|
-
|
69
|
-
NOTE: The above functionality has has been pulled out to consider_local.rb,
|
70
|
-
as interfering with rails local determination is orthogonal to notification,
|
71
|
-
unnecessarily clutters backtraces, and even occasionally errs on odd ip or
|
72
|
-
requests bugs. To return original functionality add an initializer with:
|
73
|
-
|
74
|
-
ActionController::Base.send :include, ConsiderLocal
|
75
|
-
|
76
|
-
or just include it per controller that wants it
|
77
|
-
|
78
|
-
class MyController < ApplicationController
|
79
|
-
include ExceptionNotification::ConsiderLocal
|
80
|
-
end
|
18
|
+
Whatever::Application.config.middleware.use ExceptionNotifier,
|
19
|
+
:email_prefix => "[Whatever] ",
|
20
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
21
|
+
:exception_recipients => %w{exceptions@example.com}
|
81
22
|
|
82
23
|
== Customization
|
83
24
|
|
@@ -90,27 +31,26 @@ access to the following variables:
|
|
90
31
|
* @controller: the controller that caused the error
|
91
32
|
* @request: the current request object
|
92
33
|
* @exception: the exception that was raised
|
93
|
-
* @host: the name of the host that made the request
|
94
34
|
* @backtrace: a sanitized version of the exception's backtrace
|
95
|
-
* @rails_root: a sanitized version of RAILS_ROOT
|
96
35
|
* @data: a hash of optional data values that were passed to the notifier
|
97
36
|
* @sections: the array of sections to include in the email
|
98
37
|
|
99
38
|
You can reorder the sections, or exclude sections completely, by altering the
|
100
|
-
|
39
|
+
ExceptionNotifier.sections variable. You can even add new sections that
|
101
40
|
describe application-specific data--just add the section's name to the list
|
102
41
|
(whereever you'd like), and define the corresponding partial. Then, if your
|
103
42
|
new section requires information that isn't available by default, make sure
|
104
43
|
it is made available to the email using the exception_data macro:
|
105
44
|
|
106
45
|
class ApplicationController < ActionController::Base
|
46
|
+
before_filter :log_additional_data
|
107
47
|
...
|
108
48
|
protected
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
49
|
+
def log_additional_data
|
50
|
+
request.env["exception_notifier.exception_data"] = {
|
51
|
+
:document => @document,
|
52
|
+
:person => @person
|
53
|
+
}
|
114
54
|
end
|
115
55
|
...
|
116
56
|
end
|
@@ -119,22 +59,23 @@ In the above case, @document and @person would be made available to the email
|
|
119
59
|
renderer, allowing your new section(s) to access and display them. See the
|
120
60
|
existing sections defined by the plugin for examples of how to write your own.
|
121
61
|
|
122
|
-
==
|
62
|
+
== Notification
|
123
63
|
|
124
|
-
|
125
|
-
|
64
|
+
After an exception notification has been delivered the rack environment variable
|
65
|
+
'exception_notifier.delivered' will be set to +true+.
|
126
66
|
|
127
|
-
==
|
67
|
+
== Rails 2.3 stable and earlier
|
128
68
|
|
129
|
-
If
|
130
|
-
|
131
|
-
|
69
|
+
If you are running Rails 2.3 then see the branch for that:
|
70
|
+
|
71
|
+
http://github.com/rails/exception_notification/tree/2-3-stable
|
132
72
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
73
|
+
If you are running pre-rack Rails then see this tag:
|
74
|
+
|
75
|
+
http://github.com/rails/exception_notification/tree/pre-2-3
|
76
|
+
|
77
|
+
== Support and tickets
|
78
|
+
|
79
|
+
https://github.com/smartinez87/exception_notification/issues
|
139
80
|
|
140
|
-
Copyright (c) 2005 Jamis Buck, released under the MIT license
|
81
|
+
Copyright (c) 2005 Jamis Buck, released under the MIT license
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'action_dispatch'
|
2
|
+
require 'exception_notifier/notifier'
|
3
|
+
|
4
|
+
class ExceptionNotifier
|
5
|
+
def self.default_ignore_exceptions
|
6
|
+
[].tap do |exceptions|
|
7
|
+
exceptions << ::ActiveRecord::RecordNotFound if defined? ::ActiveRecord::RecordNotFound
|
8
|
+
exceptions << ::AbstractController::ActionNotFound if defined? ::AbstractController::ActionNotFound
|
9
|
+
exceptions << ::ActionController::RoutingError if defined? ::ActionController::RoutingError
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(app, options = {})
|
14
|
+
@app, @options = app, options
|
15
|
+
@options[:ignore_exceptions] ||= self.class.default_ignore_exceptions
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
@app.call(env)
|
20
|
+
rescue Exception => exception
|
21
|
+
options = (env['exception_notifier.options'] ||= {})
|
22
|
+
options.reverse_merge!(@options)
|
23
|
+
|
24
|
+
unless Array.wrap(options[:ignore_exceptions]).include?(exception.class)
|
25
|
+
Notifier.exception_notification(env, exception).deliver
|
26
|
+
env['exception_notifier.delivered'] = true
|
27
|
+
end
|
28
|
+
|
29
|
+
raise exception
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'action_mailer'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
class ExceptionNotifier
|
5
|
+
class Notifier < ActionMailer::Base
|
6
|
+
self.mailer_name = 'exception_notifier'
|
7
|
+
self.append_view_path "#{File.dirname(__FILE__)}/views"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def default_sender_address
|
11
|
+
%("Exception Notifier" <exception.notifier@default.com>)
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_exception_recipients
|
15
|
+
[]
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_email_prefix
|
19
|
+
"[ERROR] "
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_sections
|
23
|
+
%w(request session environment backtrace)
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_options
|
27
|
+
{ :sender_address => default_sender_address,
|
28
|
+
:exception_recipients => default_exception_recipients,
|
29
|
+
:email_prefix => default_email_prefix,
|
30
|
+
:sections => default_sections }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class MissingController
|
35
|
+
def method_missing(*args, &block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def exception_notification(env, exception)
|
40
|
+
@env = env
|
41
|
+
@exception = exception
|
42
|
+
@options = (env['exception_notifier.options'] || {}).reverse_merge(self.class.default_options)
|
43
|
+
@kontroller = env['action_controller.instance'] || MissingController.new
|
44
|
+
@request = ActionDispatch::Request.new(env)
|
45
|
+
@backtrace = clean_backtrace(exception)
|
46
|
+
@sections = @options[:sections]
|
47
|
+
data = env['exception_notifier.exception_data'] || {}
|
48
|
+
|
49
|
+
data.each do |name, value|
|
50
|
+
instance_variable_set("@#{name}", value)
|
51
|
+
end
|
52
|
+
|
53
|
+
prefix = "#{@options[:email_prefix]}#{@kontroller.controller_name}##{@kontroller.action_name}"
|
54
|
+
subject = "#{prefix} (#{@exception.class}) #{@exception.message.inspect}"
|
55
|
+
|
56
|
+
mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
|
57
|
+
format.text { render "#{mailer_name}/exception_notification" }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def clean_backtrace(exception)
|
64
|
+
Rails.respond_to?(:backtrace_cleaner) ?
|
65
|
+
Rails.backtrace_cleaner.send(:filter, exception.backtrace) :
|
66
|
+
exception.backtrace
|
67
|
+
end
|
68
|
+
|
69
|
+
helper_method :inspect_object
|
70
|
+
|
71
|
+
def inspect_object(object)
|
72
|
+
case object
|
73
|
+
when Hash, Array
|
74
|
+
object.inspect
|
75
|
+
when ActionController::Base
|
76
|
+
"#{object.controller_name}##{object.action_name}"
|
77
|
+
else
|
78
|
+
object.to_s
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= raw @backtrace.join("\n") %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% filtered_env = @request.filtered_env -%>
|
2
|
+
<% max = filtered_env.keys.max { |a, b| a.length <=> b.length } -%>
|
3
|
+
<% filtered_env.keys.sort.each do |key| -%>
|
4
|
+
* <%= raw("%-*s: %s" % [max.length, key, inspect_object(filtered_env[key])]) %>
|
5
|
+
<% end -%>
|
6
|
+
|
7
|
+
* Process: <%= raw $$ %>
|
8
|
+
* Server : <%= raw `hostname -s`.chomp %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
A <%= @exception.class %> occurred in <%= @kontroller.controller_name %>#<%= @kontroller.action_name %>:
|
2
|
+
|
3
|
+
<%= raw @exception.message %>
|
4
|
+
<%= raw @backtrace.first %>
|
5
|
+
|
6
|
+
<% sections = @sections.map do |section|
|
7
|
+
summary = render(section).strip
|
8
|
+
unless summary.blank?
|
9
|
+
title = render("title", :title => section).strip
|
10
|
+
"#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
|
11
|
+
end
|
12
|
+
end %>
|
13
|
+
<%= raw sections.join %>
|
metadata
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exception_notification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 2.4.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Jamis Buck
|
8
14
|
- Josh Peek
|
9
|
-
- Tim Connor
|
10
15
|
autorequire:
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
18
|
|
14
|
-
date:
|
19
|
+
date: 2011-03-09 00:00:00 -02:00
|
15
20
|
default_executable:
|
16
21
|
dependencies: []
|
17
22
|
|
18
23
|
description:
|
19
|
-
email:
|
24
|
+
email: smartinez87@gmail.com
|
20
25
|
executables: []
|
21
26
|
|
22
27
|
extensions: []
|
@@ -25,18 +30,14 @@ extra_rdoc_files: []
|
|
25
30
|
|
26
31
|
files:
|
27
32
|
- README
|
28
|
-
- lib/
|
29
|
-
- lib/
|
30
|
-
- lib/
|
31
|
-
- lib/
|
32
|
-
- lib/exception_notification.
|
33
|
-
- views/exception_notifier/_backtrace.
|
34
|
-
- views/exception_notifier/
|
35
|
-
-
|
36
|
-
- views/exception_notifier/_request.rhtml
|
37
|
-
- views/exception_notifier/_session.rhtml
|
38
|
-
- views/exception_notifier/_title.rhtml
|
39
|
-
- views/exception_notifier/exception_notification.rhtml
|
33
|
+
- lib/exception_notifier/notifier.rb
|
34
|
+
- lib/exception_notifier/views/exception_notifier/_request.text.erb
|
35
|
+
- lib/exception_notifier/views/exception_notifier/_environment.text.erb
|
36
|
+
- lib/exception_notifier/views/exception_notifier/_session.text.erb
|
37
|
+
- lib/exception_notifier/views/exception_notifier/exception_notification.text.erb
|
38
|
+
- lib/exception_notifier/views/exception_notifier/_backtrace.text.erb
|
39
|
+
- lib/exception_notifier/views/exception_notifier/_title.text.erb
|
40
|
+
- lib/exception_notifier.rb
|
40
41
|
has_rdoc: true
|
41
42
|
homepage:
|
42
43
|
licenses: []
|
@@ -47,23 +48,29 @@ rdoc_options: []
|
|
47
48
|
require_paths:
|
48
49
|
- lib
|
49
50
|
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
50
52
|
requirements:
|
51
53
|
- - ">="
|
52
54
|
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
53
58
|
version: "0"
|
54
|
-
version:
|
55
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
56
61
|
requirements:
|
57
62
|
- - ">="
|
58
63
|
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
59
67
|
version: "0"
|
60
|
-
version:
|
61
68
|
requirements: []
|
62
69
|
|
63
70
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.5.2
|
65
72
|
signing_key:
|
66
73
|
specification_version: 3
|
67
|
-
summary: Exception notification by email for Rails apps
|
74
|
+
summary: Exception notification by email for Rails apps
|
68
75
|
test_files: []
|
69
76
|
|
@@ -1,7 +0,0 @@
|
|
1
|
-
require "action_mailer"
|
2
|
-
module ExceptionNotification
|
3
|
-
autoload :Notifiable, 'exception_notification/notifiable'
|
4
|
-
autoload :Notifier, 'exception_notification/notifier'
|
5
|
-
#autoload :NotifierHelper, 'exception_notification/notifier_helper'
|
6
|
-
autoload :ConsiderLocal, 'exception_notification/consider_local'
|
7
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#This didn't belong on ExceptionNotifier and made backtraces worse. To keep original functionality in place
|
2
|
-
#'ActionController::Base.send :include, ExceptionNotification::ConsiderLocal' or just include in your controller
|
3
|
-
module ExceptionNotification::ConsiderLocal
|
4
|
-
module ClassMethods
|
5
|
-
def self.included(target)
|
6
|
-
require 'ipaddr'
|
7
|
-
target.extend(ClassMethods)
|
8
|
-
end
|
9
|
-
|
10
|
-
def consider_local(*args)
|
11
|
-
local_addresses.concat(args.flatten.map { |a| IPAddr.new(a) })
|
12
|
-
end
|
13
|
-
|
14
|
-
def local_addresses
|
15
|
-
addresses = read_inheritable_attribute(:local_addresses)
|
16
|
-
unless addresses
|
17
|
-
addresses = [IPAddr.new("127.0.0.1")]
|
18
|
-
write_inheritable_attribute(:local_addresses, addresses)
|
19
|
-
end
|
20
|
-
addresses
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def local_request?
|
27
|
-
remote = IPAddr.new(request.remote_ip)
|
28
|
-
!self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# Copyright (c) 2005 Jamis Buck
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
# a copy of this software and associated documentation files (the
|
5
|
-
# "Software"), to deal in the Software without restriction, including
|
6
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
# the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be
|
12
|
-
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
-
module ExceptionNotification::Notifiable
|
22
|
-
def self.included(target)
|
23
|
-
target.extend(ClassMethods)
|
24
|
-
target.skip_exception_notifications false
|
25
|
-
end
|
26
|
-
|
27
|
-
module ClassMethods
|
28
|
-
def exception_data(deliverer=self)
|
29
|
-
if deliverer == self
|
30
|
-
read_inheritable_attribute(:exception_data)
|
31
|
-
else
|
32
|
-
write_inheritable_attribute(:exception_data, deliverer)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def skip_exception_notifications(boolean=true)
|
37
|
-
write_inheritable_attribute(:skip_exception_notifications, boolean)
|
38
|
-
end
|
39
|
-
|
40
|
-
def skip_exception_notifications?
|
41
|
-
read_inheritable_attribute(:skip_exception_notifications)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def rescue_action_in_public(exception)
|
48
|
-
super
|
49
|
-
notify_about_exception(exception) if deliver_exception_notification?
|
50
|
-
end
|
51
|
-
|
52
|
-
def deliver_exception_notification?
|
53
|
-
!self.class.skip_exception_notifications? && ![404, "404 Not Found"].include?(response.status)
|
54
|
-
end
|
55
|
-
|
56
|
-
def notify_about_exception(exception)
|
57
|
-
deliverer = self.class.exception_data
|
58
|
-
data = case deliverer
|
59
|
-
when nil then {}
|
60
|
-
when Symbol then send(deliverer)
|
61
|
-
when Proc then deliverer.call(self)
|
62
|
-
end
|
63
|
-
|
64
|
-
ExceptionNotification::Notifier.deliver_exception_notification(exception, self, request, data)
|
65
|
-
end
|
66
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
# Copyright (c) 2005 Jamis Buck
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
# a copy of this software and associated documentation files (the
|
7
|
-
# "Software"), to deal in the Software without restriction, including
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be
|
14
|
-
# included in all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
class ExceptionNotification::Notifier < ActionMailer::Base
|
24
|
-
self.mailer_name = 'exception_notifier'
|
25
|
-
self.view_paths << "#{File.dirname(__FILE__)}/../../views"
|
26
|
-
|
27
|
-
@@sender_address = %("Exception Notifier" <exception.notifier@default.com>)
|
28
|
-
cattr_accessor :sender_address
|
29
|
-
|
30
|
-
@@exception_recipients = []
|
31
|
-
cattr_accessor :exception_recipients
|
32
|
-
|
33
|
-
@@email_prefix = "[ERROR] "
|
34
|
-
cattr_accessor :email_prefix
|
35
|
-
|
36
|
-
@@sections = %w(request session environment backtrace)
|
37
|
-
cattr_accessor :sections
|
38
|
-
|
39
|
-
def self.reloadable?() false end
|
40
|
-
|
41
|
-
def exception_notification(exception, controller, request, data={})
|
42
|
-
source = self.class.exception_source(controller)
|
43
|
-
content_type "text/plain"
|
44
|
-
|
45
|
-
subject "#{email_prefix}#{source} (#{exception.class}) #{exception.message.inspect}"
|
46
|
-
|
47
|
-
recipients exception_recipients
|
48
|
-
from sender_address
|
49
|
-
|
50
|
-
body data.merge({ :controller => controller, :request => request,
|
51
|
-
:exception => exception, :exception_source => source, :host => (request.env["HTTP_X_FORWARDED_HOST"] || request.env["HTTP_HOST"]),
|
52
|
-
:backtrace => sanitize_backtrace(exception.backtrace),
|
53
|
-
:rails_root => rails_root, :data => data,
|
54
|
-
:sections => sections })
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.exception_source(controller)
|
58
|
-
if controller.respond_to?(:controller_name)
|
59
|
-
"in #{controller.controller_name}##{controller.action_name}"
|
60
|
-
else
|
61
|
-
"outside of a controller"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def sanitize_backtrace(trace)
|
68
|
-
re = Regexp.new(/^#{Regexp.escape(rails_root)}/)
|
69
|
-
trace.map { |line| Pathname.new(line.gsub(re, "[RAILS_ROOT]")).cleanpath.to_s }
|
70
|
-
end
|
71
|
-
|
72
|
-
def rails_root
|
73
|
-
@rails_root ||= Pathname.new(RAILS_ROOT).cleanpath.to_s
|
74
|
-
end
|
75
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
|
-
# Copyright (c) 2005 Jamis Buck
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
# a copy of this software and associated documentation files (the
|
7
|
-
# "Software"), to deal in the Software without restriction, including
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be
|
14
|
-
# included in all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
module ExceptionNotification::NotifierHelper
|
24
|
-
PARAM_FILTER_REPLACEMENT = "[FILTERED]"
|
25
|
-
|
26
|
-
def render_section(section)
|
27
|
-
RAILS_DEFAULT_LOGGER.info("rendering section #{section.inspect}")
|
28
|
-
summary = render("exception_notifier/#{section}").strip
|
29
|
-
unless summary.blank?
|
30
|
-
title = render("exception_notifier/title", :locals => { :title => section }).strip
|
31
|
-
"#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def inspect_model_object(model, locals={})
|
36
|
-
render('exception_notifier/inspect_model',
|
37
|
-
:locals => { :inspect_model => model,
|
38
|
-
:show_instance_variables => true,
|
39
|
-
:show_attributes => true }.merge(locals))
|
40
|
-
end
|
41
|
-
|
42
|
-
def inspect_value(value)
|
43
|
-
len = 512
|
44
|
-
result = object_to_yaml(value).gsub(/\n/, "\n ").strip
|
45
|
-
result = result[0,len] + "... (#{result.length-len} bytes more)" if result.length > len+20
|
46
|
-
result
|
47
|
-
end
|
48
|
-
|
49
|
-
def object_to_yaml(object)
|
50
|
-
object.to_yaml.sub(/^---\s*/m, "")
|
51
|
-
end
|
52
|
-
|
53
|
-
def exclude_raw_post_parameters?
|
54
|
-
@controller && @controller.respond_to?(:filter_parameters)
|
55
|
-
end
|
56
|
-
|
57
|
-
def filter_sensitive_post_data_parameters(parameters)
|
58
|
-
exclude_raw_post_parameters? ? @controller.__send__(:filter_parameters, parameters) : parameters
|
59
|
-
end
|
60
|
-
|
61
|
-
def filter_sensitive_post_data_from_env(env_key, env_value)
|
62
|
-
return env_value unless exclude_raw_post_parameters?
|
63
|
-
return PARAM_FILTER_REPLACEMENT if (env_key =~ /RAW_POST_DATA/i)
|
64
|
-
return @controller.__send__(:filter_parameters, {env_key => env_value}).values[0]
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= @backtrace.join "\n" %>
|
@@ -1,7 +0,0 @@
|
|
1
|
-
<% max = @request.env.keys.max { |a,b| a.length <=> b.length } -%>
|
2
|
-
<% @request.env.keys.sort.each do |key| -%>
|
3
|
-
* <%= "%-*s: %s" % [max.length, key, filter_sensitive_post_data_from_env(key, @request.env[key].to_s.strip)] %>
|
4
|
-
<% end -%>
|
5
|
-
|
6
|
-
* Process: <%= $$ %>
|
7
|
-
* Server : <%= `hostname -s`.chomp %>
|
@@ -1,16 +0,0 @@
|
|
1
|
-
<% if show_attributes -%>
|
2
|
-
[attributes]
|
3
|
-
<% attrs = inspect_model.attributes -%>
|
4
|
-
<% max = attrs.keys.max { |a,b| a.length <=> b.length } -%>
|
5
|
-
<% attrs.keys.sort.each do |attr| -%>
|
6
|
-
* <%= "%*-s: %s" % [max.length, attr, object_to_yaml(attrs[attr]).gsub(/\n/, "\n ").strip] %>
|
7
|
-
<% end -%>
|
8
|
-
<% end -%>
|
9
|
-
|
10
|
-
<% if show_instance_variables -%>
|
11
|
-
[instance variables]
|
12
|
-
<% inspect_model.instance_variables.sort.each do |variable| -%>
|
13
|
-
<%- next if variable == "@attributes" -%>
|
14
|
-
* <%= variable %>: <%= inspect_value(inspect_model.instance_variable_get(variable)) %>
|
15
|
-
<% end -%>
|
16
|
-
<% end -%>
|
@@ -1,4 +0,0 @@
|
|
1
|
-
* URL : <%= @request.protocol %><%= @host %><%= @request.request_uri %>
|
2
|
-
* IP address: <%= @request.env["HTTP_X_FORWARDED_FOR"] || @request.env["REMOTE_ADDR"] %>
|
3
|
-
* Parameters: <%= filter_sensitive_post_data_parameters(@request.parameters).inspect %>
|
4
|
-
* Rails root: <%= @rails_root %>
|