nine_one_one 1.0.0 → 2.0.1

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
- SHA1:
3
- metadata.gz: 78b082ffa0e24bc561db44377acf1355736dc129
4
- data.tar.gz: f5fef5647e90a970b7a1eaf6affd592e3733a26d
2
+ SHA256:
3
+ metadata.gz: 776940734a50ef162b69ae5fea1cf1bd0ae55c4a5362b3b2d4f683d5e69b716b
4
+ data.tar.gz: 4a92b63797a071cee321c0b498a6014e92b113743aa168a76101a4a96a269342
5
5
  SHA512:
6
- metadata.gz: 88ba14725f3a147bddd56a90134d878a189d25704d60afa2d1ce5dc0868c809a27f105c053dcd0a93088f841cc5060a02bd262b8604af6bd0b29506e2d2b9041
7
- data.tar.gz: ca7fed9b2ea62f3d16926e25742961d10108bb453ed9160281e73660b554a67dfc4977ddcacd367a087800dfe6b044c1978a832e4646fca6f7fe205369899173
6
+ metadata.gz: a14333562ab2149b86e28472eaf8674966cb0a7be6497bea159be2dfe6280b759a6fc4a948e8da968b99d5b620aa52df66024ad62ee6ee96fc0ee928ccf6a91e
7
+ data.tar.gz: 1baca0838a7c34b75b7155759cd262c94aac0dcc7c610a6279a70950217509c0262e2ee6b38df2240e2bd92309582ce3e133f7340c93a46a444805f651612181
data/.rubocop.yml CHANGED
@@ -7,7 +7,7 @@ AllCops:
7
7
  - bin/**/*
8
8
  - db/**/*
9
9
  - vendor/**/*
10
- TargetRubyVersion: 2.1
10
+ TargetRubyVersion: 2.2
11
11
 
12
12
  Style/MultilineOperationIndentation:
13
13
  EnforcedStyle: indented
data/.travis.yml CHANGED
@@ -2,7 +2,6 @@ language: ruby
2
2
  cache: bundler
3
3
  before_install: gem update --remote bundler
4
4
  rvm:
5
- - 2.1.5
6
5
  - 2.2.5
7
6
  - 2.3.1
8
7
  script: "bundle exec rake spec"
data/README.md CHANGED
@@ -77,11 +77,14 @@ NineOneOne.notify('Something happened!')
77
77
  NineOneOne.notify({attachments: [{title: 'Something happened!', text: 'More info'}]})
78
78
 
79
79
  # Send pager or log emergency using logger depending on the `send_pagers` config parameter
80
- NineOneOne.emergency('Emergency message!', 'Error source info', { optional_hash: 'with details' })
80
+ NineOneOne.emergency('Emergency message!', 'Error source info', details_hash: { optional_hash: 'with details' })
81
+
82
+ # Send multiple pagers that will be grouped into one incident
83
+ NineOneOne.emergency('Emergency message!', 'Error source info', dedup_key: 'Kinda unique key')
81
84
 
82
85
  # same for custom configurations
83
86
  NineOneOne.use(:my_custom_configuration).notify('Something happened!')
84
- NineOneOne.use(:my_custom_configuration).emergency('INCIDENT_KEY', 'Emergency message!', { optional_hash: 'with details' })
87
+ NineOneOne.use(:my_custom_configuration).emergency('Emergency message!', 'Error source info', details_hash: { optional_hash: 'with details' })
85
88
  ```
86
89
 
87
90
  ## Development
@@ -90,6 +93,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
90
93
 
91
94
  # Changelog
92
95
 
96
+ 2.0.0 Change the interface to have default parameters. Introduce dedup_key. It's backwards incompatible again.
97
+
93
98
  1.0.0 Migrate to Pager Duty Events API V2 (backwards incompatible!) and add support for slack hash message.
94
99
 
95
100
  0.3.0 Allow to have multiple configurations for notifications
data/lib/nine_one_one.rb CHANGED
@@ -27,8 +27,11 @@ module NineOneOne
27
27
  @configs ||= {}
28
28
  end
29
29
 
30
- def self.emergency(description, source, details_hash = nil, severity = PagerDutyService::HIGH_URGENCY_ERROR)
31
- use(:default).emergency(description, source, details_hash, severity)
30
+ def self.emergency(description, source: Socket.gethostname, dedup_key: nil,
31
+ severity: PagerDutyService::HIGH_URGENCY_ERROR, details_hash: nil)
32
+ use(:default).emergency(description, source: source, dedup_key: dedup_key, severity: severity,
33
+ details_hash: details_hash)
34
+
32
35
  end
33
36
 
34
37
  def self.notify(message)
@@ -4,8 +4,10 @@ module NineOneOne
4
4
  @config = config
5
5
  end
6
6
 
7
- def emergency(description, source, details_hash, severity)
8
- emergency_service.trigger_event(description, source, details_hash, severity)
7
+ def emergency(description, source, dedup_key: nil, severity: PagerDutyService::HIGH_URGENCY_ERROR,
8
+ details_hash: nil)
9
+ emergency_service.trigger_event(description, source, dedup_key: dedup_key, severity: severity,
10
+ details_hash: details_hash)
9
11
  end
10
12
 
11
13
  def notify(message)
@@ -23,7 +25,7 @@ module NineOneOne
23
25
  def notification_service
24
26
  if config.slack_enabled
25
27
  SlackService.new(config.slack_webhook_url, username: config.slack_username,
26
- channel: config.slack_channel)
28
+ channel: config.slack_channel)
27
29
  else
28
30
  LogService.new(config.logger)
29
31
  end
@@ -5,17 +5,19 @@ module NineOneOne
5
5
  THROTTLE_HTTP_STATUS = 403
6
6
  THROTTLE_RETRIES = 2
7
7
  HIGH_URGENCY_ERROR = 'error'.freeze
8
+ LOW_URGENCY_ERROR = 'warning'.freeze
8
9
 
9
10
  def initialize(api_integration_key)
10
11
  @api_integration_key = api_integration_key
11
12
  @http = Http.new(BASE_HOST)
12
13
  end
13
14
 
14
- def trigger_event(description, source, details_hash, severity)
15
+ def trigger_event(description, source: Socket.gethostname, dedup_key: nil, severity: HIGH_URGENCY_ERROR,
16
+ details_hash: nil)
15
17
  response = nil
16
18
 
17
19
  retry_on(THROTTLE_HTTP_STATUS, THROTTLE_RETRIES) do
18
- body = request_body(description, severity, source, details_hash)
20
+ body = request_body(description, source, dedup_key, severity, details_hash)
19
21
  response = make_request(body)
20
22
  response.code.to_i
21
23
  end
@@ -46,17 +48,18 @@ module NineOneOne
46
48
  http.post(EVENTS_API_V2_ENDPOINT, body, headers)
47
49
  end
48
50
 
49
- def request_body(description, severity, source, details_hash)
51
+ def request_body(description, source, dedup_key, severity, details_hash)
50
52
  body = {
51
53
  routing_key: api_integration_key,
52
54
  event_action: 'trigger',
55
+ dedup_key: dedup_key,
53
56
  payload: {
54
57
  summary: description,
55
- severity: severity,
56
58
  source: source,
59
+ severity: severity,
57
60
  custom_details: details_hash
58
- }
59
- }
61
+ }.reject { |_, v| v.nil? }
62
+ }.reject { |_, v| v.nil? }
60
63
 
61
64
  body.to_json
62
65
  end
@@ -3,15 +3,15 @@ module NineOneOne
3
3
  def initialize(webhook_url, opts = {})
4
4
  uri = URI(webhook_url)
5
5
 
6
- @channel = opts[:channel]
7
- @http = opts[:http] || Http.new(uri.host, uri.scheme)
8
- @path = uri.path
6
+ @channel = opts[:channel]
7
+ @http = opts[:http] || Http.new(uri.host, uri.scheme)
8
+ @path = uri.path
9
9
  @username = opts[:username]
10
10
  end
11
11
 
12
12
  def notify(message)
13
13
  body = request_body(message)
14
- headers = { 'Content-Type' => 'application/json' }
14
+ headers = {'Content-Type' => 'application/json'}
15
15
  http.post(path, body, headers)
16
16
  end
17
17
 
@@ -20,8 +20,8 @@ module NineOneOne
20
20
  attr_reader :channel, :http, :path, :username
21
21
 
22
22
  def request_body(message)
23
- body = message.is_a?(Hash) ? message : { text: message }
24
- body[:channel] = channel unless channel.nil?
23
+ body = message.is_a?(Hash) ? message : {text: message}
24
+ body[:channel] = channel unless channel.nil?
25
25
  body[:username] = username unless username.nil?
26
26
 
27
27
  body.to_json
@@ -1,3 +1,3 @@
1
1
  module NineOneOne
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '2.0.1'.freeze
3
3
  end
data/nine_one_one.gemspec CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
- spec.required_ruby_version = '>= 2.1'
23
- spec.post_install_message = 'From Ver 1.0.0 emergency method call is not backwards compatible!'
22
+ spec.required_ruby_version = '>= 2.2'
23
+ spec.post_install_message = 'From Ver 2.0.0 emergency method call is not backwards compatible!'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.13'
26
26
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
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: 1.0.0
4
+ version: 2.0.1
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: 2018-03-09 00:00:00.000000000 Z
12
+ date: 2018-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -198,7 +198,7 @@ homepage: https://github.com/u2i/nine_one_one
198
198
  licenses:
199
199
  - MIT
200
200
  metadata: {}
201
- post_install_message: From Ver 1.0.0 emergency method call is not backwards compatible!
201
+ post_install_message: From Ver 2.0.0 emergency method call is not backwards compatible!
202
202
  rdoc_options: []
203
203
  require_paths:
204
204
  - lib
@@ -206,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
206
  requirements:
207
207
  - - ">="
208
208
  - !ruby/object:Gem::Version
209
- version: '2.1'
209
+ version: '2.2'
210
210
  required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  requirements:
212
212
  - - ">="
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  version: '0'
215
215
  requirements: []
216
216
  rubyforge_project:
217
- rubygems_version: 2.6.13
217
+ rubygems_version: 2.7.6
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Alerts and notifications via PagerDuty and Slack for Ruby apps