uniform_notifier 1.11.0 → 1.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +1 -1
- data/CHANGELOG.md +17 -1
- data/Gemfile +3 -1
- data/README.md +95 -77
- data/Rakefile +13 -11
- data/lib/uniform_notifier.rb +37 -10
- data/lib/uniform_notifier/airbrake.rb +3 -3
- data/lib/uniform_notifier/base.rb +17 -14
- data/lib/uniform_notifier/bugsnag.rb +4 -7
- data/lib/uniform_notifier/customized_logger.rb +6 -4
- data/lib/uniform_notifier/errors.rb +3 -1
- data/lib/uniform_notifier/growl.rb +20 -21
- data/lib/uniform_notifier/honeybadger.rb +5 -4
- data/lib/uniform_notifier/javascript_alert.rb +7 -3
- data/lib/uniform_notifier/javascript_console.rb +18 -14
- data/lib/uniform_notifier/rails_logger.rb +3 -1
- data/lib/uniform_notifier/raise.rb +4 -2
- data/lib/uniform_notifier/rollbar.rb +8 -1
- data/lib/uniform_notifier/sentry.rb +3 -3
- data/lib/uniform_notifier/slack.rb +20 -22
- data/lib/uniform_notifier/terminal_notifier.rb +24 -0
- data/lib/uniform_notifier/version.rb +3 -1
- data/lib/uniform_notifier/xmpp.rb +25 -24
- data/spec/spec_helper.rb +8 -6
- data/spec/uniform_notifier/airbrake_spec.rb +12 -10
- data/spec/uniform_notifier/base_spec.rb +12 -14
- data/spec/uniform_notifier/bugsnag_spec.rb +33 -19
- data/spec/uniform_notifier/customized_logger_spec.rb +9 -7
- data/spec/uniform_notifier/growl_spec.rb +41 -23
- data/spec/uniform_notifier/honeybadger_spec.rb +12 -10
- data/spec/uniform_notifier/javascript_alert_spec.rb +29 -9
- data/spec/uniform_notifier/javascript_console_spec.rb +55 -17
- data/spec/uniform_notifier/rails_logger_spec.rb +9 -7
- data/spec/uniform_notifier/raise_spec.rb +15 -16
- data/spec/uniform_notifier/rollbar_spec.rb +15 -6
- data/spec/uniform_notifier/sentry_spec.rb +12 -10
- data/spec/uniform_notifier/slack_spec.rb +12 -8
- data/spec/uniform_notifier/terminal_notifier_spec.rb +27 -0
- data/spec/uniform_notifier/xmpp_spec.rb +21 -15
- data/uniform_notifier.gemspec +24 -17
- metadata +30 -25
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class CustomizedLogger < Base
|
3
5
|
@logger = nil
|
@@ -6,7 +8,7 @@ class UniformNotifier
|
|
6
8
|
@logger
|
7
9
|
end
|
8
10
|
|
9
|
-
def self._out_of_channel_notify(
|
11
|
+
def self._out_of_channel_notify(data)
|
10
12
|
message = data.values.compact.join("\n")
|
11
13
|
@logger.warn message
|
12
14
|
end
|
@@ -14,10 +16,10 @@ class UniformNotifier
|
|
14
16
|
def self.setup(logdev)
|
15
17
|
require 'logger'
|
16
18
|
|
17
|
-
@logger = Logger.new(
|
19
|
+
@logger = Logger.new(logdev)
|
18
20
|
|
19
|
-
def @logger.format_message(
|
20
|
-
"#{timestamp.strftime(
|
21
|
+
def @logger.format_message(severity, timestamp, _progname, msg)
|
22
|
+
"#{timestamp.strftime('%Y-%m-%d %H:%M:%S')}[#{severity}] #{msg}"
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class Growl < Base
|
3
5
|
@growl = nil
|
@@ -6,19 +8,21 @@ class UniformNotifier
|
|
6
8
|
@growl
|
7
9
|
end
|
8
10
|
|
9
|
-
def self.setup_connection(
|
11
|
+
def self.setup_connection(growl)
|
10
12
|
setup_connection_growl(growl)
|
11
13
|
rescue LoadError
|
12
14
|
begin
|
13
15
|
setup_connection_gntp(growl)
|
14
16
|
rescue LoadError
|
15
17
|
@growl = nil
|
16
|
-
raise NotificationError
|
18
|
+
raise NotificationError,
|
19
|
+
'You must install the ruby-growl or the ruby_gntp gem to use Growl notification: `gem install ruby-growl` or `gem install ruby_gntp`'
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
|
-
def self.setup_connection_growl(
|
23
|
+
def self.setup_connection_growl(growl)
|
21
24
|
return unless growl
|
25
|
+
|
22
26
|
require 'ruby-growl'
|
23
27
|
if growl.instance_of?(Hash)
|
24
28
|
@password = growl.include?(:password) ? growl[:password] : nil
|
@@ -33,8 +37,9 @@ class UniformNotifier
|
|
33
37
|
notify 'Uniform Notifier Growl has been turned on' if !growl.instance_of?(Hash) || !growl[:quiet]
|
34
38
|
end
|
35
39
|
|
36
|
-
def self.setup_connection_gntp(
|
40
|
+
def self.setup_connection_gntp(growl)
|
37
41
|
return unless growl
|
42
|
+
|
38
43
|
require 'ruby_gntp'
|
39
44
|
if growl.instance_of?(Hash)
|
40
45
|
@password = growl.include?(:password) ? growl[:password] : nil
|
@@ -42,34 +47,28 @@ class UniformNotifier
|
|
42
47
|
end
|
43
48
|
@password ||= nil
|
44
49
|
@host ||= 'localhost'
|
45
|
-
@growl = GNTP.new('uniform_notifier', @host, @password,
|
46
|
-
@growl.register({:
|
47
|
-
:name => 'uniform_notifier',
|
48
|
-
:enabled => true,
|
49
|
-
}]})
|
50
|
+
@growl = GNTP.new('uniform_notifier', @host, @password, 23_053)
|
51
|
+
@growl.register(notifications: [{ name: 'uniform_notifier', enabled: true }])
|
50
52
|
|
51
53
|
notify 'Uniform Notifier Growl has been turned on (using GNTP)' if !growl.instance_of?(Hash) || !growl[:quiet]
|
52
54
|
end
|
53
55
|
|
54
56
|
protected
|
55
57
|
|
56
|
-
def self._out_of_channel_notify(
|
58
|
+
def self._out_of_channel_notify(data)
|
57
59
|
message = data.values.compact.join("\n")
|
58
60
|
|
59
|
-
notify(
|
61
|
+
notify(message)
|
60
62
|
end
|
61
63
|
|
62
64
|
private
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
:title => 'Uniform Notifier',
|
70
|
-
:text => message
|
71
|
-
})
|
72
|
-
end
|
65
|
+
|
66
|
+
def self.notify(message)
|
67
|
+
if defined?(::Growl) && @growl.is_a?(::Growl)
|
68
|
+
@growl.notify('uniform_notifier', 'Uniform Notifier', message)
|
69
|
+
elsif defined?(::GNTP) && @growl.is_a?(::GNTP)
|
70
|
+
@growl.notify(name: 'uniform_notifier', title: 'Uniform Notifier', text: message)
|
73
71
|
end
|
72
|
+
end
|
74
73
|
end
|
75
74
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class HoneybadgerNotifier < Base
|
3
5
|
def self.active?
|
@@ -10,12 +12,11 @@ class UniformNotifier
|
|
10
12
|
message = data.values.compact.join("\n")
|
11
13
|
|
12
14
|
opt = {}
|
13
|
-
if UniformNotifier.honeybadger.is_a?(Hash)
|
14
|
-
opt = UniformNotifier.honeybadger
|
15
|
-
end
|
15
|
+
opt = UniformNotifier.honeybadger if UniformNotifier.honeybadger.is_a?(Hash)
|
16
16
|
|
17
17
|
exception = Exception.new(message)
|
18
|
-
|
18
|
+
honeybadger_class = opt[:honeybadger_class] || Honeybadger
|
19
|
+
honeybadger_class.notify(exception, opt)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
@@ -1,15 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class JavascriptAlert < Base
|
3
5
|
def self.active?
|
4
|
-
UniformNotifier.alert
|
6
|
+
!!UniformNotifier.alert
|
5
7
|
end
|
6
8
|
|
7
9
|
protected
|
8
10
|
|
9
|
-
def self._inline_notify(
|
11
|
+
def self._inline_notify(data)
|
10
12
|
message = data.values.compact.join("\n")
|
13
|
+
options = UniformNotifier.alert.is_a?(Hash) ? UniformNotifier.alert : {}
|
14
|
+
script_attributes = options[:attributes] || {}
|
11
15
|
|
12
|
-
wrap_js_association "alert( #{message.inspect} );"
|
16
|
+
wrap_js_association "alert( #{message.inspect} );", script_attributes
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -1,27 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class JavascriptConsole < Base
|
3
5
|
def self.active?
|
4
|
-
UniformNotifier.console
|
6
|
+
!!UniformNotifier.console
|
5
7
|
end
|
6
8
|
|
7
9
|
protected
|
8
10
|
|
9
|
-
def self._inline_notify(
|
11
|
+
def self._inline_notify(data)
|
10
12
|
message = data.values.compact.join("\n")
|
13
|
+
options = UniformNotifier.console.is_a?(Hash) ? UniformNotifier.console : {}
|
14
|
+
script_attributes = options[:attributes] || {}
|
11
15
|
|
12
|
-
code =
|
13
|
-
if (typeof(console) !== 'undefined' && console.log) {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
CODE
|
16
|
+
code = <<~CODE
|
17
|
+
if (typeof(console) !== 'undefined' && console.log) {
|
18
|
+
if (console.groupCollapsed && console.groupEnd) {
|
19
|
+
console.groupCollapsed(#{'Uniform Notifier'.inspect});
|
20
|
+
console.log(#{message.inspect});
|
21
|
+
console.groupEnd();
|
22
|
+
} else {
|
23
|
+
console.log(#{message.inspect});
|
24
|
+
}
|
25
|
+
}
|
26
|
+
CODE
|
23
27
|
|
24
|
-
wrap_js_association code
|
28
|
+
wrap_js_association code, script_attributes
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class RailsLogger < Base
|
3
5
|
def self.active?
|
@@ -6,7 +8,7 @@ class UniformNotifier
|
|
6
8
|
|
7
9
|
protected
|
8
10
|
|
9
|
-
def self._out_of_channel_notify(
|
11
|
+
def self._out_of_channel_notify(data)
|
10
12
|
message = data.values.compact.join("\n")
|
11
13
|
|
12
14
|
Rails.logger.warn message
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class Raise < Base
|
3
5
|
def self.active?
|
4
|
-
@exception_class
|
6
|
+
defined?(@exception_class) ? @exception_class : false
|
5
7
|
end
|
6
8
|
|
7
9
|
def self.setup_connection(exception_class)
|
@@ -10,7 +12,7 @@ class UniformNotifier
|
|
10
12
|
|
11
13
|
protected
|
12
14
|
|
13
|
-
def self._out_of_channel_notify(
|
15
|
+
def self._out_of_channel_notify(data)
|
14
16
|
message = data.values.compact.join("\n")
|
15
17
|
|
16
18
|
raise @exception_class, message
|
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class RollbarNotifier < Base
|
5
|
+
DEFAULT_LEVEL = 'info'
|
6
|
+
|
3
7
|
def self.active?
|
4
8
|
!!UniformNotifier.rollbar
|
5
9
|
end
|
@@ -10,7 +14,10 @@ class UniformNotifier
|
|
10
14
|
message = data.values.compact.join("\n")
|
11
15
|
|
12
16
|
exception = Exception.new(message)
|
13
|
-
|
17
|
+
level = UniformNotifier.rollbar.fetch(:level, DEFAULT_LEVEL) if UniformNotifier.rollbar.is_a?(Hash)
|
18
|
+
level ||= DEFAULT_LEVEL
|
19
|
+
|
20
|
+
Rollbar.log(level, exception)
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class SentryNotifier < Base
|
3
5
|
def self.active?
|
@@ -10,9 +12,7 @@ class UniformNotifier
|
|
10
12
|
message = data.values.compact.join("\n")
|
11
13
|
|
12
14
|
opt = {}
|
13
|
-
if UniformNotifier.sentry.is_a?(Hash)
|
14
|
-
opt = UniformNotifier.sentry
|
15
|
-
end
|
15
|
+
opt = UniformNotifier.sentry if UniformNotifier.sentry.is_a?(Hash)
|
16
16
|
|
17
17
|
exception = Exception.new(message)
|
18
18
|
Raven.capture_exception(exception, opt)
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class Slack < Base
|
3
|
-
POSSIBLE_OPTIONS = [
|
5
|
+
POSSIBLE_OPTIONS = %i[username channel].freeze
|
4
6
|
|
5
7
|
@slack = nil
|
6
8
|
|
@@ -9,43 +11,39 @@ class UniformNotifier
|
|
9
11
|
@slack
|
10
12
|
end
|
11
13
|
|
12
|
-
def setup_connection(config={})
|
14
|
+
def setup_connection(config = {})
|
13
15
|
webhook_url, options = parse_config(config)
|
14
16
|
fail_connection('webhook_url required for Slack notification') unless webhook_url
|
15
17
|
|
16
18
|
require 'slack-notifier'
|
17
19
|
@slack = ::Slack::Notifier.new webhook_url, options
|
18
20
|
rescue LoadError
|
19
|
-
fail_connection 'You must install the slack-notifier gem to use Slack notification: '
|
20
|
-
'`gem install slack-notifier`'
|
21
|
+
fail_connection 'You must install the slack-notifier gem to use Slack notification: `gem install slack-notifier`'
|
21
22
|
end
|
22
23
|
|
23
24
|
protected
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def _out_of_channel_notify(data)
|
27
|
+
message = data.values.compact.join("\n")
|
28
|
+
notify(message)
|
29
|
+
end
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def notify(message)
|
38
|
-
@slack.ping message
|
39
|
-
end
|
33
|
+
def fail_connection(message)
|
34
|
+
@slack = nil
|
35
|
+
raise NotificationError, message
|
36
|
+
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
38
|
+
def notify(message)
|
39
|
+
@slack.ping message
|
40
|
+
end
|
45
41
|
|
46
|
-
|
47
|
-
|
42
|
+
def parse_config(config)
|
43
|
+
options = config.select { |name, value| POSSIBLE_OPTIONS.include?(name) && !value.nil? }
|
48
44
|
|
45
|
+
[config[:webhook_url], options]
|
46
|
+
end
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UniformNotifier
|
4
|
+
class TerminalNotifier < Base
|
5
|
+
def self.active?
|
6
|
+
!!UniformNotifier.terminal_notifier
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def self._out_of_channel_notify(data)
|
12
|
+
unless defined?(::TerminalNotifier)
|
13
|
+
begin
|
14
|
+
require 'terminal-notifier'
|
15
|
+
rescue LoadError
|
16
|
+
raise NotificationError,
|
17
|
+
'You must install the terminal-notifier gem to use terminal_notifier: `gem install terminal-notifier`'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
::TerminalNotifier.notify(data[:body], title: data[:title])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UniformNotifier
|
2
4
|
class Xmpp < Base
|
3
5
|
@receiver = nil
|
@@ -8,7 +10,7 @@ class UniformNotifier
|
|
8
10
|
@xmpp
|
9
11
|
end
|
10
12
|
|
11
|
-
def self.setup_connection(
|
13
|
+
def self.setup_connection(xmpp_information)
|
12
14
|
return unless xmpp_information
|
13
15
|
|
14
16
|
require 'xmpp4r'
|
@@ -16,43 +18,42 @@ class UniformNotifier
|
|
16
18
|
@xmpp = xmpp_information
|
17
19
|
@receiver = xmpp_information[:receiver]
|
18
20
|
@password = xmpp_information[:password]
|
19
|
-
@account
|
21
|
+
@account = xmpp_information[:account]
|
20
22
|
@show_online_status = xmpp_information[:show_online_status]
|
21
23
|
@stay_connected = xmpp_information[:stay_connected].nil? ? true : xmpp_information[:stay_connected]
|
22
24
|
|
23
25
|
connect if @stay_connected
|
24
26
|
rescue LoadError
|
25
27
|
@xmpp = nil
|
26
|
-
raise NotificationError
|
28
|
+
raise NotificationError, 'You must install the xmpp4r gem to use XMPP notification: `gem install xmpp4r`'
|
27
29
|
end
|
28
30
|
|
29
31
|
protected
|
30
32
|
|
31
|
-
def self._out_of_channel_notify(
|
33
|
+
def self._out_of_channel_notify(data)
|
32
34
|
message = data.values.compact.join("\n")
|
33
35
|
|
34
|
-
notify(
|
36
|
+
notify(message)
|
35
37
|
end
|
36
38
|
|
37
39
|
private
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
40
|
+
|
41
|
+
def self.connect
|
42
|
+
jid = Jabber::JID.new(@account)
|
43
|
+
@xmpp = Jabber::Client.new(jid)
|
44
|
+
@xmpp.connect
|
45
|
+
@xmpp.auth(@password)
|
46
|
+
@xmpp.send(presence_status) if @show_online_status
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.notify(message)
|
50
|
+
connect unless @stay_connected
|
51
|
+
message = Jabber::Message.new(@receiver, message).set_type(:normal).set_subject('Uniform Notifier')
|
52
|
+
@xmpp.send(message)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.presence_status
|
56
|
+
Jabber::Presence.new.set_status("Uniform Notifier started on #{Time.now}")
|
57
|
+
end
|
57
58
|
end
|
58
59
|
end
|