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 +4 -4
- data/app/models/errdo/exception.rb +3 -12
- data/lib/errdo/extension.rb +11 -0
- data/lib/errdo/notifications/slack/notification_adapter.rb +64 -0
- data/lib/errdo/notifications/slack.rb +3 -0
- data/lib/errdo/version.rb +1 -1
- data/lib/errdo.rb +21 -26
- data/lib/generators/templates/errdo.rb +9 -9
- data/test/dummy/config/initializers/errdo.rb +2 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +78233 -0
- data/test/integrations/plugins_integration_test.rb +7 -7
- metadata +4 -5
- data/lib/errdo/models/slack_messager.rb +0 -37
- data/test/dummy/tmp/pids/server.pid +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afd0ced27a284c7156048fea8ea7cdbe545ef536
|
4
|
+
data.tar.gz: ea3ca879d18125601699fba3db1c9abef1a4af17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
data/lib/errdo/extension.rb
CHANGED
@@ -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
|
data/lib/errdo/version.rb
CHANGED
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
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
## ==
|
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
|
-
#
|
43
|
-
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
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
|
-
#
|
49
|
-
# config.slack_channel = '#channel'
|
49
|
+
# For now, slack is the only integration. More coming soon!
|
50
50
|
end
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|