opsview_rest 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpsviewRest do
4
+
5
+ let(:opsview_rest) { OpsviewRest.new("https://example.com", :username => "hi", :password => "hello") }
6
+
7
+ before :each do
8
+ stub_request(:post, "https://example.com/rest/login").
9
+ with(:body => "{\"username\":\"hi\",\"password\":\"hello\"}",
10
+ :headers => {'Content-Length'=>'36', 'Content-Type'=>'application/json'}).
11
+ to_return(:status => 200, :body => fixture("login_key"))
12
+ end
13
+
14
+ describe '#new' do
15
+ it 'can create an object with given parameters' do
16
+ opsview_rest.username.should eql 'hi'
17
+ opsview_rest.password.should eql 'hello'
18
+ opsview_rest.rest.should be_an_instance_of RestClient::Resource
19
+ opsview_rest.rest.url.should eql 'https://example.com/rest/'
20
+ end
21
+ end
22
+
23
+ describe '#login' do
24
+ it 'can login' do
25
+ login_response = opsview_rest.login
26
+ login_response.to_json.should eql "{\"token\":\"88dffa0974c364e56431697f257564fb1524b029\"}"
27
+ end
28
+
29
+ it 'stores login token from login command' do
30
+ login_response = opsview_rest.login
31
+ opsview_rest.rest.headers[:x_opsview_username].should eql 'hi'
32
+ opsview_rest.rest.headers[:x_opsview_token].should eql '88dffa0974c364e56431697f257564fb1524b029'
33
+ end
34
+ end
35
+
36
+ describe '#list' do
37
+ it 'returns list of hosts by default' do
38
+ stub_request(:get, "https://example.com/rest/config/host?rows=all").
39
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'X-Opsview-Token'=>'88dffa0974c364e56431697f257564fb1524b029', 'X-Opsview-Username'=>'hi'}).
40
+ to_return(:status => 200, :body => fixture('list'))
41
+
42
+ list_response = opsview_rest.list
43
+ list_response.to_s.should include "Network - Base", "Monitoring Servers", "/images/logos/opsview_small.png", "Application - Opsview Master"
44
+ end
45
+
46
+ it 'returns a full list for a given value' do
47
+ stub_request(:get, "https://example.com/rest/config/hosttemplate?rows=all").
48
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby', 'X-Opsview-Token'=>'88dffa0974c364e56431697f257564fb1524b029', 'X-Opsview-Username'=>'hi'}).
49
+ to_return(:status => 200, :body => fixture('list_hosttemplate'))
50
+
51
+ list_response_hosttemplate = opsview_rest.list(:type => 'hosttemplate')
52
+ list_response_hosttemplate.to_s.should include "Opsview Housekeeping Cronjob Monitor", "Microsoft Active Directory", "Apache current requests"
53
+ end
54
+ end
55
+
56
+ describe '#reload' do
57
+ it 'returns current reload status' do
58
+ pending 'Gives no response'
59
+ stub_request(:get, "https://example.com/rest/reload").
60
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby', 'X-Opsview-Token'=>'88dffa0974c364e56431697f257564fb1524b029', 'X-Opsview-Username'=>'hi'}).
61
+ to_return(:status => 200, :body => fixture('reload'))
62
+
63
+ opsview_rest.reload
64
+ end
65
+ end
66
+
67
+ describe '#find' do
68
+ it 'returns an error if name is nil' do
69
+ expect {opsview_rest.find}.to raise_error ArgumentError, "Need to specify the name of the object."
70
+ end
71
+ end
72
+
73
+ describe '#purge' do
74
+ it 'returns an error if name is nil' do
75
+ expect {opsview_rest.purge}.to raise_error ArgumentError, "Need to specify the name of the object."
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,17 @@
1
+ require 'webmock/rspec'
2
+ require 'opsview_rest'
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ config.order = 'random'
9
+ end
10
+
11
+ def project_path
12
+ File.expand_path("../..", __FILE__)
13
+ end
14
+
15
+ def fixture(fixture_name)
16
+ File.new(project_path + "/spec/fixtures/#{fixture_name}.json")
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsview_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Paredes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-15 00:00:00.000000000 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -99,9 +99,41 @@ email: christian.paredes@seattlebiomed.org
99
99
  executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files: []
102
- files: []
102
+ files:
103
+ - .gitignore
104
+ - .rspec
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - TODO.md
111
+ - lib/opsview_rest.rb
112
+ - lib/opsview_rest/attribute.rb
113
+ - lib/opsview_rest/contact.rb
114
+ - lib/opsview_rest/host.rb
115
+ - lib/opsview_rest/hostcheckcommand.rb
116
+ - lib/opsview_rest/hostgroup.rb
117
+ - lib/opsview_rest/hosttemplate.rb
118
+ - lib/opsview_rest/keyword.rb
119
+ - lib/opsview_rest/mixin.rb
120
+ - lib/opsview_rest/monitoringserver.rb
121
+ - lib/opsview_rest/notificationmethod.rb
122
+ - lib/opsview_rest/role.rb
123
+ - lib/opsview_rest/servicecheck.rb
124
+ - lib/opsview_rest/servicegroup.rb
125
+ - lib/opsview_rest/timeperiod.rb
126
+ - opsview_rest.gemspec
127
+ - spec/fixtures/list.json
128
+ - spec/fixtures/list_hosttemplate.json
129
+ - spec/fixtures/login_key.json
130
+ - spec/fixtures/logout.json
131
+ - spec/fixtures/reload.json
132
+ - spec/opsview_rest_spec.rb
133
+ - spec/spec_helper.rb
103
134
  homepage: http://github.com/cparedes/opsview_rest
104
- licenses: []
135
+ licenses:
136
+ - Apache
105
137
  metadata: {}
106
138
  post_install_message:
107
139
  rdoc_options: []
@@ -123,5 +155,12 @@ rubygems_version: 2.0.3
123
155
  signing_key:
124
156
  specification_version: 4
125
157
  summary: Opsview REST API library
126
- test_files: []
158
+ test_files:
159
+ - spec/fixtures/list.json
160
+ - spec/fixtures/list_hosttemplate.json
161
+ - spec/fixtures/login_key.json
162
+ - spec/fixtures/logout.json
163
+ - spec/fixtures/reload.json
164
+ - spec/opsview_rest_spec.rb
165
+ - spec/spec_helper.rb
127
166
  has_rdoc: