exception-alarm 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/app/views/exception_alarm/notifier/alarm.txt.erb +2 -0
- data/exception-alarm.gemspec +19 -0
- data/lib/exception-alarm.rb +4 -0
- data/lib/exception_alarm/engine.rb +10 -0
- data/lib/exception_alarm/middleware.rb +22 -0
- data/lib/exception_alarm/notifier.rb +21 -0
- data/lib/exception_alarm/version.rb +3 -0
- metadata +75 -0
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alexey Vakhov
|
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,33 @@
|
|
1
|
+
# Exception Alarm
|
2
|
+
|
3
|
+
This gem refactored clone of exception notifier plugin.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem 'exception-alarm'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Add to ApplicationController before filter
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
class ApplicationController < ActionController::Base
|
25
|
+
before_filter do
|
26
|
+
ExceptionAlarm::Notifier.sender = "project-name@example.com"
|
27
|
+
ExceptionAlarm::Notifier.prefix = '[ERROR-project-name]'
|
28
|
+
ExceptionAlarm::Notifier.recipients = %w[vakhov@gmail.com]
|
29
|
+
end
|
30
|
+
|
31
|
+
# ...
|
32
|
+
end
|
33
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/exception_alarm/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alexey Vakhov"]
|
6
|
+
gem.email = ["vakhov@gmail.com"]
|
7
|
+
gem.description = %q{Send email on exception}
|
8
|
+
gem.summary = %q{Rails exception alarm like exception notifier}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "exception-alarm"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ExceptionAlarm::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "rails", '~> 3.1'
|
19
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ExceptionAlarm
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
config.exception_alarm = ActiveSupport::OrderedOptions.new
|
4
|
+
config.exception_alarm.enable = Rails.env.production?
|
5
|
+
|
6
|
+
initializer 'exception_alarm' do |app|
|
7
|
+
app.config.middleware.use ::ExceptionAlarm::Middleware
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ExceptionAlarm
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
@app.call(env)
|
9
|
+
rescue Exception => exception
|
10
|
+
if Rails.application.config.exception_alarm.enable && !ignore_exceptions.include?(exception.class.to_s) && Notifier.recipients.present?
|
11
|
+
Notifier.alarm(env, exception).deliver
|
12
|
+
end
|
13
|
+
|
14
|
+
raise exception
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def ignore_exceptions
|
19
|
+
%w[ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ExceptionAlarm
|
2
|
+
class Notifier < ActionMailer::Base
|
3
|
+
cattr_accessor :prefix
|
4
|
+
cattr_accessor :sender
|
5
|
+
cattr_accessor :recipients
|
6
|
+
self.prefix = '[ERROR]'
|
7
|
+
self.sender = 'exception@example.com'
|
8
|
+
self.recipients = []
|
9
|
+
|
10
|
+
def alarm(env, exception)
|
11
|
+
@env = env
|
12
|
+
@exception = exception
|
13
|
+
|
14
|
+
mail(
|
15
|
+
from: self.class.sender,
|
16
|
+
to: self.class.recipients,
|
17
|
+
subject: "#{self.class.prefix} (#{@exception.class}) #{@exception.message.inspect}"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exception-alarm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexey Vakhov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &76730070 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *76730070
|
25
|
+
description: Send email on exception
|
26
|
+
email:
|
27
|
+
- vakhov@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- CHANGELOG.md
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- app/views/exception_alarm/notifier/alarm.txt.erb
|
39
|
+
- exception-alarm.gemspec
|
40
|
+
- lib/exception-alarm.rb
|
41
|
+
- lib/exception_alarm/engine.rb
|
42
|
+
- lib/exception_alarm/middleware.rb
|
43
|
+
- lib/exception_alarm/notifier.rb
|
44
|
+
- lib/exception_alarm/version.rb
|
45
|
+
homepage: ''
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
hash: -455781487
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
hash: -455781487
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.11
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Rails exception alarm like exception notifier
|
75
|
+
test_files: []
|