Lipsiasoft-exception_notifier 1.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.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,57 @@
1
+ ExceptionNotifier
2
+ =================
3
+
4
+ This plugin are raised when an exception fire up in controllers.
5
+ Now you can personalize exception and simplify the layout using templates
6
+ in app/views/exception
7
+ when an exception is raised it try to send an email, and for send an email
8
+ you need to configure in enviroment.
9
+
10
+ For test layouts and mailing do this:
11
+
12
+ Edit enviroments/development.rb
13
+
14
+ config.action_controller.consider_all_requests_local = false
15
+
16
+ Then in your browser open 192.168.1.3 where 192.168.1.3 is your lan ip.
17
+
18
+ Remember that if you use 127.0.0.1 Rails don't raise "production" errors.
19
+
20
+ Installation
21
+ ============
22
+
23
+ Rails::Initializer.run do |config|
24
+ config.gem 'mislav-will_paginate', :version => '~> 2.2.3', :lib => 'will_paginate',
25
+ :source => 'http://gems.github.com'
26
+ end
27
+
28
+ Example
29
+ =======
30
+
31
+ script/generate exception_notifier [--haml-template]
32
+
33
+ Personalize yours app/views/exceptions/ templates
34
+
35
+ Remember that they use the layout of the controller where the exception is raised
36
+
37
+ Then in /config/initializers/exception_notifier.rb
38
+
39
+ Lipsiadmin::Mailer::ExceptionNotifier.sender_address = %("Exception Notifier" <server1@lipsiasoft.com>)
40
+ Lipsiadmin::Mailer::ExceptionNotifier.recipients_addresses = %(info@lipsiasoft.com)
41
+ Lipsiadmin::Mailer::ExceptionNotifier.email_prefix = "[Your Progect]"
42
+
43
+
44
+ Redmine
45
+ =======
46
+
47
+ This plugins is useful for redmine, if you have set the mail handler
48
+ http://www.redmine.org/wiki/redmine/RedmineReceivingEmails
49
+
50
+ you need to set the inizializers/exception_notifier.rb like this
51
+
52
+ Lipsiadmin::Mailer::ExceptionNotifier.sender_address = %("Exception Notifier" <server1@lipsiasoft.com>)
53
+ Lipsiadmin::Mailer::ExceptionNotifier.recipients_addresses = %(info@lipsiasoft.com)
54
+ Lipsiadmin::Mailer::ExceptionNotifier.email_prefix = "[Your Project]"
55
+ Lipsiadmin::Mailer::ExceptionNotifier.extra_options = { :project => "your-project-in-redmine", :tracker => "Bug", :priority => "Urgent" }
56
+
57
+ Copyright (c) 2009 Lipsiasoft s.r.l., released under the MIT license
@@ -0,0 +1,63 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/packagetask'
5
+ require 'rake/gempackagetask'
6
+
7
+ PKG_NAME = 'exception_notifier'
8
+ PKG_VERSION = "1.0"
9
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
10
+
11
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
12
+
13
+ desc 'Default: install the gem.'
14
+ task :default => [:install]
15
+
16
+ desc 'Generate documentation for the paperclip plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'doc'
19
+ rdoc.title = 'Lipsiadmin Exception Notifier'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README*')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ desc 'Clean up files.'
26
+ task :clean do |t|
27
+ FileUtils.rm_rf "doc"
28
+ FileUtils.rm_rf "tmp"
29
+ FileUtils.rm_rf "pkg"
30
+ end
31
+
32
+ spec = Gem::Specification.new do |s|
33
+ s.name = PKG_NAME
34
+ s.version = PKG_VERSION
35
+ s.author = "Davide D'Agostino"
36
+ s.email = "d.dagostino@lipsiasoft.com"
37
+ s.homepage = "http://groups.google.com/group/lipsiadmin"
38
+ s.platform = Gem::Platform::RUBY
39
+ s.summary = "Extracted exception notifier of Lipsiadmin"
40
+ s.files = FileList["README", "MIT-LICENSE", "Rakefile", "init.rb", "{generators,lib,test}/**/*"].to_a
41
+ s.has_rdoc = true
42
+ s.requirements << 'none'
43
+ s.require_path = 'lib'
44
+ s.autorequire = 'exception_notifier'
45
+ end
46
+
47
+ Rake::GemPackageTask.new(spec) do |p|
48
+ p.gem_spec = spec
49
+ p.need_tar = true
50
+ p.need_zip = true
51
+ end
52
+
53
+ desc "Install the gem locally"
54
+ task :install => [:repackage] do
55
+ sh %{sudo gem install pkg/#{PKG_FILE_NAME}.gem}
56
+ end
57
+
58
+ desc "Generate a gemspec file for GitHub"
59
+ task :gemspec do
60
+ File.open("#{spec.name}.gemspec", 'w') do |f|
61
+ f.write spec.to_ruby
62
+ end
63
+ end
@@ -0,0 +1,9 @@
1
+
2
+ ================================================================
3
+
4
+ Please remember to:
5
+
6
+ - Edit app/views/exceptions
7
+ - Edit config/initializers/exception_notifier.rb
8
+
9
+ ================================================================
@@ -0,0 +1,37 @@
1
+ class ExceptionNotifierGenerator < Rails::Generator::NamedBase
2
+ default_options :haml_templates => false
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ runtime_args = ["none"].concat(runtime_args) # Skip usage
6
+ super
7
+ end
8
+
9
+ def manifest
10
+ template = options[:haml_templates] ? "haml" : "erb"
11
+
12
+ record do |m|
13
+ m.directory File.join('app/views', 'exceptions')
14
+ m.directory File.join('config', 'initializers')
15
+
16
+ m.template('exception_notifier.rb', 'config/initializers/exception_notifier.rb')
17
+
18
+ %w(404 422 500).each do |page|
19
+ m.template("views/#{page}.html.#{template}", "app/views/exceptions/#{page}.html.#{template}")
20
+ end
21
+
22
+ m.readme "../REMEMBER"
23
+ end
24
+ end
25
+
26
+ protected
27
+ def banner
28
+ "Usage: #{$0} exception_notifier [--template]"
29
+ end
30
+
31
+ def add_options!(opt)
32
+ opt.separator ''
33
+ opt.separator 'Options:'
34
+ opt.on("-t", "--haml-templates",
35
+ "Generate exception templates using haml template") { |v| options[:haml_templates] = v; puts v }
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ Lipsiadmin::Mailer::ExceptionNotifier.sender_address = %("Exception Notifier" <exceptions@lipsiasoft.com>)
2
+ Lipsiadmin::Mailer::ExceptionNotifier.recipients_addresses = %(helpdesk@lipsiasoft.com)
3
+ Lipsiadmin::Mailer::ExceptionNotifier.email_prefix = "[Project Name]"
4
+
5
+ # Uncomment this if this mail is for redmine handler
6
+ # Lipsiadmin::Mailer::ExceptionNotifier.extra_options = { :project => "lipsiabug", :tracker => "Bug", :priority => "Immediata" }
@@ -0,0 +1,4 @@
1
+ <div class="exception">
2
+ <h1>The page you were looking for doesn't exist.</h1>
3
+ <p>You may have mistyped the address or the page may have moved.</p>
4
+ </div>
@@ -0,0 +1,5 @@
1
+ .exception
2
+ %h1 The page you were looking for doesn't exist.
3
+ %p You may have mistyped the address or the page may have moved.
4
+
5
+
@@ -0,0 +1,4 @@
1
+ <div class="exception">
2
+ <h1>The change you wanted was rejected.</h1>
3
+ <p>Maybe you tried to change something you didn't have access to.</p>
4
+ </div>
@@ -0,0 +1,3 @@
1
+ .exception
2
+ %h1 The change you wanted was rejected.
3
+ %p Maybe you tried to change something you didn't have access to.
@@ -0,0 +1,7 @@
1
+ <div class="exception">
2
+ <h1>We're sorry, but something went wrong.</h1>
3
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
4
+ <p><small>(If you're the administrator of this website, then please read
5
+ the log file "<%=h RAILS_ENV %>.log"
6
+ to find out what went wrong.)</small></p>
7
+ </div>
@@ -0,0 +1,8 @@
1
+ .exception
2
+ %h1 We're sorry, but something went wrong.
3
+ %p We've been notified about this issue and we'll take a look at it shortly.
4
+ %p
5
+ %small
6
+ (If you're the administrator of this website, then please read the log file
7
+ =h "#{RAILS_ENV}.log"
8
+ to find out what went wrong.)
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'exception_notifier'
@@ -0,0 +1,41 @@
1
+ module Lipsiadmin
2
+ module Controller
3
+ # This module are raised when an exception fire up in controllers.
4
+ # Now you can personalize exception and simplify the layout using templates
5
+ # in app/views/exception
6
+ # when an exception is raised it try to send an email, and for send an email
7
+ # you need to configure in enviroment or in an initializer some like this:
8
+ #
9
+ # Examples:
10
+ #
11
+ # Lipsiadmin::Mailer::ExceptionNotifier.sender_address = %("Exception Notifier" <server1@lipsiasoft.com>)
12
+ # Lipsiadmin::Mailer::ExceptionNotifier.recipients_addresses = %(info@lipsiasoft.com)
13
+ # Lipsiadmin::Mailer::ExceptionNotifier.email_prefix = "[Your Project]"
14
+ #
15
+ module Rescue
16
+
17
+ def self.included(base)
18
+ base.class_eval do
19
+ alias_method_chain :rescue_action_in_public, :notifier
20
+ end
21
+ end
22
+
23
+ # Overwrite to implement public exception handling (for requests answering false to <tt>local_request?</tt>). By
24
+ # default will call render_optional_error_file. Override this method to provide more user friendly error messages.
25
+ def rescue_action_in_public_with_notifier(exception) #:doc:
26
+ response_code = response_code_for_rescue(exception)
27
+ status = interpret_status(response_code)[0,3]
28
+ render :template => "/exceptions/#{status}", :status => status
29
+ if response_code != :not_found
30
+ Lipsiadmin::Mailer::ExceptionNotifier.deliver_exception(exception, self, request)
31
+ end
32
+ rescue Exception => e
33
+ logger.error e.message
34
+ erase_results
35
+ rescue_action_in_public_without_notifier(exception)
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,6 @@
1
+ require 'mailer/exception_notifier'
2
+ require 'controller/rescue'
3
+
4
+ ActionController::Base.class_eval do
5
+ include Lipsiadmin::Controller::Rescue
6
+ end
@@ -0,0 +1,11 @@
1
+ A <%= @exception.class %> occurred in <%= @controller.controller_name %>#<%= @controller.action_name %>:
2
+
3
+ <%= @exception.message %>
4
+ <%= @backtrace.join("\n") %>
5
+
6
+ * URL : <%= @request.protocol %><%= @host %><%= @request.request_uri %>
7
+ * IP address: <%= @request.env["HTTP_X_FORWARDED_FOR"] || @request.env["REMOTE_ADDR"] %>
8
+ * Parameters: <%= @request.parameters.inspect %>
9
+ * Rails root: <%= RAILS_ROOT %>
10
+
11
+ <%= @extra_options.collect { |k,v| "#{k.to_s.capitalize}: #{v}" }.join("\n") %>
@@ -0,0 +1,38 @@
1
+ module Lipsiadmin
2
+ module Mailer
3
+ class ExceptionNotifier < ActionMailer::Base
4
+
5
+ @@sender_address = %("Exception Notifier" <exception.notifier@default.com>)
6
+ cattr_accessor :sender_address
7
+
8
+ @@recipients_addresses = []
9
+ cattr_accessor :recipients_addresses
10
+
11
+ @@extra_options = {}
12
+ cattr_accessor :extra_options
13
+
14
+ @@email_prefix = "[ERROR] "
15
+ cattr_accessor :email_prefix
16
+
17
+ self.mailer_name = "exception"
18
+ self.template_root = "#{File.dirname(__FILE__)}"
19
+
20
+ def self.reloadable?() false end
21
+
22
+ def exception(exception, controller, request)
23
+ content_type "text/plain"
24
+
25
+ subject "#{email_prefix} #{exception.message.inspect}"
26
+
27
+ recipients recipients_addresses
28
+ from sender_address
29
+
30
+ body :controller => controller, :request => request,
31
+ :exception => exception, :host => (request.env["HTTP_X_FORWARDED_HOST"] || request.env["HTTP_HOST"]),
32
+ :backtrace => exception.backtrace, :extra_options => extra_options
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class ExceptionNotifierTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Lipsiasoft-exception_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - Davide D'Agostino
8
+ autorequire: exception_notifier
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-23 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: d.dagostino@lipsiasoft.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README
26
+ - MIT-LICENSE
27
+ - Rakefile
28
+ - init.rb
29
+ - generators/exception_notifier
30
+ - generators/exception_notifier/exception_notifier_generator.rb
31
+ - generators/exception_notifier/REMEMBER
32
+ - generators/exception_notifier/templates
33
+ - generators/exception_notifier/templates/exception_notifier.rb
34
+ - generators/exception_notifier/templates/views
35
+ - generators/exception_notifier/templates/views/404.html.erb
36
+ - generators/exception_notifier/templates/views/404.html.haml
37
+ - generators/exception_notifier/templates/views/422.html.erb
38
+ - generators/exception_notifier/templates/views/422.html.haml
39
+ - generators/exception_notifier/templates/views/500.html.erb
40
+ - generators/exception_notifier/templates/views/500.html.haml
41
+ - lib/controller
42
+ - lib/controller/rescue.rb
43
+ - lib/exception_notifier.rb
44
+ - lib/mailer
45
+ - lib/mailer/exception
46
+ - lib/mailer/exception/exception.html.erb
47
+ - lib/mailer/exception_notifier.rb
48
+ - test/exception_notifier_test.rb
49
+ - test/test_helper.rb
50
+ has_rdoc: true
51
+ homepage: http://groups.google.com/group/lipsiadmin
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements:
70
+ - none
71
+ rubyforge_project:
72
+ rubygems_version: 1.2.0
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: Extracted exception notifier of Lipsiadmin
76
+ test_files: []
77
+