uniform_notifier 1.14.0 → 1.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/uniform_notifier.rb +7 -6
- data/lib/uniform_notifier/airbrake.rb +12 -10
- data/lib/uniform_notifier/appsignal.rb +13 -11
- data/lib/uniform_notifier/base.rb +28 -26
- data/lib/uniform_notifier/bugsnag.rb +12 -10
- data/lib/uniform_notifier/customized_logger.rb +15 -13
- data/lib/uniform_notifier/errors.rb +2 -1
- data/lib/uniform_notifier/growl.rb +52 -50
- data/lib/uniform_notifier/honeybadger.rb +13 -11
- data/lib/uniform_notifier/javascript_alert.rb +11 -9
- data/lib/uniform_notifier/javascript_console.rb +21 -19
- data/lib/uniform_notifier/rails_logger.rb +9 -7
- data/lib/uniform_notifier/raise.rb +12 -10
- data/lib/uniform_notifier/rollbar.rb +12 -10
- data/lib/uniform_notifier/sentry.rb +12 -10
- data/lib/uniform_notifier/slack.rb +2 -2
- data/lib/uniform_notifier/terminal_notifier.rb +15 -13
- data/lib/uniform_notifier/version.rb +1 -1
- data/lib/uniform_notifier/xmpp.rb +42 -40
- data/spec/uniform_notifier/appsignal_spec.rb +22 -15
- data/spec/uniform_notifier/bugsnag_spec.rb +14 -4
- data/spec/uniform_notifier/growl_spec.rb +11 -16
- data/spec/uniform_notifier/javascript_alert_spec.rb +1 -1
- data/spec/uniform_notifier/javascript_console_spec.rb +1 -1
- data/spec/uniform_notifier/sentry_spec.rb +3 -3
- data/spec/uniform_notifier/slack_spec.rb +2 -2
- data/spec/uniform_notifier/xmpp_spec.rb +8 -2
- data/uniform_notifier.gemspec +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9fa5744a54e1bff245ab1f1b03974250a6a0880d63ba05b6594ada564bf4c87
|
4
|
+
data.tar.gz: ae4f6c59d2377f88f50419bcc1abe9215987a9b9c1d549b1323919d9f2d5841a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d739e807172146c2647ab96b122825efc3c033bc27dc3a27cf05c7d7e1c07bc2a273a15df6dd1f8574273663b30143b82cb997756c65a61c69c051c332c81dee
|
7
|
+
data.tar.gz: 785945370f105bacf35cc12b2d769a6d3038d4520df5f376e9d42cf055ea0959777431058c0f9f0f05bd1a2a823dcf2aaa929201d07122ab3aef3128732cda56
|
data/CHANGELOG.md
CHANGED
data/lib/uniform_notifier.rb
CHANGED
@@ -55,7 +55,8 @@ class UniformNotifier
|
|
55
55
|
TerminalNotifier
|
56
56
|
].freeze
|
57
57
|
|
58
|
-
class NotificationError < StandardError
|
58
|
+
class NotificationError < StandardError
|
59
|
+
end
|
59
60
|
|
60
61
|
class << self
|
61
62
|
attr_accessor(*AVAILABLE_NOTIFIERS)
|
@@ -64,27 +65,27 @@ class UniformNotifier
|
|
64
65
|
NOTIFIERS.select(&:active?)
|
65
66
|
end
|
66
67
|
|
67
|
-
undef
|
68
|
+
undef growl=
|
68
69
|
def growl=(growl)
|
69
70
|
UniformNotifier::Growl.setup_connection(growl)
|
70
71
|
end
|
71
72
|
|
72
|
-
undef
|
73
|
+
undef xmpp=
|
73
74
|
def xmpp=(xmpp)
|
74
75
|
UniformNotifier::Xmpp.setup_connection(xmpp)
|
75
76
|
end
|
76
77
|
|
77
|
-
undef
|
78
|
+
undef customized_logger=
|
78
79
|
def customized_logger=(logdev)
|
79
80
|
UniformNotifier::CustomizedLogger.setup(logdev)
|
80
81
|
end
|
81
82
|
|
82
|
-
undef
|
83
|
+
undef slack=
|
83
84
|
def slack=(slack)
|
84
85
|
UniformNotifier::Slack.setup_connection(slack)
|
85
86
|
end
|
86
87
|
|
87
|
-
undef
|
88
|
+
undef raise=
|
88
89
|
def raise=(exception_class)
|
89
90
|
UniformNotifier::Raise.setup_connection(exception_class)
|
90
91
|
end
|
@@ -2,20 +2,22 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class AirbrakeNotifier < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
!!UniformNotifier.airbrake
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
protected
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
def _out_of_channel_notify(data)
|
13
|
+
message = data.values.compact.join("\n")
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
opt = {}
|
16
|
+
opt = UniformNotifier.airbrake if UniformNotifier.airbrake.is_a?(Hash)
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
exception = Exception.new(message)
|
19
|
+
Airbrake.notify(exception, opt)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -2,22 +2,24 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class AppsignalNotifier < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
!!UniformNotifier.appsignal
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
protected
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
def _out_of_channel_notify(data)
|
13
|
+
opt = UniformNotifier.appsignal.is_a?(Hash) ? UniformNotifier.appsignal : {}
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
exception = Exception.new(data[:title])
|
16
|
+
exception.set_backtrace(data[:backtrace]) if data[:backtrace]
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
tags = opt.fetch(:tags, {}).merge(data.fetch(:tags, {}))
|
19
|
+
namespace = data[:namespace] || opt[:namespace]
|
19
20
|
|
20
|
-
|
21
|
+
Appsignal.send_error(*[exception, tags, namespace].compact)
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -2,43 +2,45 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
false
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
def inline_notify(data)
|
11
|
+
return unless active?
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
# For compatibility to the old protocol
|
14
|
+
data = { title: data } if data.is_a?(String)
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
_inline_notify(data)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
def out_of_channel_notify(data)
|
20
|
+
return unless active?
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
# For compatibility to the old protocol
|
23
|
+
data = { title: data } if data.is_a?(String)
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
_out_of_channel_notify(data)
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
protected
|
28
29
|
|
29
|
-
|
30
|
+
def _inline_notify(data); end
|
30
31
|
|
31
|
-
|
32
|
+
def _out_of_channel_notify(data); end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def wrap_js_association(code, attributes = {})
|
35
|
+
attributes = { type: 'text/javascript' }.merge(attributes || {})
|
36
|
+
attributes_string = attributes.map { |k, v| "#{k}=#{v.to_s.inspect}" }.join(' ')
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
<<~CODE
|
39
|
+
<script #{attributes_string}>/*<![CDATA[*/
|
40
|
+
#{code}
|
41
|
+
/*]]>*/</script>
|
42
|
+
CODE
|
43
|
+
end
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -2,19 +2,21 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class BugsnagNotifier < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
!!UniformNotifier.bugsnag
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
protected
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def _out_of_channel_notify(data)
|
13
|
+
opt = {}
|
14
|
+
opt = UniformNotifier.bugsnag if UniformNotifier.bugsnag.is_a?(Hash)
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
exception = Exception.new(data[:title])
|
17
|
+
exception.set_backtrace(data[:backtrace]) if data[:backtrace]
|
18
|
+
Bugsnag.notify(exception, opt.merge(grouping_hash: data[:body] || data[:title], notification: data))
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -2,24 +2,26 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class CustomizedLogger < Base
|
5
|
-
|
5
|
+
class << self
|
6
|
+
@logger = nil
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def active?
|
9
|
+
@logger
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def _out_of_channel_notify(data)
|
13
|
+
message = data.values.compact.join("\n")
|
14
|
+
@logger.warn message
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
def setup(logdev)
|
18
|
+
require 'logger'
|
18
19
|
|
19
|
-
|
20
|
+
@logger = Logger.new(logdev)
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def @logger.format_message(severity, timestamp, _progname, msg)
|
23
|
+
"#{timestamp.strftime('%Y-%m-%d %H:%M:%S')}[#{severity}] #{msg}"
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -2,72 +2,74 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class Growl < Base
|
5
|
-
|
5
|
+
class << self
|
6
|
+
@growl = nil
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def active?
|
9
|
+
@growl
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
rescue LoadError
|
14
|
-
begin
|
15
|
-
setup_connection_gntp(growl)
|
12
|
+
def setup_connection(growl)
|
13
|
+
setup_connection_growl(growl)
|
16
14
|
rescue LoadError
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
begin
|
16
|
+
setup_connection_gntp(growl)
|
17
|
+
rescue LoadError
|
18
|
+
@growl = nil
|
19
|
+
raise NotificationError,
|
20
|
+
'You must install the ruby-growl or the ruby_gntp gem to use Growl notification: `gem install ruby-growl` or `gem install ruby_gntp`'
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
def setup_connection_growl(growl)
|
25
|
+
return unless growl
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
require 'ruby-growl'
|
28
|
+
if growl.instance_of?(Hash)
|
29
|
+
@password = growl.include?(:password) ? growl[:password] : nil
|
30
|
+
@host = growl.include?(:host) ? growl[:host] : 'localhost'
|
31
|
+
end
|
32
|
+
@password ||= nil
|
33
|
+
@host ||= 'localhost'
|
34
|
+
@growl = ::Growl.new @host, 'uniform_notifier'
|
35
|
+
@growl.add_notification 'uniform_notifier'
|
36
|
+
@growl.password = @password
|
37
|
+
|
38
|
+
notify 'Uniform Notifier Growl has been turned on' if !growl.instance_of?(Hash) || !growl[:quiet]
|
30
39
|
end
|
31
|
-
@password ||= nil
|
32
|
-
@host ||= 'localhost'
|
33
|
-
@growl = ::Growl.new @host, 'uniform_notifier'
|
34
|
-
@growl.add_notification 'uniform_notifier'
|
35
|
-
@growl.password = @password
|
36
40
|
|
37
|
-
|
38
|
-
|
41
|
+
def setup_connection_gntp(growl)
|
42
|
+
return unless growl
|
39
43
|
|
40
|
-
|
41
|
-
|
44
|
+
require 'ruby_gntp'
|
45
|
+
if growl.instance_of?(Hash)
|
46
|
+
@password = growl.include?(:password) ? growl[:password] : nil
|
47
|
+
@host = growl.include?(:host) ? growl[:host] : 'localhost'
|
48
|
+
end
|
49
|
+
@password ||= nil
|
50
|
+
@host ||= 'localhost'
|
51
|
+
@growl = GNTP.new('uniform_notifier', @host, @password, 23_053)
|
52
|
+
@growl.register(notifications: [{ name: 'uniform_notifier', enabled: true }])
|
42
53
|
|
43
|
-
|
44
|
-
if growl.instance_of?(Hash)
|
45
|
-
@password = growl.include?(:password) ? growl[:password] : nil
|
46
|
-
@host = growl.include?(:host) ? growl[:host] : 'localhost'
|
54
|
+
notify 'Uniform Notifier Growl has been turned on (using GNTP)' if !growl.instance_of?(Hash) || !growl[:quiet]
|
47
55
|
end
|
48
|
-
@password ||= nil
|
49
|
-
@host ||= 'localhost'
|
50
|
-
@growl = GNTP.new('uniform_notifier', @host, @password, 23_053)
|
51
|
-
@growl.register(notifications: [{ name: 'uniform_notifier', enabled: true }])
|
52
56
|
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
protected
|
57
|
+
protected
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
def _out_of_channel_notify(data)
|
60
|
+
message = data.values.compact.join("\n")
|
60
61
|
|
61
|
-
|
62
|
-
|
62
|
+
notify(message)
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
+
private
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
def notify(message)
|
68
|
+
if defined?(::Growl) && @growl.is_a?(::Growl)
|
69
|
+
@growl.notify('uniform_notifier', 'Uniform Notifier', message)
|
70
|
+
elsif defined?(::GNTP) && @growl.is_a?(::GNTP)
|
71
|
+
@growl.notify(name: 'uniform_notifier', title: 'Uniform Notifier', text: message)
|
72
|
+
end
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|
@@ -2,21 +2,23 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class HoneybadgerNotifier < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
!!UniformNotifier.honeybadger
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
protected
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
def _out_of_channel_notify(data)
|
13
|
+
message = data.values.compact.join("\n")
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
opt = {}
|
16
|
+
opt = UniformNotifier.honeybadger if UniformNotifier.honeybadger.is_a?(Hash)
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
exception = Exception.new(message)
|
19
|
+
honeybadger_class = opt[:honeybadger_class] || Honeybadger
|
20
|
+
honeybadger_class.notify(exception, opt)
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -2,18 +2,20 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class JavascriptAlert < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
!!UniformNotifier.alert
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
protected
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def _inline_notify(data)
|
13
|
+
message = data.values.compact.join("\n")
|
14
|
+
options = UniformNotifier.alert.is_a?(Hash) ? UniformNotifier.alert : {}
|
15
|
+
script_attributes = options[:attributes] || {}
|
15
16
|
|
16
|
-
|
17
|
+
wrap_js_association "alert( #{message.inspect} );", script_attributes
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -2,30 +2,32 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class JavascriptConsole < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
!!UniformNotifier.console
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
protected
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def _inline_notify(data)
|
13
|
+
message = data.values.compact.join("\n")
|
14
|
+
options = UniformNotifier.console.is_a?(Hash) ? UniformNotifier.console : {}
|
15
|
+
script_attributes = options[:attributes] || {}
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
code = <<~CODE
|
18
|
+
if (typeof(console) !== 'undefined' && console.log) {
|
19
|
+
if (console.groupCollapsed && console.groupEnd) {
|
20
|
+
console.groupCollapsed(#{'Uniform Notifier'.inspect});
|
21
|
+
console.log(#{message.inspect});
|
22
|
+
console.groupEnd();
|
23
|
+
} else {
|
24
|
+
console.log(#{message.inspect});
|
25
|
+
}
|
24
26
|
}
|
25
|
-
|
26
|
-
CODE
|
27
|
+
CODE
|
27
28
|
|
28
|
-
|
29
|
+
wrap_js_association code, script_attributes
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -2,16 +2,18 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class RailsLogger < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
UniformNotifier.rails_logger
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
protected
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
def _out_of_channel_notify(data)
|
13
|
+
message = data.values.compact.join("\n")
|
13
14
|
|
14
|
-
|
15
|
+
Rails.logger.warn message
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -2,20 +2,22 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class Raise < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
defined?(@exception_class) ? @exception_class : false
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def setup_connection(exception_class)
|
11
|
+
@exception_class = exception_class == true ? Exception : exception_class
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
+
protected
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
def _out_of_channel_notify(data)
|
17
|
+
message = data.values.compact.join("\n")
|
17
18
|
|
18
|
-
|
19
|
+
raise @exception_class, message
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -4,20 +4,22 @@ class UniformNotifier
|
|
4
4
|
class RollbarNotifier < Base
|
5
5
|
DEFAULT_LEVEL = 'info'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
class << self
|
8
|
+
def active?
|
9
|
+
!!UniformNotifier.rollbar
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
+
protected
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
def _out_of_channel_notify(data)
|
15
|
+
message = data.values.compact.join("\n")
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
exception = Exception.new(message)
|
18
|
+
level = UniformNotifier.rollbar.fetch(:level, DEFAULT_LEVEL) if UniformNotifier.rollbar.is_a?(Hash)
|
19
|
+
level ||= DEFAULT_LEVEL
|
19
20
|
|
20
|
-
|
21
|
+
Rollbar.log(level, exception)
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -2,20 +2,22 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class SentryNotifier < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
!!UniformNotifier.sentry
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
protected
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
def _out_of_channel_notify(data)
|
13
|
+
message = data.values.compact.join("\n")
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
opt = {}
|
16
|
+
opt = UniformNotifier.sentry if UniformNotifier.sentry.is_a?(Hash)
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
exception = Exception.new(message)
|
19
|
+
Sentry.capture_exception(exception, opt)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -2,23 +2,25 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class TerminalNotifier < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def active?
|
7
|
+
!!UniformNotifier.terminal_notifier
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
protected
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def _out_of_channel_notify(data)
|
13
|
+
unless defined?(::TerminalNotifier)
|
14
|
+
begin
|
15
|
+
require 'terminal-notifier'
|
16
|
+
rescue LoadError
|
17
|
+
raise NotificationError,
|
18
|
+
'You must install the terminal-notifier gem to use terminal_notifier: `gem install terminal-notifier`'
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
+
::TerminalNotifier.notify(data[:body], title: data[:title])
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -2,58 +2,60 @@
|
|
2
2
|
|
3
3
|
class UniformNotifier
|
4
4
|
class Xmpp < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
@receiver = nil
|
7
|
+
@xmpp = nil
|
8
|
+
@password = nil
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def active?
|
11
|
+
@xmpp
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
def setup_connection(xmpp_information)
|
15
|
+
return unless xmpp_information
|
15
16
|
|
16
|
-
|
17
|
+
require 'xmpp4r'
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
@xmpp = xmpp_information
|
20
|
+
@receiver = xmpp_information[:receiver]
|
21
|
+
@password = xmpp_information[:password]
|
22
|
+
@account = xmpp_information[:account]
|
23
|
+
@show_online_status = xmpp_information[:show_online_status]
|
24
|
+
@stay_connected = xmpp_information[:stay_connected].nil? ? true : xmpp_information[:stay_connected]
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
connect if @stay_connected
|
27
|
+
rescue LoadError
|
28
|
+
@xmpp = nil
|
29
|
+
raise NotificationError, 'You must install the xmpp4r gem to use XMPP notification: `gem install xmpp4r`'
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
+
protected
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
def _out_of_channel_notify(data)
|
35
|
+
message = data.values.compact.join("\n")
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
notify(message)
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
+
private
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
def connect
|
43
|
+
jid = Jabber::JID.new(@account)
|
44
|
+
@xmpp = Jabber::Client.new(jid)
|
45
|
+
@xmpp.connect
|
46
|
+
@xmpp.auth(@password)
|
47
|
+
@xmpp.send(presence_status) if @show_online_status
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def notify(message)
|
51
|
+
connect unless @stay_connected
|
52
|
+
message = Jabber::Message.new(@receiver, message).set_type(:normal).set_subject('Uniform Notifier')
|
53
|
+
@xmpp.send(message)
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
def presence_status
|
57
|
+
Jabber::Presence.new.set_status("Uniform Notifier started on #{Time.now}")
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -12,57 +12,64 @@ RSpec.describe UniformNotifier::AppsignalNotifier do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should notify appsignal with keyword title' do
|
15
|
-
expect(Appsignal).to receive(:send_error)
|
16
|
-
.with(UniformNotifier::Exception.new('notify appsignal'), {})
|
15
|
+
expect(Appsignal).to receive(:send_error).with(UniformNotifier::Exception.new('notify appsignal'), {})
|
17
16
|
|
18
17
|
UniformNotifier.appsignal = true
|
19
18
|
expect(UniformNotifier::AppsignalNotifier.out_of_channel_notify(title: 'notify appsignal'))
|
20
19
|
end
|
21
20
|
|
22
21
|
it 'should notify appsignal with first argument title' do
|
23
|
-
expect(Appsignal).to receive(:send_error)
|
24
|
-
.with(UniformNotifier::Exception.new('notify appsignal'), {})
|
22
|
+
expect(Appsignal).to receive(:send_error).with(UniformNotifier::Exception.new('notify appsignal'), {})
|
25
23
|
|
26
24
|
UniformNotifier.appsignal = true
|
27
25
|
UniformNotifier::AppsignalNotifier.out_of_channel_notify('notify appsignal')
|
28
26
|
end
|
29
27
|
|
30
28
|
it 'should notify appsignal with tags' do
|
31
|
-
expect(Appsignal).to receive(:send_error)
|
32
|
-
.with(UniformNotifier::Exception.new('notify appsignal'), { foo: :bar })
|
29
|
+
expect(Appsignal).to receive(:send_error).with(UniformNotifier::Exception.new('notify appsignal'), { foo: :bar })
|
33
30
|
|
34
31
|
UniformNotifier.appsignal = true
|
35
|
-
UniformNotifier::AppsignalNotifier.out_of_channel_notify(title: 'notify appsignal', tags: { foo: :bar})
|
32
|
+
UniformNotifier::AppsignalNotifier.out_of_channel_notify(title: 'notify appsignal', tags: { foo: :bar })
|
36
33
|
end
|
37
34
|
|
38
35
|
it 'should notify appsignal with default namespace' do
|
39
|
-
expect(Appsignal).to receive(:send_error)
|
40
|
-
.with(UniformNotifier::Exception.new('notify appsignal'), {}, 'web')
|
36
|
+
expect(Appsignal).to receive(:send_error).with(UniformNotifier::Exception.new('notify appsignal'), {}, 'web')
|
41
37
|
|
42
38
|
UniformNotifier.appsignal = { namespace: 'web' }
|
43
39
|
UniformNotifier::AppsignalNotifier.out_of_channel_notify('notify appsignal')
|
44
40
|
end
|
45
41
|
|
46
42
|
it 'should notify appsignal with overridden namespace' do
|
47
|
-
expect(Appsignal).to receive(:send_error)
|
48
|
-
|
43
|
+
expect(Appsignal).to receive(:send_error).with(
|
44
|
+
UniformNotifier::Exception.new('notify appsignal'),
|
45
|
+
{ foo: :bar },
|
46
|
+
'background'
|
47
|
+
)
|
49
48
|
|
50
49
|
UniformNotifier.appsignal = { namespace: 'web' }
|
51
50
|
UniformNotifier::AppsignalNotifier.out_of_channel_notify(
|
52
51
|
title: 'notify appsignal',
|
53
|
-
tags: {
|
52
|
+
tags: {
|
53
|
+
foo: :bar
|
54
|
+
},
|
54
55
|
namespace: 'background'
|
55
56
|
)
|
56
57
|
end
|
57
58
|
|
58
59
|
it 'should notify appsignal with merged tags' do
|
59
|
-
expect(Appsignal).to receive(:send_error)
|
60
|
-
|
60
|
+
expect(Appsignal).to receive(:send_error).with(
|
61
|
+
UniformNotifier::Exception.new('notify appsignal'),
|
62
|
+
{ user: 'Bob', hostname: 'frontend2', site: 'first' },
|
63
|
+
'background'
|
64
|
+
)
|
61
65
|
|
62
66
|
UniformNotifier.appsignal = { namespace: 'web', tags: { hostname: 'frontend1', user: 'Bob' } }
|
63
67
|
UniformNotifier::AppsignalNotifier.out_of_channel_notify(
|
64
68
|
title: 'notify appsignal',
|
65
|
-
tags: {
|
69
|
+
tags: {
|
70
|
+
hostname: 'frontend2',
|
71
|
+
site: 'first'
|
72
|
+
},
|
66
73
|
namespace: 'background'
|
67
74
|
)
|
68
75
|
end
|
@@ -18,7 +18,8 @@ RSpec.describe UniformNotifier::BugsnagNotifier do
|
|
18
18
|
it 'should notify bugsnag' do
|
19
19
|
expect(Bugsnag).to receive(:notify).with(
|
20
20
|
UniformNotifier::Exception.new(notification_data[:title]),
|
21
|
-
grouping_hash: notification_data[:body],
|
21
|
+
grouping_hash: notification_data[:body],
|
22
|
+
notification: notification_data
|
22
23
|
)
|
23
24
|
|
24
25
|
UniformNotifier.bugsnag = true
|
@@ -28,7 +29,9 @@ RSpec.describe UniformNotifier::BugsnagNotifier do
|
|
28
29
|
it 'should notify bugsnag with option' do
|
29
30
|
expect(Bugsnag).to receive(:notify).with(
|
30
31
|
UniformNotifier::Exception.new(notification_data[:title]),
|
31
|
-
foo: :bar,
|
32
|
+
foo: :bar,
|
33
|
+
grouping_hash: notification_data[:body],
|
34
|
+
notification: notification_data
|
32
35
|
)
|
33
36
|
|
34
37
|
UniformNotifier.bugsnag = { foo: :bar }
|
@@ -41,7 +44,10 @@ RSpec.describe UniformNotifier::BugsnagNotifier do
|
|
41
44
|
it 'should notify bugsnag' do
|
42
45
|
expect(Bugsnag).to receive(:notify).with(
|
43
46
|
UniformNotifier::Exception.new('notify bugsnag'),
|
44
|
-
grouping_hash: 'notify bugsnag',
|
47
|
+
grouping_hash: 'notify bugsnag',
|
48
|
+
notification: {
|
49
|
+
title: 'notify bugsnag'
|
50
|
+
}
|
45
51
|
)
|
46
52
|
|
47
53
|
UniformNotifier.bugsnag = true
|
@@ -51,7 +57,11 @@ RSpec.describe UniformNotifier::BugsnagNotifier do
|
|
51
57
|
it 'should notify bugsnag with option' do
|
52
58
|
expect(Bugsnag).to receive(:notify).with(
|
53
59
|
UniformNotifier::Exception.new('notify bugsnag'),
|
54
|
-
foo: :bar,
|
60
|
+
foo: :bar,
|
61
|
+
grouping_hash: 'notify bugsnag',
|
62
|
+
notification: {
|
63
|
+
title: 'notify bugsnag'
|
64
|
+
}
|
55
65
|
)
|
56
66
|
|
57
67
|
UniformNotifier.bugsnag = { foo: :bar }
|
@@ -12,12 +12,11 @@ RSpec.describe UniformNotifier::Growl do
|
|
12
12
|
expect(Growl).to receive(:new).with('localhost', 'uniform_notifier').and_return(growl)
|
13
13
|
expect(growl).to receive(:add_notification).with('uniform_notifier')
|
14
14
|
expect(growl).to receive(:password=).with(nil)
|
15
|
-
expect(growl).to receive(:notify)
|
16
|
-
'uniform_notifier',
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl without password')
|
15
|
+
expect(growl).to receive(:notify)
|
16
|
+
.with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on')
|
17
|
+
.ordered
|
18
|
+
expect(growl).to receive(:notify)
|
19
|
+
.with('uniform_notifier', 'Uniform Notifier', 'notify growl without password')
|
21
20
|
.ordered
|
22
21
|
|
23
22
|
UniformNotifier.growl = true
|
@@ -29,11 +28,9 @@ RSpec.describe UniformNotifier::Growl do
|
|
29
28
|
expect(Growl).to receive(:new).with('localhost', 'uniform_notifier').and_return(growl)
|
30
29
|
expect(growl).to receive(:add_notification).with('uniform_notifier')
|
31
30
|
expect(growl).to receive(:password=).with('123456')
|
32
|
-
expect(growl).to receive(:notify)
|
33
|
-
'uniform_notifier',
|
34
|
-
|
35
|
-
'Uniform Notifier Growl has been turned on'
|
36
|
-
).ordered
|
31
|
+
expect(growl).to receive(:notify)
|
32
|
+
.with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on')
|
33
|
+
.ordered
|
37
34
|
expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password').ordered
|
38
35
|
|
39
36
|
UniformNotifier.growl = { password: '123456' }
|
@@ -45,11 +42,9 @@ RSpec.describe UniformNotifier::Growl do
|
|
45
42
|
expect(Growl).to receive(:new).with('10.10.156.17', 'uniform_notifier').and_return(growl)
|
46
43
|
expect(growl).to receive(:add_notification).with('uniform_notifier')
|
47
44
|
expect(growl).to receive(:password=).with('123456')
|
48
|
-
expect(growl).to receive(:notify)
|
49
|
-
'uniform_notifier',
|
50
|
-
|
51
|
-
'Uniform Notifier Growl has been turned on'
|
52
|
-
).ordered
|
45
|
+
expect(growl).to receive(:notify)
|
46
|
+
.with('uniform_notifier', 'Uniform Notifier', 'Uniform Notifier Growl has been turned on')
|
47
|
+
.ordered
|
53
48
|
expect(growl).to receive(:notify).with('uniform_notifier', 'Uniform Notifier', 'notify growl with password').ordered
|
54
49
|
|
55
50
|
UniformNotifier.growl = { password: '123456', host: '10.10.156.17' }
|
@@ -17,7 +17,7 @@ RSpec.describe UniformNotifier::JavascriptAlert do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should accept custom attributes' do
|
20
|
-
UniformNotifier.alert = { attributes: { nonce
|
20
|
+
UniformNotifier.alert = { attributes: { :nonce => 'my-nonce', 'data-key' => :value } }
|
21
21
|
expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE
|
22
22
|
<script type="text/javascript" nonce="my-nonce" data-key="value">/*<![CDATA[*/
|
23
23
|
alert( "javascript alert!" );
|
@@ -26,7 +26,7 @@ RSpec.describe UniformNotifier::JavascriptConsole do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should accept custom attributes' do
|
29
|
-
UniformNotifier.console = { attributes: { nonce
|
29
|
+
UniformNotifier.console = { attributes: { :nonce => 'my-nonce', 'data-key' => :value } }
|
30
30
|
expect(UniformNotifier::JavascriptConsole.inline_notify(title: 'javascript console!')).to eq <<~CODE
|
31
31
|
<script type="text/javascript" nonce="my-nonce" data-key="value">/*<![CDATA[*/
|
32
32
|
if (typeof(console) !== 'undefined' && console.log) {
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
class
|
5
|
+
class Sentry
|
6
6
|
# mock Sentry
|
7
7
|
end
|
8
8
|
|
@@ -12,14 +12,14 @@ RSpec.describe UniformNotifier::SentryNotifier do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should notify sentry' do
|
15
|
-
expect(
|
15
|
+
expect(Sentry).to receive(:capture_exception).with(UniformNotifier::Exception.new('notify sentry'), {})
|
16
16
|
|
17
17
|
UniformNotifier.sentry = true
|
18
18
|
UniformNotifier::SentryNotifier.out_of_channel_notify(title: 'notify sentry')
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should notify sentry' do
|
22
|
-
expect(
|
22
|
+
expect(Sentry).to receive(:capture_exception).with(UniformNotifier::Exception.new('notify sentry'), foo: :bar)
|
23
23
|
|
24
24
|
UniformNotifier.sentry = { foo: :bar }
|
25
25
|
UniformNotifier::SentryNotifier.out_of_channel_notify('notify sentry')
|
@@ -20,7 +20,6 @@ RSpec.describe UniformNotifier::Slack do
|
|
20
20
|
begin
|
21
21
|
UniformNotifier.slack = {}
|
22
22
|
rescue UniformNotifier::NotificationError
|
23
|
-
|
24
23
|
ensure
|
25
24
|
expect_any_instance_of(Slack::Notifier).to_not receive(:ping)
|
26
25
|
expect(UniformNotifier::Slack.out_of_channel_notify(title: 'notify slack')).to be_nil
|
@@ -35,7 +34,8 @@ RSpec.describe UniformNotifier::Slack do
|
|
35
34
|
end
|
36
35
|
|
37
36
|
it 'should allow username and channel config options' do
|
38
|
-
expect(Slack::Notifier).to receive(:new)
|
37
|
+
expect(Slack::Notifier).to receive(:new)
|
38
|
+
.with('http://some.slack.url', username: 'The Dude', channel: '#carpets')
|
39
39
|
.and_return(true)
|
40
40
|
UniformNotifier.slack = { webhook_url: 'http://some.slack.url', username: 'The Dude', channel: '#carpets' }
|
41
41
|
expect(UniformNotifier::Slack.active?).to eq true
|
@@ -22,7 +22,10 @@ RSpec.describe UniformNotifier::Xmpp do
|
|
22
22
|
expect(xmpp).to receive(:send).with(message)
|
23
23
|
|
24
24
|
UniformNotifier.xmpp = {
|
25
|
-
account: 'from@gmail.com',
|
25
|
+
account: 'from@gmail.com',
|
26
|
+
password: '123456',
|
27
|
+
receiver: 'to@gmail.com',
|
28
|
+
show_online_status: false
|
26
29
|
}
|
27
30
|
UniformNotifier::Xmpp.out_of_channel_notify(title: 'notify xmpp')
|
28
31
|
end
|
@@ -49,7 +52,10 @@ RSpec.describe UniformNotifier::Xmpp do
|
|
49
52
|
expect(xmpp).to receive(:send).with(message)
|
50
53
|
|
51
54
|
UniformNotifier.xmpp = {
|
52
|
-
account: 'from@gmail.com',
|
55
|
+
account: 'from@gmail.com',
|
56
|
+
password: '123456',
|
57
|
+
receiver: 'to@gmail.com',
|
58
|
+
show_online_status: true
|
53
59
|
}
|
54
60
|
UniformNotifier::Xmpp.out_of_channel_notify(title: 'notify xmpp')
|
55
61
|
end
|
data/uniform_notifier.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.required_ruby_version = '>= 2.3'
|
18
18
|
|
19
19
|
s.add_development_dependency 'rspec', ['> 0']
|
20
|
-
s.add_development_dependency 'ruby-growl', ['= 4.0']
|
21
20
|
s.add_development_dependency 'ruby_gntp', ['= 0.3.4']
|
21
|
+
s.add_development_dependency 'ruby-growl', ['= 4.0']
|
22
22
|
s.add_development_dependency 'slack-notifier', ['>= 1.0']
|
23
23
|
s.add_development_dependency 'xmpp4r', ['= 0.5']
|
24
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uniform_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.14.
|
4
|
+
version: 1.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -25,33 +25,33 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: ruby_gntp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.3.4
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.3.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: ruby-growl
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
47
|
+
version: '4.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
54
|
+
version: '4.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: slack-notifier
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|