errdo 0.9.1 → 0.10.0

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: bcc8bc45f83d4e56758de834b00faf00248fda69
4
- data.tar.gz: d914ab5cb2923b2355b8d8556ed9ebb2a4ffb319
3
+ metadata.gz: afd0ced27a284c7156048fea8ea7cdbe545ef536
4
+ data.tar.gz: ea3ca879d18125601699fba3db1c9abef1a4af17
5
5
  SHA512:
6
- metadata.gz: 81a12eabf89eb076dff857bd16ccd22e9eb0057ab79b6286a4de517d0497c350d1aab4477133ba068d0be0391724845402e023bcc1e88fb4b5b8bd7995b3377c
7
- data.tar.gz: eaa11a4adbf37e7bd2bc8684b0d2428f864ee26c4f1ae107cd86982f5498d422b07917ad5b2727325f02a4bc7584bf8692ed3916baca9336264631f7c6e9fc15
6
+ metadata.gz: 941461a2b07d34e392b40e6c667e6c481750379ddf95a971860e4e6c3ac19a3ed9cc17557f03a4429a74b8b8e32feb8f72376978e1f8a6cdda47f1e6ed7f4828
7
+ data.tar.gz: 1f1ee20cb3f0d06355ee5b062ab62a8f2712e53513f9c8cbd6920ea7a68f92b5b27fd1f6df0bec41ae3524f0ce0ef03881fd826c989cd14ffea8551a68271666
@@ -5,7 +5,9 @@ module Errdo
5
5
  user_parser = Errdo::Models::UserParser.new(env)
6
6
  @env_parser = Errdo::Models::ErrorEnvParser.new(env, user_parser)
7
7
  error = create_errors(@env_parser) unless Errdo.error_name.blank?
8
- send_slack_notification(error, @env_parser)
8
+ Errdo.notify_with.each do |notifier|
9
+ notifier.notify(error, @env_parser)
10
+ end
9
11
  end
10
12
 
11
13
  private
@@ -16,16 +18,5 @@ module Errdo
16
18
  return error
17
19
  end
18
20
 
19
- def send_slack_notification(error, parser)
20
- if Errdo.slack_notifier
21
- messager = Errdo::Models::SlackMessager.new(error, parser)
22
- begin
23
- Errdo.slack_notifier.ping messager.message
24
- rescue => e
25
- Rails.logger.error e
26
- end
27
- end
28
- end
29
-
30
21
  end
31
22
  end
@@ -2,6 +2,7 @@ module Errdo
2
2
  # rubocop:disable MutableConstant
3
3
  EXTENSIONS = []
4
4
  AUTHORIZATION_ADAPTERS = {}
5
+ NOTIFICATION_ADAPTERS = {}
5
6
  # rubocop:enable MutableConstant
6
7
 
7
8
  # The extension may define various adapters (e.g., for authorization) and
@@ -15,4 +16,14 @@ module Errdo
15
16
  AUTHORIZATION_ADAPTERS[extension_key] = extension_definition::AuthorizationAdapter
16
17
  end
17
18
  end
19
+
20
+ def self.add_notification(notification_key, notification_definition, options = {})
21
+ options.assert_valid_keys(:notification)
22
+
23
+ EXTENSIONS << notification_key
24
+
25
+ if options[:notification]
26
+ NOTIFICATION_ADAPTERS[notification_key] = notification_definition::NotificationAdapter
27
+ end
28
+ end
18
29
  end
@@ -0,0 +1,64 @@
1
+ require 'slack-notifier'
2
+ require_relative '../../helpers/views_helper.rb'
3
+
4
+ module Errdo
5
+ module Notifications
6
+ module Slack
7
+ # This adapter is for slack notifier
8
+ class NotificationAdapter
9
+
10
+ # See the slack notifier for where the initialization happens.
11
+ def initialize(options = {})
12
+ @slack_notifier = ::Slack::Notifier.new options[:webhook],
13
+ channel: options[:channel] || nil,
14
+ icon_emoji: options[:icon] || ':boom:',
15
+ username: options[:name] || 'Errdo-bot'
16
+ end
17
+
18
+ def notify(error, parser)
19
+ messager = SlackMessager.new(error, parser)
20
+ begin
21
+ @slack_notifier.ping messager.message
22
+ rescue => e
23
+ Rails.logger.error e
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ class SlackMessager
30
+
31
+ include Errdo::Helpers::ViewsHelper # For the naming of the user in the message
32
+
33
+ def initialize(error, parser)
34
+ if error.nil?
35
+ @user = parser.user
36
+ @backtrace = parser.short_backtrace
37
+ @exception_name = parser.exception_name
38
+ @exception_message = parser.exception_message
39
+ else
40
+ @user = error.last_experiencer
41
+ @backtrace = error.short_backtrace
42
+ @exception_name = error.exception_class_name
43
+ @exception_message = error.exception_message
44
+ end
45
+ end
46
+
47
+ def message
48
+ "#{exception_string}#{user_message_addon}\n#{@backtrace}"
49
+ end
50
+
51
+ private
52
+
53
+ def exception_string
54
+ "#{@exception_name} | #{@exception_message}"
55
+ end
56
+
57
+ def user_message_addon
58
+ "\nExperienced by #{user_show_string(@user)} " if @user
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ require 'errdo/notifications/slack/notification_adapter'
2
+
3
+ Errdo.add_notification(:slack, Errdo::Notifications::Slack, notification: true)
data/lib/errdo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Errdo
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.10.0'.freeze
3
3
  end
data/lib/errdo.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'errdo/engine'
2
2
  require 'errdo/extension'
3
3
  require 'errdo/extensions/cancancan'
4
- require 'slack-notifier'
4
+ require 'errdo/notifications/slack'
5
5
 
6
6
  module Errdo
7
7
  # A lot of this authorization/authentication code was heavily inspired by Rails Admin gem, which is a great gem
@@ -27,22 +27,6 @@ module Errdo
27
27
  mattr_accessor :user_show_path
28
28
  @@user_show_path = nil
29
29
 
30
- # This is the webhook path for slack integration
31
- mattr_accessor :slack_webhook
32
- @@slack_webhook = nil
33
-
34
- # The icon that the slack integration posts with
35
- mattr_accessor :slack_icon
36
- @@slack_icon = ":boom:"
37
-
38
- # The name that the slack integration posts with
39
- mattr_accessor :slack_name
40
- @@slack_name = "Errdo-bot"
41
-
42
- # The channel to post the errors to. Default is whatever the default of the integration is
43
- mattr_accessor :slack_channel
44
- @@slack_channel = nil
45
-
46
30
  mattr_accessor :dirty_words
47
31
  @@dirty_words = %w(password passwd password_confirmation secret confirm_password secret_token)
48
32
  # rubocop:enable Style/ClassVars
@@ -92,16 +76,27 @@ module Errdo
92
76
  @authorize || DEFAULT_AUTHORIZE
93
77
  end
94
78
 
95
- def self.slack_notifier
96
- @slack_notifier ||= nil
97
- if @slack_notifier
98
- @slack_notifier
99
- elsif slack_webhook
100
- @slack_notifier = Slack::Notifier.new slack_webhook,
101
- channel: slack_channel || nil,
102
- icon_emoji: slack_icon,
103
- username: slack_name
79
+ # == Notifications ==
80
+ # Setup notifications
81
+ #
82
+ # Every configured notifier can be set here as
83
+ # @example
84
+ # Errdo.notify_with slack: { webhook: "WEBHOOK-URL",
85
+ # channel: "#general"
86
+ # icon: ":boom:",
87
+ # name: "Errdo-bot" }
88
+ #
89
+ #
90
+ # Right now, only slack is supported
91
+ def self.notify_with(notifiers = nil)
92
+ if notifiers
93
+ @notifiers = []
94
+ notifiers.each do |notifier|
95
+ klass = Errdo::NOTIFICATION_ADAPTERS[notifier[0]]
96
+ @notifiers.append(klass.new(**notifier[1])) # The options will be in the second field
97
+ end
104
98
  end
99
+ @notifiers ||= []
105
100
  end
106
101
 
107
102
  def self.setup
@@ -36,15 +36,15 @@ Errdo.setup do |config|
36
36
  # Default is the errdo root path
37
37
  # config.user_show_path = :user_path
38
38
 
39
- ## == Slack Integration ====================
39
+ ## == Notification Integration ====================
40
40
  # See the github page at https://github.com/erichaydel/errdo for more info on how to set up slack
41
- # If you want to set up slack, this is the only required parameter
42
- # config.slack_webhook = 'YOUR-WEBHOOK-HERE'
43
-
44
- # You can customize what icon and name the notification posts with. Default is an explosion and "Errdo-bot"
45
- # config.slack_icon = ':boom:'
46
- # config.slack_name = 'Errdo-bot'
41
+ # If you want to set up slack, this is the only required parameter.
42
+ # The rest are totally optional, and default to the values here
43
+ #
44
+ # Errdo.notify_with slack: { webhook: "WEBHOOK-URL",
45
+ # channel: nil
46
+ # icon: ":boom:",
47
+ # name: "Errdo-bot" }
47
48
 
48
- # This configures the channel to post error notifications to. If nothing is set, it will post the the default
49
- # config.slack_channel = '#channel'
49
+ # For now, slack is the only integration. More coming soon!
50
50
  end
@@ -15,4 +15,6 @@ Errdo.setup do |config|
15
15
  # Note: The model name "{name}_instance" should also be free
16
16
  #
17
17
  config.error_name = :errors
18
+
19
+ # config.notify_with slack: { webhook: "https://hooks.slack.com/services/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" }
18
20
  end
Binary file