nine_one_one 0.3.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -3
- data/.rubocop_todo.yml +31 -0
- data/Guardfile +3 -3
- data/README.md +17 -1
- data/Rakefile +2 -2
- data/lib/nine_one_one/configuration.rb +1 -3
- data/lib/nine_one_one/log_service.rb +2 -2
- data/lib/nine_one_one/notifier.rb +2 -2
- data/lib/nine_one_one/pager_duty_service.rb +17 -14
- data/lib/nine_one_one/slack_service.rb +2 -7
- data/lib/nine_one_one/version.rb +1 -1
- data/lib/nine_one_one.rb +2 -2
- data/nine_one_one.gemspec +6 -5
- metadata +27 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78b082ffa0e24bc561db44377acf1355736dc129
|
4
|
+
data.tar.gz: f5fef5647e90a970b7a1eaf6affd592e3733a26d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88ba14725f3a147bddd56a90134d878a189d25704d60afa2d1ce5dc0868c809a27f105c053dcd0a93088f841cc5060a02bd262b8604af6bd0b29506e2d2b9041
|
7
|
+
data.tar.gz: ca7fed9b2ea62f3d16926e25742961d10108bb453ed9160281e73660b554a67dfc4977ddcacd367a087800dfe6b044c1978a832e4646fca6f7fe205369899173
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
1
3
|
AllCops:
|
2
4
|
Include:
|
3
5
|
- '**/Rakefile'
|
@@ -16,9 +18,6 @@ Style/Documentation:
|
|
16
18
|
Style/FormatString:
|
17
19
|
Enabled: false
|
18
20
|
|
19
|
-
Style/WhileUntilModifier:
|
20
|
-
MaxLineLength: 120
|
21
|
-
|
22
21
|
Metrics/LineLength:
|
23
22
|
Max: 120
|
24
23
|
Enabled: true
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-03-08 01:39:54 +0100 using RuboCop version 0.47.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: CountComments.
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Max: 11
|
13
|
+
|
14
|
+
# Offense count: 3
|
15
|
+
# Cop supports --auto-correct.
|
16
|
+
# Configuration parameters: PreferredDelimiters.
|
17
|
+
Style/PercentLiteralDelimiters:
|
18
|
+
Exclude:
|
19
|
+
- 'Rakefile'
|
20
|
+
- 'spec/spec_helper.rb'
|
21
|
+
|
22
|
+
# Offense count: 8
|
23
|
+
# Cop supports --auto-correct.
|
24
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces.
|
25
|
+
# SupportedStyles: space, no_space, compact
|
26
|
+
# SupportedStylesForEmptyBraces: space, no_space
|
27
|
+
Style/SpaceInsideHashLiteralBraces:
|
28
|
+
Exclude:
|
29
|
+
- 'lib/nine_one_one/pager_duty_service.rb'
|
30
|
+
- 'spec/nine_one_one/pager_duty_service_spec.rb'
|
31
|
+
- 'spec/nine_one_one/slack_service_spec.rb'
|
data/Guardfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
guard :rspec, cmd:
|
2
|
-
require
|
1
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
2
|
+
require 'guard/rspec/dsl'
|
3
3
|
dsl = Guard::RSpec::Dsl.new(self)
|
4
4
|
|
5
5
|
# Feel free to open issues for suggestions and improvements
|
@@ -16,6 +16,6 @@ guard :rspec, cmd: "bundle exec rspec" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
guard :rubocop do
|
19
|
-
watch(
|
19
|
+
watch(/.+\.rb$/)
|
20
20
|
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
21
21
|
end
|
data/README.md
CHANGED
@@ -10,6 +10,10 @@ Count](https://codeclimate.com/repos/58207e5ee72dfa227600001d/badges/ecd3be37c49
|
|
10
10
|
|
11
11
|
Common notification logic for PagerDuty/Slack notifications.
|
12
12
|
|
13
|
+
Please note that starting with version 1.0.0 this gem uses Pager Duty events api V2, which breaks backwards compatibility.
|
14
|
+
If you don't want to change your existing API V1 calls made via this game please stick to 0.X.0 version. If you migrate
|
15
|
+
though, please make sure all the trigger_event function calls in your app got updated and meet the new param requirements.
|
16
|
+
|
13
17
|
## Installation
|
14
18
|
|
15
19
|
Add this line to your application's Gemfile:
|
@@ -69,9 +73,11 @@ end
|
|
69
73
|
```ruby
|
70
74
|
# Send message to Slack channel or log it using logger depending on the `slack_enabled` config parameter
|
71
75
|
NineOneOne.notify('Something happened!')
|
76
|
+
# You can also send a hash message (compatible with the slack message spec: https://api.slack.com/docs/messages/builder)
|
77
|
+
NineOneOne.notify({attachments: [{title: 'Something happened!', text: 'More info'}]})
|
72
78
|
|
73
79
|
# Send pager or log emergency using logger depending on the `send_pagers` config parameter
|
74
|
-
NineOneOne.emergency('
|
80
|
+
NineOneOne.emergency('Emergency message!', 'Error source info', { optional_hash: 'with details' })
|
75
81
|
|
76
82
|
# same for custom configurations
|
77
83
|
NineOneOne.use(:my_custom_configuration).notify('Something happened!')
|
@@ -82,6 +88,16 @@ NineOneOne.use(:my_custom_configuration).emergency('INCIDENT_KEY', 'Emergency me
|
|
82
88
|
|
83
89
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
90
|
|
91
|
+
# Changelog
|
92
|
+
|
93
|
+
1.0.0 Migrate to Pager Duty Events API V2 (backwards incompatible!) and add support for slack hash message.
|
94
|
+
|
95
|
+
0.3.0 Allow to have multiple configurations for notifications
|
96
|
+
|
97
|
+
0.2.0 Add the ability to customize slack username and channel
|
98
|
+
|
99
|
+
0.1.0 Initial version of the gem implementing Slack and Pager Duty services
|
100
|
+
|
85
101
|
## Contributing
|
86
102
|
|
87
103
|
Bug reports and pull requests are welcome on GitHub at https://github.com/u2i/nine_one_one.
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rubocop/rake_task'
|
|
5
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
6
|
|
7
7
|
RuboCop::RakeTask.new do |task|
|
8
|
-
task.options = %w
|
8
|
+
task.options = %w[--display-cop-names --format simple]
|
9
9
|
end
|
10
10
|
|
11
|
-
task default: [
|
11
|
+
task default: %i[spec rubocop]
|
@@ -23,9 +23,7 @@ module NineOneOne
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def validate_send_pagers
|
26
|
-
unless [true, false].include?(send_pagers)
|
27
|
-
raise ConfigurationError, "Illegal 'send_pagers' value: #{send_pagers}"
|
28
|
-
end
|
26
|
+
raise ConfigurationError, "Illegal 'send_pagers' value: #{send_pagers}" unless [true, false].include?(send_pagers)
|
29
27
|
|
30
28
|
raise ConfigurationError, "'send_pagers' is false but no logger given" if !send_pagers && logger.nil?
|
31
29
|
end
|
@@ -4,8 +4,8 @@ module NineOneOne
|
|
4
4
|
@logger = logger
|
5
5
|
end
|
6
6
|
|
7
|
-
def trigger_event(
|
8
|
-
logger.error "TRIGGERED INCIDENT #{
|
7
|
+
def trigger_event(description, source, details_hash, severity)
|
8
|
+
logger.error "TRIGGERED INCIDENT (#{severity}): #{description} | #{details_hash} | #{source}"
|
9
9
|
end
|
10
10
|
|
11
11
|
def notify(message)
|
@@ -4,8 +4,8 @@ module NineOneOne
|
|
4
4
|
@config = config
|
5
5
|
end
|
6
6
|
|
7
|
-
def emergency(
|
8
|
-
emergency_service.trigger_event(
|
7
|
+
def emergency(description, source, details_hash, severity)
|
8
|
+
emergency_service.trigger_event(description, source, details_hash, severity)
|
9
9
|
end
|
10
10
|
|
11
11
|
def notify(message)
|
@@ -1,21 +1,22 @@
|
|
1
1
|
module NineOneOne
|
2
2
|
class PagerDutyService
|
3
3
|
BASE_HOST = 'events.pagerduty.com'.freeze
|
4
|
-
|
5
|
-
|
4
|
+
EVENTS_API_V2_ENDPOINT = '/v2/enqueue'.freeze
|
6
5
|
THROTTLE_HTTP_STATUS = 403
|
7
6
|
THROTTLE_RETRIES = 2
|
7
|
+
HIGH_URGENCY_ERROR = 'error'.freeze
|
8
8
|
|
9
9
|
def initialize(api_integration_key)
|
10
10
|
@api_integration_key = api_integration_key
|
11
11
|
@http = Http.new(BASE_HOST)
|
12
12
|
end
|
13
13
|
|
14
|
-
def trigger_event(
|
14
|
+
def trigger_event(description, source, details_hash, severity)
|
15
15
|
response = nil
|
16
16
|
|
17
17
|
retry_on(THROTTLE_HTTP_STATUS, THROTTLE_RETRIES) do
|
18
|
-
|
18
|
+
body = request_body(description, severity, source, details_hash)
|
19
|
+
response = make_request(body)
|
19
20
|
response.code.to_i
|
20
21
|
end
|
21
22
|
|
@@ -39,21 +40,23 @@ module NineOneOne
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
def make_request(
|
43
|
-
headers = {
|
44
|
-
body = request_body(incident_key, description, details_hash)
|
43
|
+
def make_request(body)
|
44
|
+
headers = {'Content-Type' => 'application/json'}
|
45
45
|
|
46
|
-
http.post(
|
46
|
+
http.post(EVENTS_API_V2_ENDPOINT, body, headers)
|
47
47
|
end
|
48
48
|
|
49
|
-
def request_body(
|
49
|
+
def request_body(description, severity, source, details_hash)
|
50
50
|
body = {
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
routing_key: api_integration_key,
|
52
|
+
event_action: 'trigger',
|
53
|
+
payload: {
|
54
|
+
summary: description,
|
55
|
+
severity: severity,
|
56
|
+
source: source,
|
57
|
+
custom_details: details_hash
|
58
|
+
}
|
55
59
|
}
|
56
|
-
body[:details] = details_hash if details_hash
|
57
60
|
|
58
61
|
body.to_json
|
59
62
|
end
|
@@ -11,12 +11,8 @@ module NineOneOne
|
|
11
11
|
|
12
12
|
def notify(message)
|
13
13
|
body = request_body(message)
|
14
|
-
|
15
14
|
headers = { 'Content-Type' => 'application/json' }
|
16
|
-
|
17
|
-
response = http.post(path, body, headers)
|
18
|
-
|
19
|
-
response.is_a?(Net::HTTPSuccess)
|
15
|
+
http.post(path, body, headers)
|
20
16
|
end
|
21
17
|
|
22
18
|
private
|
@@ -24,8 +20,7 @@ module NineOneOne
|
|
24
20
|
attr_reader :channel, :http, :path, :username
|
25
21
|
|
26
22
|
def request_body(message)
|
27
|
-
body = { text: message }
|
28
|
-
|
23
|
+
body = message.is_a?(Hash) ? message : { text: message }
|
29
24
|
body[:channel] = channel unless channel.nil?
|
30
25
|
body[:username] = username unless username.nil?
|
31
26
|
|
data/lib/nine_one_one/version.rb
CHANGED
data/lib/nine_one_one.rb
CHANGED
@@ -27,8 +27,8 @@ module NineOneOne
|
|
27
27
|
@configs ||= {}
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.emergency(
|
31
|
-
use(:default).emergency(
|
30
|
+
def self.emergency(description, source, details_hash = nil, severity = PagerDutyService::HIGH_URGENCY_ERROR)
|
31
|
+
use(:default).emergency(description, source, details_hash, severity)
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.notify(message)
|
data/nine_one_one.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'nine_one_one/version'
|
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = NineOneOne::VERSION
|
9
9
|
spec.licenses = ['MIT']
|
10
10
|
spec.authors = ['Kacper Madej', 'Marek Mateja']
|
11
|
-
spec.email = %w
|
11
|
+
spec.email = %w[kacper.madej@u2i.com marek.mateja@u2i.com]
|
12
12
|
|
13
|
-
spec.summary =
|
13
|
+
spec.summary = 'Alerts and notifications via PagerDuty and Slack for Ruby apps'
|
14
14
|
spec.homepage = 'https://github.com/u2i/nine_one_one'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -20,16 +20,17 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
spec.required_ruby_version = '>= 2.1'
|
23
|
+
spec.post_install_message = 'From Ver 1.0.0 emergency method call is not backwards compatible!'
|
23
24
|
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
26
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
25
27
|
spec.add_development_dependency 'guard', '~> 2.14'
|
26
28
|
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
27
29
|
spec.add_development_dependency 'guard-rubocop', '~> 1.2'
|
28
30
|
spec.add_development_dependency 'rake', '~> 10.0'
|
29
31
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
32
|
spec.add_development_dependency 'rubocop', '~> 0.47'
|
33
|
+
spec.add_development_dependency 'simplecov', '~> 0.13'
|
31
34
|
spec.add_development_dependency 'vcr', '~> 3.0'
|
32
35
|
spec.add_development_dependency 'webmock', '~> 2.3'
|
33
|
-
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
34
|
-
spec.add_development_dependency 'simplecov', '~> 0.13'
|
35
36
|
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.
|
4
|
+
version: 1.0.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-
|
12
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.13'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: codeclimate-test-reporter
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: guard
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,61 +124,47 @@ dependencies:
|
|
110
124
|
- !ruby/object:Gem::Version
|
111
125
|
version: '0.47'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - "~>"
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '3.0'
|
119
|
-
type: :development
|
120
|
-
prerelease: false
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
requirements:
|
123
|
-
- - "~>"
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '3.0'
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: webmock
|
127
|
+
name: simplecov
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
132
|
+
version: '0.13'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: '
|
139
|
+
version: '0.13'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
|
-
name:
|
141
|
+
name: vcr
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - "~>"
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: '
|
146
|
+
version: '3.0'
|
147
147
|
type: :development
|
148
148
|
prerelease: false
|
149
149
|
version_requirements: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
151
|
- - "~>"
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version: '
|
153
|
+
version: '3.0'
|
154
154
|
- !ruby/object:Gem::Dependency
|
155
|
-
name:
|
155
|
+
name: webmock
|
156
156
|
requirement: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
158
|
- - "~>"
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version: '
|
160
|
+
version: '2.3'
|
161
161
|
type: :development
|
162
162
|
prerelease: false
|
163
163
|
version_requirements: !ruby/object:Gem::Requirement
|
164
164
|
requirements:
|
165
165
|
- - "~>"
|
166
166
|
- !ruby/object:Gem::Version
|
167
|
-
version: '
|
167
|
+
version: '2.3'
|
168
168
|
description:
|
169
169
|
email:
|
170
170
|
- kacper.madej@u2i.com
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- ".gitignore"
|
177
177
|
- ".rspec"
|
178
178
|
- ".rubocop.yml"
|
179
|
+
- ".rubocop_todo.yml"
|
179
180
|
- ".travis.yml"
|
180
181
|
- Gemfile
|
181
182
|
- Guardfile
|
@@ -197,7 +198,7 @@ homepage: https://github.com/u2i/nine_one_one
|
|
197
198
|
licenses:
|
198
199
|
- MIT
|
199
200
|
metadata: {}
|
200
|
-
post_install_message:
|
201
|
+
post_install_message: From Ver 1.0.0 emergency method call is not backwards compatible!
|
201
202
|
rdoc_options: []
|
202
203
|
require_paths:
|
203
204
|
- lib
|