flapjack-diner 1.0.0.rc1 → 1.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -4
- data/flapjack-diner.gemspec +2 -2
- data/lib/flapjack-diner.rb +40 -5
- data/lib/flapjack-diner/version.rb +1 -1
- data/spec/argument_validator_spec.rb +15 -15
- data/spec/flapjack-diner_spec.rb +112 -23
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c4b55ae7da90b7fb53ee8cf79933c4498aa587
|
4
|
+
data.tar.gz: 8d2e64a0e3d18884c4d88f871400ff5b1dcca9f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 904a7a6940342b64c01e61de9bbdc5798ab1931012ee0c5cc381c8382461850964312e0c13d951cd3ce2a6c8720d6a57657b0824521f64f8534f94bace1324bc
|
7
|
+
data.tar.gz: a6280e173fc280e609e8444480dcac2a2bbd772f3afdc30aa9577b0151b87390f8a0050a62dd589553ea57b05f5dd47c0813a15a59dee2df5019283d59bc2ffa
|
data/README.md
CHANGED
@@ -2,21 +2,26 @@
|
|
2
2
|
|
3
3
|
[![Travis CI Status][id_travis_img]][id_travis_link]
|
4
4
|
|
5
|
-
[id_travis_link]: https://
|
6
|
-
[id_travis_img]: https://
|
5
|
+
[id_travis_link]: https://travis-ci.org/flapjack/flapjack-diner
|
6
|
+
[id_travis_img]: https://travis-ci.org/flapjack/flapjack-diner.png
|
7
|
+
|
8
|
+
Access the JSON API of a [Flapjack](http://flapjack.io/) system monitoring server.
|
9
|
+
|
10
|
+
Note that flapjack-diner [releases](https://github.com/flapjack/flapjack-diner/releases) after [1.0.0.rc1](https://github.com/flapjack/flapjack-diner/releases/tag/v1.0.0.rc1) require the [JSONAPI](http://flapjack.io/docs/jsonapi) gateway of Flapjack to connect to. All previous releases (0.x) require the older [API](http://flapjack.io/docs/0.9/API) Flapjack gateway.
|
7
11
|
|
8
|
-
Access the API of a [Flapjack](http://flapjack-project.com/) system monitoring server.
|
9
12
|
|
10
13
|
## Installation
|
11
14
|
|
12
15
|
Add this line to your application's Gemfile:
|
13
16
|
|
14
|
-
gem 'flapjack-diner', :
|
17
|
+
gem 'flapjack-diner', :github => 'flapjack/flapjack-diner'
|
15
18
|
|
16
19
|
And then execute:
|
17
20
|
|
18
21
|
$ bundle
|
19
22
|
|
23
|
+
Note, you can also install from [RubyGems.org](https://rubygems.org/gems/flapjack-diner) as usual.
|
24
|
+
|
20
25
|
## Usage
|
21
26
|
|
22
27
|
Set the URI of the Flapjack server:
|
@@ -31,6 +36,12 @@ Optionally, set a logger to log requests & responses:
|
|
31
36
|
Flapjack::Diner.logger = Logger.new('logs/flapjack_diner.log')
|
32
37
|
```
|
33
38
|
|
39
|
+
If you want the old behaviour wrt returning hashes with keys as strings (they're now symbols by default) then:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Flapjack::Diner.return_keys_as_strings = true
|
43
|
+
```
|
44
|
+
|
34
45
|
## Functions
|
35
46
|
|
36
47
|
Parameters for all of **flapjack-diner**'s functions are organised into three categories:
|
@@ -87,6 +98,8 @@ If any operation fails, `Flapjack::Diner.last_error` will contain an error messa
|
|
87
98
|
|
88
99
|
### Checks
|
89
100
|
|
101
|
+
* [checks](#checks)
|
102
|
+
|
90
103
|
* [create_scheduled_maintenances_checks](#create_scheduled_maintenances_checks)
|
91
104
|
* [delete_scheduled_maintenances_checks](#delete_scheduled_maintenances_checks)
|
92
105
|
|
@@ -539,6 +552,19 @@ Returns true if creation succeeded or false if creation failed.
|
|
539
552
|
|
540
553
|
---
|
541
554
|
|
555
|
+
<a name="checks"> </a>
|
556
|
+
### checks
|
557
|
+
|
558
|
+
Return basic identity data for one, some or all checks. (Check ids are composed by joining together the check's entity's name, the character ':' and the check's name.)
|
559
|
+
|
560
|
+
```ruby
|
561
|
+
check = Flapjack::Diner.check(ID)
|
562
|
+
some_checks = Flapjack::Diner.checks(ID1, ID2, ...)
|
563
|
+
all_checks = Flapjack::Diner.checks
|
564
|
+
```
|
565
|
+
|
566
|
+
---
|
567
|
+
|
542
568
|
<a name="create_scheduled_maintenances_checks"> </a>
|
543
569
|
### create_scheduled_maintenances_checks
|
544
570
|
|
data/flapjack-diner.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["ali.graham@bulletproof.net"]
|
7
7
|
gem.summary = %q{Access the API of a Flapjack system monitoring server}
|
8
8
|
gem.description = %q{Wraps raw API calls to a Flapjack server API with friendlier ruby methods.}
|
9
|
-
gem.homepage = 'https://github.com/
|
9
|
+
gem.homepage = 'https://github.com/flapjack/flapjack-diner'
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\) - ['Gemfile.lock']
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
|
21
21
|
gem.add_development_dependency('bundler')
|
22
22
|
gem.add_development_dependency('rake')
|
23
|
-
gem.add_development_dependency('rspec', '
|
23
|
+
gem.add_development_dependency('rspec', '~> 2.0')
|
24
24
|
gem.add_development_dependency('simplecov')
|
25
25
|
gem.add_development_dependency('webmock')
|
26
26
|
end
|
data/lib/flapjack-diner.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'json'
|
3
3
|
require 'uri'
|
4
|
-
require 'cgi'
|
5
4
|
|
6
5
|
require 'flapjack-diner/version'
|
7
6
|
require 'flapjack-diner/argument_validator'
|
@@ -16,7 +15,7 @@ module Flapjack
|
|
16
15
|
|
17
16
|
class << self
|
18
17
|
|
19
|
-
attr_accessor :logger
|
18
|
+
attr_accessor :logger, :return_keys_as_strings
|
20
19
|
|
21
20
|
# NB: clients will need to handle any exceptions caused by,
|
22
21
|
# e.g., network failures or non-parseable JSON data.
|
@@ -237,6 +236,10 @@ module Flapjack
|
|
237
236
|
extract_get('entities', perform_get('/entities', ids))
|
238
237
|
end
|
239
238
|
|
239
|
+
def checks(*ids)
|
240
|
+
extract_get('checks', perform_get('/checks', ids))
|
241
|
+
end
|
242
|
+
|
240
243
|
def update_entities(*args)
|
241
244
|
ids, params, data = unwrap_ids_and_params(*args)
|
242
245
|
raise "'update_entities' requires at least one entity id parameter" if ids.nil? || ids.empty?
|
@@ -264,6 +267,25 @@ module Flapjack
|
|
264
267
|
perform_patch("/entities/#{escaped_ids(ids)}", nil, ops)
|
265
268
|
end
|
266
269
|
|
270
|
+
def update_checks(*args)
|
271
|
+
ids, params, data = unwrap_ids_and_params(*args)
|
272
|
+
raise "'update_checks' requires at least one check id parameter" if ids.nil? || ids.empty?
|
273
|
+
validate_params(params) do
|
274
|
+
validate :query => :enabled, :as => :boolean
|
275
|
+
end
|
276
|
+
ops = params.inject([]) do |memo, (k,v)|
|
277
|
+
case k
|
278
|
+
when :enabled
|
279
|
+
memo << {:op => 'replace',
|
280
|
+
:path => "/checks/0/#{k.to_s}",
|
281
|
+
:value => v}
|
282
|
+
end
|
283
|
+
memo
|
284
|
+
end
|
285
|
+
raise "'update_checks' did not find any valid update fields" if ops.empty?
|
286
|
+
perform_patch("/checks/#{escaped_ids(ids)}", nil, ops)
|
287
|
+
end
|
288
|
+
|
267
289
|
['entities', 'checks'].each do |data_type|
|
268
290
|
|
269
291
|
define_method("create_scheduled_maintenances_#{data_type}") do |*args|
|
@@ -360,8 +382,14 @@ module Flapjack
|
|
360
382
|
|
361
383
|
private
|
362
384
|
|
363
|
-
def extract_get(name,
|
364
|
-
(
|
385
|
+
def extract_get(name, response)
|
386
|
+
result = (response.nil? || response.is_a?(TrueClass)) ? response : response[name]
|
387
|
+
|
388
|
+
if return_keys_as_strings.is_a?(TrueClass)
|
389
|
+
return result
|
390
|
+
else
|
391
|
+
return symbolize(result)
|
392
|
+
end
|
365
393
|
end
|
366
394
|
|
367
395
|
def perform_get(path, ids = [], data = [])
|
@@ -449,7 +477,7 @@ module Flapjack
|
|
449
477
|
end
|
450
478
|
|
451
479
|
def escaped_ids(ids = [])
|
452
|
-
ids.collect{|id|
|
480
|
+
ids.collect{|id| URI.escape(id.to_s)}.join(',')
|
453
481
|
end
|
454
482
|
|
455
483
|
def escape(s)
|
@@ -526,6 +554,13 @@ module Flapjack
|
|
526
554
|
def last_error=(error)
|
527
555
|
@last_error = error
|
528
556
|
end
|
557
|
+
|
558
|
+
def symbolize(obj)
|
559
|
+
return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo} if obj.is_a? Hash
|
560
|
+
return obj.inject([]){|memo,v | memo << symbolize(v); memo} if obj.is_a? Array
|
561
|
+
return obj
|
562
|
+
end
|
563
|
+
|
529
564
|
end
|
530
565
|
end
|
531
566
|
end
|
@@ -12,21 +12,21 @@ describe Flapjack::ArgumentValidator do
|
|
12
12
|
subject { Flapjack::ArgumentValidator.new(query) }
|
13
13
|
|
14
14
|
it 'does not raise an exception when query entity is valid' do
|
15
|
-
lambda { subject.validate(:query => :entity, :as => :required) }.should_not raise_exception
|
15
|
+
lambda { subject.validate(:query => :entity, :as => :required) }.should_not raise_exception
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'raises ArgumentError when query entity is invalid' do
|
19
19
|
query[:entity] = nil
|
20
|
-
lambda { subject.validate(:query => :entity, :as => :required) }.should raise_exception
|
20
|
+
lambda { subject.validate(:query => :entity, :as => :required) }.should raise_exception
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'handles arrays as query values valid' do
|
24
|
-
lambda { subject.validate(:query => [:entity, :check], :as => :required) }.should_not raise_exception
|
24
|
+
lambda { subject.validate(:query => [:entity, :check], :as => :required) }.should_not raise_exception
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'handles arrays as query values invalid' do
|
28
28
|
query[:check] = nil
|
29
|
-
lambda { subject.validate(:query => [:entity, :check], :as => :required) }.should raise_exception
|
29
|
+
lambda { subject.validate(:query => [:entity, :check], :as => :required) }.should raise_exception
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -39,37 +39,37 @@ describe Flapjack::ArgumentValidator do
|
|
39
39
|
subject { Flapjack::ArgumentValidator.new(query) }
|
40
40
|
|
41
41
|
it 'does not raise an exception when query start_time is valid' do
|
42
|
-
lambda { subject.validate(:query => :start_time, :as => :time) }.should_not raise_exception
|
42
|
+
lambda { subject.validate(:query => :start_time, :as => :time) }.should_not raise_exception
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'raises an exception when query start_time is invalid' do
|
46
46
|
query[:start_time] = 1234
|
47
|
-
lambda { subject.validate(:query => :start_time, :as => :time) }.should raise_exception
|
47
|
+
lambda { subject.validate(:query => :start_time, :as => :time) }.should raise_exception
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'handles arrays as query values valid' do
|
51
51
|
query[:end_time] = Time.now
|
52
|
-
lambda { subject.validate(:query => [:start_time, :end_time], :as => :time) }.should_not raise_exception
|
52
|
+
lambda { subject.validate(:query => [:start_time, :end_time], :as => :time) }.should_not raise_exception
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'handles arrays as query values invalid' do
|
56
56
|
query[:end_time] = 3904
|
57
|
-
lambda { subject.validate(:query => [:start_time, :end_time], :as => :time) }.should raise_exception
|
57
|
+
lambda { subject.validate(:query => [:start_time, :end_time], :as => :time) }.should raise_exception
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'handles dates as query values' do
|
61
61
|
query[:end_time] = Date.today
|
62
|
-
lambda { subject.validate(:query => :end_time, :as => :time) }.should_not raise_exception
|
62
|
+
lambda { subject.validate(:query => :end_time, :as => :time) }.should_not raise_exception
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'handles ISO 8601 strings as query values' do
|
66
66
|
query[:end_time] = Time.now.iso8601
|
67
|
-
lambda { subject.validate(:query => :end_time, :as => :time) }.should_not raise_exception
|
67
|
+
lambda { subject.validate(:query => :end_time, :as => :time) }.should_not raise_exception
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'raises an exception when invalid time strings are provided' do
|
71
71
|
query[:end_time] = '2011-08-01T00:00'
|
72
|
-
lambda { subject.validate(:query => :end_time, :as => :time) }.should raise_exception
|
72
|
+
lambda { subject.validate(:query => :end_time, :as => :time) }.should raise_exception
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -82,12 +82,12 @@ describe Flapjack::ArgumentValidator do
|
|
82
82
|
subject { Flapjack::ArgumentValidator.new(query) }
|
83
83
|
|
84
84
|
it 'does not raise an exception when query duration is valid' do
|
85
|
-
lambda { subject.validate(:query => :duration, :as => :integer) }.should_not raise_exception
|
85
|
+
lambda { subject.validate(:query => :duration, :as => :integer) }.should_not raise_exception
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'raises an exception when query duration is invalid' do
|
89
89
|
query[:duration] = '23'
|
90
|
-
lambda { subject.validate(:query => :duration, :as => :integer) }.should raise_exception
|
90
|
+
lambda { subject.validate(:query => :duration, :as => :integer) }.should raise_exception
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -100,12 +100,12 @@ describe Flapjack::ArgumentValidator do
|
|
100
100
|
subject { Flapjack::ArgumentValidator.new(query) }
|
101
101
|
|
102
102
|
it 'does not raise an exception when query start_time is valid' do
|
103
|
-
lambda { subject.validate(:query => :start_time, :as => [:time, :required]) }.should_not raise_exception
|
103
|
+
lambda { subject.validate(:query => :start_time, :as => [:time, :required]) }.should_not raise_exception
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'raises an exception when query start_time is invalid' do
|
107
107
|
query[:start_time] = nil
|
108
|
-
lambda { subject.validate(:query => :start_time, :as => [:time, :required]) }.should raise_exception
|
108
|
+
lambda { subject.validate(:query => :start_time, :as => [:time, :required]) }.should raise_exception
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
data/spec/flapjack-diner_spec.rb
CHANGED
@@ -14,6 +14,7 @@ describe Flapjack::Diner do
|
|
14
14
|
before(:each) do
|
15
15
|
Flapjack::Diner.base_uri(server)
|
16
16
|
Flapjack::Diner.logger = nil
|
17
|
+
Flapjack::Diner.return_keys_as_strings = true
|
17
18
|
end
|
18
19
|
|
19
20
|
after(:each) do
|
@@ -66,12 +67,48 @@ describe Flapjack::Diner do
|
|
66
67
|
|
67
68
|
context 'read' do
|
68
69
|
it "submits a GET request for all contacts" do
|
70
|
+
data = [{:id => "21"}]
|
71
|
+
|
72
|
+
req = stub_request(:get, "http://#{server}/contacts").to_return(
|
73
|
+
:status => 200, :body => response_with_data('contacts', data))
|
74
|
+
|
75
|
+
result = Flapjack::Diner.contacts
|
76
|
+
req.should have_been_requested
|
77
|
+
result.should_not be_nil
|
78
|
+
result.should be_an_instance_of(Array)
|
79
|
+
result.length.should be(1)
|
80
|
+
result[0].should be_an_instance_of(Hash)
|
81
|
+
result[0].should have_key('id')
|
82
|
+
end
|
83
|
+
|
84
|
+
it "can return keys as symbols" do
|
85
|
+
Flapjack::Diner.return_keys_as_strings = false
|
86
|
+
data = [{
|
87
|
+
:id => "21",
|
88
|
+
:first_name => "Ada",
|
89
|
+
:last_name => "Lovelace",
|
90
|
+
:email => "ada@example.com",
|
91
|
+
:timezone => "Europe/London",
|
92
|
+
:tags => [ "legend", "first computer programmer" ],
|
93
|
+
:links => {
|
94
|
+
:entities => ["7", "12", "83"],
|
95
|
+
:media => ["21_email", "21_sms"],
|
96
|
+
:notification_rules => ["30fd36ae-3922-4957-ae3e-c8f6dd27e543"]
|
97
|
+
}
|
98
|
+
}]
|
99
|
+
|
69
100
|
req = stub_request(:get, "http://#{server}/contacts").to_return(
|
70
|
-
:status => 200, :body => response_with_data('contacts'))
|
101
|
+
:status => 200, :body => response_with_data('contacts', data))
|
71
102
|
|
72
103
|
result = Flapjack::Diner.contacts
|
73
104
|
req.should have_been_requested
|
74
105
|
result.should_not be_nil
|
106
|
+
result.should be_an_instance_of(Array)
|
107
|
+
result.length.should be(1)
|
108
|
+
result[0].should be_an_instance_of(Hash)
|
109
|
+
result[0].should have_key(:id)
|
110
|
+
result[0].should have_key(:links)
|
111
|
+
result[0][:links].should have_key(:entities)
|
75
112
|
end
|
76
113
|
|
77
114
|
it "submits a GET request for one contact" do
|
@@ -845,7 +882,7 @@ describe Flapjack::Diner do
|
|
845
882
|
|
846
883
|
it "submits a POST request on a check" do
|
847
884
|
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
|
848
|
-
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com
|
885
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH").
|
849
886
|
with(:body => {:scheduled_maintenances => data}.to_json,
|
850
887
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
851
888
|
to_return(:status => 204)
|
@@ -858,7 +895,7 @@ describe Flapjack::Diner do
|
|
858
895
|
|
859
896
|
it "submits a POST request on several checks" do
|
860
897
|
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
|
861
|
-
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com
|
898
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
|
862
899
|
with(:body => {:scheduled_maintenances => data}.to_json,
|
863
900
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
864
901
|
to_return(:status => 204)
|
@@ -872,7 +909,7 @@ describe Flapjack::Diner do
|
|
872
909
|
it "submits a POST request for multiple periods on a check" do
|
873
910
|
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
|
874
911
|
{:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
|
875
|
-
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com
|
912
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH").
|
876
913
|
with(:body => {:scheduled_maintenances => data}.to_json,
|
877
914
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
878
915
|
to_return(:status => 204)
|
@@ -886,7 +923,7 @@ describe Flapjack::Diner do
|
|
886
923
|
it "submits a POST request for multiple periods on several checks" do
|
887
924
|
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
|
888
925
|
{:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
|
889
|
-
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com
|
926
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
|
890
927
|
with(:body => {:scheduled_maintenances => data}.to_json,
|
891
928
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
892
929
|
to_return(:status => 204)
|
@@ -903,7 +940,7 @@ describe Flapjack::Diner do
|
|
903
940
|
|
904
941
|
it "submits a POST request on a check" do
|
905
942
|
data = [{:duration => 3600, :summary => 'working'}]
|
906
|
-
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com
|
943
|
+
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH").
|
907
944
|
with(:body => {:unscheduled_maintenances => data}.to_json,
|
908
945
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
909
946
|
to_return(:status => 204)
|
@@ -916,7 +953,7 @@ describe Flapjack::Diner do
|
|
916
953
|
|
917
954
|
it "submits a POST request on several checks" do
|
918
955
|
data = [{:duration => 3600, :summary => 'working'}]
|
919
|
-
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com
|
956
|
+
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
|
920
957
|
with(:body => {:unscheduled_maintenances => data}.to_json,
|
921
958
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
922
959
|
to_return(:status => 204)
|
@@ -930,7 +967,7 @@ describe Flapjack::Diner do
|
|
930
967
|
it "submits a POST request for multiple periods on several checks" do
|
931
968
|
data = [{:duration => 3600, :summary => 'working'},
|
932
969
|
{:duration => 3600, :summary => 'more work'}]
|
933
|
-
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com
|
970
|
+
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
|
934
971
|
with(:body => {:unscheduled_maintenances => data}.to_json,
|
935
972
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
936
973
|
to_return(:status => 204)
|
@@ -946,7 +983,7 @@ describe Flapjack::Diner do
|
|
946
983
|
context 'test notifications' do
|
947
984
|
|
948
985
|
it "submits a POST request for a check" do
|
949
|
-
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com
|
986
|
+
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com%3ASSH").
|
950
987
|
with(:body => {:test_notifications => [{:summary => 'testing'}]}.to_json,
|
951
988
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
952
989
|
to_return(:status => 204)
|
@@ -958,7 +995,7 @@ describe Flapjack::Diner do
|
|
958
995
|
end
|
959
996
|
|
960
997
|
it "submits a POST request for several checks" do
|
961
|
-
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com
|
998
|
+
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com%3ASSH,example2.com%3APING").
|
962
999
|
with(:test_notifications => [{:summary => 'testing'}]).
|
963
1000
|
to_return(:status => 204)
|
964
1001
|
|
@@ -970,7 +1007,7 @@ describe Flapjack::Diner do
|
|
970
1007
|
|
971
1008
|
it "submits a POST request for multiple notifications on a check" do
|
972
1009
|
data = [{:summary => 'testing'}, {:summary => 'more testing'}]
|
973
|
-
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com
|
1010
|
+
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com%3ASSH").
|
974
1011
|
with(:body => {:test_notifications => data}.to_json,
|
975
1012
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
976
1013
|
to_return(:status => 204)
|
@@ -983,7 +1020,7 @@ describe Flapjack::Diner do
|
|
983
1020
|
|
984
1021
|
it "submits a POST request for multiple notifications on several checks" do
|
985
1022
|
data = [{:summary => 'testing'}, {:summary => 'more testing'}]
|
986
|
-
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com
|
1023
|
+
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com%3ASSH,example2.com%3APING").
|
987
1024
|
with(:body => {:test_notifications => data}.to_json,
|
988
1025
|
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
989
1026
|
to_return(:status => 204)
|
@@ -998,10 +1035,51 @@ describe Flapjack::Diner do
|
|
998
1035
|
|
999
1036
|
end
|
1000
1037
|
|
1038
|
+
context 'read' do
|
1039
|
+
it "submits a GET request for all checks" do
|
1040
|
+
req = stub_request(:get, "http://#{server}/checks").
|
1041
|
+
to_return(:body => response_with_data('checks'))
|
1042
|
+
|
1043
|
+
result = Flapjack::Diner.checks
|
1044
|
+
req.should have_been_requested
|
1045
|
+
result.should_not be_nil
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
it "submits a GET request for one check" do
|
1049
|
+
req = stub_request(:get, "http://#{server}/checks/example.com%3ASSH").
|
1050
|
+
to_return(:body => response_with_data('checks'))
|
1051
|
+
|
1052
|
+
result = Flapjack::Diner.checks('example.com:SSH')
|
1053
|
+
req.should have_been_requested
|
1054
|
+
result.should_not be_nil
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
it "submits a GET request for several checks" do
|
1058
|
+
req = stub_request(:get, "http://#{server}/checks/example.com%3ASSH,example2.com%3APING").
|
1059
|
+
to_return(:body => response_with_data('checks'))
|
1060
|
+
|
1061
|
+
result = Flapjack::Diner.checks('example.com:SSH', 'example2.com:PING')
|
1062
|
+
req.should have_been_requested
|
1063
|
+
result.should_not be_nil
|
1064
|
+
end
|
1065
|
+
end
|
1066
|
+
|
1001
1067
|
context 'update' do
|
1002
1068
|
|
1069
|
+
it "submits a PATCH request for a check" do
|
1070
|
+
req = stub_request(:patch, "http://#{server}/checks/www.example.com%3APING").
|
1071
|
+
with(:body => [{:op => 'replace', :path => '/checks/0/enabled', :value => false}].to_json,
|
1072
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
1073
|
+
to_return(:status => 204)
|
1074
|
+
|
1075
|
+
result = Flapjack::Diner.update_checks('www.example.com:PING', :enabled => false)
|
1076
|
+
req.should have_been_requested
|
1077
|
+
result.should_not be_nil
|
1078
|
+
result.should be_true
|
1079
|
+
end
|
1080
|
+
|
1003
1081
|
it "submits a PATCH request for unscheduled maintenances on a check" do
|
1004
|
-
req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/checks/example.com
|
1082
|
+
req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH").
|
1005
1083
|
with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
|
1006
1084
|
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
1007
1085
|
to_return(:status => 204)
|
@@ -1013,7 +1091,7 @@ describe Flapjack::Diner do
|
|
1013
1091
|
end
|
1014
1092
|
|
1015
1093
|
it "submits a PATCH request for unscheduled maintenances on several checks" do
|
1016
|
-
req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/checks/example.com
|
1094
|
+
req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
|
1017
1095
|
with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
|
1018
1096
|
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
1019
1097
|
to_return(:status => 204)
|
@@ -1029,7 +1107,7 @@ describe Flapjack::Diner do
|
|
1029
1107
|
context 'delete' do
|
1030
1108
|
|
1031
1109
|
it "submits a DELETE request for scheduled maintenances on a check" do
|
1032
|
-
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com
|
1110
|
+
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH").
|
1033
1111
|
with(:query => {:start_time => time.iso8601}).
|
1034
1112
|
to_return(:status => 204)
|
1035
1113
|
|
@@ -1039,8 +1117,19 @@ describe Flapjack::Diner do
|
|
1039
1117
|
result.should be_true
|
1040
1118
|
end
|
1041
1119
|
|
1120
|
+
it "submits a DELETE request for scheduled maintenances on a check with spaces in the name, percent-encoded" do
|
1121
|
+
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com%3ADisk%20C%3A%20Utilisation").
|
1122
|
+
with(:query => {:start_time => time.iso8601}).
|
1123
|
+
to_return(:status => 204)
|
1124
|
+
|
1125
|
+
result = Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:Disk C: Utilisation', :start_time => time.iso8601)
|
1126
|
+
req.should have_been_requested
|
1127
|
+
result.should_not be_nil
|
1128
|
+
result.should be_true
|
1129
|
+
end
|
1130
|
+
|
1042
1131
|
it "submits a DELETE request for scheduled maintenances on several checks" do
|
1043
|
-
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com
|
1132
|
+
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH,example2.com%3APING").
|
1044
1133
|
with(:query => {:start_time => time.iso8601}).
|
1045
1134
|
to_return(:status => 204)
|
1046
1135
|
|
@@ -1095,7 +1184,7 @@ describe Flapjack::Diner do
|
|
1095
1184
|
end
|
1096
1185
|
|
1097
1186
|
it "submits a GET request for a #{report_type} report on one check" do
|
1098
|
-
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com
|
1187
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com%3ASSH").
|
1099
1188
|
to_return(:body => response_with_data("#{report_type}_reports"))
|
1100
1189
|
|
1101
1190
|
result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
|
@@ -1105,7 +1194,7 @@ describe Flapjack::Diner do
|
|
1105
1194
|
end
|
1106
1195
|
|
1107
1196
|
it "submits a GET request for a #{report_type} report on several checks" do
|
1108
|
-
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com
|
1197
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com%3ASSH,example2.com%3APING").
|
1109
1198
|
to_return(:body => response_with_data("#{report_type}_reports"))
|
1110
1199
|
|
1111
1200
|
result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
|
@@ -1166,7 +1255,7 @@ describe Flapjack::Diner do
|
|
1166
1255
|
end
|
1167
1256
|
|
1168
1257
|
it "submits a time-limited GET request for a #{report_type} report on one check" do
|
1169
|
-
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com
|
1258
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com%3ASSH").
|
1170
1259
|
with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
|
1171
1260
|
to_return(:body => response_with_data("#{report_type}_reports"))
|
1172
1261
|
|
@@ -1177,7 +1266,7 @@ describe Flapjack::Diner do
|
|
1177
1266
|
end
|
1178
1267
|
|
1179
1268
|
it "submits a time-limited GET request for a #{report_type} report on several checks" do
|
1180
|
-
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com
|
1269
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com%3ASSH,example2.com%3APING").
|
1181
1270
|
with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
|
1182
1271
|
to_return(:body => response_with_data("#{report_type}_reports"))
|
1183
1272
|
|
@@ -1195,7 +1284,7 @@ describe Flapjack::Diner do
|
|
1195
1284
|
|
1196
1285
|
context "logging" do
|
1197
1286
|
|
1198
|
-
let(:logger) {
|
1287
|
+
let(:logger) { double('logger') }
|
1199
1288
|
|
1200
1289
|
before do
|
1201
1290
|
Flapjack::Diner.logger = logger
|
@@ -1228,11 +1317,11 @@ describe Flapjack::Diner do
|
|
1228
1317
|
end
|
1229
1318
|
|
1230
1319
|
it "logs a DELETE request" do
|
1231
|
-
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com
|
1320
|
+
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com%3ASSH").
|
1232
1321
|
with(:query => {:start_time => time.iso8601}).
|
1233
1322
|
to_return(:status => 204)
|
1234
1323
|
|
1235
|
-
logger.should_receive(:info).with("DELETE http://#{server}/scheduled_maintenances/checks
|
1324
|
+
logger.should_receive(:info).with("DELETE http://#{server}/scheduled_maintenances/checks/example.com:SSH?start_time=#{URI.encode_www_form_component(time.iso8601)}")
|
1236
1325
|
logger.should_receive(:info).with(" Response Code: 204")
|
1237
1326
|
|
1238
1327
|
result = Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:SSH', :start_time => time)
|
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.0.0.rc2
|
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-
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.0
|
75
|
+
version: '2.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.0
|
82
|
+
version: '2.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,7 +129,7 @@ files:
|
|
129
129
|
- spec/argument_validator_spec.rb
|
130
130
|
- spec/flapjack-diner_spec.rb
|
131
131
|
- spec/spec_helper.rb
|
132
|
-
homepage: https://github.com/
|
132
|
+
homepage: https://github.com/flapjack/flapjack-diner
|
133
133
|
licenses: []
|
134
134
|
metadata: {}
|
135
135
|
post_install_message:
|