flapjack-diner 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +21 -0
  4. data/.rubocop_todo.yml +135 -0
  5. data/Gemfile +7 -0
  6. data/README.md +86 -20
  7. data/flapjack-diner.gemspec +11 -15
  8. data/lib/flapjack-diner.rb +23 -548
  9. data/lib/flapjack-diner/argument_validator.rb +31 -22
  10. data/lib/flapjack-diner/resources/checks.rb +58 -0
  11. data/lib/flapjack-diner/resources/contacts.rb +70 -0
  12. data/lib/flapjack-diner/resources/entities.rb +68 -0
  13. data/lib/flapjack-diner/resources/maintenance_periods.rb +82 -0
  14. data/lib/flapjack-diner/resources/media.rb +61 -0
  15. data/lib/flapjack-diner/resources/notification_rules.rb +66 -0
  16. data/lib/flapjack-diner/resources/notifications.rb +27 -0
  17. data/lib/flapjack-diner/resources/pagerduty_credentials.rb +60 -0
  18. data/lib/flapjack-diner/resources/reports.rb +33 -0
  19. data/lib/flapjack-diner/tools.rb +277 -0
  20. data/lib/flapjack-diner/version.rb +1 -1
  21. data/spec/argument_validator_spec.rb +15 -15
  22. data/spec/flapjack-diner_spec.rb +58 -1275
  23. data/spec/pacts/flapjack-diner-flapjack.json +4522 -0
  24. data/spec/resources/checks_spec.rb +171 -0
  25. data/spec/resources/contacts_spec.rb +297 -0
  26. data/spec/resources/entities_spec.rb +181 -0
  27. data/spec/resources/maintenance_periods_spec.rb +603 -0
  28. data/spec/resources/media_spec.rb +277 -0
  29. data/spec/resources/notification_rules_spec.rb +341 -0
  30. data/spec/resources/notifications_spec.rb +210 -0
  31. data/spec/resources/pagerduty_credentials_spec.rb +243 -0
  32. data/spec/resources/reports_spec.rb +255 -0
  33. data/spec/spec_helper.rb +14 -2
  34. metadata +35 -72
@@ -0,0 +1,255 @@
1
+ require 'spec_helper'
2
+ require 'flapjack-diner'
3
+
4
+ describe Flapjack::Diner::Resources::Reports, :pact => true do
5
+
6
+ before(:each) do
7
+ Flapjack::Diner.base_uri('localhost:19081')
8
+ Flapjack::Diner.logger = nil
9
+ end
10
+
11
+ let(:linked_check) { {
12
+ :entity => ['1234'],
13
+ :check => ['www.example.com:SSH']
14
+ } }
15
+
16
+ let(:linked_check_2) { {
17
+ :entity => ['5678'],
18
+ :check => ['www2.example.com:PING']
19
+ } }
20
+
21
+ def report_data(report_type, links = {})
22
+ case report_type
23
+ when 'status'
24
+ {} # generic matcher for hash including anything
25
+ when 'downtime'
26
+ {} # generic matcher for hash including anything
27
+ else
28
+ {"#{report_type}s".to_sym => [], :links => links}
29
+ end
30
+ end
31
+
32
+ context 'read' do
33
+
34
+ ['status', 'scheduled_maintenance', 'unscheduled_maintenance', 'downtime', 'outage'].each do |report_type|
35
+
36
+ it "submits a GET request for a #{report_type} report on all entities" do
37
+ data = [report_data(report_type, linked_check)]
38
+
39
+ flapjack.given("a check 'www.example.com:SSH' exists").
40
+ upon_receiving("a GET request for a #{report_type} report on all entities").
41
+ with(:method => :get, :path => "/#{report_type}_report/entities").
42
+ will_respond_with(
43
+ :status => 200,
44
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
45
+ :body => {"#{report_type}_reports".to_sym => data} )
46
+
47
+ result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym)
48
+ expect(result).to eq(data)
49
+ end
50
+
51
+ it "submits a GET request for a #{report_type} report on one entity" do
52
+ data = [report_data(report_type, linked_check)]
53
+
54
+ flapjack.given("a check 'www.example.com:SSH' exists").
55
+ upon_receiving("a GET request for a #{report_type} report on one entity").
56
+ with(:method => :get, :path => "/#{report_type}_report/entities/1234").
57
+ will_respond_with(
58
+ :status => 200,
59
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
60
+ :body => {"#{report_type}_reports".to_sym => data} )
61
+
62
+ result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym, '1234')
63
+ expect(result).to eq(data)
64
+ end
65
+
66
+ it "submits a GET request for a #{report_type} report on several entities" do
67
+ data = [report_data(report_type, linked_check),
68
+ report_data(report_type, linked_check_2)]
69
+
70
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
71
+ upon_receiving("a GET request for a #{report_type} report on two entities").
72
+ with(:method => :get, :path => "/#{report_type}_report/entities/1234,5678").
73
+ will_respond_with(
74
+ :status => 200,
75
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
76
+ :body => {"#{report_type}_reports".to_sym => data} )
77
+
78
+ result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym, '1234', '5678')
79
+ expect(result).to eq(data)
80
+ end
81
+
82
+ it "submits a GET request for a #{report_type} report on all checks" do
83
+ data = [report_data(report_type, linked_check)]
84
+
85
+ flapjack.given("a check 'www.example.com:SSH' exists").
86
+ upon_receiving("a GET request for a #{report_type} report on all checks").
87
+ with(:method => :get,
88
+ :path => "/#{report_type}_report/checks").
89
+ will_respond_with(
90
+ :status => 200,
91
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
92
+ :body => {"#{report_type}_reports".to_sym => data} )
93
+
94
+ result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym)
95
+ expect(result).to eq(data)
96
+ end
97
+
98
+ it "submits a GET request for a #{report_type} report on one check" do
99
+ data = [report_data(report_type, linked_check)]
100
+
101
+ flapjack.given("a check 'www.example.com:SSH' exists").
102
+ upon_receiving("a GET request for a #{report_type} report on a single check").
103
+ with(:method => :get,
104
+ :path => "/#{report_type}_report/checks/www.example.com:SSH").
105
+ will_respond_with(
106
+ :status => 200,
107
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
108
+ :body => {"#{report_type}_reports".to_sym => data} )
109
+
110
+ result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym, 'www.example.com:SSH')
111
+ expect(result).to eq(data)
112
+ end
113
+
114
+ it "submits a GET request for a #{report_type} report on several checks" do
115
+ data = [report_data(report_type, linked_check),
116
+ report_data(report_type, linked_check_2)]
117
+
118
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
119
+ upon_receiving("a GET request for a #{report_type} report on two checks").
120
+ with(:method => :get,
121
+ :path => "/#{report_type}_report/checks/www.example.com:SSH,www2.example.com:PING").
122
+ will_respond_with(
123
+ :status => 200,
124
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
125
+ :body => {"#{report_type}_reports".to_sym => data} )
126
+
127
+ result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym, 'www.example.com:SSH', 'www2.example.com:PING')
128
+ expect(result).to eq(data)
129
+ end
130
+
131
+ end
132
+
133
+ ['scheduled_maintenance', 'unscheduled_maintenance', 'downtime', 'outage'].each do |report_type|
134
+
135
+ let(:start_time) { Time.now }
136
+ let(:end_time) { start_time + (60 * 60 * 12) }
137
+
138
+ let(:esc_st) { URI.encode_www_form_component(start_time.iso8601) }
139
+ let(:esc_et) { URI.encode_www_form_component(end_time.iso8601) }
140
+
141
+ it "submits a time-limited GET request for a #{report_type} report on all entities" do
142
+ data = [report_data(report_type, linked_check)]
143
+
144
+ flapjack.given("a check 'www.example.com:SSH' exists").
145
+ upon_receiving("a time limited GET request for a #{report_type} report on all entities").
146
+ with(:method => :get,
147
+ :path => "/#{report_type}_report/entities",
148
+ :query => "start_time=#{esc_st}&end_time=#{esc_et}").
149
+ will_respond_with(
150
+ :status => 200,
151
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
152
+ :body => {"#{report_type}_reports".to_sym => data} )
153
+
154
+ result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym,
155
+ :start_time => start_time, :end_time => end_time)
156
+ expect(result).to eq(data)
157
+ end
158
+
159
+ it "submits a time-limited GET request for a #{report_type} report on one entity" do
160
+ data = [report_data(report_type, linked_check)]
161
+
162
+ flapjack.given("a check 'www.example.com:SSH' exists").
163
+ upon_receiving("a time limited GET request for a #{report_type} report on one entity").
164
+ with(:method => :get,
165
+ :path => "/#{report_type}_report/entities/1234",
166
+ :query => "start_time=#{esc_st}&end_time=#{esc_et}").
167
+ will_respond_with(
168
+ :status => 200,
169
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
170
+ :body => {"#{report_type}_reports".to_sym => data} )
171
+
172
+ result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym, '1234',
173
+ :start_time => start_time, :end_time => end_time)
174
+ expect(result).to eq(data)
175
+ end
176
+
177
+ it "submits a time-limited GET request for a #{report_type} report on several entities" do
178
+ data = [report_data(report_type, linked_check),
179
+ report_data(report_type, linked_check_2)]
180
+
181
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
182
+ upon_receiving("a time limited GET request for a #{report_type} report on two entities").
183
+ with(:method => :get,
184
+ :path => "/#{report_type}_report/entities/1234,5678",
185
+ :query => "start_time=#{esc_st}&end_time=#{esc_et}").
186
+ will_respond_with(
187
+ :status => 200,
188
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
189
+ :body => {"#{report_type}_reports".to_sym => data} )
190
+
191
+ result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym, '1234', '5678',
192
+ :start_time => start_time, :end_time => end_time)
193
+ expect(result).to eq(data)
194
+ end
195
+
196
+ it "submits a time-limited GET request for a #{report_type} report on all checks" do
197
+ data = [report_data(report_type, linked_check)]
198
+
199
+ flapjack.given("a check 'www.example.com:SSH' exists").
200
+ upon_receiving("a time limited GET request for a #{report_type} report on all checks").
201
+ with(:method => :get,
202
+ :path => "/#{report_type}_report/checks",
203
+ :query => "start_time=#{esc_st}&end_time=#{esc_et}").
204
+ will_respond_with(
205
+ :status => 200,
206
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
207
+ :body => {"#{report_type}_reports".to_sym => data} )
208
+
209
+ result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
210
+ :start_time => start_time, :end_time => end_time)
211
+ expect(result).to eq(data)
212
+ end
213
+
214
+ it "submits a time-limited GET request for a #{report_type} report on one check" do
215
+ data = [report_data(report_type, linked_check)]
216
+
217
+ flapjack.given("a check 'www.example.com:SSH' exists").
218
+ upon_receiving("a time limited GET request for a #{report_type} report on a single check").
219
+ with(:method => :get,
220
+ :path => "/#{report_type}_report/checks/www.example.com:SSH",
221
+ :query => "start_time=#{esc_st}&end_time=#{esc_et}").
222
+ will_respond_with(
223
+ :status => 200,
224
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
225
+ :body => {"#{report_type}_reports".to_sym => data} )
226
+
227
+ result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym, 'www.example.com:SSH',
228
+ :start_time => start_time, :end_time => end_time)
229
+ expect(result).to eq(data)
230
+ end
231
+
232
+ it "submits a time-limited GET request for a #{report_type} report on several checks" do
233
+ data = [report_data(report_type, linked_check),
234
+ report_data(report_type, linked_check_2)]
235
+
236
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
237
+ upon_receiving("a time-limited GET request for a #{report_type} report on two checks").
238
+ with(:method => :get,
239
+ :path => "/#{report_type}_report/checks/www.example.com:SSH,www2.example.com:PING",
240
+ :query => "start_time=#{esc_st}&end_time=#{esc_et}").
241
+ will_respond_with(
242
+ :status => 200,
243
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
244
+ :body => {"#{report_type}_reports".to_sym => data} )
245
+
246
+ result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym, 'www.example.com:SSH', 'www2.example.com:PING',
247
+ :start_time => start_time, :end_time => end_time)
248
+ expect(result).to eq(data)
249
+ end
250
+
251
+ end
252
+
253
+ end
254
+
255
+ end
@@ -14,12 +14,24 @@ end
14
14
 
15
15
  require 'webmock/rspec'
16
16
 
17
- WebMock.disable_net_connect!
17
+ WebMock.disable_net_connect!(:allow_localhost => true)
18
+
19
+ require 'pact'
20
+ require 'pact/consumer/rspec'
18
21
 
19
22
  $:.unshift(File.dirname(__FILE__) + '/../lib')
20
23
 
24
+ Pact.service_consumer 'flapjack-diner' do
25
+
26
+ has_pact_with "flapjack" do
27
+ mock_service :flapjack do
28
+ port 19081
29
+ end
30
+ end
31
+
32
+ end
33
+
21
34
  RSpec.configure do |config|
22
- config.treat_symbols_as_metadata_keys_with_true_values = true
23
35
  config.run_all_when_everything_filtered = true
24
36
  config.filter_run :focus
25
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flapjack-diner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Graham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-11 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -38,76 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.7.7
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '2.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '2.0'
83
- - !ruby/object:Gem::Dependency
84
- name: simplecov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: webmock
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
41
  description: Wraps raw API calls to a Flapjack server API with friendlier ruby methods.
112
42
  email:
113
43
  - ali.graham@bulletproof.net
@@ -117,6 +47,8 @@ extra_rdoc_files: []
117
47
  files:
118
48
  - ".gitignore"
119
49
  - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".rubocop_todo.yml"
120
52
  - ".travis.yml"
121
53
  - Gemfile
122
54
  - LICENSE
@@ -125,9 +57,30 @@ files:
125
57
  - flapjack-diner.gemspec
126
58
  - lib/flapjack-diner.rb
127
59
  - lib/flapjack-diner/argument_validator.rb
60
+ - lib/flapjack-diner/resources/checks.rb
61
+ - lib/flapjack-diner/resources/contacts.rb
62
+ - lib/flapjack-diner/resources/entities.rb
63
+ - lib/flapjack-diner/resources/maintenance_periods.rb
64
+ - lib/flapjack-diner/resources/media.rb
65
+ - lib/flapjack-diner/resources/notification_rules.rb
66
+ - lib/flapjack-diner/resources/notifications.rb
67
+ - lib/flapjack-diner/resources/pagerduty_credentials.rb
68
+ - lib/flapjack-diner/resources/reports.rb
69
+ - lib/flapjack-diner/tools.rb
128
70
  - lib/flapjack-diner/version.rb
71
+ - log/.gitkeep
129
72
  - spec/argument_validator_spec.rb
130
73
  - spec/flapjack-diner_spec.rb
74
+ - spec/pacts/flapjack-diner-flapjack.json
75
+ - spec/resources/checks_spec.rb
76
+ - spec/resources/contacts_spec.rb
77
+ - spec/resources/entities_spec.rb
78
+ - spec/resources/maintenance_periods_spec.rb
79
+ - spec/resources/media_spec.rb
80
+ - spec/resources/notification_rules_spec.rb
81
+ - spec/resources/notifications_spec.rb
82
+ - spec/resources/pagerduty_credentials_spec.rb
83
+ - spec/resources/reports_spec.rb
131
84
  - spec/spec_helper.rb
132
85
  homepage: https://github.com/flapjack/flapjack-diner
133
86
  licenses: []
@@ -155,4 +108,14 @@ summary: Access the API of a Flapjack system monitoring server
155
108
  test_files:
156
109
  - spec/argument_validator_spec.rb
157
110
  - spec/flapjack-diner_spec.rb
111
+ - spec/pacts/flapjack-diner-flapjack.json
112
+ - spec/resources/checks_spec.rb
113
+ - spec/resources/contacts_spec.rb
114
+ - spec/resources/entities_spec.rb
115
+ - spec/resources/maintenance_periods_spec.rb
116
+ - spec/resources/media_spec.rb
117
+ - spec/resources/notification_rules_spec.rb
118
+ - spec/resources/notifications_spec.rb
119
+ - spec/resources/pagerduty_credentials_spec.rb
120
+ - spec/resources/reports_spec.rb
158
121
  - spec/spec_helper.rb