nine_one_one 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 776f59439067b38ac22ab874e2353f77a7022a56
4
- data.tar.gz: 9bf0a5b2a23a317d6fffe9f43da635be80b90238
3
+ metadata.gz: f932d2b4548af5aa6190e8e64e384616d426353c
4
+ data.tar.gz: 393635fc1515b29de54cab5fb373bd2d67d2e1ab
5
5
  SHA512:
6
- metadata.gz: 30af137d4bdd8fb9cc9b34d2273e8f2a30933db66ec47ef75951d20cd95dea9d2b374fc8565653271a25f9f221e2b6bdaefb5b7203907ae1660e3d90e709826a
7
- data.tar.gz: 9b2690b1b38ac8a95ba9b9d9909bfdbc882fc27fae1c1fc5d923110ebee523f9b5cd7cb68f3c0cee835c53bc5e998803b32d6c10a9e2d6070b9915dc7e4863ae
6
+ metadata.gz: 629f7e378c4d8ff5835c61ed60a791bed5d92bedec8688a40f44fafd2d25125cf14d27679aa4b934b3e01eabaabe8f51d6e7b7280f17ac0618fcba166b9e3d61
7
+ data.tar.gz: 242511982a2132d84a400fdd4306344588ef770b48923dc24cb0834367a83f2397cac924d60bf85c90d8ed7dd6ae9bfadbbc5a212555509d195d453b79c3a183
data/README.md CHANGED
@@ -28,7 +28,7 @@ Or install it yourself as:
28
28
 
29
29
  ## Configuration
30
30
 
31
- By default NineOneOne loggs notifications and emegencies to STDOUT. You can override default settings with:
31
+ By default NineOneOne logs notifications and emergencies to STDOUT. You can override default settings with:
32
32
 
33
33
  ```ruby
34
34
  NineOneOne.configure do |config|
@@ -50,6 +50,18 @@ NineOneOne.configure do |config|
50
50
  # Defaults to Logger.new(STDOUT)
51
51
  config.logger = Logger.new('incidents.log')
52
52
  end
53
+
54
+ # optional custom configurations
55
+
56
+ NineOneOne.configure(:my_custom_configuration) do |config|
57
+ config.send_pagers = false
58
+
59
+ config.slack_enabled = true
60
+ config.slack_webhook_url = 'https://hooks.slack.com/services/XXX/YYY/ZZZ'
61
+
62
+ config.slack_username = 'NineOneOne'
63
+ config.slack_channel = '#my-notifications'
64
+ end
53
65
  ```
54
66
 
55
67
  ## Usage
@@ -60,6 +72,10 @@ NineOneOne.notify('Something happened!')
60
72
 
61
73
  # Send pager or log emergency using logger depending on the `send_pagers` config parameter
62
74
  NineOneOne.emergency('INCIDENT_KEY', 'Emergency message!', { optional_hash: 'with details' })
75
+
76
+ # same for custom configurations
77
+ NineOneOne.use(:my_custom_configuration).notify('Something happened!')
78
+ NineOneOne.use(:my_custom_configuration).emergency('INCIDENT_KEY', 'Emergency message!', { optional_hash: 'with details' })
63
79
  ```
64
80
 
65
81
  ## Development
data/lib/nine_one_one.rb CHANGED
@@ -2,47 +2,44 @@ require_relative './nine_one_one/errors'
2
2
  require_relative './nine_one_one/http'
3
3
  require_relative './nine_one_one/version'
4
4
  require_relative './nine_one_one/configuration'
5
+ require_relative './nine_one_one/notifier'
5
6
  require_relative './nine_one_one/log_service'
6
7
  require_relative './nine_one_one/slack_service'
7
8
  require_relative './nine_one_one/pager_duty_service'
8
9
 
9
10
  module NineOneOne
10
- def self.emergency_service
11
- if config.send_pagers
12
- PagerDutyService.new(config.pager_duty_integration_key)
13
- else
14
- LogService.new(config.logger)
15
- end
16
- end
17
-
18
- def self.notification_service
19
- if config.slack_enabled
20
- SlackService.new(config.slack_webhook_url, username: config.slack_username,
21
- channel: config.slack_channel)
22
- else
23
- LogService.new(config.logger)
24
- end
25
- end
26
-
27
- def self.configure
11
+ def self.configure(type = :default)
28
12
  config = Configuration.new
29
13
 
30
14
  yield config
31
15
 
32
16
  config.validate
33
17
 
34
- @config = config
18
+ configs[type] = config
19
+ end
20
+
21
+ def self.use(type = :default)
22
+ config = configs.fetch(type) { raise NotConfiguredError, "Configuration type=#{type} is not configured." }
23
+ Notifier.new(config)
35
24
  end
36
25
 
37
- def self.config
38
- @config ||= Configuration.new
26
+ def self.configs
27
+ @configs ||= {}
39
28
  end
40
29
 
41
30
  def self.emergency(incident_key, description, details_hash = nil)
42
- emergency_service.trigger_event(incident_key, description, details_hash)
31
+ use(:default).emergency(incident_key, description, details_hash)
43
32
  end
44
33
 
45
34
  def self.notify(message)
46
- notification_service.notify(message)
35
+ use(:default).notify(message)
36
+ end
37
+
38
+ def self.notification_service
39
+ use(:default).notification_service
40
+ end
41
+
42
+ def self.emergency_service
43
+ use(:default).emergency_service
47
44
  end
48
45
  end
@@ -1,6 +1,7 @@
1
1
  module NineOneOne
2
2
  class Error < RuntimeError; end
3
3
 
4
+ class NotConfiguredError < Error; end
4
5
  class ConfigurationError < Error; end
5
6
  class IncidentReportingError < Error; end
6
7
  class NotificationError < Error; end
@@ -0,0 +1,36 @@
1
+ module NineOneOne
2
+ class Notifier
3
+ def initialize(config)
4
+ @config = config
5
+ end
6
+
7
+ def emergency(incident_key, description, details_hash = nil)
8
+ emergency_service.trigger_event(incident_key, description, details_hash)
9
+ end
10
+
11
+ def notify(message)
12
+ notification_service.notify(message)
13
+ end
14
+
15
+ def emergency_service
16
+ if config.send_pagers
17
+ PagerDutyService.new(config.pager_duty_integration_key)
18
+ else
19
+ LogService.new(config.logger)
20
+ end
21
+ end
22
+
23
+ def notification_service
24
+ if config.slack_enabled
25
+ SlackService.new(config.slack_webhook_url, username: config.slack_username,
26
+ channel: config.slack_channel)
27
+ else
28
+ LogService.new(config.logger)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :config
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module NineOneOne
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nine_one_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kacper Madej
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-03-13 00:00:00.000000000 Z
12
+ date: 2018-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -188,6 +188,7 @@ files:
188
188
  - lib/nine_one_one/errors.rb
189
189
  - lib/nine_one_one/http.rb
190
190
  - lib/nine_one_one/log_service.rb
191
+ - lib/nine_one_one/notifier.rb
191
192
  - lib/nine_one_one/pager_duty_service.rb
192
193
  - lib/nine_one_one/slack_service.rb
193
194
  - lib/nine_one_one/version.rb
@@ -212,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
213
  version: '0'
213
214
  requirements: []
214
215
  rubyforge_project:
215
- rubygems_version: 2.5.1
216
+ rubygems_version: 2.6.13
216
217
  signing_key:
217
218
  specification_version: 4
218
219
  summary: Alerts and notifications via PagerDuty and Slack for Ruby apps