exception_notification-hato_notifier 0.0.1
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 +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +11 -0
- data/exception_notification-hato_nitifier.gemspec +26 -0
- data/lib/exception_notifier/hato_notifier.rb +84 -0
- data/lib/exception_notifier/hato_notifier/version.rb +5 -0
- data/spec/lib/exception_notifier/hato_notifier_spec.rb +66 -0
- data/spec/spec_helper.rb +2 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b028d1832fd30775f54a28a0da29c6c0c6140ac
|
4
|
+
data.tar.gz: 74a2002c31177261b0e67c0bcf28510361cfaa8b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c73ea662fcdc7e723e9cc6ee8977a3298f20e85bbc40b73a366c80804ffd76c49de7b40e3eeef80bd107a108d42ef79bacee9e2d414eabd606b08176c03b2f3
|
7
|
+
data.tar.gz: 205c77ddb48b8937112e9f3faf0520bf651ebb06ec20a40499a781bd1bb2f3041f26f95888e93f991c1f281a3c5ae3cb33248c56eda461be6381cca28991a46d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kentaro Kuribayashi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# exception_notification-hato_notifier [](http://travis-ci.org/kentaro/exception_notification-hato_notifier)
|
2
|
+
|
3
|
+
`ExceptionNotifier::HatoNotifier` is a custom notifier for [Exception Notification](http://smartinez87.github.io/exception_notification/). It sends exception notification via [Hato](https://github.com/kentaro/hato).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
As other exception notifiers, add settings at the environments:
|
8
|
+
|
9
|
+
* `host` is the host of Hato server
|
10
|
+
* `port` is the port of the server (optional, default is `9699`)
|
11
|
+
* `api_key` is to set the API key if the server requires it (optional)
|
12
|
+
* `template` is to set templates for tag and message to be sent to Hato
|
13
|
+
|
14
|
+
### Example
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
18
|
+
hato: {
|
19
|
+
host: 'localhost',
|
20
|
+
port: 9699,
|
21
|
+
api_key: 'YOUR API KEY',
|
22
|
+
template: {
|
23
|
+
tag: ->(exception, options) { "exception.#{exception.class}" },
|
24
|
+
message: ->(exception, options) { "Exception: #{exception.class}: #{exception.message}" },
|
25
|
+
},
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
Add this line to your application's Gemfile:
|
32
|
+
|
33
|
+
gem 'exception_notification-hato_notifier'
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
$ bundle
|
38
|
+
|
39
|
+
Or install it yourself as:
|
40
|
+
|
41
|
+
$ gem install exception_notification-hato_notifier
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'exception_notifier/hato_notifier/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'exception_notification-hato_notifier'
|
8
|
+
spec.version = ExceptionNotifier::HatoNotifier::VERSION
|
9
|
+
spec.authors = ['Kentaro Kuribayashi']
|
10
|
+
spec.email = ['kentarok@gmail.com']
|
11
|
+
spec.description = %q{Custom notifier for ExceptionNotification to send notification via Hato}
|
12
|
+
spec.summary = %q{Custom notifier for ExceptionNotification to send notification via Hato}
|
13
|
+
spec.homepage = 'https://github.com/kentaro/exception_notification-hato'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'webmock'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module ExceptionNotifier
|
2
|
+
class HatoNotifier
|
3
|
+
class ConfigurationError < Exception; end
|
4
|
+
|
5
|
+
attr_reader :logger
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
template = options.delete(:template)
|
9
|
+
raise ConfigurationError.new('`template` key must be set') unless template
|
10
|
+
|
11
|
+
@tag_template = template.delete(:tag)
|
12
|
+
@message_template = template.delete(:message)
|
13
|
+
|
14
|
+
if !@tag_template || !@message_template
|
15
|
+
raise ConfigurationError.new('Both `templlate.message` and `templlate.message` keys must be set')
|
16
|
+
end
|
17
|
+
|
18
|
+
@logger = Logger.new(
|
19
|
+
host: options.delete(:host),
|
20
|
+
port: options.delete(:port),
|
21
|
+
api_key: options.delete(:api_key),
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(exception, options = {})
|
26
|
+
tag = Query.build(@tag_template, exception, options)
|
27
|
+
message = Query.build(@message_template, exception, options)
|
28
|
+
|
29
|
+
logger.post(tag, message)
|
30
|
+
end
|
31
|
+
|
32
|
+
class Logger
|
33
|
+
require 'uri'
|
34
|
+
require 'net/http'
|
35
|
+
|
36
|
+
def initialize(settings)
|
37
|
+
@host = settings.delete(:host)
|
38
|
+
@port = settings.delete(:port) || 9699
|
39
|
+
@api_key = settings.delete(:api_key)
|
40
|
+
end
|
41
|
+
|
42
|
+
def post(tag, message)
|
43
|
+
client = Net::HTTP.new(@host, @port)
|
44
|
+
req = Net::HTTP::Post.new('/notify')
|
45
|
+
|
46
|
+
req.form_data = { tag: tag, message: message }
|
47
|
+
req.form_data.merge!(api_key: api_key) if @api_key
|
48
|
+
|
49
|
+
client.request(req)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Query
|
54
|
+
def initialize(template, exception, options = {})
|
55
|
+
@exception = exception
|
56
|
+
@options = options
|
57
|
+
@template = template
|
58
|
+
end
|
59
|
+
|
60
|
+
def build
|
61
|
+
expand_object(@template)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.build(template, exception, options = {})
|
65
|
+
self.new(template, exception, options).build
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def expand_object(obj)
|
71
|
+
case obj
|
72
|
+
when Proc
|
73
|
+
expand_proc(obj)
|
74
|
+
else
|
75
|
+
obj
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def expand_proc(prok)
|
80
|
+
expand_object(prok.call(@exception, @options))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe ExceptionNotifier::HatoNotifier do
|
4
|
+
class FooException < Exception; end
|
5
|
+
|
6
|
+
let(:exception) do
|
7
|
+
FooException.new('bar message')
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:notifier) do
|
11
|
+
ExceptionNotifier::HatoNotifier.new(
|
12
|
+
host: 'localhost',
|
13
|
+
port: 9699,
|
14
|
+
api_key: 'test',
|
15
|
+
template: {
|
16
|
+
tag: ->(exception, options) { "exception.#{exception.class}" },
|
17
|
+
message: ->(exception, options) { "Exception: #{exception.class}: #{exception.message}" },
|
18
|
+
}
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#call' do
|
23
|
+
context 'success' do
|
24
|
+
before do
|
25
|
+
stub_request(:any, 'localhost').to_return(
|
26
|
+
status: 200,
|
27
|
+
body: %q{"status":"success","message":"Successfully sent the message you notified to me."},
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'logs valid data' do
|
32
|
+
expect(notifier.logger).to receive(:post).with(
|
33
|
+
'exception.FooException',
|
34
|
+
'Exception: FooException: bar message',
|
35
|
+
)
|
36
|
+
notifier.call(FooException.new('bar message'))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ExceptionNotifier::HatoNotifier::Query do
|
42
|
+
subject do
|
43
|
+
ExceptionNotifier::HatoNotifier::Query.build(template, exception, {})
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with String' do
|
47
|
+
let(:template) do
|
48
|
+
'string'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns string without any change' do
|
52
|
+
should == 'string'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with Proc' do
|
57
|
+
let(:template) do
|
58
|
+
->(e, opts) { "Exception: #{e.class}: #{e.message}" }
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns intended string' do
|
62
|
+
should == 'Exception: FooException: bar message'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exception_notification-hato_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kentaro Kuribayashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webmock
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Custom notifier for ExceptionNotification to send notification via Hato
|
70
|
+
email:
|
71
|
+
- kentarok@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- exception_notification-hato_nitifier.gemspec
|
83
|
+
- lib/exception_notifier/hato_notifier.rb
|
84
|
+
- lib/exception_notifier/hato_notifier/version.rb
|
85
|
+
- spec/lib/exception_notifier/hato_notifier_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: https://github.com/kentaro/exception_notification-hato
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.14
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Custom notifier for ExceptionNotification to send notification via Hato
|
111
|
+
test_files:
|
112
|
+
- spec/lib/exception_notifier/hato_notifier_spec.rb
|
113
|
+
- spec/spec_helper.rb
|