exception_notification 4.1.4 → 4.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d847c323ad183933f5a1d63e29f06e9e8d6aaa9
4
- data.tar.gz: 06b5d75b2ca566178384e2d8c60982b73aa1b567
3
+ metadata.gz: 1ea5f9bb411eb98d44e93a3c8f1c6bc5cd90169f
4
+ data.tar.gz: 75d218c247a08ec8d4020a71441326adce120f1e
5
5
  SHA512:
6
- metadata.gz: 2d0744472e25aab1f35eaf6c66ab6ddd771885560fec22d3b60d6799ddff773689e1faf75af486b48280f59528fc119a54661474e0c56a86ed855799b213ba33
7
- data.tar.gz: 2e51a10be77772151a0f866f81f105bf8b76d2d92bbd98537b36377db752592abd7704387380118bf3b40cb36c825b232f8bb26a41d7f27e5de9bb43928fbf60
6
+ metadata.gz: 8b1e2f2b115a707aeae5b7f88ea9c9fda6cd1fa72312328cef6ad9236038b473eb75f3f6fe3d721af39101b532d650de1c8232739f3e1fd6246f0f5e4d6e182e
7
+ data.tar.gz: 6ff2e5aab261ad918ea3049f2cfc924332902e8f1a9127ef3e23cd1dde9c8e82f3923cc63f5f520b205b3f93d41ea79ef23883e909b7c8bc69bab14bf68e786b
data/Appraisals CHANGED
@@ -1,11 +1,8 @@
1
- appraise "rails4_0" do
2
- gem 'rails', '4.0.5'
3
- end
4
-
5
- appraise "rails4_1" do
6
- gem 'rails', '~> 4.1.1'
7
- end
1
+ rails_versions = ['~> 4.0.5', '~> 4.1.1', '~> 4.2.0', '~> 5.0.0']
8
2
 
9
- appraise "rails4_2" do
10
- gem 'rails', '~> 4.2.0'
3
+ rails_versions.each do |rails_version|
4
+ appraise "rails#{rails_version.slice(/\d+\.\d+/).gsub('.', '_')}" do
5
+ gem 'rails', rails_version
6
+ gem "sqlite3"
7
+ end
11
8
  end
@@ -1,8 +1,21 @@
1
+ == 4.2.0
2
+
3
+ * enhancements
4
+ * update URL in gemspec (by @ktdreyer)
5
+ * Add `hostname` to Slack notifier (by @juanazam)
6
+ * Allow `exception_recipients` to be a proc (by @kellyjosephprice)
7
+ * Add Mattermost integration (by @Aschen)
8
+ * Rails 5 compatible
9
+
10
+ * bug fixes
11
+ * Fix error when showing timestamp on non Rails apps
12
+ * Fix delivery failure when deliver_with specified (by @grzuy)
13
+
1
14
  == 4.1.4
2
15
 
3
16
  * bug fixes
4
- * HTML-escape exception messages sent to hipchat
5
- * Send the correct options in send_notice
17
+ * HTML-escape exception messages sent to hipchat (by @gburt)
18
+ * Send the correct options in send_notice (by @pcboy)
6
19
 
7
20
  == 4.1.3
8
21
 
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant, version 1.2.0](http://contributor-covenant.org/version/1/2/0/).
@@ -1,4 +1,7 @@
1
- Copyright (c) 2005 Jamis Buck
1
+ Copyright (c) 2011-2016 Sebastian Martinez
2
+ Copyright (c) 2005-2010 Jamis Buck
3
+
4
+ The MIT License (MIT)
2
5
 
3
6
  Permission is hereby granted, free of charge, to any person obtaining
4
7
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ---
11
11
 
12
- The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application. The built-in notifiers can deliver notifications by [email](#email-notifier), [Campfire](#campfire-notifier), [HipChat](#hipchat-notifier), [Slack](#slack-notifier), [IRC](#irc-notifier) or via custom [WebHooks](#webhook-notifier).
12
+ The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application. The built-in notifiers can deliver notifications by [email](#email-notifier), [Campfire](#campfire-notifier), [HipChat](#hipchat-notifier), [Slack](#slack-notifier), [Mattermost](#mattermost-notifier), [IRC](#irc-notifier) or via custom [WebHooks](#webhook-notifier).
13
13
 
14
14
  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.
15
15
 
@@ -37,6 +37,7 @@ ExceptionNotification is used as a rack middleware, or in the environment you wa
37
37
  ```ruby
38
38
  Rails.application.config.middleware.use ExceptionNotification::Rack,
39
39
  :email => {
40
+ :deliver_with => :deliver, # Rails >= 4.2.1 do not need this option since it defaults to :deliver_now
40
41
  :email_prefix => "[PREFIX] ",
41
42
  :sender_address => %{"notifier" <notifier@example.com>},
42
43
  :exception_recipients => %w{exceptions@example.com}
@@ -49,6 +50,36 @@ Rails.application.config.middleware.use ExceptionNotification::Rack,
49
50
 
50
51
  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).
51
52
 
53
+ ### Custom Data, e.g. Current User
54
+
55
+ Save the current user in the `request` using a controller callback.
56
+
57
+ ```ruby
58
+ class ApplicationController < ActionController::Base
59
+ before_filter :prepare_exception_notifier
60
+ private
61
+ def prepare_exception_notifier
62
+ request.env["exception_notifier.exception_data"] = {
63
+ :current_user => current_user
64
+ }
65
+ end
66
+ end
67
+ ```
68
+
69
+ The current user will show up in your email, in a new section titled "Data".
70
+
71
+ ```
72
+ ------------------------------- Data:
73
+
74
+ * data: {:current_user=>
75
+ #<User:0x007ff03c0e5860
76
+ id: 3,
77
+ email: "jane.doe@example.com", # etc...
78
+ ```
79
+
80
+ For more control over the display of custom data, see "Email notifier ->
81
+ Options -> sections" below.
82
+
52
83
  ## Notifiers
53
84
 
54
85
  ExceptionNotification relies on notifiers to deliver notifications when errors occur in your applications. By default, six notifiers are available:
@@ -58,6 +89,7 @@ ExceptionNotification relies on notifiers to deliver notifications when errors o
58
89
  * [HipChat notifier](#hipchat-notifier)
59
90
  * [IRC notifier](#irc-notifier)
60
91
  * [Slack notifier](#slack-notifier)
92
+ * [Mattermost notifier](#mattermost-notifier)
61
93
  * [WebHook notifier](#webhook-notifier)
62
94
 
63
95
  But, you also can easily implement your own [custom notifier](#custom-notifier).
@@ -144,9 +176,9 @@ Who the message is from.
144
176
 
145
177
  ##### exception_recipients
146
178
 
147
- *String/Array of strings, default: []*
179
+ *String/Array of strings/Proc, default: []*
148
180
 
149
- Who the message is destined for, can be a string of addresses, or an array of addresses.
181
+ Who the message is destined for, can be a string of addresses, an array of addresses, or it can be a proc that returns a string of addresses or an array of addresses. The proc will be evaluated when the mail is sent.
150
182
 
151
183
  ##### email_prefix
152
184
 
@@ -308,7 +340,7 @@ This notifier sends notifications to your Hipchat room.
308
340
 
309
341
  #### Usage
310
342
 
311
- Just add the [hipchat](https://github.com/hipchat/hipchat) gem to your `Gemfile`:
343
+ Just add the [hipchat](https://github.com/hipchat/hipchat-rb) gem to your `Gemfile`:
312
344
 
313
345
  ```ruby
314
346
  gem 'hipchat'
@@ -493,7 +525,20 @@ Rails.application.config.middleware.use ExceptionNotification::Rack,
493
525
  }
494
526
  ```
495
527
 
496
- The slack notification will include any data saved under `env["exception_notifier.exception_data"]`. If you find this too verbose, you can determine to exclude certain information by doing the following:
528
+ The slack notification will include any data saved under `env["exception_notifier.exception_data"]`.
529
+
530
+ An example of how to send the server name to Slack in Rails (put this code in application_controller.rb):
531
+
532
+ ```ruby
533
+ before_filter :set_notification
534
+
535
+ def set_notification
536
+ request.env['exception_notifier.exception_data'] = {"server" => request.env['SERVER_NAME']}
537
+ # can be any key-value pairs
538
+ end
539
+ ```
540
+
541
+ If you find this too verbose, you can determine to exclude certain information by doing the following:
497
542
 
498
543
  ```ruby
499
544
  Rails.application.config.middleware.use ExceptionNotification::Rack,
@@ -545,6 +590,121 @@ more information. Default: 'incoming-webhook'
545
590
 
546
591
  Contains additional payload for a message (e.g avatar, attachments, etc). See [slack-notifier](https://github.com/stevenosloan/slack-notifier#additional-parameters) for more information.. Default: '{}'
547
592
 
593
+ ## Mattermost notifier
594
+
595
+ Post notification in a mattermost channel via [incoming webhook](http://docs.mattermost.com/developer/webhooks-incoming.html)
596
+
597
+ Just add the [HTTParty](https://github.com/jnunemaker/httparty) gem to your `Gemfile`:
598
+
599
+ ```ruby
600
+ gem 'httparty'
601
+ ```
602
+
603
+ To configure it, you **need** to set the `webhook_url` option.
604
+ You can also specify an other channel with `channel` option.
605
+
606
+ ```ruby
607
+ Rails.application.config.middleware.use ExceptionNotification::Rack,
608
+ :email => {
609
+ :email_prefix => "[PREFIX] ",
610
+ :sender_address => %{"notifier" <notifier@example.com>},
611
+ :exception_recipients => %w{exceptions@example.com}
612
+ },
613
+ :mattermost => {
614
+ :webhook_url => 'http://your-mattermost.com/hooks/blablabla',
615
+ :channel => 'my-channel'
616
+ }
617
+ ```
618
+
619
+ If you are using Github or Gitlab for issues tracking, you can specify `git_url` as follow to add a *Create issue* link in you notification.
620
+ By default this will use your Rails application name to match the git repository. If yours differ you can specify `app_name`.
621
+
622
+
623
+ ```ruby
624
+ Rails.application.config.middleware.use ExceptionNotification::Rack,
625
+ :email => {
626
+ :email_prefix => "[PREFIX] ",
627
+ :sender_address => %{"notifier" <notifier@example.com>},
628
+ :exception_recipients => %w{exceptions@example.com}
629
+ },
630
+ :mattermost => {
631
+ :webhook_url => 'http://your-mattermost.com/hooks/blablabla',
632
+ :git_url => 'github.com/aschen'
633
+ }
634
+ ```
635
+
636
+ You can also specify the bot name and avatar with `username` and `avatar` options.
637
+
638
+ ```ruby
639
+ Rails.application.config.middleware.use ExceptionNotification::Rack,
640
+ :email => {
641
+ :email_prefix => "[PREFIX] ",
642
+ :sender_address => %{"notifier" <notifier@example.com>},
643
+ :exception_recipients => %w{exceptions@example.com}
644
+ },
645
+ :mattermost => {
646
+ :webhook_url => 'http://your-mattermost.com/hooks/blablabla',
647
+ :avatar => 'http://example.com/your-image.png',
648
+ :username => 'Fail bot'
649
+ }
650
+ ```
651
+
652
+ Finally since the notifier use HTTParty, you can include all HTTParty options, like basic_auth for example.
653
+
654
+ ```ruby
655
+ Rails.application.config.middleware.use ExceptionNotification::Rack,
656
+ :email => {
657
+ :email_prefix => "[PREFIX] ",
658
+ :sender_address => %{"notifier" <notifier@example.com>},
659
+ :exception_recipients => %w{exceptions@example.com}
660
+ },
661
+ :mattermost => {
662
+ :webhook_url => 'http://your-mattermost.com/hooks/blablabla',
663
+ :basic_auth => {
664
+ :username => 'clara',
665
+ :password => 'password'
666
+ }
667
+ }
668
+ ```
669
+
670
+ #### Options
671
+
672
+ ##### webhook_url
673
+
674
+ *String, required*
675
+
676
+ The Incoming WebHook URL on mattermost.
677
+
678
+ ##### channel
679
+
680
+ *String, optional*
681
+
682
+ Message will appear in this channel. Defaults to the channel you set as such on mattermost.
683
+
684
+ ##### username
685
+
686
+ *String, optional*
687
+
688
+ Username of the bot. Defaults to "Incoming Webhook"
689
+
690
+ ##### avatar
691
+
692
+ *String, optional*
693
+
694
+ Avatar of the bot. Defaults to incoming webhook icon.
695
+
696
+ ##### git_url
697
+
698
+ *String, optional*
699
+
700
+ Url of your gitlab or github with your organisation name for issue creation link (Eg: `github.com/aschen`). Defaults to nil and don't add link to the notification.
701
+
702
+ ##### app_name
703
+
704
+ *String, optional*
705
+
706
+ Your application name used for issue creation link. Defaults to ``` Rails.application.class.parent_name.underscore```.
707
+
548
708
 
549
709
  ### WebHook notifier
550
710
 
@@ -650,7 +810,6 @@ Rails.application.config.middleware.use ExceptionNotification::Rack,
650
810
  }
651
811
  ```
652
812
 
653
-
654
813
  ## Ignore Exceptions
655
814
 
656
815
  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:
@@ -775,6 +934,7 @@ Since his first version, ExceptionNotification was just a simple rack middleware
775
934
 
776
935
  This command generates an initialize file (`config/initializers/exception_notification.rb`) where you can customize your configurations.
777
936
 
937
+ Make sure the gem is not listed solely under the `production` group, since this initializer will be loaded regardless of environment.
778
938
 
779
939
  ### Resque/Sidekiq
780
940
 
@@ -786,6 +946,7 @@ or
786
946
 
787
947
  rails g exception_notification:install --sidekiq
788
948
 
949
+ As above, make sure the gem is not listed solely under the `production` group, since this initializer will be loaded regardless of environment.
789
950
 
790
951
  ## Versions
791
952
 
@@ -824,6 +985,9 @@ Here's the list of [issues](https://github.com/smartinez87/exception_notificatio
824
985
 
825
986
  To contribute, please read first the [Contributing Guide](https://github.com/smartinez87/exception_notification/blob/master/CONTRIBUTING.md).
826
987
 
988
+ ## Code of Conduct
989
+
990
+ Everyone interacting in this project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow our [code of conduct](https://github.com/smartinez87/exception_notification/blob/master/CODE_OF_CONDUCT.md).
827
991
 
828
992
  ## License
829
993
 
data/Rakefile CHANGED
@@ -5,13 +5,7 @@ require 'appraisal'
5
5
 
6
6
  require 'rake/testtask'
7
7
 
8
- task 'setup_dummy_app' do
9
- unless File.exists? "test/dummy/db/test.sqlite3"
10
- Bundler.with_clean_env do
11
- sh "cd test/dummy; bundle; bundle exec rake db:migrate; bundle exec rake db:test:prepare; cd ../../;"
12
- end
13
- end
14
- end
8
+ task :default => [:test]
15
9
 
16
10
  Rake::TestTask.new(:test) do |t|
17
11
  t.libs << 'lib'
@@ -19,5 +13,3 @@ Rake::TestTask.new(:test) do |t|
19
13
  t.pattern = 'test/**/*_test.rb'
20
14
  t.verbose = true
21
15
  end
22
-
23
- task :default => [:setup_dummy_app, :test]
@@ -1,9 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'exception_notification'
3
- s.version = '4.1.4'
3
+ s.version = '4.2.0.rc1'
4
4
  s.authors = ["Jamis Buck", "Josh Peek"]
5
+ s.date = %q{2016-07-08}
5
6
  s.summary = "Exception notification for Rails apps"
6
- s.homepage = "http://smartinez87.github.com/exception_notification"
7
+ s.homepage = "https://smartinez87.github.io/exception_notification/"
7
8
  s.email = "smartinez87@gmail.com"
8
9
  s.license = "MIT"
9
10
 
@@ -15,10 +16,10 @@ Gem::Specification.new do |s|
15
16
  s.test_files = `git ls-files -- test`.split("\n")
16
17
  s.require_path = 'lib'
17
18
 
18
- s.add_dependency("actionmailer", "~> 4.0")
19
- s.add_dependency("activesupport", "~> 4.0")
19
+ s.add_dependency("actionmailer", ">= 4.0", "< 6")
20
+ s.add_dependency("activesupport", ">= 4.0", "< 6")
20
21
 
21
- s.add_development_dependency "rails", "~> 4.0"
22
+ s.add_development_dependency "rails", ">= 4.0", "< 6"
22
23
  s.add_development_dependency "resque", "~> 1.2.0"
23
24
  # Sidekiq 3.2.2 does not support Ruby 1.9.
24
25
  s.add_development_dependency "sidekiq", "~> 3.0.0", "< 3.2.2"
@@ -27,7 +28,7 @@ Gem::Specification.new do |s|
27
28
  s.add_development_dependency "mocha", ">= 0.13.0"
28
29
  s.add_development_dependency "sqlite3", ">= 1.3.4"
29
30
  s.add_development_dependency "coveralls", "~> 0.8.2"
30
- s.add_development_dependency "appraisal", "~> 1.0.0"
31
+ s.add_development_dependency "appraisal", "~> 2.0.0"
31
32
  s.add_development_dependency "hipchat", ">= 1.0.0"
32
33
  s.add_development_dependency "carrier-pigeon", ">= 0.7.0"
33
34
  s.add_development_dependency "slack-notifier", ">= 1.0.0"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "4.0.5"
5
+ gem "rails", "~> 4.0.5"
6
+ gem "sqlite3"
6
7
 
7
8
  gemspec :path => "../"
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.1.1"
6
+ gem "sqlite3"
6
7
 
7
8
  gemspec :path => "../"
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.2.0"
6
+ gem "sqlite3"
6
7
 
7
8
  gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.0"
6
+ gem "sqlite3"
7
+
8
+ gemspec :path => "../"
@@ -14,6 +14,7 @@ module ExceptionNotifier
14
14
  autoload :WebhookNotifier, 'exception_notifier/webhook_notifier'
15
15
  autoload :IrcNotifier, 'exception_notifier/irc_notifier'
16
16
  autoload :SlackNotifier, 'exception_notifier/slack_notifier'
17
+ autoload :MattermostNotifier, 'exception_notifier/mattermost_notifier'
17
18
 
18
19
  class UndefinedNotifierError < StandardError; end
19
20
 
@@ -23,7 +24,10 @@ module ExceptionNotifier
23
24
 
24
25
  # Define a set of exceptions to be ignored, ie, dont send notifications when any of them are raised.
25
26
  mattr_accessor :ignored_exceptions
26
- @@ignored_exceptions = %w{ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError ActionController::UnknownFormat}
27
+ @@ignored_exceptions = %w{ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError ActionController::UnknownFormat ActionController::UrlGenerationError}
28
+
29
+ mattr_accessor :testing_mode
30
+ @@testing_mode = false
27
31
 
28
32
  class << self
29
33
  # Store conditions that decide when exceptions must be ignored or not.
@@ -32,6 +36,10 @@ module ExceptionNotifier
32
36
  # Store notifiers that send notifications when exceptions are raised.
33
37
  @@notifiers = {}
34
38
 
39
+ def testing_mode!
40
+ self.testing_mode = true
41
+ end
42
+
35
43
  def notify_exception(exception, options={})
36
44
  return false if ignored_exception?(options[:ignore_exceptions], exception)
37
45
  return false if ignored?(exception, options)
@@ -82,6 +90,8 @@ module ExceptionNotifier
82
90
  def ignored?(exception, options)
83
91
  @@ignores.any?{ |condition| condition.call(exception, options) }
84
92
  rescue Exception => e
93
+ raise e if @@testing_mode
94
+
85
95
  logger.warn "An error occurred when evaluating an ignore condition. #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
86
96
  false
87
97
  end
@@ -94,6 +104,8 @@ module ExceptionNotifier
94
104
  notifier = registered_exception_notifier(notifier_name)
95
105
  notifier.call(exception, options)
96
106
  rescue Exception => e
107
+ raise e if @@testing_mode
108
+
97
109
  logger.warn "An error occurred when sending a notification using '#{notifier_name}' notifier. #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
98
110
  false
99
111
  end