nine_one_one 2.0.4 → 2.1.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: ba4ec764772f241f23b6377c0fe39a1de964bbfa
4
- data.tar.gz: 2b907c93c2ea597ddd46c2f677e077db4c2d2117
3
+ metadata.gz: e7369af9b16de21e2f270ff4df0b611fcf2e0dc7
4
+ data.tar.gz: 31abafe8fd9f34161d5ea6a2f13af5ec0a667712
5
5
  SHA512:
6
- metadata.gz: 5f89b54ead1e9a4bc6cb7420fdd50d30579a4584d65c4ff410f8e2d0a11c55776accc2f3cadddfb7418687154b5af1fd0e69bad4035b25f17fb603ab954be8b0
7
- data.tar.gz: 82cda078425b07e0526a270c1e8ee1175d2efad7f49caac7bd1f67bf784e50a7ddf8a122bdbd04b91cfdcfd728655d816d2a0707e2f5c6737b1b476548ada6e3
6
+ metadata.gz: ff1db99849019ae185dcf10c82651c41ffaab4cc029744485273a5c9b7645343c544f3dd8116ded309321c9c39d9b1be5f129612990511255f52474a5f51d9bc
7
+ data.tar.gz: '087a879cbfed16b73df5d6864addd4557149ac529af7187bacfe0ab19ca88e421dee51bb28885761a9efa35ca2a1099caa6341ae98d0889c0fb64f0bee70eb72'
@@ -33,6 +33,10 @@ module NineOneOne
33
33
  details_hash: details_hash)
34
34
  end
35
35
 
36
+ def self.resolve_emergency(dedup_key)
37
+ use(:default).resolve_emergency(dedup_key)
38
+ end
39
+
36
40
  def self.notify(message)
37
41
  use(:default).notify(message)
38
42
  end
@@ -8,6 +8,8 @@ module NineOneOne
8
8
  logger.error("TRIGGERED INCIDENT: #{description} (#{details_hash})")
9
9
  end
10
10
 
11
+ def resolve_event(_dedup_key); end
12
+
11
13
  def notify(message)
12
14
  logger.info(message)
13
15
  end
@@ -10,6 +10,10 @@ module NineOneOne
10
10
  details_hash: details_hash)
11
11
  end
12
12
 
13
+ def resolve_emergency(dedup_key)
14
+ emergency_service.resolve_event(dedup_key)
15
+ end
16
+
13
17
  def notify(message)
14
18
  notification_service.notify(message)
15
19
  end
@@ -14,25 +14,33 @@ module NineOneOne
14
14
 
15
15
  def trigger_event(description, source: Socket.gethostname, dedup_key: nil, severity: HIGH_URGENCY_ERROR,
16
16
  details_hash: nil)
17
+ make_request(request_body('trigger', dedup_key, description, source, severity, details_hash))
18
+ end
19
+
20
+ def resolve_event(dedup_key)
21
+ make_request(request_body('resolve', dedup_key))
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :api_integration_key, :http
27
+
28
+ def make_request(request_body)
29
+ headers = {'Content-Type' => 'application/json'}
17
30
  response = nil
18
31
 
19
32
  retry_on(THROTTLE_HTTP_STATUS, THROTTLE_RETRIES) do
20
- body = request_body(description, source, dedup_key, severity, details_hash)
21
- response = make_request(body)
33
+ response = http.post(EVENTS_API_V2_ENDPOINT, request_body, headers)
22
34
  response.code.to_i
23
35
  end
24
36
 
25
37
  # rubocop:disable Style/GuardClause
26
38
  unless response.is_a?(Net::HTTPSuccess)
27
- raise IncidentReportingError, "Failed to create PagerDuty event: #{response.body}"
39
+ raise IncidentReportingError, "Failed to send an event to PagerDuty: #{response.body} #{request_body}"
28
40
  end
29
41
  # rubocop:enable Style/GuardClause
30
42
  end
31
43
 
32
- private
33
-
34
- attr_reader :api_integration_key, :http
35
-
36
44
  def retry_on(value, retries_number)
37
45
  retry_number = 0
38
46
 
@@ -42,16 +50,10 @@ module NineOneOne
42
50
  end
43
51
  end
44
52
 
45
- def make_request(body)
46
- headers = {'Content-Type' => 'application/json'}
47
-
48
- http.post(EVENTS_API_V2_ENDPOINT, body, headers)
49
- end
50
-
51
- def request_body(description, source, dedup_key, severity, details_hash)
52
- body = {
53
+ def request_body(event_action, dedup_key, description = nil, source = nil, severity = nil, details_hash = nil)
54
+ {
53
55
  routing_key: api_integration_key,
54
- event_action: 'trigger',
56
+ event_action: event_action,
55
57
  dedup_key: dedup_key,
56
58
  payload: {
57
59
  summary: description,
@@ -59,9 +61,7 @@ module NineOneOne
59
61
  severity: severity,
60
62
  custom_details: details_hash
61
63
  }.reject { |_, v| v.nil? }
62
- }.reject { |_, v| v.nil? }
63
-
64
- body.to_json
64
+ }.reject { |_, v| v.nil? || v.empty? }.to_json
65
65
  end
66
66
  end
67
67
  end
@@ -1,3 +1,3 @@
1
1
  module NineOneOne
2
- VERSION = '2.0.4'.freeze
2
+ VERSION = '2.1.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: 2.0.4
4
+ version: 2.1.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: 2018-08-08 00:00:00.000000000 Z
12
+ date: 2019-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -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.11
217
+ rubygems_version: 2.6.14.1
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Alerts and notifications via PagerDuty and Slack for Ruby apps