ragios-client 0.0.4 → 0.0.5
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/README.rdoc +9 -9
- data/VERSION +1 -1
- data/lib/ragios-client.rb +5 -4
- data/ragios-client.gemspec +3 -3
- data/spec/ragios-client_spec.rb +170 -339
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 694083a982523bfda3ff6c41619416b9acb78245
|
|
4
|
+
data.tar.gz: 562c7f99a44d0ddf523e15cf064b561504f49c8b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 22c9c0995303ea0d864691f597140ca9409b135335de99b6296fc1fe8c405402e4de0e1104acae0c55f17c9ce4bd6116d21711a7e3f17ea601cd252cf8611120
|
|
7
|
+
data.tar.gz: 76113d058ea49825a1350e9f26be09e2ac4f296b4faaf6d4842c299d3cfe3f67e095c4236b7458cd34c1be77839051d39a0dddb9eb133af2266a492f0e47094b
|
data/README.rdoc
CHANGED
|
@@ -15,14 +15,15 @@
|
|
|
15
15
|
|
|
16
16
|
ragios.login('admin', 'password')
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
monitor = {
|
|
19
|
+
monitor: "my website",
|
|
20
|
+
every: "5m",
|
|
21
|
+
url: "http://mywebsite.com",
|
|
22
|
+
via: "twtter_notifier",
|
|
23
|
+
plugin: "url_monitor"
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
ragios.add
|
|
26
|
+
ragios.add monitor
|
|
26
27
|
|
|
27
28
|
ragios.find(monitor_id)
|
|
28
29
|
|
|
@@ -49,6 +50,5 @@
|
|
|
49
50
|
|
|
50
51
|
== Copyright
|
|
51
52
|
|
|
52
|
-
Copyright (c)
|
|
53
|
+
Copyright (c) 2014 obi-a. See LICENSE.txt for
|
|
53
54
|
further details.
|
|
54
|
-
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.5
|
data/lib/ragios-client.rb
CHANGED
|
@@ -15,8 +15,8 @@ module Ragios
|
|
|
15
15
|
def initialize(args = {})
|
|
16
16
|
@address = args.fetch(:address, 'http://127.0.0.1')
|
|
17
17
|
@port = args.fetch(:port, '5041')
|
|
18
|
-
@username = args.fetch(:username,
|
|
19
|
-
@password = args.fetch(:password,
|
|
18
|
+
@username = args.fetch(:username, nil)
|
|
19
|
+
@password = args.fetch(:password, nil)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def login(username,password)
|
|
@@ -25,8 +25,8 @@ module Ragios
|
|
|
25
25
|
auth_session
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def add(
|
|
29
|
-
api_request { RestClient.post "#{address_port}/monitors/", generate_json(
|
|
28
|
+
def add(monitor)
|
|
29
|
+
api_request { RestClient.post "#{address_port}/monitors/", generate_json(monitor), http_request_options }
|
|
30
30
|
end
|
|
31
31
|
def find(monitor_id)
|
|
32
32
|
api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/", auth_cookie }
|
|
@@ -89,6 +89,7 @@ private
|
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
def auth_session
|
|
92
|
+
return "" if [@username, @password].any? { |e| e.nil? }
|
|
92
93
|
auth = RestClient.post "#{address_port}/session", { :username=> @username, :password => @password}
|
|
93
94
|
hash = parse_json(auth)
|
|
94
95
|
hash[:AuthSession]
|
data/ragios-client.gemspec
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
-
# stub: ragios-client 0.0.
|
|
5
|
+
# stub: ragios-client 0.0.5 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "ragios-client"
|
|
9
|
-
s.version = "0.0.
|
|
9
|
+
s.version = "0.0.5"
|
|
10
10
|
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
12
|
s.require_paths = ["lib"]
|
|
13
13
|
s.authors = ["obi-a"]
|
|
14
|
-
s.date = "2014-
|
|
14
|
+
s.date = "2014-08-23"
|
|
15
15
|
s.description = "ruby client for ragios"
|
|
16
16
|
s.email = "obioraakubue@yahoo.com"
|
|
17
17
|
s.extra_rdoc_files = [
|
data/spec/ragios-client_spec.rb
CHANGED
|
@@ -1,329 +1,189 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/ragios-client'))
|
|
3
3
|
|
|
4
|
-
#use for fast
|
|
4
|
+
#use for fast tests
|
|
5
5
|
plugin = "mock_plugin"
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
def generate_json(str)
|
|
8
|
+
JSON.generate(str)
|
|
9
|
+
end
|
|
8
10
|
|
|
9
11
|
admin = 'admin'
|
|
10
12
|
password = 'ragios'
|
|
11
13
|
|
|
12
14
|
describe "Ragios Client" do
|
|
13
15
|
before(:each) do
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
it "cannot add a monitor with no plugin" do
|
|
35
|
-
monitors = [{monitor: "Google",
|
|
36
|
-
url: "http://google.com",
|
|
37
|
-
every: "5m",
|
|
38
|
-
contact: "admin@mail.com",
|
|
39
|
-
via: "gmail_notifier"}]
|
|
40
|
-
begin
|
|
41
|
-
@ragios.add monitors
|
|
42
|
-
rescue => e
|
|
43
|
-
e.should be_an_instance_of Ragios::ClientException
|
|
44
|
-
e.message.should include("No Plugin Found")
|
|
16
|
+
#@ragios = Ragios::Client.new(username: admin, password: password)
|
|
17
|
+
@ragios = Ragios::Client.new
|
|
18
|
+
end
|
|
19
|
+
describe "#add" do
|
|
20
|
+
it "adds a monitor" do
|
|
21
|
+
monitor = {
|
|
22
|
+
monitor: "Google",
|
|
23
|
+
url: "http://google.com",
|
|
24
|
+
every: "5m",
|
|
25
|
+
contact: "admin@mail.com",
|
|
26
|
+
via: ["gmail_notifier","twitter_notifier"],
|
|
27
|
+
plugin: plugin
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
returned_monitor = @ragios.add(monitor)
|
|
31
|
+
returned_monitor.should include(monitor)
|
|
32
|
+
monitor_id = returned_monitor[:_id]
|
|
33
|
+
|
|
34
|
+
#teardown
|
|
35
|
+
@ragios.delete(monitor_id)
|
|
45
36
|
end
|
|
46
|
-
end
|
|
47
37
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
it "cannot add a monitor with no plugin" do
|
|
39
|
+
monitor = {
|
|
40
|
+
monitor: "Google",
|
|
41
|
+
url: "http://google.com",
|
|
42
|
+
every: "5m",
|
|
43
|
+
contact: "admin@mail.com",
|
|
44
|
+
via: "gmail_notifier"
|
|
45
|
+
}
|
|
46
|
+
begin
|
|
47
|
+
@ragios.add monitor
|
|
48
|
+
rescue => e
|
|
49
|
+
e.should be_an_instance_of Ragios::ClientException
|
|
50
|
+
e.message.should include("No Plugin Found")
|
|
51
|
+
end
|
|
59
52
|
end
|
|
60
|
-
end
|
|
61
53
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
returned_monitors = @ragios.add monitors
|
|
77
|
-
monitor_id = returned_monitors.first[:_id]
|
|
78
|
-
#setup ends
|
|
79
|
-
|
|
80
|
-
received_monitor = @ragios.find(monitor_id)
|
|
81
|
-
received_monitor.should include(monitors.first)
|
|
82
|
-
#teardown
|
|
83
|
-
hash = @ragios.delete(monitor_id)
|
|
84
|
-
hash[:ok].should == true
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "cannot retrieve a monitor that doesnt exist" do
|
|
88
|
-
begin
|
|
89
|
-
@ragios.find('dont_exist')
|
|
90
|
-
rescue => e
|
|
91
|
-
e.should be_an_instance_of Ragios::ClientException
|
|
92
|
-
e.message.should include("No monitor found with id = dont_exist")
|
|
54
|
+
it "cannot add a monitor with no notifier" do
|
|
55
|
+
monitor = {
|
|
56
|
+
monitor: "Google",
|
|
57
|
+
url: "http://google.com",
|
|
58
|
+
every: "5m",
|
|
59
|
+
contact: "admin@mail.com",
|
|
60
|
+
plugin: plugin
|
|
61
|
+
}
|
|
62
|
+
begin
|
|
63
|
+
@ragios.add monitor
|
|
64
|
+
rescue Exception => e
|
|
65
|
+
e.should be_an_instance_of Ragios::ClientException
|
|
66
|
+
e.message.should include("No Notifier Found")
|
|
67
|
+
end
|
|
93
68
|
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it "should find monitors that match multiple key/value pairs" do
|
|
97
|
-
#setup starts
|
|
98
|
-
unique_name = "Google #{Time.now.to_i}"
|
|
99
|
-
monitors = [{monitor: unique_name,
|
|
100
|
-
url: "http://google.com",
|
|
101
|
-
every: "5m",
|
|
102
|
-
contact: "admin@mail.com",
|
|
103
|
-
via: ["gmail_notifier"],
|
|
104
|
-
plugin: plugin,
|
|
105
|
-
tag: "test" }]
|
|
106
|
-
returned_monitors = @ragios.add monitors
|
|
107
|
-
monitor_id = returned_monitors.first[:_id]
|
|
108
|
-
#setup ends
|
|
109
69
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
found_monitors.first.should include(monitors.first)
|
|
113
|
-
|
|
114
|
-
#teardown
|
|
115
|
-
hash = @ragios.delete(monitor_id)
|
|
116
|
-
hash[:ok].should == true
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "returns an empty array when no monitor matches multiple key/value pairs" do
|
|
120
|
-
options = {something: "dont_exist", every: "5m", monitor: "dont_exist"}
|
|
121
|
-
@ragios.where(options).should == []
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it "should update a monitor" do
|
|
125
|
-
#setup starts
|
|
126
|
-
unique_name = "Google #{Time.now.to_i}"
|
|
127
|
-
monitors = [{monitor: unique_name,
|
|
128
|
-
url: "http://google.com",
|
|
129
|
-
every: "5m",
|
|
130
|
-
contact: "admin@mail.com",
|
|
131
|
-
via: ["gmail_notifier"],
|
|
132
|
-
plugin: plugin }]
|
|
133
|
-
|
|
134
|
-
returned_monitors = @ragios.add monitors
|
|
135
|
-
monitor_id = returned_monitors.first[:_id]
|
|
136
|
-
#setup ends
|
|
137
|
-
|
|
138
|
-
update_options = {every: "10m", via: ["twitter_notifier"]}
|
|
139
|
-
updated_monitor = @ragios.update(monitor_id, update_options)
|
|
140
|
-
updated_monitor.should include(update_options)
|
|
141
|
-
|
|
142
|
-
#teardown
|
|
143
|
-
hash = @ragios.delete(monitor_id)
|
|
144
|
-
hash[:ok].should == true
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it "cannot update a monitor with bad data" do
|
|
148
|
-
#setup starts
|
|
149
|
-
unique_name = "Google #{Time.now.to_i}"
|
|
150
|
-
monitors = [{monitor: unique_name,
|
|
151
|
-
url: "http://google.com",
|
|
152
|
-
every: "5m",
|
|
153
|
-
contact: "admin@mail.com",
|
|
154
|
-
via: ["gmail_notifier"],
|
|
155
|
-
plugin: plugin }]
|
|
156
|
-
|
|
157
|
-
returned_monitors = @ragios.add monitors
|
|
158
|
-
monitor_id = returned_monitors.first[:_id]
|
|
159
|
-
#setup ends
|
|
160
|
-
|
|
161
|
-
expect { @ragios.update(monitor_id,"bad data") }.to raise_error(JSON::GeneratorError)
|
|
162
|
-
|
|
163
|
-
#teardown
|
|
164
|
-
hash = @ragios.delete(monitor_id)
|
|
165
|
-
hash[:ok].should == true
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
it "cannot update a monitor that don't exist" do
|
|
169
|
-
update_options = {every: "5m", via: ["twitter_notifier"]}
|
|
170
|
-
monitor_id = "dont_exist"
|
|
171
|
-
begin
|
|
172
|
-
@ragios.update(monitor_id,update_options)
|
|
173
|
-
rescue => e
|
|
174
|
-
e.should be_an_instance_of Ragios::ClientException
|
|
175
|
-
e.message.should include("No monitor found with id = dont_exist")
|
|
70
|
+
it "cannot add a badly formed monitor" do
|
|
71
|
+
expect{@ragios.add("bad data")}.to raise_error(JSON::GeneratorError)
|
|
176
72
|
end
|
|
177
73
|
end
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
hash = @ragios.test(monitor_id)
|
|
194
|
-
hash[:ok].should == true
|
|
195
|
-
|
|
196
|
-
#teardown
|
|
197
|
-
hash = @ragios.delete(monitor_id)
|
|
198
|
-
hash[:ok].should == true
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
it "cannot test a monitor that don't exist" do
|
|
202
|
-
monitor_id = "dont_exist"
|
|
203
|
-
begin
|
|
204
|
-
@ragios.test(monitor_id)
|
|
205
|
-
rescue => e
|
|
206
|
-
e.should be_an_instance_of Ragios::ClientException
|
|
207
|
-
e.message.should include("No monitor found with id = dont_exist")
|
|
74
|
+
describe "More API calls" do
|
|
75
|
+
before(:each) do
|
|
76
|
+
@unique_name = "Google #{Time.now.to_i}"
|
|
77
|
+
@monitor = {
|
|
78
|
+
monitor: @unique_name,
|
|
79
|
+
url: "http://google.com",
|
|
80
|
+
every: "5m",
|
|
81
|
+
contact: "admin@mail.com",
|
|
82
|
+
via: ["gmail_notifier"],
|
|
83
|
+
plugin: plugin,
|
|
84
|
+
tag: "test"
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
returned_monitor = @ragios.add(@monitor)
|
|
88
|
+
@monitor_id = returned_monitor[:_id]
|
|
208
89
|
end
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
contact: "admin@mail.com",
|
|
218
|
-
via: ["gmail_notifier"],
|
|
219
|
-
plugin: plugin }]
|
|
220
|
-
|
|
221
|
-
returned_monitors = @ragios.add monitors
|
|
222
|
-
monitor_id = returned_monitors.first[:_id]
|
|
223
|
-
#setup ends
|
|
224
|
-
|
|
225
|
-
hash = @ragios.delete(monitor_id)
|
|
226
|
-
hash[:ok].should == true
|
|
227
|
-
begin
|
|
228
|
-
@ragios.find(monitor_id)
|
|
229
|
-
rescue => e
|
|
230
|
-
e.should be_an_instance_of Ragios::ClientException
|
|
231
|
-
e.message.should include("No monitor found with id = #{monitor_id}")
|
|
90
|
+
describe "#find" do
|
|
91
|
+
it "should retrieve a monitor by id" do
|
|
92
|
+
received_monitor = @ragios.find(@monitor_id)
|
|
93
|
+
received_monitor.should include(@monitor)
|
|
94
|
+
end
|
|
95
|
+
it "cannot retrieve a monitor that doesnt exist" do
|
|
96
|
+
expect{ @ragios.find('dont_exist') }.to raise_error(Ragios::ClientException, generate_json(error: "No monitor found with id = dont_exist"))
|
|
97
|
+
end
|
|
232
98
|
end
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
99
|
+
describe "#where" do
|
|
100
|
+
it "should find monitors that match multiple key/value pairs" do
|
|
101
|
+
options = {tag: 'test', every: '5m', monitor: @unique_name}
|
|
102
|
+
found_monitors = @ragios.where(options)
|
|
103
|
+
found_monitors.first.should include(@monitor)
|
|
104
|
+
end
|
|
105
|
+
it "returns an empty array when no monitor matches multiple key/value pairs" do
|
|
106
|
+
options = {something: "dont_exist", every: "5m", monitor: "dont_exist"}
|
|
107
|
+
@ragios.where(options).should == []
|
|
108
|
+
end
|
|
242
109
|
end
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
returned_monitors = @ragios.add monitors
|
|
256
|
-
monitor_id = returned_monitors.first[:_id]
|
|
257
|
-
#setup ends
|
|
258
|
-
|
|
259
|
-
active_monitor = @ragios.find(monitor_id)
|
|
260
|
-
active_monitor[:status_].should == "active"
|
|
261
|
-
|
|
262
|
-
hash = @ragios.stop(monitor_id)
|
|
263
|
-
hash[:ok].should == true
|
|
264
|
-
|
|
265
|
-
stopped_monitor = @ragios.find(monitor_id)
|
|
266
|
-
stopped_monitor[:status_].should == "stopped"
|
|
267
|
-
|
|
268
|
-
#stop monitor is idempotent
|
|
269
|
-
hash = @ragios.stop(monitor_id)
|
|
270
|
-
hash[:ok].should == true
|
|
271
|
-
|
|
272
|
-
#teardown
|
|
273
|
-
hash = @ragios.delete(monitor_id)
|
|
274
|
-
hash[:ok].should == true
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
it "cannot stop a monitor that dont exist" do
|
|
278
|
-
monitor_id = "dont_exist"
|
|
279
|
-
begin
|
|
280
|
-
@ragios.stop(monitor_id)
|
|
281
|
-
rescue => e
|
|
282
|
-
e.should be_an_instance_of Ragios::ClientException
|
|
283
|
-
e.message.should include("No monitor found with id = #{monitor_id}")
|
|
110
|
+
describe "#update" do
|
|
111
|
+
it "should update a monitor" do
|
|
112
|
+
update_options = {every: "10m", via: ["twitter_notifier"]}
|
|
113
|
+
@ragios.update(@monitor_id, update_options).should == {ok: true}
|
|
114
|
+
end
|
|
115
|
+
it "cannot update a monitor with bad data" do
|
|
116
|
+
expect { @ragios.update(@monitor_id,"bad data") }.to raise_error(JSON::GeneratorError)
|
|
117
|
+
end
|
|
118
|
+
it "cannot update a monitor that don't exist" do
|
|
119
|
+
update_options = {every: "5m", via: ["twitter_notifier"]}
|
|
120
|
+
expect { @ragios.update("dont_exist", update_options) }.to raise_error(Ragios::ClientException, generate_json(error: "No monitor found with id = dont_exist"))
|
|
121
|
+
end
|
|
284
122
|
end
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
123
|
+
describe "#test" do
|
|
124
|
+
it "tests a monitor" do
|
|
125
|
+
@ragios.test(@monitor_id).should == {ok: true}
|
|
126
|
+
end
|
|
127
|
+
it "cannot test a monitor that don't exist" do
|
|
128
|
+
expect { @ragios.test("dont_exist") }.to raise_error(Ragios::ClientException, generate_json(error: "No monitor found with id = dont_exist"))
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
describe "#delete" do
|
|
132
|
+
it "deletes a monitor" do
|
|
133
|
+
new_monitor_id = @ragios.add(@monitor)[:_id]
|
|
134
|
+
@ragios.delete(new_monitor_id).should == {ok: true}
|
|
135
|
+
end
|
|
136
|
+
it "cannot delete a monitor that doesnt exist" do
|
|
137
|
+
this_monitor_id = "dont_exist"
|
|
138
|
+
expect{ @ragios.find(this_monitor_id) }.to raise_error(Ragios::ClientException, generate_json(error: "No monitor found with id = #{this_monitor_id}"))
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
describe "#stop" do
|
|
142
|
+
it "stops an active monitor" do
|
|
143
|
+
active_monitor = @ragios.find(@monitor_id)
|
|
144
|
+
active_monitor[:status_].should == "active"
|
|
145
|
+
|
|
146
|
+
@ragios.stop(@monitor_id).should == {ok: true}
|
|
147
|
+
|
|
148
|
+
stopped_monitor = @ragios.find(@monitor_id)
|
|
149
|
+
stopped_monitor[:status_].should == "stopped"
|
|
150
|
+
|
|
151
|
+
#stop monitor is idempotent
|
|
152
|
+
@ragios.stop(@monitor_id).should == {ok: true}
|
|
153
|
+
end
|
|
154
|
+
it "cannot stop a monitor that dont exist" do
|
|
155
|
+
this_monitor_id = "dont_exist"
|
|
156
|
+
expect { @ragios.stop(this_monitor_id) }.to raise_error(Ragios::ClientException, generate_json(error: "No monitor found with id = #{this_monitor_id}"))
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
describe "#restart" do
|
|
160
|
+
it "restarts a stopped monitor" do
|
|
161
|
+
@ragios.stop(@monitor_id)
|
|
162
|
+
stopped_monitor = @ragios.find(@monitor_id)
|
|
163
|
+
stopped_monitor[:status_].should == "stopped"
|
|
164
|
+
|
|
165
|
+
@ragios.restart(@monitor_id).should == {ok: true}
|
|
166
|
+
|
|
167
|
+
active_monitor = @ragios.find(@monitor_id)
|
|
168
|
+
active_monitor[:status_].should == "active"
|
|
169
|
+
|
|
170
|
+
#restart monitor is idempotent
|
|
171
|
+
@ragios.restart(@monitor_id).should == {ok: true}
|
|
172
|
+
end
|
|
173
|
+
it "cannot restart a monitor that dont exist" do
|
|
174
|
+
this_monitor_id = "dont_exist"
|
|
175
|
+
expect { @ragios.restart(this_monitor_id) }.to raise_error(Ragios::ClientException, generate_json(error: "No monitor found with id = #{this_monitor_id}"))
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
describe "#all" do
|
|
179
|
+
it "retrieves all monitors" do
|
|
180
|
+
retrieved_monitors = @ragios.all
|
|
181
|
+
retrieved_monitors.should_not be_empty
|
|
182
|
+
retrieved_monitors.should be_an_instance_of Array
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
after(:each) do
|
|
186
|
+
@ragios.delete(@monitor_id)
|
|
327
187
|
end
|
|
328
188
|
end
|
|
329
189
|
|
|
@@ -332,51 +192,23 @@ describe "Ragios Client" do
|
|
|
332
192
|
end
|
|
333
193
|
|
|
334
194
|
it "rejects incorrect login credentials" do
|
|
335
|
-
|
|
336
|
-
@ragios.login('incorret','incorret')
|
|
337
|
-
rescue => e
|
|
338
|
-
e.should be_an_instance_of Ragios::ClientException
|
|
339
|
-
e.message.should include("You are not authorized to access this resource")
|
|
340
|
-
end
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
it "retrieves all monitors" do
|
|
344
|
-
#setup starts
|
|
345
|
-
unique_name = "Google #{Time.now.to_i}"
|
|
346
|
-
monitors = [{monitor: unique_name,
|
|
347
|
-
url: "http://google.com",
|
|
348
|
-
every: "5m",
|
|
349
|
-
contact: "admin@mail.com",
|
|
350
|
-
via: ["gmail_notifier"],
|
|
351
|
-
plugin: plugin }]
|
|
352
|
-
|
|
353
|
-
returned_monitors = @ragios.add monitors
|
|
354
|
-
monitor_id = returned_monitors.first[:_id]
|
|
355
|
-
#setup ends
|
|
356
|
-
|
|
357
|
-
retrieved_monitors = @ragios.all
|
|
358
|
-
retrieved_monitors.should_not be_empty
|
|
359
|
-
retrieved_monitors.should be_an_instance_of Array
|
|
360
|
-
|
|
361
|
-
#teardown
|
|
362
|
-
hash = @ragios.delete(monitor_id)
|
|
363
|
-
hash[:ok].should == true
|
|
195
|
+
expect { @ragios.login('incorret','incorret') }.to raise_error(Ragios::ClientException, generate_json(error: "You are not authorized to access this resource"))
|
|
364
196
|
end
|
|
365
197
|
|
|
366
198
|
it "has default settings" do
|
|
367
199
|
ragios_client = Ragios::Client.new
|
|
368
200
|
ragios_client.address.should == "http://127.0.0.1"
|
|
369
201
|
ragios_client.port.should == "5041"
|
|
370
|
-
ragios_client.username.should ==
|
|
371
|
-
ragios_client.password.should ==
|
|
202
|
+
ragios_client.username.should == nil
|
|
203
|
+
ragios_client.password.should == nil
|
|
372
204
|
end
|
|
373
205
|
|
|
374
206
|
it "accepts new default address" do
|
|
375
207
|
ragios_client = Ragios::Client.new(address: 'https://mysite.com', port: '6802')
|
|
376
208
|
ragios_client.address.should == "https://mysite.com"
|
|
377
209
|
ragios_client.port.should == "6802"
|
|
378
|
-
ragios_client.username.should ==
|
|
379
|
-
ragios_client.password.should ==
|
|
210
|
+
ragios_client.username.should == nil
|
|
211
|
+
ragios_client.password.should == nil
|
|
380
212
|
end
|
|
381
213
|
|
|
382
214
|
it "accepts new default login credentials" do
|
|
@@ -387,12 +219,11 @@ describe "Ragios Client" do
|
|
|
387
219
|
ragios_client.password.should == "abc123"
|
|
388
220
|
end
|
|
389
221
|
|
|
390
|
-
|
|
222
|
+
it "accepts new default settings" do
|
|
391
223
|
ragios_client = Ragios::Client.new(username: 'superadmin', password: 'abc123', address: 'https://mysite.com', port: '6802')
|
|
392
224
|
ragios_client.address.should == "https://mysite.com"
|
|
393
225
|
ragios_client.port.should == "6802"
|
|
394
226
|
ragios_client.username.should == "superadmin"
|
|
395
227
|
ragios_client.password.should == "abc123"
|
|
396
228
|
end
|
|
397
|
-
|
|
398
229
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ragios-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- obi-a
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-08-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rest-client
|