rnotifier 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,51 +0,0 @@
1
- module Rnotifier
2
- class Configuration
3
- DEFAULT_CONFIG = {
4
- :api_host => 'http://rnotifier.com/notify/api/v1',
5
- :validate_path => 'validate',
6
- :notify_path => 'exception'
7
- }
8
-
9
- FILTER_PARAMS = ['password', 'password_confirmation']
10
-
11
- class << self
12
- attr_accessor :api_key
13
- attr_accessor :client_ip
14
- attr_accessor :client_host_name
15
- attr_accessor :is_valid
16
- attr_accessor :filter_params
17
- attr_accessor :notification_server
18
- attr_accessor :exception_recipients
19
-
20
- def [](key)
21
- DEFAULT_CONFIG[key] || send(key)
22
- end
23
-
24
- def validate_config
25
-
26
- unless self.notification_server
27
- self.notification_server = DEFAULT_CONFIG[:api_host]
28
- else
29
- self.notification_server += '/notify/api/v1'
30
- end
31
-
32
- =begin
33
- if self.api_key
34
- response = Util.get(self[:validate_path])
35
- self.is_valid = true if response['valid_api_key']
36
- else
37
- Rlogger.error('[CONFIG] Check your config API key is not define.')
38
- end
39
-
40
- unless self.is_valid
41
- Rlogger.error('[CONFIG] Invalid API KEY. Please check it.')
42
- else
43
- Rlogger.info('[CONFIG] API key is valid.')
44
- end
45
- =end
46
-
47
- end
48
- end
49
- end
50
- end
51
-
@@ -1,19 +0,0 @@
1
- module Rnotifier
2
- class EmailNotifier < ActionMailer::Base
3
- default :from => 'Rnotifier Exception<exception@rnotifier.in>'
4
- self.mailer_name = 'email_notifier'
5
- self.append_view_path "#{File.dirname(__FILE__)}/views"
6
-
7
- def exception_notify(exception)
8
- @exception = exception
9
- @project_name = Rails.application.class.to_s.sub('::Application', '')
10
-
11
- emails = Configuration.exception_recipients
12
- subject = "[RNOTIFIER][#{@project_name}##{@exception[:environment]}] #{@exception[:message]}"
13
-
14
- mail(:to => emails, :subject => subject) do |format|
15
- format.html { render "#{mailer_name}/exception_notify" }
16
- end
17
- end
18
- end
19
- end
@@ -1,48 +0,0 @@
1
- module Rnotifier
2
- module RailsException
3
- module Catcher
4
-
5
- def self.included(base)
6
- base.send(:alias_method, :render_exception_without_rnotifier, :render_exception)
7
- base.send(:alias_method, :render_exception, :render_exception_with_rnotifier)
8
- end
9
-
10
- private
11
- def render_exception_with_rnotifier(env,exception)
12
- request = ActionDispatch::Request.new(env)
13
- unless (@consider_all_requests_local || request.local?)
14
- exception_data = {
15
- :url => request.url,
16
- :params => request.params,
17
- :session => request.session,
18
- :ip => request.ip,
19
- :http_method => request.method,
20
- :status_code => status_code(exception),
21
- :class_name => exception.class.to_s,
22
- :message => exception.message,
23
- :exception_line => Rails.backtrace_cleaner.clean(exception.backtrace, :silent).first,
24
- :backtrace => Rails.backtrace_cleaner.clean(exception.backtrace, nil),
25
- :environment => Rails.env.capitalize,
26
- :user_agent => request.user_agent
27
- }
28
-
29
- exception_data[:session].delete('session_id')
30
- exception_data[:exception_hash] = Digest::MD5.hexdigest("#{exception_data[:message].gsub(/#<\w*:\w*>/, '')}#{exception_data[:exception_line]}")
31
- exception_data[:env_variables] = Util.request_env(request.filtered_env)
32
-
33
- Notifier.send_exception(exception_data)
34
- end
35
-
36
- render_exception_without_rnotifier(env, exception)
37
- end
38
-
39
- end
40
-
41
- def self.initialize
42
- if defined?(ActionDispatch::ShowExceptions)
43
- Configuration.filter_params = Rails.application.config.filter_parameters.uniq
44
- ActionDispatch::ShowExceptions.send(:include, Rnotifier::RailsException::Catcher)
45
- end
46
- end
47
- end
48
- end
@@ -1,29 +0,0 @@
1
- module Rnotifier
2
- class Util
3
- class << self
4
- def post(path, data = {})
5
- url = URI.parse(Configuration.notification_server)
6
- post = Net::HTTP::Post.new("#{url.path}/#{path}/#{Configuration[:api_key]}",{'Content-Type' =>'application/json'})
7
-
8
- http = Net::HTTP.new(url.host, url.port)
9
- http.use_ssl = true if url.port == 443
10
- JSON.parse(http.request(post, data.to_json).body)
11
- end
12
-
13
- def get(path, params = {})
14
- url = "#{Configuration.notification_server}/#{path}/#{Configuration[:api_key]}"
15
- JSON.parse(Net::HTTP.get(URI.parse(url)))
16
- end
17
-
18
- def request_env(env)
19
- env_hash = env.reject{|k,v| k.include?('action') || k.include?('rack')}
20
- env_hash.delete('HTTP_COOKIE')
21
- env_hash['HOSTNAME'] = Socket.gethostname
22
-
23
- env_hash.to_json
24
- end
25
-
26
-
27
- end
28
- end
29
- end
@@ -1,29 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
5
- </head>
6
- <body style='color:#333;font-size:14px;margin-top:30px;'>
7
- <span style='font-size:15px;'>
8
- <strong style='margin-right:45px;'>Project</strong> : <%= @project_name %>
9
- <br/>
10
- <strong style='margin-right:5px;'>Environment</strong> : <%= @exception[:environment] %>
11
- </span>
12
- <div style='border:2px solid #FBC7C6;padding:10px 15px;margin-top:20px;'>
13
- <p style='font-weight:bold'>
14
- Exception: <%= @exception[:message] %>
15
- </p>
16
- <p>
17
- <strong>Action : </strong><%= "#{@exception[:params][:controller]}##{@exception[:params][:action]}" %>
18
- </p>
19
- <p>
20
- <strong>Exception Line : </strong><%= @exception[:exception_line] %>
21
- </p>
22
- <p>
23
- <strong>Occurred at : </strong><%= @exception[:occurred_at] %> </p>
24
- <p>
25
- <strong>Request Url : </strong><%= "#{@exception[:http_method]} #{@exception[:url]}" %>
26
- </p>
27
- </div>
28
- </body>
29
- </html>