ragios-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +85 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +54 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/ragios-client.rb +120 -0
- data/spec/ragios-client_spec.rb +390 -0
- metadata +171 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "rest-client"
|
6
|
+
gem "yajl-ruby"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "shoulda", ">= 0"
|
12
|
+
gem "rdoc", "~> 3.12"
|
13
|
+
gem "bundler", "~> 1.0"
|
14
|
+
gem "jeweler", "~> 1.8.7"
|
15
|
+
gem "simplecov"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (4.0.2)
|
5
|
+
i18n (~> 0.6, >= 0.6.4)
|
6
|
+
minitest (~> 4.2)
|
7
|
+
multi_json (~> 1.3)
|
8
|
+
thread_safe (~> 0.1)
|
9
|
+
tzinfo (~> 0.3.37)
|
10
|
+
addressable (2.3.5)
|
11
|
+
atomic (1.1.14)
|
12
|
+
builder (3.2.2)
|
13
|
+
docile (1.1.1)
|
14
|
+
faraday (0.8.8)
|
15
|
+
multipart-post (~> 1.2.0)
|
16
|
+
git (1.2.6)
|
17
|
+
github_api (0.10.1)
|
18
|
+
addressable
|
19
|
+
faraday (~> 0.8.1)
|
20
|
+
hashie (>= 1.2)
|
21
|
+
multi_json (~> 1.4)
|
22
|
+
nokogiri (~> 1.5.2)
|
23
|
+
oauth2
|
24
|
+
hashie (2.0.5)
|
25
|
+
highline (1.6.20)
|
26
|
+
httpauth (0.2.0)
|
27
|
+
i18n (0.6.9)
|
28
|
+
jeweler (1.8.8)
|
29
|
+
builder
|
30
|
+
bundler (~> 1.0)
|
31
|
+
git (>= 1.2.5)
|
32
|
+
github_api (= 0.10.1)
|
33
|
+
highline (>= 1.6.15)
|
34
|
+
nokogiri (= 1.5.10)
|
35
|
+
rake
|
36
|
+
rdoc
|
37
|
+
json (1.8.1)
|
38
|
+
jwt (0.1.8)
|
39
|
+
multi_json (>= 1.5)
|
40
|
+
mime-types (1.25.1)
|
41
|
+
minitest (4.7.5)
|
42
|
+
multi_json (1.8.2)
|
43
|
+
multi_xml (0.5.5)
|
44
|
+
multipart-post (1.2.0)
|
45
|
+
nokogiri (1.5.10)
|
46
|
+
oauth2 (0.9.2)
|
47
|
+
faraday (~> 0.8)
|
48
|
+
httpauth (~> 0.2)
|
49
|
+
jwt (~> 0.1.4)
|
50
|
+
multi_json (~> 1.0)
|
51
|
+
multi_xml (~> 0.5)
|
52
|
+
rack (~> 1.2)
|
53
|
+
rack (1.5.2)
|
54
|
+
rake (10.1.0)
|
55
|
+
rdoc (3.12.2)
|
56
|
+
json (~> 1.4)
|
57
|
+
rest-client (1.6.7)
|
58
|
+
mime-types (>= 1.16)
|
59
|
+
shoulda (3.5.0)
|
60
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
61
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
62
|
+
shoulda-context (1.1.6)
|
63
|
+
shoulda-matchers (2.4.0)
|
64
|
+
activesupport (>= 3.0.0)
|
65
|
+
simplecov (0.8.2)
|
66
|
+
docile (~> 1.1.0)
|
67
|
+
multi_json
|
68
|
+
simplecov-html (~> 0.8.0)
|
69
|
+
simplecov-html (0.8.0)
|
70
|
+
thread_safe (0.1.3)
|
71
|
+
atomic
|
72
|
+
tzinfo (0.3.38)
|
73
|
+
yajl-ruby (1.1.0)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
ruby
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
bundler (~> 1.0)
|
80
|
+
jeweler (~> 1.8.7)
|
81
|
+
rdoc (~> 3.12)
|
82
|
+
rest-client
|
83
|
+
shoulda
|
84
|
+
simplecov
|
85
|
+
yajl-ruby
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2013 Obi Akubue, obi-akubue.org
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= ragios-client
|
2
|
+
|
3
|
+
Documentation coming soon.
|
4
|
+
|
5
|
+
== Specifications
|
6
|
+
require 'ragios-client'
|
7
|
+
|
8
|
+
ragios = Ragios::Client.new
|
9
|
+
|
10
|
+
ragios = Ragios::Client.new(username: 'admin', password: 'password')
|
11
|
+
|
12
|
+
ragios = Ragios::Client.new(address: 'http://localhost', port: '5041')
|
13
|
+
|
14
|
+
ragios = Ragios::Client.new(username: 'admin', password: 'password', address: 'http://localhost', port: '5041')
|
15
|
+
|
16
|
+
ragios.login('admin', 'password')
|
17
|
+
|
18
|
+
monitors = [{monitor: "my website",
|
19
|
+
every: "5m",
|
20
|
+
url: "http://mywebsite.com",
|
21
|
+
via: "twtter_notifier",
|
22
|
+
plugin: "url_monitor"
|
23
|
+
}]
|
24
|
+
|
25
|
+
ragios.add monitors
|
26
|
+
|
27
|
+
ragios.find(monitor_id)
|
28
|
+
|
29
|
+
ragios.all
|
30
|
+
|
31
|
+
ragios.stop(monitor_id)
|
32
|
+
|
33
|
+
ragios.restart(monitor_id)
|
34
|
+
|
35
|
+
ragios.delete(monitor_id)
|
36
|
+
|
37
|
+
ragios.find_by(options)
|
38
|
+
|
39
|
+
ragios.update(monitor_id, options)
|
40
|
+
|
41
|
+
ragios.test(monitor_id)
|
42
|
+
|
43
|
+
ragios.address
|
44
|
+
#=> http://localhost
|
45
|
+
|
46
|
+
ragios.port
|
47
|
+
#=> 5041
|
48
|
+
|
49
|
+
|
50
|
+
== Copyright
|
51
|
+
|
52
|
+
Copyright (c) 2013 obi-a. See LICENSE.txt for
|
53
|
+
further details.
|
54
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "ragios-client"
|
18
|
+
gem.homepage = "http://github.com/obi-a/ragios-client"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby client for ragios}
|
21
|
+
gem.description = %Q{ruby client for ragios}
|
22
|
+
gem.email = "obioraakubue@yahoo.com"
|
23
|
+
gem.authors = ["obi-a"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
#require 'rcov/rcovtask'
|
36
|
+
#Rcov::RcovTask.new do |test|
|
37
|
+
# test.libs << 'test'
|
38
|
+
# test.pattern = 'test/**/test_*.rb'
|
39
|
+
# test.verbose = true
|
40
|
+
# test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
#end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "ragios-client #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'yajl'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Ragios
|
6
|
+
|
7
|
+
class ClientException < StandardError; end
|
8
|
+
|
9
|
+
class Client
|
10
|
+
attr_reader :address
|
11
|
+
attr_reader :port
|
12
|
+
attr_reader :username
|
13
|
+
attr_reader :password
|
14
|
+
|
15
|
+
def initialize(args = {})
|
16
|
+
@address = args.fetch(:address, 'http://127.0.0.1')
|
17
|
+
@port = args.fetch(:port, '5041')
|
18
|
+
@username = args.fetch(:username, '')
|
19
|
+
@password = args.fetch(:password, '')
|
20
|
+
end
|
21
|
+
|
22
|
+
def login(username,password)
|
23
|
+
@username = username
|
24
|
+
@password = password
|
25
|
+
auth_session
|
26
|
+
end
|
27
|
+
|
28
|
+
def add(monitors)
|
29
|
+
response = RestClient.post "#{address_port}/monitors/", json(monitors), http_request_options
|
30
|
+
parse_json(response.body)
|
31
|
+
rescue => e
|
32
|
+
raise ClientException, e.response
|
33
|
+
end
|
34
|
+
|
35
|
+
def find(monitor_id)
|
36
|
+
response = RestClient.get "#{address_port}/monitors/#{monitor_id}/", auth_cookie
|
37
|
+
parse_json(response.body)
|
38
|
+
rescue => e
|
39
|
+
raise ClientException, e.response
|
40
|
+
end
|
41
|
+
|
42
|
+
def all
|
43
|
+
response = RestClient.get "#{address_port}/monitors/", auth_cookie
|
44
|
+
parse_json(response.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def stop(monitor_id)
|
48
|
+
response = RestClient.put "#{address_port}/monitors/#{monitor_id}",{:status => "stopped"}, http_request_options
|
49
|
+
parse_json(response)
|
50
|
+
rescue => e
|
51
|
+
raise ClientException, e.response
|
52
|
+
end
|
53
|
+
|
54
|
+
def restart(monitor_id)
|
55
|
+
response = RestClient.put "#{address_port}/monitors/#{monitor_id}",{:status => "active"},http_request_options
|
56
|
+
parse_json(response)
|
57
|
+
rescue => e
|
58
|
+
raise ClientException, e.response
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete(monitor_id)
|
62
|
+
response = RestClient.delete "#{address_port}/monitors/#{monitor_id}", auth_cookie
|
63
|
+
parse_json(response)
|
64
|
+
rescue => e
|
65
|
+
raise ClientException, e.response
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_by(options)
|
69
|
+
response = RestClient.get "#{address_port}/monitors?#{URI.encode_www_form(options)}", auth_cookie
|
70
|
+
parse_json(response)
|
71
|
+
end
|
72
|
+
|
73
|
+
def update(monitor_id, options)
|
74
|
+
response = RestClient.put "#{address_port}/monitors/#{monitor_id}",json(options), http_request_options
|
75
|
+
parse_json(response)
|
76
|
+
rescue => e
|
77
|
+
raise ClientException, e.response
|
78
|
+
end
|
79
|
+
|
80
|
+
def test(monitor_id)
|
81
|
+
response = RestClient.post "#{address_port}/tests", {:id => monitor_id}, http_request_options
|
82
|
+
parse_json(response)
|
83
|
+
rescue => e
|
84
|
+
raise ClientException, e.response
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def auth_cookie
|
90
|
+
{:cookies => {:AuthSession => auth_session}}
|
91
|
+
end
|
92
|
+
|
93
|
+
def http_request_options
|
94
|
+
{:content_type => :json,
|
95
|
+
:cookies => {:AuthSession => auth_session}
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
def address_port
|
100
|
+
"#{@address}:#{@port}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def json(str)
|
104
|
+
Yajl::Encoder.encode(str)
|
105
|
+
end
|
106
|
+
|
107
|
+
def parse_json(str)
|
108
|
+
Yajl::Parser.parse(str, :symbolize_keys => true)
|
109
|
+
end
|
110
|
+
|
111
|
+
def auth_session
|
112
|
+
#deal with performance when it becomes a problem not yet a priority
|
113
|
+
auth = RestClient.post "#{address_port}/session", { :username=> @username, :password => @password}
|
114
|
+
hash = Yajl::Parser.parse(auth.to_str)
|
115
|
+
hash['AuthSession']
|
116
|
+
rescue => e
|
117
|
+
raise ClientException, e.response
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,390 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/ragios-client'))
|
3
|
+
|
4
|
+
#use for fast testing
|
5
|
+
plugin = "mock_plugin"
|
6
|
+
#using the url_monitor plugin will perform a real http request on each check leading to slow tests
|
7
|
+
#plugin = "url_monitor"
|
8
|
+
|
9
|
+
admin = 'admin'
|
10
|
+
password = 'ragios'
|
11
|
+
|
12
|
+
describe "Ragios Client" do
|
13
|
+
before(:each) do
|
14
|
+
@ragios = Ragios::Client.new(username: admin,password: password)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "adds a monitor" do
|
18
|
+
monitors = [{monitor: "Google",
|
19
|
+
url: "http://google.com",
|
20
|
+
every: "5m",
|
21
|
+
contact: "admin@mail.com",
|
22
|
+
via: ["gmail_notifier","twitter_notifier"],
|
23
|
+
plugin: plugin }]
|
24
|
+
|
25
|
+
returned_monitors = @ragios.add monitors
|
26
|
+
returned_monitors.first.should include(monitors.first)
|
27
|
+
monitor_id = returned_monitors.first[:_id]
|
28
|
+
|
29
|
+
#teardown
|
30
|
+
hash = @ragios.delete(monitor_id)
|
31
|
+
hash[:ok].should == true
|
32
|
+
end
|
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")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "cannot add a monitor with no notifier" do
|
49
|
+
monitors = [{monitor: "Google",
|
50
|
+
url: "http://google.com",
|
51
|
+
every: "5m",
|
52
|
+
contact: "admin@mail.com",
|
53
|
+
plugin: plugin }]
|
54
|
+
begin
|
55
|
+
@ragios.add monitors
|
56
|
+
rescue Exception => e
|
57
|
+
e.should be_an_instance_of Ragios::ClientException
|
58
|
+
e.message.should include("No Notifier Found")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "cannot add a badly formed monitor" do
|
63
|
+
expect{@ragios.add("bad data")}.to raise_error(Ragios::ClientException)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should retrieve a monitor by id" do
|
67
|
+
#setup starts
|
68
|
+
unique_name = "Google #{Time.now.to_i}"
|
69
|
+
monitors = [{monitor: unique_name,
|
70
|
+
url: "http://google.com",
|
71
|
+
every: "5m",
|
72
|
+
contact: "admin@mail.com",
|
73
|
+
via: ["gmail_notifier"],
|
74
|
+
plugin: plugin }]
|
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")
|
93
|
+
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
|
+
|
110
|
+
options = {tag: 'test', every: '5m', monitor: unique_name}
|
111
|
+
found_monitors = @ragios.find_by(options)
|
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.find_by(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(Ragios::ClientException)
|
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")
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it "tests a monitor" do
|
180
|
+
#setup starts
|
181
|
+
unique_name = "Google #{Time.now.to_i}"
|
182
|
+
monitors = [{monitor: unique_name,
|
183
|
+
url: "http://google.com",
|
184
|
+
every: "5m",
|
185
|
+
contact: "admin@mail.com",
|
186
|
+
via: ["gmail_notifier"],
|
187
|
+
plugin: plugin }]
|
188
|
+
|
189
|
+
returned_monitors = @ragios.add monitors
|
190
|
+
monitor_id = returned_monitors.first[:_id]
|
191
|
+
#setup ends
|
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")
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
it "deletes a monitor" do
|
212
|
+
#setup starts
|
213
|
+
unique_name = "Google #{Time.now.to_i}"
|
214
|
+
monitors = [{monitor: unique_name,
|
215
|
+
url: "http://google.com",
|
216
|
+
every: "5m",
|
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}")
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
it "cannot delete a monitor that doesnt exist" do
|
236
|
+
monitor_id = "dont_exist"
|
237
|
+
begin
|
238
|
+
@ragios.find(monitor_id)
|
239
|
+
rescue => e
|
240
|
+
e.should be_an_instance_of Ragios::ClientException
|
241
|
+
e.message.should include("No monitor found with id = #{monitor_id}")
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
it "stops an active monitor" do
|
246
|
+
#setup starts
|
247
|
+
unique_name = "Google #{Time.now.to_i}"
|
248
|
+
monitors = [{monitor: unique_name,
|
249
|
+
url: "http://google.com",
|
250
|
+
every: "5m",
|
251
|
+
contact: "admin@mail.com",
|
252
|
+
via: ["gmail_notifier"],
|
253
|
+
plugin: plugin }]
|
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}")
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
it "restarts a stopped monitor" do
|
288
|
+
#setup starts
|
289
|
+
unique_name = "Google #{Time.now.to_i}"
|
290
|
+
monitors = [{monitor: unique_name,
|
291
|
+
url: "http://google.com",
|
292
|
+
every: "5m",
|
293
|
+
contact: "admin@mail.com",
|
294
|
+
via: ["gmail_notifier"],
|
295
|
+
plugin: plugin }]
|
296
|
+
|
297
|
+
returned_monitors = @ragios.add monitors
|
298
|
+
monitor_id = returned_monitors.first[:_id]
|
299
|
+
#setup ends
|
300
|
+
|
301
|
+
@ragios.stop(monitor_id)
|
302
|
+
stopped_monitor = @ragios.find(monitor_id)
|
303
|
+
stopped_monitor[:status_].should == "stopped"
|
304
|
+
|
305
|
+
hash = @ragios.restart(monitor_id)
|
306
|
+
hash[:ok].should == true
|
307
|
+
|
308
|
+
active_monitor = @ragios.find(monitor_id)
|
309
|
+
active_monitor[:status_].should == "active"
|
310
|
+
|
311
|
+
#restart monitor is idempotent
|
312
|
+
hash = @ragios.restart(monitor_id)
|
313
|
+
hash[:ok].should == true
|
314
|
+
|
315
|
+
#teardown
|
316
|
+
hash = @ragios.delete(monitor_id)
|
317
|
+
hash[:ok].should == true
|
318
|
+
end
|
319
|
+
|
320
|
+
it "cannot restart a monitor that dont exist" do
|
321
|
+
monitor_id = "dont_exist"
|
322
|
+
begin
|
323
|
+
@ragios.restart(monitor_id)
|
324
|
+
rescue => e
|
325
|
+
e.should be_an_instance_of Ragios::ClientException
|
326
|
+
e.message.should include("No monitor found with id = #{monitor_id}")
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
it "accepts correct login credentials" do
|
331
|
+
expect{ @ragios.login(admin, password) }.to_not raise_error
|
332
|
+
end
|
333
|
+
|
334
|
+
it "rejects incorrect login credentials" do
|
335
|
+
begin
|
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
|
364
|
+
end
|
365
|
+
|
366
|
+
it "has default settings" do
|
367
|
+
ragios_client = Ragios::Client.new
|
368
|
+
ragios_client.address.should == "http://127.0.0.1"
|
369
|
+
ragios_client.port.should == "5041"
|
370
|
+
ragios_client.username.should == ""
|
371
|
+
ragios_client.password.should == ""
|
372
|
+
end
|
373
|
+
|
374
|
+
it "accepts new default address" do
|
375
|
+
ragios_client = Ragios::Client.new(address: 'http://mysite.com', port: '6802')
|
376
|
+
ragios_client.address.should == "http://mysite.com"
|
377
|
+
ragios_client.port.should == "6802"
|
378
|
+
ragios_client.username.should == ""
|
379
|
+
ragios_client.password.should == ""
|
380
|
+
end
|
381
|
+
|
382
|
+
it "accepts new default login credentials" do
|
383
|
+
ragios_client = Ragios::Client.new(username: 'superadmin', password: 'abc123')
|
384
|
+
ragios_client.address.should == "http://127.0.0.1"
|
385
|
+
ragios_client.port.should == "5041"
|
386
|
+
ragios_client.username.should == "superadmin"
|
387
|
+
ragios_client.password.should == "abc123"
|
388
|
+
end
|
389
|
+
|
390
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ragios-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- obi-a
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: yajl-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.7
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.7
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: simplecov
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: ruby client for ragios
|
127
|
+
email: obioraakubue@yahoo.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.rdoc
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.rdoc
|
139
|
+
- Rakefile
|
140
|
+
- VERSION
|
141
|
+
- lib/ragios-client.rb
|
142
|
+
- spec/ragios-client_spec.rb
|
143
|
+
homepage: http://github.com/obi-a/ragios-client
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ! '>='
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
hash: 683079085202571979
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 1.8.24
|
168
|
+
signing_key:
|
169
|
+
specification_version: 3
|
170
|
+
summary: Ruby client for ragios
|
171
|
+
test_files: []
|