rusen 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,19 +4,25 @@ module Rusen
4
4
 
5
5
  attr_writer :outputs
6
6
  attr_writer :email_prefix
7
+ attr_writer :email_via
7
8
  attr_writer :sender_address
8
9
  attr_writer :exception_recipients
9
10
  attr_writer :sections
10
11
  attr_writer :smtp_settings
11
12
  attr_writer :exclude_if
12
13
 
14
+ attr_writer :filter_parameters
15
+
16
+ attr_accessor :logger_name
17
+ attr_accessor :log4r_config_file
18
+
13
19
  # Returns the configured outputs.
14
20
  #
15
- # Default: [:io, :email]
21
+ # Default: []
16
22
  #
17
23
  # @return [Array<Symbol>]
18
24
  def outputs
19
- @outputs || [:io, :email]
25
+ @outputs || []
20
26
  end
21
27
 
22
28
  # Returns the notification email prefix.
@@ -28,6 +34,15 @@ module Rusen
28
34
  @email_prefix || '[Exception] '
29
35
  end
30
36
 
37
+ # Returns the email for email notifications.
38
+ #
39
+ # Default: :smtp
40
+ #
41
+ # @return [Symbol]
42
+ def email_via
43
+ @email_via || :smtp
44
+ end
45
+
31
46
  # Returns the notification email sender.
32
47
  #
33
48
  # Default: ''
@@ -73,6 +88,24 @@ module Rusen
73
88
  @exclude_if || lambda { |exception| false }
74
89
  end
75
90
 
91
+ # Returns the parameters we need to filter from being sent on
92
+ # the notification, this will be used to not send sensitive
93
+ # data to the developers credit card numbers for instance.
94
+ #
95
+ # @note
96
+ # If this is used with a rails app we use the config filter
97
+ # parameters from there if the filter parameters are not
98
+ # defined.
99
+ #
100
+ # @return [Array]
101
+ def filter_parameters
102
+ if @filter_parameter
103
+ @filter_parameters || []
104
+ else
105
+ defined?(Rails) && Rails.application.config.filter_parameters
106
+ end
107
+ end
108
+
76
109
  end
77
110
 
78
111
  end
@@ -0,0 +1,19 @@
1
+ require 'rusen'
2
+ require 'sidekiq'
3
+
4
+ Rusen.settings.outputs = [:mail]
5
+ Rusen.settings.sections = [:backtrace]
6
+
7
+ if Sidekiq::VERSION < '3'
8
+ require_relative 'middleware/rusen_sidekiq'
9
+
10
+ Sidekiq.configure_server do |config|
11
+ config.server_middleware do |chain|
12
+ chain.add Rusen::Middleware::RusenSidekiq
13
+ end
14
+ end
15
+ else
16
+ Sidekiq.configure_server do |config|
17
+ config.error_handlers << Proc.new { |ex, context| Rusen.notify(ex) }
18
+ end
19
+ end
@@ -1,77 +1,31 @@
1
1
  <%= @notification.exception.class %>: <%= @notification.exception.message %>
2
2
 
3
- <% if @settings.sections.include?(:backtrace) %>
4
- <table style="border-collapse: collapse; border-spacing: 0; width: 100%; border: double; margin-bottom: 10px;">
5
- <thead style="background-color: #EFEFEF; font-size: 10pt; font-weight: bold;">
6
- <tr>
7
- <td><h4>Backtrace:</h4></td>
8
- <td></td>
9
- </tr>
10
- </thead>
11
- <tbody style="font-size: 11pt;">
12
- <% @notification.exception.backtrace.each do |backtrace_step| %>
13
- <tr>
14
- <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= backtrace_step %></td>
15
- </tr>
16
- <% end %>
17
- </tbody>
18
- </table>
19
- <% end %>
20
-
21
- <% if @settings.sections.include?(:request) %>
22
- <table style="border-collapse: collapse; border-spacing: 0; width: 100%; border: double; margin-bottom: 10px;">
23
- <thead style="background-color: #EFEFEF; font-size: 10pt; font-weight: bold;">
24
- <tr>
25
- <td><h4>Request:</h4></td>
26
- <td></td>
27
- </tr>
28
- </thead>
29
- <tbody style="font-size: 11pt;">
30
- <% @notification.request.each do |k, v| %>
31
- <tr>
32
- <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= k %></td>
33
- <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= v %></td>
34
- </tr>
35
- <% end %>
36
- </tbody>
37
- </table>
38
- <% end %>
39
-
40
- <% if @settings.sections.include?(:session) %>
41
- <table style="border-collapse: collapse; border-spacing: 0; width: 100%; border: double; margin-bottom: 10px;">
42
- <thead style="background-color: #EFEFEF; font-size: 10pt; font-weight: bold;">
43
- <tr>
44
- <td><h4>Session:</h4></td>
45
- <td></td>
46
- </tr>
47
- </thead>
48
- <tbody style="font-size: 11pt;">
49
- <% @notification.session.each do |k, v| %>
50
- <tr>
51
- <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= k %></td>
52
- <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= v %></td>
53
- </tr>
54
- <% end %>
55
- </tbody>
56
- </table>
57
- <% end %>
58
-
59
-
60
- <% if @settings.sections.include?(:environment) %>
61
- <table style="border-collapse: collapse; border-spacing: 0; width: 100%; border: double; margin-bottom: 10px;">
62
- <thead style="background-color: #EFEFEF; font-size: 10pt; font-weight: bold;">
63
- <tr>
64
- <td><h4>Environment:</h4></td>
65
- <td></td>
66
- </tr>
67
- </thead>
68
- <tbody style="font-size: 11pt;">
69
- <% @notification.environment.each do |k, v| %>
70
- <tr>
71
- <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= k %></td>
72
- <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= v %></td>
73
- </tr>
74
- <% end %>
75
- </tbody>
76
- </table>
3
+ <% @sessions.each do |name, session| %>
4
+ <table style="border-collapse: collapse; border-spacing: 0; width: 100%; border: double; margin-bottom: 10px;">
5
+ <thead style="background-color: #EFEFEF; font-size: 10pt; font-weight: bold;">
6
+ <tr>
7
+ <td>
8
+ <h4><%= name %>:</h4>
9
+ </td>
10
+ <td></td>
11
+ </tr>
12
+ </thead>
13
+ <tbody style="font-size: 11pt;">
14
+ <% if session.is_a?(Hash) %>
15
+ <% session.each do |key, value| %>
16
+ <tr>
17
+ <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= key %></td>
18
+ <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= value %></td>
19
+ </tr>
20
+ <% end %>
21
+ <% else %>
22
+ <% session.each do |session_step| %>
23
+ <tr>
24
+ <td style="border: solid 1px #000000; margin: 0; padding: 4pt 6pt;"><%= session_step %></td>
25
+ <td></td>
26
+ </tr>
27
+ <% end %>
28
+ <% end %>
29
+ </tbody>
30
+ </table>
77
31
  <% end %>
@@ -0,0 +1,19 @@
1
+ *******************************************************************************
2
+ <%= @notification.exception.class %>: <%= @notification.exception.message -%>
3
+ <% @sessions.each do |name, session| -%>
4
+ <%= "\n" %>
5
+ -------------------------------
6
+ <%= name %>:
7
+ -------------------------------
8
+ <% if session.is_a?(Hash) -%>
9
+ <% session.each do |key, value| -%>
10
+ <%= "\n#{key.to_s}:\t\t\t#{value.to_s}" -%>
11
+ <% end -%>
12
+ <% else -%>
13
+ <% session.each do |session_step| -%>
14
+ <%= "\n#{session_step}" -%>
15
+ <% end -%>
16
+ <% end -%>
17
+ <% end -%>
18
+
19
+ *******************************************************************************
@@ -0,0 +1,19 @@
1
+ *******************************************************************************
2
+ <%= @notification.exception.class %>: <%= @notification.exception.message %>
3
+
4
+ <% @sessions.each do |name, session| %>
5
+ -------------------------------
6
+ <%= name %>:
7
+ -------------------------------
8
+ <% if session.is_a?(Hash) -%>
9
+ <% session.each do |key, value| -%>
10
+ <%= key.to_s + ":\t\t\t" + value.to_s -%>
11
+ <% end -%>
12
+ <% else -%>
13
+ <% session.each do |session_step| -%>
14
+ <%= "\t" + session_step %>
15
+ <% end -%>
16
+ <% end -%>
17
+ <% end -%>
18
+
19
+ *******************************************************************************
@@ -0,0 +1,68 @@
1
+ class ParameterFilter
2
+ FILTERED = '[FILTERED]'.freeze # :nodoc:
3
+
4
+ def initialize(filters = [])
5
+ @filters = filters
6
+ end
7
+
8
+ def filter(params)
9
+ compiled_filter.call(params)
10
+ end
11
+
12
+ private
13
+
14
+ def compiled_filter
15
+ @compiled_filter ||= CompiledFilter.compile(@filters)
16
+ end
17
+
18
+ class CompiledFilter # :nodoc:
19
+ def self.compile(filters)
20
+ return lambda { |params| params.dup } if filters.nil? || filters.empty?
21
+
22
+ strings, regexps, blocks = [], [], []
23
+
24
+ filters.each do |item|
25
+ case item
26
+ when Proc
27
+ blocks << item
28
+ when Regexp
29
+ regexps << item
30
+ else
31
+ strings << item.to_s
32
+ end
33
+ end
34
+
35
+ regexps << Regexp.new(strings.join('|'), true) unless strings.empty?
36
+ new regexps, blocks
37
+ end
38
+
39
+ attr_reader :regexps, :blocks
40
+
41
+ def initialize(regexps, blocks)
42
+ @regexps = regexps
43
+ @blocks = blocks
44
+ end
45
+
46
+ def call(original_params)
47
+ filtered_params = {}
48
+
49
+ original_params.each do |key, value|
50
+ if regexps.any? { |r| key =~ r }
51
+ value = FILTERED
52
+ elsif value.is_a?(Hash)
53
+ value = call(value)
54
+ elsif value.is_a?(Array)
55
+ value = value.map { |v| v.is_a?(Hash) ? call(v) : v }
56
+ elsif blocks.any?
57
+ key = key.dup
58
+ value = value.dup if value.duplicable?
59
+ blocks.each { |b| b.call(key, value) }
60
+ end
61
+
62
+ filtered_params[key] = value
63
+ end
64
+
65
+ filtered_params
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module Rusen
2
+ VERSION='0.0.3'
3
+ end
metadata CHANGED
@@ -1,101 +1,226 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rusen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adrian Gomez
8
+ - Pablo Ifran
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-25 00:00:00.000000000 Z
12
+ date: 2014-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: log4r
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: pony
16
30
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
31
  requirements:
19
- - - ! '>='
32
+ - - '>='
20
33
  - !ruby/object:Gem::Version
21
34
  version: '0'
22
- type: :runtime
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: mail
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
23
50
  prerelease: false
24
51
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
52
  requirements:
27
- - - ! '>='
53
+ - - '>='
28
54
  - !ruby/object:Gem::Version
29
55
  version: '0'
30
56
  - !ruby/object:Gem::Dependency
31
57
  name: rspec
32
58
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
59
  requirements:
35
- - - ! '>='
60
+ - - '>='
36
61
  - !ruby/object:Gem::Version
37
62
  version: '0'
38
63
  type: :development
39
64
  prerelease: false
40
65
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
66
  requirements:
43
- - - ! '>='
67
+ - - '>='
44
68
  - !ruby/object:Gem::Version
45
69
  version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: shoulda
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - <
75
+ - !ruby/object:Gem::Version
76
+ version: '3.6'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - <
82
+ - !ruby/object:Gem::Version
83
+ version: '3.6'
84
+ - !ruby/object:Gem::Dependency
85
+ name: shoulda-matchers
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - <
89
+ - !ruby/object:Gem::Version
90
+ version: '1.6'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - <
96
+ - !ruby/object:Gem::Version
97
+ version: '1.6'
46
98
  - !ruby/object:Gem::Dependency
47
99
  name: simplecov
48
100
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
101
  requirements:
51
- - - ! '>='
102
+ - - '>='
52
103
  - !ruby/object:Gem::Version
53
104
  version: '0'
54
105
  type: :development
55
106
  prerelease: false
56
107
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
108
  requirements:
59
- - - ! '>='
109
+ - - '>='
60
110
  - !ruby/object:Gem::Version
61
111
  version: '0'
62
- description: ! "RUby Simple Exception Notification (a.k.a. rusen) as it names indicates
63
- is a\n simple exception notification for ruby."
112
+ - !ruby/object:Gem::Dependency
113
+ name: coveralls
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: reek
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: 1.2.8
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: 1.2.8
140
+ - !ruby/object:Gem::Dependency
141
+ name: roodi
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: 2.1.0
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: 2.1.0
154
+ - !ruby/object:Gem::Dependency
155
+ name: rake
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ description: |-
169
+ RUby Simple Exception Notification (a.k.a. rusen) as it names indicates is a
170
+ simple exception notification for ruby.
64
171
  email: adri4n.gomez@gmail.com
65
172
  executables: []
66
173
  extensions: []
67
- extra_rdoc_files: []
174
+ extra_rdoc_files:
175
+ - CHANGELOG.md
176
+ - LICENSE
177
+ - README.md
68
178
  files:
179
+ - CHANGELOG.md
180
+ - LICENSE
181
+ - README.md
182
+ - Rakefile
69
183
  - lib/rusen.rb
70
- - lib/rusen/templates/email_template.html.erb
184
+ - lib/rusen/middleware/rusen_rack.rb
185
+ - lib/rusen/middleware/rusen_sidekiq.rb
186
+ - lib/rusen/notification.rb
71
187
  - lib/rusen/notifier.rb
72
- - lib/rusen/settings.rb
188
+ - lib/rusen/notifiers.rb
189
+ - lib/rusen/notifiers/base_notifier.rb
73
190
  - lib/rusen/notifiers/io_notifier.rb
74
- - lib/rusen/notifiers/email_notifier.rb
75
- - lib/rusen/notification.rb
76
- - lib/rusen/middleware/rusen_rack.rb
191
+ - lib/rusen/notifiers/log4r_notifier.rb
192
+ - lib/rusen/notifiers/mail_notifier.rb
193
+ - lib/rusen/notifiers/pony_notifier.rb
194
+ - lib/rusen/settings.rb
195
+ - lib/rusen/sidekiq.rb
196
+ - lib/rusen/templates/email_template.html.erb
197
+ - lib/rusen/templates/io_template.txt.erb
198
+ - lib/rusen/templates/log4r_template.txt.erb
199
+ - lib/rusen/utils/parameter_filter.rb
200
+ - lib/rusen/version.rb
77
201
  homepage: https://github.com/Moove-it/rusen
78
- licenses: []
202
+ licenses:
203
+ - MIT
204
+ metadata: {}
79
205
  post_install_message:
80
- rdoc_options: []
206
+ rdoc_options:
207
+ - --charset=UTF-8
81
208
  require_paths:
82
209
  - lib
83
210
  required_ruby_version: !ruby/object:Gem::Requirement
84
- none: false
85
211
  requirements:
86
- - - ! '>='
212
+ - - '>='
87
213
  - !ruby/object:Gem::Version
88
214
  version: '0'
89
215
  required_rubygems_version: !ruby/object:Gem::Requirement
90
- none: false
91
216
  requirements:
92
- - - ! '>='
217
+ - - '>='
93
218
  - !ruby/object:Gem::Version
94
219
  version: '0'
95
220
  requirements: []
96
221
  rubyforge_project:
97
- rubygems_version: 1.8.23
222
+ rubygems_version: 2.2.1
98
223
  signing_key:
99
- specification_version: 3
224
+ specification_version: 4
100
225
  summary: RUby Simple Exception Notification
101
226
  test_files: []