exception_notification 3.0.1 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +9 -0
  3. data/Appraisals +11 -0
  4. data/CHANGELOG.rdoc +21 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +49 -7
  7. data/README.md +417 -184
  8. data/Rakefile +4 -2
  9. data/examples/sinatra/Gemfile +8 -0
  10. data/examples/sinatra/Gemfile.lock +95 -0
  11. data/examples/sinatra/Procfile +2 -0
  12. data/examples/sinatra/README.md +11 -0
  13. data/examples/sinatra/config.ru +3 -0
  14. data/examples/sinatra/sinatra_app.rb +28 -0
  15. data/exception_notification.gemspec +10 -4
  16. data/gemfiles/rails3_1.gemfile +7 -0
  17. data/gemfiles/rails3_2.gemfile +7 -0
  18. data/gemfiles/rails4_0.gemfile +7 -0
  19. data/lib/exception_notification.rb +10 -0
  20. data/lib/exception_notification/rack.rb +45 -0
  21. data/lib/exception_notification/rails.rb +8 -0
  22. data/lib/exception_notification/resque.rb +24 -0
  23. data/lib/exception_notification/sidekiq.rb +22 -0
  24. data/lib/exception_notifier.rb +89 -61
  25. data/lib/exception_notifier/campfire_notifier.rb +2 -7
  26. data/lib/exception_notifier/email_notifier.rb +181 -0
  27. data/lib/exception_notifier/notifier.rb +9 -178
  28. data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +3 -1
  29. data/lib/exception_notifier/views/exception_notifier/_data.html.erb +6 -1
  30. data/lib/exception_notifier/views/exception_notifier/_environment.html.erb +16 -6
  31. data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +1 -1
  32. data/lib/exception_notifier/views/exception_notifier/_request.html.erb +24 -5
  33. data/lib/exception_notifier/views/exception_notifier/_request.text.erb +2 -0
  34. data/lib/exception_notifier/views/exception_notifier/_session.html.erb +10 -2
  35. data/lib/exception_notifier/views/exception_notifier/_session.text.erb +1 -1
  36. data/lib/exception_notifier/views/exception_notifier/_title.html.erb +3 -3
  37. data/lib/exception_notifier/views/exception_notifier/background_exception_notification.html.erb +38 -11
  38. data/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb +0 -1
  39. data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +39 -21
  40. data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +0 -1
  41. data/lib/exception_notifier/webhook_notifier.rb +21 -0
  42. data/lib/generators/exception_notification/install_generator.rb +15 -0
  43. data/lib/generators/exception_notification/templates/exception_notification.rb +47 -0
  44. data/test/dummy/Gemfile +2 -1
  45. data/test/dummy/Gemfile.lock +79 -78
  46. data/test/dummy/config/environment.rb +9 -7
  47. data/test/dummy/test/functional/posts_controller_test.rb +22 -37
  48. data/test/{campfire_test.rb → exception_notifier/campfire_notifier_test.rb} +4 -4
  49. data/test/exception_notifier/email_notifier_test.rb +144 -0
  50. data/test/exception_notifier/webhook_notifier_test.rb +41 -0
  51. data/test/exception_notifier_test.rb +101 -0
  52. data/test/test_helper.rb +4 -1
  53. metadata +136 -18
  54. data/test/background_exception_notification_test.rb +0 -82
  55. data/test/exception_notification_test.rb +0 -73
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /coverage/
2
+ *.gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ gemfile:
6
+ - Gemfile
7
+ - gemfiles/rails3_1.gemfile
8
+ - gemfiles/rails3_2.gemfile
9
+ - gemfiles/rails4_0.gemfile
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise "rails3_1" do
2
+ gem 'rails', '~> 3.1.0'
3
+ end
4
+
5
+ appraise "rails3_2" do
6
+ gem 'rails', '~> 3.2.0'
7
+ end
8
+
9
+ appraise "rails4_0" do
10
+ gem 'rails', '4.0.0.rc2'
11
+ end
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,24 @@
1
+ == 4.0.0
2
+
3
+ * enhancements
4
+ * Be able to override delivery_method (by @jweslley)
5
+ * Add logger to log when notifications cannot be shiped (by @jweslley)
6
+ * Add Rails generator to create an initializer file (by @jweslley)
7
+ * Add rails engine (by @jweslley)
8
+ * Add sidekiq support (by @jweslley)
9
+ * Add resque support (by @jweslley)
10
+ * Better style for html views (by @jweslley)
11
+ * Support customizable Mailer class (by @Bishop)
12
+ * Turn ExceptionNotification Rails agnostic (by @jweslley)
13
+ * Support custom ignore exceptions for background notifications (by @jweslley)
14
+ * Be able to implement custom notifiers (by @jweslley)
15
+ * Add Webhook notifier (by @jweslley)
16
+ * Rails 4 compatible
17
+
18
+ * bug fixes
19
+ * Don't error if Rails isn't defined. (by @dpogue)
20
+ * Fix call to #normalize_digits (by @ghiculescu)
21
+
1
22
  == 3.0.1
2
23
 
3
24
  * enhancements
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
data/Gemfile.lock CHANGED
@@ -3,9 +3,10 @@ PATH
3
3
  specs:
4
4
  exception_notification (3.0.1)
5
5
  actionmailer (>= 3.0.4)
6
+ activesupport (>= 3.0.4)
6
7
 
7
8
  GEM
8
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
9
10
  specs:
10
11
  actionmailer (3.2.6)
11
12
  actionpack (= 3.2.6)
@@ -34,17 +35,33 @@ GEM
34
35
  activesupport (3.2.6)
35
36
  i18n (~> 0.6)
36
37
  multi_json (~> 1.0)
38
+ appraisal (0.5.2)
39
+ bundler
40
+ rake
37
41
  arel (3.0.2)
38
42
  builder (3.0.0)
43
+ celluloid (0.14.0)
44
+ timers (>= 1.0.0)
45
+ colorize (0.5.8)
46
+ connection_pool (1.0.0)
47
+ coveralls (0.6.5)
48
+ colorize
49
+ multi_json (~> 1.3)
50
+ rest-client
51
+ simplecov (>= 0.7)
52
+ thor
39
53
  erubis (2.7.0)
40
- eventmachine (1.0.0)
41
- faraday (0.8.4)
54
+ eventmachine (1.0.3)
55
+ faraday (0.8.7)
42
56
  multipart-post (~> 1.1)
43
- faraday_middleware (0.8.8)
57
+ faraday_middleware (0.9.0)
44
58
  faraday (>= 0.7.4, < 0.9)
45
59
  hashie (1.2.0)
46
60
  hike (1.2.1)
47
61
  http_parser.rb (0.5.3)
62
+ httparty (0.10.2)
63
+ multi_json (~> 1.0)
64
+ multi_xml (>= 0.5.2)
48
65
  i18n (0.6.0)
49
66
  journey (1.0.4)
50
67
  json (1.7.3)
@@ -54,10 +71,11 @@ GEM
54
71
  treetop (~> 1.4.8)
55
72
  metaclass (0.0.1)
56
73
  mime-types (1.19)
57
- mocha (0.12.0)
74
+ mocha (0.13.3)
58
75
  metaclass (~> 0.0.1)
59
76
  multi_json (1.3.6)
60
- multipart-post (1.1.5)
77
+ multi_xml (0.5.3)
78
+ multipart-post (1.2.0)
61
79
  polyglot (0.3.3)
62
80
  rack (1.4.1)
63
81
  rack-cache (1.2)
@@ -84,7 +102,25 @@ GEM
84
102
  rake (0.9.2.2)
85
103
  rdoc (3.12)
86
104
  json (~> 1.4)
105
+ redis (3.0.4)
106
+ redis-namespace (1.3.0)
107
+ redis (~> 3.0.0)
108
+ resque (1.2.3)
109
+ redis
110
+ redis-namespace
111
+ rest-client (1.6.7)
112
+ mime-types (>= 1.16)
113
+ sidekiq (2.12.0)
114
+ celluloid (>= 0.14.0)
115
+ connection_pool (>= 1.0.0)
116
+ json
117
+ redis (>= 3.0)
118
+ redis-namespace
87
119
  simple_oauth (0.1.9)
120
+ simplecov (0.7.1)
121
+ multi_json (~> 1.0)
122
+ simplecov-html (~> 0.7.1)
123
+ simplecov-html (0.7.1)
88
124
  sprockets (2.1.3)
89
125
  hike (~> 1.2)
90
126
  rack (~> 1.0)
@@ -92,6 +128,7 @@ GEM
92
128
  sqlite3 (1.3.6)
93
129
  thor (0.15.4)
94
130
  tilt (1.3.3)
131
+ timers (1.1.0)
95
132
  tinder (1.9.1)
96
133
  eventmachine (>= 0.12.0, < 2)
97
134
  faraday (~> 0.8)
@@ -115,8 +152,13 @@ PLATFORMS
115
152
  ruby
116
153
 
117
154
  DEPENDENCIES
155
+ appraisal
156
+ coveralls (~> 0.6.5)
118
157
  exception_notification!
119
- mocha (>= 0.11.3)
158
+ httparty (~> 0.10.2)
159
+ mocha (>= 0.13.0)
120
160
  rails (>= 3.0.4)
161
+ resque (~> 1.2.0)
162
+ sidekiq (~> 2.0)
121
163
  sqlite3 (>= 1.3.4)
122
164
  tinder (~> 1.8)
data/README.md CHANGED
@@ -1,77 +1,112 @@
1
- Exception Notifier Plugin for Rails ![project status](http://stillmaintained.com/smartinez87/exception_notification.png) [![Travis](http://travis-ci.org/smartinez87/exception_notification.png)](http://travis-ci.org/smartinez87/exception_notification) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/smartinez87/exception_notification)
2
- ====
1
+ # Exception Notification
3
2
 
4
- The Exception Notifier plugin provides a mailer object and a default set of
5
- templates for sending email notifications when errors occur in a Rails
6
- application.
3
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/exception_notification.png)](http://badge.fury.io/rb/exception_notification)
4
+ [![Travis](https://api.travis-ci.org/smartinez87/exception_notification.png)](http://travis-ci.org/smartinez87/exception_notification)
5
+ [![Coverage Status](https://coveralls.io/repos/smartinez87/exception_notification/badge.png?branch=master)](https://coveralls.io/r/smartinez87/exception_notification)
6
+ [![Code Climate](https://codeclimate.com/github/smartinez87/exception_notification.png)](https://codeclimate.com/github/smartinez87/exception_notification)
7
+ ![project status](http://stillmaintained.com/smartinez87/exception_notification.png)
7
8
 
8
- The email includes information about the current request, session, and
9
- environment, and also gives a backtrace of the exception.
9
+ **THIS README IS FOR THE MASTER BRANCH AND REFLECTS THE WORK CURRENTLY EXISTING ON THE MASTER BRANCH. IF YOU ARE WISHING TO USE A NON-MASTER BRANCH OF EXCEPTION NOTIFICATION, PLEASE CONSULT THAT BRANCH'S README AND NOT THIS ONE.**
10
10
 
11
- There's a great [Railscast about Exception Notifications](http://railscasts.com/episodes/104-exception-notifications-revised)
12
- you can see that may help you getting started.
11
+ -
12
+
13
+ The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application.
14
+
15
+ The built-in notifiers can deliver notifications by [email](#email-notifier), [campfire rooms](#campfire-notifier) or via [webhooks](#webhook-notifier).
16
+
17
+
18
+ There's a great [Railscast about Exception Notification](http://railscasts.com/episodes/104-exception-notifications-revised) you can see that may help you getting started.
13
19
 
14
20
  [Follow us on Twitter](https://twitter.com/exception_notif) to get updates and notices about new releases.
15
21
 
16
- Installation
17
- ---
18
22
 
19
- You can use the latest ExceptionNotification gem with Rails 3, by adding
20
- the following line in your Gemfile
23
+ ## Requirements
24
+
25
+ * Ruby 1.9.3 or greater
26
+ * Rails 3.1 or greater, Sinatra or another Rack-based application.
27
+
28
+ For previous releases, please checkout [this](#versions).
29
+
30
+
31
+ ## Getting Started
32
+
33
+ Add the following line to your application's Gemfile:
21
34
 
22
35
  ```ruby
23
36
  gem 'exception_notification'
24
37
  ```
25
38
 
26
- As of Rails 3 ExceptionNotification is used as a rack middleware, so you can
27
- configure its options on your config.ru file, or in the environment you
28
- want it to run. In most cases you would want ExceptionNotification to
29
- run on production. You can make it work by
39
+ As of Rails 3 ExceptionNotification is used as a rack middleware, or in the environment you want it to run. In most cases you would want ExceptionNotification to run on production. Thus, you can make it work by putting the following lines in your `config/environments/production.rb`:
30
40
 
31
41
  ```ruby
32
- Whatever::Application.config.middleware.use ExceptionNotifier,
33
- :email_prefix => "[Whatever] ",
34
- :sender_address => %{"notifier" <notifier@example.com>},
35
- :exception_recipients => %w{exceptions@example.com}
42
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
43
+ :email => {
44
+ :email_prefix => "[Whatever] ",
45
+ :sender_address => %{"notifier" <notifier@example.com>},
46
+ :exception_recipients => %w{exceptions@example.com}
47
+ }
36
48
  ```
37
49
 
38
- Campfire Integration
39
- ---
50
+ > **Note**: In order delivery notifications by email make sure you have [ActionMailer configured](#actionmailer-configuration).
40
51
 
41
- Additionally, ExceptionNotification supports sending notifications to
42
- your Campfire room.
43
52
 
44
- First you'll need to add [tinder](https://github.com/collectiveidea/tinder)
45
- to your `Gemfile`:
53
+ In order to use ExceptionNotification with Sinatra, please take a look in the [example application](https://github.com/smartinez87/exception_notification/tree/master/examples/sinatra).
46
54
 
47
- ```ruby
48
- gem 'tinder'
49
- ```
50
55
 
51
- To configure it, you need to set the subdomain, token and room name,
52
- like this:
56
+ ## Notifiers
57
+
58
+ ExceptionNotification relies on notifiers to deliver notifications when errors occur in your applications. By default, three notifiers are available: [email notifier](#email-notifier), [campfire notifier](#campfire-notifier) and [webhook notifier](#webhook-notifier). But, you also can easily implement your own [custom notifier](#custom-notifier).
59
+
60
+
61
+ ## Email notifier
62
+
63
+ The Email notifier sends notifications by email. The notifications/emails sent includes information about the current request, session, and environment, and also gives a backtrace of the exception.
64
+
65
+ After an exception notification has been delivered the rack environment variable 'exception_notifier.delivered' will be set to true.
66
+
67
+ ### ActionMailer configuration
68
+
69
+ For the email to be sent, there must be a default ActionMailer `delivery_method` setting configured. If you do not have one, you can use the following code (assuming your app server machine has `sendmail`). Depending on the environment you want ExceptionNotification to run in, put the following code in your `config/environments/production.rb` and/or `config/environments/development.rb`:
53
70
 
54
71
  ```ruby
55
- Whatever::Application.config.middleware.use ExceptionNotifier,
56
- :email_prefix => "[Whatever] ",
57
- :sender_address => %{"notifier" <notifier@example.com>},
58
- :exception_recipients => %w{exceptions@example.com},
59
- :campfire => {:subdomain => 'my_subdomain', :token => 'my_token', :room_name => 'my_room'}
72
+ config.action_mailer.delivery_method = :sendmail
73
+ # Defaults to:
74
+ # config.action_mailer.sendmail_settings = {
75
+ # :location => '/usr/sbin/sendmail',
76
+ # :arguments => '-i -t'
77
+ # }
78
+ config.action_mailer.perform_deliveries = true
79
+ config.action_mailer.raise_delivery_errors = true
60
80
  ```
61
81
 
62
- For more options to set Campfire, like _ssl_, check
63
- [here](https://github.com/collectiveidea/tinder/blob/master/lib/tinder/campfire.rb#L17).
82
+ ### Options
64
83
 
65
- Customization
66
- ---
84
+ #### sender_address
67
85
 
68
- ### Sections
86
+ *String, default: %("Exception Notifier" <exception.notifier@example.com>)*
69
87
 
70
- By default, the notification email includes four parts: request, session,
71
- environment, and backtrace (in that order). You can customize how each of those
72
- sections are rendered by placing a partial named for that part in your
73
- app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has
74
- access to the following variables:
88
+ Who the message is from.
89
+
90
+
91
+ #### exception_recipients
92
+
93
+ *String/Array of strings, default: []*
94
+
95
+ Who the message is destined for, can be a string of addresses, or an array of addresses.
96
+
97
+
98
+ #### email_prefix
99
+
100
+ *String, default: [ERROR]*
101
+
102
+ The subject's prefix of the message.
103
+
104
+
105
+ #### sections
106
+
107
+ *Array of strings, default: %w(request session environment backtrace)*
108
+
109
+ By default, the notification email includes four parts: request, session, environment, and backtrace (in that order). You can customize how each of those sections are rendered by placing a partial named for that part in your `app/views/exception_notifier` directory (e.g., `_session.rhtml`). Each partial has access to the following variables:
75
110
 
76
111
  ```ruby
77
112
  @kontroller # the controller that caused the error
@@ -82,27 +117,22 @@ access to the following variables:
82
117
  @sections # the array of sections to include in the email
83
118
  ```
84
119
 
85
- Background views will not have access to @kontroller and @request.
86
-
87
- You can reorder the sections, or exclude sections completely, by altering the
88
- ExceptionNotifier.sections variable. You can even add new sections that
89
- describe application-specific data--just add the section's name to the list
90
- (wherever you'd like), and define the corresponding partial.
120
+ You can reorder the sections, or exclude sections completely, by using `sections` option. You can even add new sections that
121
+ describe application-specific data--just add the section's name to the list (wherever you'd like), and define the corresponding partial. Like the following example with two new added sections:
91
122
 
92
123
  ```ruby
93
- #Example with two new added sections
94
- Whatever::Application.config.middleware.use ExceptionNotifier,
95
- :email_prefix => "[Whatever] ",
96
- :sender_address => %{"notifier" <notifier@example.com>},
97
- :exception_recipients => %w{exceptions@example.com},
98
- :sections => %w{my_section1 my_section2} + ExceptionNotifier::Notifier.default_sections
124
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
125
+ :email => {
126
+ :email_prefix => "[Whatever] ",
127
+ :sender_address => %{"notifier" <notifier@example.com>},
128
+ :exception_recipients => %w{exceptions@example.com},
129
+ :sections => %w{my_section1 my_section2}
130
+ }
99
131
  ```
100
132
 
101
- Place your custom sections under `./app/views/exception_notifier/` with the suffix `.text.erb`, e.g.
102
- `./app/views/exception_notifier/_my_section1.text.erb`.
133
+ Place your custom sections under `./app/views/exception_notifier/` with the suffix `.text.erb`, e.g. `./app/views/exception_notifier/_my_section1.text.erb`.
103
134
 
104
- If your new section requires information that isn't available by default, make sure
105
- it is made available to the email using the exception_data macro:
135
+ If your new section requires information that isn't available by default, make sure it is made available to the email using the `exception_data` macro:
106
136
 
107
137
  ```ruby
108
138
  class ApplicationController < ActionController::Base
@@ -119,151 +149,355 @@ class ApplicationController < ActionController::Base
119
149
  end
120
150
  ```
121
151
 
122
- In the above case, @document and @person would be made available to the email
123
- renderer, allowing your new section(s) to access and display them. See the
124
- existing sections defined by the plugin for examples of how to write your own.
152
+ In the above case, `@document` and `@person` would be made available to the email renderer, allowing your new section(s) to access and display them. See the existing sections defined by the plugin for examples of how to write your own.
153
+
154
+
155
+ #### background_sections
156
+
157
+ *Array of strings, default: %w(backtrace data)*
158
+
159
+ When using [background notifications](#background-notifications) some variables are not available in the views, like `@kontroller` and `@request`. Thus, you may want to include different sections for background notifications:
160
+
161
+ ```ruby
162
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
163
+ :email => {
164
+ :email_prefix => "[Whatever] ",
165
+ :sender_address => %{"notifier" <notifier@example.com>},
166
+ :exception_recipients => %w{exceptions@example.com},
167
+ :background_sections => %w{my_section1 my_section2 backtrace data}
168
+ }
169
+ ```
170
+
171
+
172
+ #### email_headers
125
173
 
126
- You may want to include different sections for background notifications:
174
+ *Hash os strings, default: {}*
175
+
176
+ Additionally, you may want to set customized headers on the outcoming emails. To do so, simply use the `:email_headers` option:
127
177
 
128
178
  ```ruby
129
- #Example with two new added sections
130
- Whatever::Application.config.middleware.use ExceptionNotifier,
131
- :email_prefix => "[Whatever] ",
132
- :sender_address => %{"notifier" <notifier@example.com>},
133
- :exception_recipients => %w{exceptions@example.com},
134
- :background_sections => %w{my_section1 my_section2} + ExceptionNotifier::Notifier.default_background_sections
179
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
180
+ :email => {
181
+ :email_prefix => "[Whatever] ",
182
+ :sender_address => %{"notifier" <notifier@example.com>},
183
+ :exception_recipients => %w{exceptions@example.com},
184
+ :email_headers => { "X-Custom-Header" => "foobar" }
185
+ }
135
186
  ```
136
187
 
137
- By default, the backtrace and data sections are included in background
138
- notifications.
139
188
 
140
- ### Ignore Exceptions
189
+ #### verbose_subject
190
+
191
+ *Boolean, default: true*
192
+
193
+ If enabled, include the exception message in the subject. Use `:verbose_subject => false` to exclude it.
194
+
141
195
 
142
- You can choose to ignore certain exceptions, which will make
143
- ExceptionNotifier avoid sending notifications for those specified.
144
- There are three ways of specifying which exceptions to ignore:
196
+ #### normalize_subject
145
197
 
146
- - `:ignore_exceptions` - By exception class (i.e. ignore RecordNotFound ones)
198
+ *Boolean, default: false*
147
199
 
148
- - `:ignore_crawlers` - From crawler (i.e. ignore ones originated by Googlebot)
200
+ If enabled, remove numbers from subject so they thread as a single one. Use `:normalize_subject => true` to enable it.
149
201
 
150
- - `:ignore_if` - Custom (i.e. ignore exceptions that satisfy some condition)
151
202
 
152
- ---
203
+ #### email_format
153
204
 
154
- * _:ignore_exceptions_
205
+ *Symbol, default: :text*
155
206
 
156
- Ignore specified exception types.
157
- To achieve that, you should use the _:ignore_exceptions_ option, like this:
207
+ By default, ExceptionNotification sends emails in plain text, in order to sends multipart notifications (aka HTML emails) use `:email_format => :html`.
208
+
209
+
210
+ #### delivery_method
211
+
212
+ *Symbol, default: :smtp*
213
+
214
+ By default, ExceptionNotification sends emails using the ActionMailer configuration of the application. In order to send emails by another delivery method, use the `delivery_method` option:
215
+
216
+ ```ruby
217
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
218
+ :email => {
219
+ :email_prefix => "[Whatever] ",
220
+ :sender_address => %{"notifier" <notifier@example.com>},
221
+ :exception_recipients => %w{exceptions@example.com},
222
+ :delivery_method => :postmark,
223
+ :postmark_settings => {
224
+ :api_key => ENV["POSTMARK_API_KEY"]
225
+ }
226
+ }
227
+ ```
228
+
229
+ Besides the `delivery_method` option, you also can customize the mailer settings by passing a hash under an option named `DELIVERY_METHOD_settings`. Thus, you can use override specific SMTP settings for notifications using:
158
230
 
159
231
  ```ruby
160
- Whatever::Application.config.middleware.use ExceptionNotifier,
161
- :email_prefix => "[Whatever] ",
162
- :sender_address => %{"notifier" <notifier@example.com>},
163
- :exception_recipients => %w{exceptions@example.com},
164
- :ignore_exceptions => ['ActionView::TemplateError'] + ExceptionNotifier.default_ignore_exceptions
232
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
233
+ :email => {
234
+ :email_prefix => "[Whatever] ",
235
+ :sender_address => %{"notifier" <notifier@example.com>},
236
+ :exception_recipients => %w{exceptions@example.com},
237
+ :delivery_method => :stmp,
238
+ :smtp_settings => {
239
+ :user_name => "bob",
240
+ :password => "password",
241
+ }
242
+ }
165
243
  ```
166
244
 
167
- The above will make ExceptionNotifier ignore a *TemplateError*
168
- exception, plus the ones ignored by default.
169
- By default, ExceptionNotifier ignores _ActiveRecord::RecordNotFound_,
170
- _AbstractController::ActionNotFound_ and
171
- _ActionController::RountingError_.
172
245
 
173
- * _:ignore_crawlers_
246
+ #### mailer_parent
174
247
 
175
- In some cases you may want to avoid getting notifications from exceptions
176
- made by crawlers. Using _:ignore_crawlers_ option like this,
248
+ *String, default: ActionMailer::Base*
249
+
250
+ The parent mailer which ExceptionNotification mailer inherit from.
251
+
252
+
253
+ ## Campfire notifier
254
+
255
+ This notifier sends notifications to your Campfire room.
256
+
257
+ ### Usage
258
+
259
+ Just add the [tinder](https://github.com/collectiveidea/tinder) gem to your `Gemfile`:
177
260
 
178
261
  ```ruby
179
- Whatever::Application.config.middleware.use ExceptionNotifier,
180
- :email_prefix => "[Whatever] ",
181
- :sender_address => %{"notifier" <notifier@example.com>},
182
- :exception_recipients => %w{exceptions@example.com},
183
- :ignore_crawlers => %w{Googlebot bingbot}
262
+ gem 'tinder'
184
263
  ```
185
264
 
186
- will prevent sending those unwanted notifications.
265
+ To configure it, you need to set the `subdomain`, `token` and `room_name` options, like this:
266
+
267
+ ```ruby
268
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
269
+ :email => {
270
+ :email_prefix => "[Whatever] ",
271
+ :sender_address => %{"notifier" <notifier@example.com>},
272
+ :exception_recipients => %w{exceptions@example.com}
273
+ },
274
+ :campfire => {
275
+ :subdomain => 'my_subdomain',
276
+ :token => 'my_token',
277
+ :room_name => 'my_room'
278
+ }
279
+ ```
280
+
281
+ ### Options
282
+
283
+ #### subdomain
284
+
285
+ *String, required*
286
+
287
+ Your subdomain at Campfire.
288
+
289
+ #### room_name
290
+
291
+ *String, required*
292
+
293
+ The Campfire room where the notifications must be published to.
294
+
295
+ #### token
187
296
 
188
- * _:ignore_if_
297
+ *String, required*
189
298
 
190
- Last but not least, you can ignore exceptions based on a condition, by
299
+ The API token to allow access to your Campfire account.
300
+
301
+
302
+ For more options to set Campfire, like _ssl_, check [here](https://github.com/collectiveidea/tinder/blob/master/lib/tinder/campfire.rb#L17).
303
+
304
+
305
+ ## Webhook notifier
306
+
307
+ This notifier ships notifications over the HTTP protocol.
308
+
309
+ ### Usage
310
+
311
+ Just add the [HTTParty](https://github.com/jnunemaker/httparty) gem to your `Gemfile`:
312
+
313
+ ```ruby
314
+ gem 'httparty'
315
+ ```
316
+
317
+ To configure it, you need to set the `url` option, like this:
191
318
 
192
319
  ```ruby
193
- Whatever::Application.config.middleware.use ExceptionNotifier,
194
- :email_prefix => "[Whatever] ",
195
- :sender_address => %{"notifier" <notifier@example.com>},
196
- :exception_recipients => %w{exceptions@example.com},
197
- :ignore_if => lambda { |env, e| e.message =~ /^Couldn't find Page with ID=/ }
320
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
321
+ :email => {
322
+ :email_prefix => "[Whatever] ",
323
+ :sender_address => %{"notifier" <notifier@example.com>},
324
+ :exception_recipients => %w{exceptions@example.com}
325
+ },
326
+ :webhook => {
327
+ :url => 'http://domain.com:5555/hubot/path'
328
+ }
198
329
  ```
199
330
 
200
- You can make use of both the environment and the exception inside the lambda to decide wether to
201
- avoid or not sending the notification.
331
+ By default, the WebhookNotifier will call the URLs using the POST method. But, you can change this using the `http_method` option.
202
332
 
203
- ### Headers
333
+ ```ruby
334
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
335
+ :email => {
336
+ :email_prefix => "[Whatever] ",
337
+ :sender_address => %{"notifier" <notifier@example.com>},
338
+ :exception_recipients => %w{exceptions@example.com}
339
+ },
340
+ :webhook => {
341
+ :url => 'http://domain.com:5555/hubot/path',
342
+ :http_method => :get
343
+ }
344
+ ```
204
345
 
205
- Additionally, you may want to set customized headers on the outcoming
206
- emails. To do so, simply use the _:email_headers_ option:
346
+ Besides the `url` and `http_method` options, all the other options are passed directly to HTTParty. Thus, if the HTTP server requires authentication, you can include the following options:
207
347
 
208
348
  ```ruby
209
- Whatever::Application.config.middleware.use ExceptionNotifier,
210
- :email_prefix => "[Whatever] ",
211
- :sender_address => %{"notifier" <notifier@example.com>},
212
- :exception_recipients => %w{exceptions@example.com},
213
- :ignore_if => lambda { |env, e| e.message =~ /^Couldn't find Page with ID=/ },
214
- :email_headers => { "X-Custom-Header" => "foobar" }
349
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
350
+ :email => {
351
+ :email_prefix => "[Whatever] ",
352
+ :sender_address => %{"notifier" <notifier@example.com>},
353
+ :exception_recipients => %w{exceptions@example.com}
354
+ },
355
+ :webhook => {
356
+ :url => 'http://domain.com:5555/hubot/path',
357
+ :basic_auth => {
358
+ :username => 'alice',
359
+ :password => 'password'
360
+ }
361
+ }
215
362
  ```
216
363
 
217
- ### Verbose
364
+ For more HTTParty options, check out the [documentation](https://github.com/jnunemaker/httparty).
365
+
366
+
367
+ ## Custom notifier
368
+
369
+ Simply put, notifiers are objects which respond to `#call(exception, options)` method. Thus, a lambda can be used as a notifier as follow:
370
+
371
+ ```ruby
372
+ ExceptionNotifier.add_notifier :custom_notifier_name,
373
+ ->(exception, options) { puts "Something goes wrong: #{exception.message}"}
374
+ ```
375
+
376
+ More advanced users or third-party framework developers, also can create notifiers to be shipped in gems and take advantage of ExceptionNotification's Notifier API to standardize the [various](https://github.com/airbrake/airbrake) [solutions](https://www.honeybadger.io) [out](http://www.exceptional.io) [there](https://bugsnag.com). For this, beyond the `#call(exception, options)` method, the notifier class MUST BE defined under the ExceptionNotifier namespace and its name sufixed by `Notifier`, e.g: ExceptionNotifier::SimpleNotifier.
377
+
378
+ ### Example
379
+
380
+ Define the custom notifier:
381
+
382
+ ```ruby
383
+ module ExceptionNotifier
384
+ class SimpleNotifier
385
+ def initialize(options)
386
+ # do something with the options...
387
+ end
388
+
389
+ def call(exception, options={})
390
+ # send the notification
391
+ end
392
+ end
393
+ end
394
+ ```
395
+
396
+ Using it:
397
+
398
+ ```ruby
399
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
400
+ :email => {
401
+ :email_prefix => "[Whatever] ",
402
+ :sender_address => %{"notifier" <notifier@example.com>},
403
+ :exception_recipients => %w{exceptions@example.com}
404
+ },
405
+ :simple => {
406
+ # simple notifier options
407
+ }
408
+ ```
409
+
410
+
411
+ ## Ignore Exceptions
218
412
 
219
- You can also choose to exclude the exception message from the subject, which is included by default.
220
- Use _:verbose_subject => false_ to exclude it.
413
+ You can choose to ignore certain exceptions, which will make ExceptionNotification avoid sending notifications for those specified. There are three ways of specifying which exceptions to ignore:
221
414
 
222
- ### Normalize subject
415
+ * `:ignore_exceptions` - By exception class (i.e. ignore RecordNotFound ones)
223
416
 
224
- You can also choose to remove numbers from subject so they thread as a single one.
225
- This is disabled by default.
226
- Use _:normalize_subject => true_ to enable it.
417
+ * `:ignore_crawlers` - From crawler (i.e. ignore ones originated by Googlebot)
227
418
 
228
- ### HTML
419
+ * `:ignore_if` - Custom (i.e. ignore exceptions that satisfy some condition)
229
420
 
230
- You may want to send multipart notifications instead of just plain text, which ExceptionNotification sends by default.
231
- You can do so by adding this to the configuration: _:email_format => :html_.
232
421
 
422
+ ### :ignore_exceptions
233
423
 
234
- Background Notifications
235
- ---
424
+ *Array of strings, default: %w{ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError}*
236
425
 
237
- If you want to send notifications from a background process like
238
- DelayedJob, you should use the background_exception_notification method
239
- like this:
426
+ Ignore specified exception types. To achieve that, you should use the `:ignore_exceptions` option, like this:
427
+
428
+ ```ruby
429
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
430
+ :ignore_exceptions => ['ActionView::TemplateError'] + ExceptionNotifier.ignored_exceptions,
431
+ :email => {
432
+ :email_prefix => "[Whatever] ",
433
+ :sender_address => %{"notifier" <notifier@example.com>},
434
+ :exception_recipients => %w{exceptions@example.com}
435
+ }
436
+ ```
437
+
438
+ The above will make ExceptionNotifier ignore a *TemplateError* exception, plus the ones ignored by default.
439
+
440
+ ### :ignore_crawlers
441
+
442
+ *Array of strings, default: []*
443
+
444
+ In some cases you may want to avoid getting notifications from exceptions made by crawlers. To prevent sending those unwanted notifications, use the `:ignore_crawlers` option like this:
445
+
446
+ ```ruby
447
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
448
+ :ignore_crawlers => %w{Googlebot bingbot},
449
+ :email => {
450
+ :email_prefix => "[Whatever] ",
451
+ :sender_address => %{"notifier" <notifier@example.com>},
452
+ :exception_recipients => %w{exceptions@example.com}
453
+ }
454
+ ```
455
+
456
+ ### :ignore_if
457
+
458
+ *Lambda, default: nil*
459
+
460
+ Last but not least, you can ignore exceptions based on a condition. Take a look:
461
+
462
+ ```ruby
463
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
464
+ :ignore_if => ->(env, exception) { exception.message =~ /^Couldn't find Page with ID=/ },
465
+ :email => {
466
+ :email_prefix => "[Whatever] ",
467
+ :sender_address => %{"notifier" <notifier@example.com>},
468
+ :exception_recipients => %w{exceptions@example.com},
469
+ }
470
+ ```
471
+
472
+ You can make use of both the environment and the exception inside the lambda to decide wether to avoid or not sending the notification.
473
+
474
+
475
+ ## Background Notifications
476
+
477
+ If you want to send notifications from a background process like DelayedJob, you should use the `notify_exception` method like this:
240
478
 
241
479
  ```ruby
242
480
  begin
243
481
  some code...
244
482
  rescue => e
245
- ExceptionNotifier::Notifier.background_exception_notification(e).deliver
483
+ ExceptionNotifier.notify_exception(e)
246
484
  end
247
485
  ```
248
486
 
249
- You can include information about the background process that created
250
- the error by including a data parameter:
487
+ You can include information about the background process that created the error by including a data parameter:
251
488
 
252
489
  ```ruby
253
490
  begin
254
491
  some code...
255
492
  rescue => exception
256
- ExceptionNotifier::Notifier.background_exception_notification(exception,
257
- :data => {:worker => worker.to_s, :queue => queue, :payload => payload}).deliver
493
+ ExceptionNotifier.notify_exception(exception,
494
+ :data => {:worker => worker.to_s, :queue => queue, :payload => payload})
258
495
  end
259
496
  ```
260
497
 
498
+ ### Manually notify of exception
261
499
 
262
- Manually notify of exception
263
- ---
264
-
265
- If your controller action manually handles an error, the notifier will never be
266
- run. To manually notify of an error you can do something like the following:
500
+ If your controller action manually handles an error, the notifier will never be run. To manually notify of an error you can do something like the following:
267
501
 
268
502
  ```ruby
269
503
  rescue_from Exception, :with => :server_error
@@ -271,69 +505,68 @@ rescue_from Exception, :with => :server_error
271
505
  def server_error(exception)
272
506
  # Whatever code that handles the exception
273
507
 
274
- ExceptionNotifier::Notifier.exception_notification(request.env, exception,
275
- :data => {:message => "was doing something wrong"}).deliver
508
+ ExceptionNotifier.notify_exception(exception,
509
+ :env => request.env, :data => {:message => "was doing something wrong"})
276
510
  end
277
511
  ```
278
512
 
279
- Notification
280
- ---
281
513
 
282
- After an exception notification has been delivered the rack environment variable
283
- 'exception_notifier.delivered' will be set to `true`.
514
+ ## Extras
284
515
 
516
+ ### Rails
285
517
 
286
- Override SMTP settings
287
- ---
518
+ Since his first version, ExceptionNotification was just a simple rack middleware. But, the version 4.0.0 introduced the option to use it as a Rails engine. In order to use ExceptionNotification as an engine, just run the following command from the terminal:
288
519
 
289
- You can use specific SMTP settings for notifications:
520
+ rails g exception_notification:install
290
521
 
291
- ```ruby
292
- Whatever::Application.config.middleware.use ExceptionNotifier,
293
- :email_prefix => "[Whatever] ",
294
- :sender_address => %{"notifier" <notifier@example.com>},
295
- :exception_recipients => %w{exceptions@example.com},
296
- :smtp_settings => {
297
- :user_name => "bob",
298
- :password => "password",
299
- }
300
- ```
522
+ This command generates an initialize file (`config/initializers/exception_notification.rb`) where you can customize your configurations.
301
523
 
302
- Versions
303
- ---
304
524
 
305
- NOTE: Master branch is currently set for v3.0.0
525
+ ### Resque/Sidekiq
306
526
 
307
- For v2.6.1, see this tag:
527
+ Instead of manually calling background notifications foreach job/worker, you can configure ExceptionNotification to do this automatically. For this, run:
528
+
529
+ rails g exception_notification:install --resque
308
530
 
309
- <a href="http://github.com/smartinez87/exception_notification/tree/v2.6.1">http://github.com/smartinez87/exception_notification/tree/v2.6.1</a>
531
+ or
310
532
 
311
- For v2.6.0, see this tag:
533
+ rails g exception_notification:install --sidekiq
312
534
 
313
- <a href="http://github.com/smartinez87/exception_notification/tree/v2.6.0">http://github.com/smartinez87/exception_notification/tree/v2.6.0</a>
314
535
 
315
- For v2.5.2, see this tag:
536
+ ## Versions
316
537
 
317
- <a href="http://github.com/smartinez87/exception_notification/tree/v2.5.2">http://github.com/smartinez87/exception_notification/tree/v2.5.2</a>
538
+ For v3.0.1, see this tag:
539
+
540
+ http://github.com/smartinez87/exception_notification/tree/v3.0.1
541
+
542
+ For v3.0.0, see this tag:
543
+
544
+ http://github.com/smartinez87/exception_notification/tree/v3.0.0
545
+
546
+ For v2.6.1, see this tag:
547
+
548
+ http://github.com/smartinez87/exception_notification/tree/v2.6.1
318
549
 
319
550
  For previous releases, visit:
320
551
 
321
- <a href="https://github.com/smartinez87/exception_notification/tags">https://github.com/smartinez87/exception_notification/tags</a>
552
+ https://github.com/smartinez87/exception_notification/tags
322
553
 
323
554
  If you are running Rails 2.3 then see the branch for that:
324
555
 
325
- <a href="http://github.com/smartinez87/exception_notification/tree/2-3-stable">http://github.com/smartinez87/exception_notification/tree/2-3-stable</a>
556
+ http://github.com/smartinez87/exception_notification/tree/2-3-stable
326
557
 
327
558
  If you are running pre-rack Rails then see this tag:
328
559
 
329
- <a href="http://github.com/smartinez87/exception_notification/tree/pre-2-3">http://github.com/smartinez87/exception_notification/tree/pre-2-3</a>
560
+ http://github.com/smartinez87/exception_notification/tree/pre-2-3
561
+
330
562
 
331
- Support and tickets
332
- ---
563
+ ## Support and tickets
333
564
 
334
565
  Here's the list of [issues](https://github.com/smartinez87/exception_notification/issues) we're currently working on.
335
566
 
336
- To contribute, please read first the [Contributing
337
- Guide](https://github.com/smartinez87/exception_notification/blob/master/CONTRIBUTING.md).
567
+ To contribute, please read first the [Contributing Guide](https://github.com/smartinez87/exception_notification/blob/master/CONTRIBUTING.md).
568
+
569
+
570
+ ## License
338
571
 
339
- Copyright (c) 2005 Jamis Buck, released under the MIT license: <a href="http://www.opensource.org/licenses/MIT">http://www.opensource.org/licenses/MIT</a>
572
+ Copyright (c) 2005 Jamis Buck, released under the [MIT license](http://www.opensource.org/licenses/MIT).