exceptions_to_slack 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -5
- data/Rakefile +4 -3
- data/exceptions_to_slack.gemspec +1 -1
- data/lib/exceptions_to_slack/notifier.rb +16 -7
- data/lib/exceptions_to_slack/version.rb +1 -1
- data/lib/exceptions_to_slack.rb +2 -2
- data/test/exceptions_to_slack/notifier_test.rb +47 -0
- data/test/test_helper.rb +5 -0
- metadata +17 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1041c85765abefc1378bcd1474ce18c48d487f3
|
4
|
+
data.tar.gz: 1d982c665a395c011f0c2a83770b3da45ce1cac5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21b0a3358b1d1a67f5fb162c6bbd04bb899bf96e6da6499483084000e03c842569a5a5efa852bb67b81373ae850169337451d26ea6687de615740ca8b597033
|
7
|
+
data.tar.gz: b72aaa2ac06cf42701b28933267490ccbba023f1fce26d8abef0982fe9fd462e6622f8d57e60cf56b8183263393650ef0940f202b08e4aa1040ea8a16361eab0
|
data/README.md
CHANGED
@@ -12,9 +12,13 @@ Add this line to your application's Gemfile:
|
|
12
12
|
|
13
13
|
Rails 3: add as rack middleware to `application.rb'
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
```ruby
|
16
|
+
config.middleware.use ExceptionsToSlack::Notifier,
|
17
|
+
team: 'your-team-name', # required
|
18
|
+
token: 'your-api-token', # required, https://my.slack.com/services/new/incoming-webhook
|
19
|
+
channel: '#general', # required
|
20
|
+
user: 'Exception Notifier', # optional, defaults to Notifier
|
21
|
+
ignore: /Foo/, # optional pattern for exceptions not to be sent
|
22
|
+
additional_parameters: {icon_emoji: ':ghost:'} # optional parameters to send to slack
|
23
|
+
```
|
20
24
|
|
data/Rakefile
CHANGED
data/exceptions_to_slack.gemspec
CHANGED
@@ -8,6 +8,7 @@ module ExceptionsToSlack
|
|
8
8
|
@notifier.channel = options[:channel] || raise("Channel is required")
|
9
9
|
@notifier.username = options[:user] || "Notifier"
|
10
10
|
@ignore = options[:ignore]
|
11
|
+
@additional_parameters = options[:additional_parameters] || {}
|
11
12
|
end
|
12
13
|
|
13
14
|
def call(env)
|
@@ -17,20 +18,16 @@ module ExceptionsToSlack
|
|
17
18
|
raise exception
|
18
19
|
end
|
19
20
|
|
21
|
+
private
|
22
|
+
|
20
23
|
def send_to_slack(exception)
|
21
24
|
begin
|
22
|
-
@notifier.ping message_for(exception)
|
25
|
+
@notifier.ping message_for(exception), @additional_parameters.merge({attachments: [attachment_for(exception)]})
|
23
26
|
rescue => slack_exception
|
24
27
|
$stderr.puts "\nWARN: Unable to send message to Slack: #{slack_exception}\n"
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
|
-
def message_for(exception)
|
29
|
-
"[#{exception.class}] #{exception}"
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
31
|
def team(options)
|
35
32
|
options[:team] || raise("Team name is required")
|
36
33
|
end
|
@@ -38,6 +35,18 @@ module ExceptionsToSlack
|
|
38
35
|
def token(options)
|
39
36
|
options[:token] || raise("Token is required")
|
40
37
|
end
|
38
|
+
|
39
|
+
def message_for(exception)
|
40
|
+
"[#{exception.class}] #{exception}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def attachment_for(exception)
|
44
|
+
{
|
45
|
+
fallback: 'Stack trace',
|
46
|
+
color: 'warning',
|
47
|
+
text: exception.backtrace.join("\n")
|
48
|
+
}
|
49
|
+
end
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
data/lib/exceptions_to_slack.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'exceptions_to_slack/version'
|
2
|
+
require 'exceptions_to_slack/notifier'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class TestNotifier < MiniTest::Unit::TestCase
|
4
|
+
TEAM = 'the-team'
|
5
|
+
TOKEN = 'the-token'
|
6
|
+
CHANNEL = 'the-channel'
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@app = MiniTest::Mock.new
|
10
|
+
|
11
|
+
@notifier = ExceptionsToSlack::Notifier.new(@app, {
|
12
|
+
team: TEAM,
|
13
|
+
token: TOKEN,
|
14
|
+
channel: CHANNEL,
|
15
|
+
ignore: /ignored/
|
16
|
+
})
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_exceptions_are_sent_to_slack
|
20
|
+
def @app.call(env) raise ':boom:' end
|
21
|
+
|
22
|
+
WebMock.stub_request(:post, 'https://the-team.slack.com/services/hooks/incoming-webhook?token=the-token').with do |request|
|
23
|
+
form = URI.decode_www_form(request.body)
|
24
|
+
|
25
|
+
assert_equal 1, form.size
|
26
|
+
assert_equal 2, form[0].size
|
27
|
+
assert_equal 'payload', form[0][0]
|
28
|
+
|
29
|
+
payload = JSON.parse(form[0][1])
|
30
|
+
assert_equal '[RuntimeError] :boom:', payload['text']
|
31
|
+
assert_equal CHANNEL, payload['channel']
|
32
|
+
assert_equal 'Notifier', payload['username']
|
33
|
+
assert !payload['attachments'][0]['text'].empty?
|
34
|
+
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
-> {@notifier.call([])}.must_raise RuntimeError
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_exceptions_that_are_ignored
|
42
|
+
def @app.call(env) raise 'should be ignored if raised' end
|
43
|
+
# WebMock will raise if we try to send something to slack
|
44
|
+
|
45
|
+
-> {@notifier.call([])}.must_raise RuntimeError
|
46
|
+
end
|
47
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exceptions_to_slack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darrin Holst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-notifier
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.5.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: webmock
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.18.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.18.0
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- darrinholst@gmail.com
|
@@ -45,7 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
-
|
48
|
+
- .gitignore
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE
|
51
51
|
- README.md
|
@@ -54,6 +54,8 @@ files:
|
|
54
54
|
- lib/exceptions_to_slack.rb
|
55
55
|
- lib/exceptions_to_slack/notifier.rb
|
56
56
|
- lib/exceptions_to_slack/version.rb
|
57
|
+
- test/exceptions_to_slack/notifier_test.rb
|
58
|
+
- test/test_helper.rb
|
57
59
|
homepage: http://github.com/darrinholst/exceptions_to_slack
|
58
60
|
licenses: []
|
59
61
|
metadata: {}
|
@@ -63,12 +65,12 @@ require_paths:
|
|
63
65
|
- lib
|
64
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
67
|
requirements:
|
66
|
-
- -
|
68
|
+
- - '>='
|
67
69
|
- !ruby/object:Gem::Version
|
68
70
|
version: '0'
|
69
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
72
|
requirements:
|
71
|
-
- -
|
73
|
+
- - '>='
|
72
74
|
- !ruby/object:Gem::Version
|
73
75
|
version: '0'
|
74
76
|
requirements: []
|
@@ -77,4 +79,6 @@ rubygems_version: 2.2.2
|
|
77
79
|
signing_key:
|
78
80
|
specification_version: 4
|
79
81
|
summary: Send rails exceptions to Slack
|
80
|
-
test_files:
|
82
|
+
test_files:
|
83
|
+
- test/exceptions_to_slack/notifier_test.rb
|
84
|
+
- test/test_helper.rb
|