denouncer 0.6.1 → 0.7.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.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/denouncer.rb +21 -1
- data/lib/denouncer/info_error.rb +4 -0
- data/lib/denouncer/notifiers/airbrake_notifier.rb +11 -0
- data/lib/denouncer/notifiers/amqp_notifier.rb +21 -4
- data/lib/denouncer/notifiers/base_notifier.rb +9 -1
- data/lib/denouncer/notifiers/console_notifier.rb +11 -1
- data/lib/denouncer/notifiers/honeybadger_notifier.rb +12 -0
- data/lib/denouncer/notifiers/smtp_notifier.rb +51 -5
- data/lib/denouncer/version.rb +1 -1
- data/spec/lib/denouncer/notifiers/amqp_notifier_spec.rb +17 -24
- data/spec/lib/denouncer/notifiers/smtp_notifier_spec.rb +6 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed284b585007fb67403b53f2a89977c8275765e1
|
4
|
+
data.tar.gz: d893fbd56d104bda09efdf692a0eeac088522267
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 233ec02b14c08f01db39a204cb4699d1488fd2d037dff0caf1f46c2a985447411afcf777aec337f15a2c4022515253a6d28c75838e48bbd40da92c6601350b30
|
7
|
+
data.tar.gz: e8920a8f456feff216979ed0dbc8f19e38b7b9b48ab341a813a86119fff8658f1db602acf9a359181fa9c1fca602e9ea5f05d8205d707b1f394e8ff117b084bd
|
data/README.md
CHANGED
@@ -195,6 +195,8 @@ The example below configures the amqp and smtp notifiers in parallel.
|
|
195
195
|
|
196
196
|
## Usage
|
197
197
|
|
198
|
+
### Error notification
|
199
|
+
|
198
200
|
The example below shows a basic usage pattern for denouncer notifications.
|
199
201
|
Catch exceptions, then use denouncer's notify function and then re-raise the error again.
|
200
202
|
|
@@ -215,6 +217,10 @@ or
|
|
215
217
|
|
216
218
|
The metadata is optional and defaults to nil.
|
217
219
|
|
220
|
+
### Information notification
|
221
|
+
|
222
|
+
Denouncer.info 'This contains lots of valuable information :)', { t1: "metadata 1", t2: "metadata 2" }
|
223
|
+
|
218
224
|
## Test Suite
|
219
225
|
|
220
226
|
bundle exec rspec
|
@@ -223,6 +229,10 @@ The metadata is optional and defaults to nil.
|
|
223
229
|
|
224
230
|
[This](https://docs.google.com/drawings/d/16DaQhsAwcr-5zlguhKGwigpdNpOgO4-IXssLst7zlUM/edit?usp=sharing) illustration shows the basic architecture of the denouncer gem.
|
225
231
|
|
232
|
+
## TODOs
|
233
|
+
|
234
|
+
* Implement better test coverage
|
235
|
+
|
226
236
|
## Contributing
|
227
237
|
|
228
238
|
1. Fork it ( https://github.com/[my-github-username]/denouncer/fork )
|
data/lib/denouncer.rb
CHANGED
@@ -2,6 +2,7 @@ require "denouncer/version"
|
|
2
2
|
|
3
3
|
module Denouncer
|
4
4
|
autoload :Notifiers, File.expand_path('../denouncer/notifiers', __FILE__)
|
5
|
+
autoload :InfoError, File.expand_path('../denouncer/info_error', __FILE__)
|
5
6
|
|
6
7
|
DEFAULT_NOTIFIER = :smtp
|
7
8
|
|
@@ -50,7 +51,7 @@ module Denouncer
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
# Sends a notification using the configured
|
54
|
+
# Sends a notification using the configured notifiers.
|
54
55
|
#
|
55
56
|
# @param error [StandardError]
|
56
57
|
# @param metadata [Hash]
|
@@ -71,6 +72,25 @@ module Denouncer
|
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
75
|
+
# Sends a info notification using the configured notifiers.
|
76
|
+
#
|
77
|
+
# @param error [StandardError]
|
78
|
+
# @param metadata [Hash]
|
79
|
+
def self.info(info_message, metadata = nil)
|
80
|
+
if is_configured?
|
81
|
+
begin
|
82
|
+
notifiers.each do |notif|
|
83
|
+
notif.info info_message, metadata
|
84
|
+
end
|
85
|
+
return true
|
86
|
+
rescue => err
|
87
|
+
puts "An error occured while sending an info notification via denouncer! Error: #{err.message}, Backtrace: #{err.backtrace}"
|
88
|
+
end
|
89
|
+
else
|
90
|
+
return false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
74
94
|
# Sends a notification and raises the given error on return
|
75
95
|
#
|
76
96
|
# @param error [StandardError]
|
@@ -30,6 +30,17 @@ module Denouncer
|
|
30
30
|
backtrace: error.backtrace
|
31
31
|
)
|
32
32
|
end
|
33
|
+
|
34
|
+
# Sends a info notification.
|
35
|
+
#
|
36
|
+
# @param info_message [String]
|
37
|
+
# @param metadata [Hash]
|
38
|
+
def info(info_message, metadata = nil)
|
39
|
+
Airbrake.notify(Denouncer::InfoError.new(info_message),
|
40
|
+
api_key: config[:api_key],
|
41
|
+
error_message: info_message
|
42
|
+
)
|
43
|
+
end
|
33
44
|
end
|
34
45
|
end
|
35
46
|
end
|
@@ -33,13 +33,22 @@ module Denouncer
|
|
33
33
|
# @param error [StandardError]
|
34
34
|
# @param metadata [Hash]
|
35
35
|
def notify(error, metadata = nil)
|
36
|
-
msg =
|
36
|
+
msg = generate_error_hash(error, metadata).to_json
|
37
|
+
send_message_via_amqp msg
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sends a info notification.
|
41
|
+
#
|
42
|
+
# @param info_message [String]
|
43
|
+
# @param metadata [Hash]
|
44
|
+
def info(info_message, metadata = nil)
|
45
|
+
msg = generate_info_hash(info_message, metadata).to_json
|
37
46
|
send_message_via_amqp msg
|
38
47
|
end
|
39
48
|
|
40
49
|
private
|
41
50
|
|
42
|
-
def
|
51
|
+
def generate_error_hash(error, metadata = nil)
|
43
52
|
hostname = Socket.gethostname
|
44
53
|
time_now = get_current_timestamp
|
45
54
|
{
|
@@ -54,8 +63,16 @@ module Denouncer
|
|
54
63
|
}
|
55
64
|
end
|
56
65
|
|
57
|
-
def
|
58
|
-
|
66
|
+
def generate_info_hash(message, metadata = nil)
|
67
|
+
hostname = Socket.gethostname
|
68
|
+
time_now = get_current_timestamp
|
69
|
+
{
|
70
|
+
notification_time: time_now,
|
71
|
+
application_name: config[:application_name],
|
72
|
+
hostname: hostname,
|
73
|
+
message: message,
|
74
|
+
metadata: metadata
|
75
|
+
}
|
59
76
|
end
|
60
77
|
|
61
78
|
def send_message_via_amqp(message)
|
@@ -36,13 +36,21 @@ module Denouncer
|
|
36
36
|
raise NotImplementedException("This method needs to be implemented in a sub-class!")
|
37
37
|
end
|
38
38
|
|
39
|
-
# Sends
|
39
|
+
# Sends an error notification.
|
40
40
|
#
|
41
41
|
# @param error [StandardError]
|
42
42
|
# @param metadata [Hash]
|
43
43
|
def notify(error, metadata = nil)
|
44
44
|
raise NotImplementedException("This method needs to be implemented in a sub-class!")
|
45
45
|
end
|
46
|
+
|
47
|
+
# Sends a info notification.
|
48
|
+
#
|
49
|
+
# @param info_message [String]
|
50
|
+
# @param metadata [Hash]
|
51
|
+
def info(info_message, metadata = nil)
|
52
|
+
raise NotImplementedException("This method needs to be implemented in a sub-class!")
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Denouncer
|
2
2
|
module Notifiers
|
3
3
|
class ConsoleNotifier < BaseNotifier
|
4
|
-
|
4
|
+
|
5
5
|
# @return [String]
|
6
6
|
def name
|
7
7
|
'console'
|
@@ -17,6 +17,16 @@ module Denouncer
|
|
17
17
|
puts "Error Message: #{error.message}"
|
18
18
|
puts "Metadata: #{metadata.to_s}"
|
19
19
|
end
|
20
|
+
|
21
|
+
# Sends a info notification.
|
22
|
+
#
|
23
|
+
# @param info_message [String]
|
24
|
+
# @param metadata [Hash]
|
25
|
+
def info(info_message, metadata = nil)
|
26
|
+
puts "Timestamp: #{get_current_timestamp.to_s}"
|
27
|
+
puts "INFO: #{info_message.to_s}"
|
28
|
+
puts "Metadata: #{metadata.to_s}"
|
29
|
+
end
|
20
30
|
end
|
21
31
|
end
|
22
32
|
end
|
@@ -28,6 +28,18 @@ module Denouncer
|
|
28
28
|
parameters: metadata
|
29
29
|
)
|
30
30
|
end
|
31
|
+
|
32
|
+
# Sends a info notification.
|
33
|
+
#
|
34
|
+
# @param info_message [String]
|
35
|
+
# @param metadata [Hash]
|
36
|
+
def info(info_message, metadata = nil)
|
37
|
+
Honeybadger.notify(
|
38
|
+
error_message: info_message,
|
39
|
+
parameters: metadata
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
31
43
|
end
|
32
44
|
end
|
33
45
|
end
|
@@ -33,20 +33,30 @@ module Denouncer
|
|
33
33
|
# @param metadata [Hash]
|
34
34
|
def notify(error, metadata = nil)
|
35
35
|
Net::SMTP.start(config[:server], config[:port], config[:domain], config[:username], config[:password], config[:authtype]) do |smtp|
|
36
|
-
smtp.send_message
|
36
|
+
smtp.send_message generate_error_text_message(error, metadata), config[:sender], config[:recipients]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sends a info notification.
|
41
|
+
#
|
42
|
+
# @param info_message [String]
|
43
|
+
# @param metadata [Hash]
|
44
|
+
def info(info_message, metadata = nil)
|
45
|
+
Net::SMTP.start(config[:server], config[:port], config[:domain], config[:username], config[:password], config[:authtype]) do |smtp|
|
46
|
+
smtp.send_message generate_info_text_message(info_message, metadata), config[:sender], config[:recipients]
|
37
47
|
end
|
38
48
|
end
|
39
49
|
|
40
50
|
private
|
41
51
|
|
42
|
-
def
|
52
|
+
def generate_error_text_message(error, metadata = nil)
|
43
53
|
hostname = Socket.gethostname
|
44
54
|
time_now = get_current_timestamp
|
45
55
|
recipients_list = formatted_recipients
|
46
56
|
msgstr = <<END_OF_MESSAGE
|
47
57
|
From: #{config[:application_name]} <#{config[:sender]}>
|
48
58
|
To: #{recipients_list}
|
49
|
-
Subject: #{
|
59
|
+
Subject: #{generate_error_subject(error)}
|
50
60
|
Date: #{formatted_time(time_now)}
|
51
61
|
|
52
62
|
Application name:
|
@@ -73,6 +83,38 @@ Error cause:
|
|
73
83
|
Metadata:
|
74
84
|
#{metadata.to_s}
|
75
85
|
|
86
|
+
-- -- -- -- -- -- -- -- -- -- --
|
87
|
+
This message was generated using the denouncer exception notifier gem.
|
88
|
+
( http://github.com/julweber/denouncer )
|
89
|
+
END_OF_MESSAGE
|
90
|
+
return msgstr
|
91
|
+
end
|
92
|
+
|
93
|
+
def generate_info_text_message(message, metadata = nil)
|
94
|
+
hostname = Socket.gethostname
|
95
|
+
time_now = get_current_timestamp
|
96
|
+
recipients_list = formatted_recipients
|
97
|
+
msgstr = <<END_OF_MESSAGE
|
98
|
+
From: #{config[:application_name]} <#{config[:sender]}>
|
99
|
+
To: #{recipients_list}
|
100
|
+
Subject: #{generate_info_subject}
|
101
|
+
Date: #{formatted_time(time_now)}
|
102
|
+
|
103
|
+
Application name:
|
104
|
+
#{config[:application_name]}
|
105
|
+
|
106
|
+
Hostname:
|
107
|
+
#{hostname}
|
108
|
+
|
109
|
+
Notification time:
|
110
|
+
#{time_now}
|
111
|
+
|
112
|
+
Info message:
|
113
|
+
#{message}
|
114
|
+
|
115
|
+
Metadata:
|
116
|
+
#{metadata.to_s}
|
117
|
+
|
76
118
|
-- -- -- -- -- -- -- -- -- -- --
|
77
119
|
This message was generated using the denouncer exception notifier gem.
|
78
120
|
( http://github.com/julweber/denouncer )
|
@@ -106,8 +148,12 @@ END_OF_MESSAGE
|
|
106
148
|
return str
|
107
149
|
end
|
108
150
|
|
109
|
-
def
|
110
|
-
"[Denouncer] - [
|
151
|
+
def generate_error_subject(error)
|
152
|
+
"[Denouncer] - [ERROR] - #{config[:application_name]} - #{error.class.name} - #{get_current_timestamp.to_s}"
|
153
|
+
end
|
154
|
+
|
155
|
+
def generate_info_subject
|
156
|
+
"[Denouncer] - [INFO] - #{config[:application_name]} - #{get_current_timestamp.to_s}"
|
111
157
|
end
|
112
158
|
end
|
113
159
|
end
|
data/lib/denouncer/version.rb
CHANGED
@@ -66,52 +66,45 @@ describe Denouncer::Notifiers::AmqpNotifier do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
describe "#
|
69
|
+
describe "#generate_error_hash" do
|
70
70
|
let(:notifier) { Denouncer::Notifiers::AmqpNotifier.new config }
|
71
71
|
let(:metadata_var) { "HASHVAR123" }
|
72
72
|
let(:metadata) { { hash_var: metadata_var } }
|
73
73
|
|
74
|
-
it "should generate a
|
75
|
-
msg = notifier.send(:
|
76
|
-
expect(msg).to be_kind_of
|
77
|
-
expect { JSON.parse(msg) }.not_to raise_error
|
74
|
+
it "should generate a hash" do
|
75
|
+
msg = notifier.send(:generate_error_hash, error, metadata)
|
76
|
+
expect(msg).to be_kind_of Hash
|
78
77
|
end
|
79
78
|
|
80
79
|
it "should contain the error message" do
|
81
|
-
|
82
|
-
|
83
|
-
expect(parsed["error_message"]).to match (error.message)
|
80
|
+
h = notifier.send(:generate_error_hash, error, metadata)
|
81
|
+
expect(h[:error_message]).to match (error.message)
|
84
82
|
end
|
85
83
|
|
86
84
|
it "should contain the error class" do
|
87
|
-
|
88
|
-
|
89
|
-
expect(parsed["error_class"]).to eq (error.class.name)
|
85
|
+
h = notifier.send(:generate_error_hash, error, metadata)
|
86
|
+
expect(h[:error_class]).to eq (error.class.name)
|
90
87
|
end
|
91
88
|
|
92
89
|
it "should contain the application_name" do
|
93
|
-
|
94
|
-
|
95
|
-
expect(parsed["application_name"]).to eq app_name
|
90
|
+
h = notifier.send(:generate_error_hash, error, metadata)
|
91
|
+
expect(h[:application_name]).to eq app_name
|
96
92
|
end
|
97
93
|
|
98
94
|
it "should contain the metadata hash" do
|
99
|
-
|
100
|
-
|
101
|
-
expect(
|
102
|
-
expect(parsed["metadata"]["hash_var"]).to eq metadata_var
|
95
|
+
h = notifier.send(:generate_error_hash, error, metadata)
|
96
|
+
expect(h[:metadata]).to be_kind_of Hash
|
97
|
+
expect(h[:metadata][:hash_var]).to eq metadata_var
|
103
98
|
end
|
104
99
|
|
105
100
|
it "should contain the backtrace" do
|
106
|
-
|
107
|
-
|
108
|
-
expect(parsed["error_backtrace"]).to be_kind_of Array
|
101
|
+
h = notifier.send(:generate_error_hash, error, metadata)
|
102
|
+
expect(h[:error_backtrace]).to be_kind_of Array
|
109
103
|
end
|
110
104
|
|
111
105
|
it "should contain the notification_time" do
|
112
|
-
|
113
|
-
|
114
|
-
expect(parsed["notification_time"]).not_to be_nil
|
106
|
+
h = notifier.send(:generate_error_hash, error, metadata)
|
107
|
+
expect(h[:notification_time]).not_to be_nil
|
115
108
|
end
|
116
109
|
end
|
117
110
|
end
|
@@ -99,33 +99,33 @@ describe Denouncer::Notifiers::SmtpNotifier do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
describe "#
|
102
|
+
describe "#generate_error_text_message" do
|
103
103
|
let(:notifier) { Denouncer::Notifiers::SmtpNotifier.new config }
|
104
104
|
let(:metadata_var) { "HASHVAR123" }
|
105
105
|
let(:metadata) { { hash_var: metadata_var } }
|
106
106
|
|
107
107
|
it "should generate a text message" do
|
108
|
-
msg = notifier.send(:
|
108
|
+
msg = notifier.send(:generate_error_text_message, error, metadata)
|
109
109
|
expect(msg).to be_kind_of String
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should contain the error message" do
|
113
|
-
msg = notifier.send(:
|
113
|
+
msg = notifier.send(:generate_error_text_message, error, metadata)
|
114
114
|
expect(msg).to match error.message
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should contain the error class" do
|
118
|
-
msg = notifier.send(:
|
118
|
+
msg = notifier.send(:generate_error_text_message, error, metadata)
|
119
119
|
expect(msg).to match error.class.name
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should contain the application_name" do
|
123
|
-
msg = notifier.send(:
|
123
|
+
msg = notifier.send(:generate_error_text_message, error, metadata)
|
124
124
|
expect(msg).to match app_name
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should contain the metadata hash" do
|
128
|
-
msg = notifier.send(:
|
128
|
+
msg = notifier.send(:generate_error_text_message, error, metadata)
|
129
129
|
expect(msg).to match metadata_var
|
130
130
|
end
|
131
131
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: denouncer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Weber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- Rakefile
|
156
156
|
- denouncer.gemspec
|
157
157
|
- lib/denouncer.rb
|
158
|
+
- lib/denouncer/info_error.rb
|
158
159
|
- lib/denouncer/notifiers.rb
|
159
160
|
- lib/denouncer/notifiers/airbrake_notifier.rb
|
160
161
|
- lib/denouncer/notifiers/amqp_notifier.rb
|