opsview_rest 0.4.4 → 0.4.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/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +67 -0
- data/.travis.yml +1 -6
- data/Gemfile +0 -2
- data/Rakefile +3 -3
- data/lib/opsview_rest.rb +29 -34
- data/lib/opsview_rest/attribute.rb +10 -12
- data/lib/opsview_rest/contact.rb +45 -47
- data/lib/opsview_rest/host.rb +52 -54
- data/lib/opsview_rest/hostcheckcommand.rb +9 -11
- data/lib/opsview_rest/hostgroup.rb +7 -9
- data/lib/opsview_rest/hosttemplate.rb +7 -9
- data/lib/opsview_rest/keyword.rb +17 -19
- data/lib/opsview_rest/mixin.rb +8 -10
- data/lib/opsview_rest/monitoringserver.rb +11 -13
- data/lib/opsview_rest/notificationmethod.rb +9 -11
- data/lib/opsview_rest/role.rb +19 -21
- data/lib/opsview_rest/servicecheck.rb +31 -33
- data/lib/opsview_rest/servicegroup.rb +5 -7
- data/lib/opsview_rest/timeperiod.rb +19 -21
- data/opsview_rest.gemspec +16 -16
- data/spec/opsview_rest_spec.rb +42 -27
- data/spec/spec_helper.rb +2 -2
- metadata +19 -17
@@ -2,40 +2,38 @@ require 'opsview_rest/mixin'
|
|
2
2
|
|
3
3
|
class OpsviewRest
|
4
4
|
class Timeperiod
|
5
|
-
|
6
5
|
include OpsviewRest::Mixin
|
7
6
|
|
8
7
|
attr_accessor :options, :opsview, :resource_type
|
9
8
|
|
10
9
|
def initialize(opsview, options = {})
|
11
10
|
@options = {
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
11
|
+
name: 'nonworkhours',
|
12
|
+
monday: '00:00-09:00,17:00-24:00',
|
13
|
+
tuesday: '00:00-09:00,17:00-24:00',
|
14
|
+
wednesday: '00:00-09:00,17:00-24:00',
|
15
|
+
thursday: '00:00-09:00,17:00-24:00',
|
16
|
+
friday: '00:00-09:00,17:00-24:00',
|
17
|
+
saturday: '00:00-24:00',
|
18
|
+
sunday: '00:00-24:00',
|
19
|
+
servicecheck_notification_periods: [],
|
20
|
+
servicecheck_check_periods: [],
|
21
|
+
host_check_periods: [],
|
22
|
+
alias: 'Non-work hours',
|
23
|
+
host_notification_periods: [],
|
24
|
+
save: true,
|
25
|
+
replace: false
|
27
26
|
}.update options
|
28
27
|
|
29
28
|
@opsview = opsview
|
30
29
|
@resource_type = @options[:type]
|
31
30
|
|
32
|
-
@options[:servicecheck_notification_periods] = @options[:servicecheck_notification_periods].map { |x| {
|
33
|
-
@options[:servicecheck_check_periods] = @options[:servicecheck_check_periods].map { |x| {
|
34
|
-
@options[:host_check_periods] = @options[:host_check_periods].map { |x| {
|
35
|
-
@options[:host_notification_periods] = @options[:host_notification_periods].map { |x| {
|
31
|
+
@options[:servicecheck_notification_periods] = @options[:servicecheck_notification_periods].map { |x| { 'name' => x } } unless @options[:servicecheck_notification_periods].nil?
|
32
|
+
@options[:servicecheck_check_periods] = @options[:servicecheck_check_periods].map { |x| { 'name' => x } } unless @options[:servicecheck_check_periods].nil?
|
33
|
+
@options[:host_check_periods] = @options[:host_check_periods].map { |x| { 'name' => x } } unless @options[:host_check_periods].nil?
|
34
|
+
@options[:host_notification_periods] = @options[:host_notification_periods].map { |x| { 'name' => x } } unless @options[:host_notification_periods].nil?
|
36
35
|
|
37
36
|
save(@options[:replace]) if @options[:save]
|
38
37
|
end
|
39
|
-
|
40
38
|
end
|
41
39
|
end
|
data/opsview_rest.gemspec
CHANGED
@@ -3,26 +3,26 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
|
-
gem.name =
|
7
|
-
gem.summary = %
|
8
|
-
gem.description = %
|
9
|
-
gem.email =
|
10
|
-
gem.homepage =
|
11
|
-
gem.authors = [
|
12
|
-
gem.license = 'Apache'
|
6
|
+
gem.name = 'opsview_rest'
|
7
|
+
gem.summary = %(Opsview REST API library)
|
8
|
+
gem.description = %(Update configuration on Opsview server via REST API)
|
9
|
+
gem.email = 'cp@redbluemagenta.com'
|
10
|
+
gem.homepage = 'http://github.com/cparedes/opsview_rest'
|
11
|
+
gem.authors = ['Christian Paredes']
|
12
|
+
gem.license = 'Apache-2.0'
|
13
13
|
|
14
|
-
gem.files = `git ls-files`.split(
|
15
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.require_paths = ['lib']
|
18
18
|
|
19
|
-
gem.add_development_dependency
|
20
|
-
gem.add_development_dependency
|
21
|
-
gem.add_development_dependency
|
22
|
-
gem.add_development_dependency
|
19
|
+
gem.add_development_dependency 'rake', '~> 11.3.0'
|
20
|
+
gem.add_development_dependency 'rspec', '~> 3.5.0'
|
21
|
+
gem.add_development_dependency 'yard', '~> 0.9.5'
|
22
|
+
gem.add_development_dependency 'webmock', '~> 2.1.0'
|
23
23
|
|
24
|
-
gem.add_dependency 'json', '~>
|
25
|
-
gem.add_dependency 'rest-client', '~>
|
24
|
+
gem.add_dependency 'json', '~> 2.0.2'
|
25
|
+
gem.add_dependency 'rest-client', '~> 2.0.0'
|
26
26
|
|
27
|
-
gem.version = '0.4.
|
27
|
+
gem.version = '0.4.5'
|
28
28
|
end
|
data/spec/opsview_rest_spec.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OpsviewRest do
|
4
|
-
|
5
|
-
let(:opsview_rest) { OpsviewRest.new("https://example.com", :username => "hi", :password => "hello") }
|
4
|
+
let(:opsview_rest) { OpsviewRest.new('https://example.com', username: 'hi', password: 'hello') }
|
6
5
|
|
7
6
|
before :each do
|
8
|
-
stub_request(:post,
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
stub_request(:post, 'https://example.com/rest/login')
|
8
|
+
.with(body: '{"username":"hi","password":"hello"}',
|
9
|
+
headers: { 'Content-Length' => '36', 'Content-Type' => 'application/json' })
|
10
|
+
.to_return(status: 200, body: fixture('login_key'))
|
12
11
|
end
|
13
12
|
|
14
13
|
describe '#new' do
|
@@ -23,7 +22,7 @@ describe OpsviewRest do
|
|
23
22
|
describe '#login' do
|
24
23
|
it 'can login' do
|
25
24
|
login_response = opsview_rest.login
|
26
|
-
login_response.to_json.should eql
|
25
|
+
login_response.to_json.should eql '{"token":"88dffa0974c364e56431697f257564fb1524b029"}'
|
27
26
|
end
|
28
27
|
|
29
28
|
it 'stores login token from login command' do
|
@@ -35,45 +34,61 @@ describe OpsviewRest do
|
|
35
34
|
|
36
35
|
describe '#list' do
|
37
36
|
it 'returns list of hosts by default' do
|
38
|
-
stub_request(:get,
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
stub_request(:get, 'https://example.com/rest/config/host?rows=all')
|
38
|
+
.with(headers: { 'Accept' => '*/*',
|
39
|
+
'Accept-Encoding' => 'gzip, deflate',
|
40
|
+
'Content-Type' => 'application/json',
|
41
|
+
'Host' => 'example.com',
|
42
|
+
'User-Agent' => %r{rest-client\/2\.0\.0.*},
|
43
|
+
'X-Opsview-Token' => '88dffa0974c364e56431697f257564fb1524b029',
|
44
|
+
'X-Opsview-Username' => 'hi' })
|
45
|
+
.to_return(status: 200, body: fixture('list'), headers: {})
|
42
46
|
list_response = opsview_rest.list
|
43
|
-
list_response.to_s.should include
|
47
|
+
list_response.to_s.should include 'Network - Base',
|
48
|
+
'Monitoring Servers', '/images/logos/opsview_small.png',
|
49
|
+
'Application - Opsview Master'
|
44
50
|
end
|
45
51
|
|
46
52
|
it 'returns a full list for a given value' do
|
47
|
-
stub_request(:get,
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
stub_request(:get, 'https://example.com/rest/config/hosttemplate?rows=all')
|
54
|
+
.with(headers: { 'Accept' => '*/*',
|
55
|
+
'Accept-Encoding' => 'gzip, deflate',
|
56
|
+
'Content-Type' => 'application/json',
|
57
|
+
'Host' => 'example.com',
|
58
|
+
'User-Agent' => %r{rest-client\/2\.0\.0.*},
|
59
|
+
'X-Opsview-Token' => '88dffa0974c364e56431697f257564fb1524b029',
|
60
|
+
'X-Opsview-Username' => 'hi' })
|
61
|
+
.to_return(status: 200, body: fixture('list_hosttemplate'))
|
62
|
+
list_response_hosttemplate = opsview_rest.list(type: 'hosttemplate')
|
63
|
+
list_response_hosttemplate.to_s.should include 'Opsview Housekeeping Cronjob Monitor',
|
64
|
+
'Microsoft Active Directory',
|
65
|
+
'Apache current requests'
|
53
66
|
end
|
54
67
|
end
|
55
68
|
|
56
69
|
describe '#reload' do
|
57
70
|
it 'returns current reload status' do
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
71
|
+
stub_request(:get, 'https://example.com/rest/reload')
|
72
|
+
.with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip, deflate',
|
73
|
+
'Content-Type' => 'application/json',
|
74
|
+
'Host' => 'example.com',
|
75
|
+
'User-Agent' => %r{rest-client\/2\.0\.0.*},
|
76
|
+
'X-Opsview-Token' => '88dffa0974c364e56431697f257564fb1524b029',
|
77
|
+
'X-Opsview-Username' => 'hi' })
|
78
|
+
.to_return(status: 200, body: fixture('reload'))
|
63
79
|
opsview_rest.reload
|
64
80
|
end
|
65
81
|
end
|
66
82
|
|
67
83
|
describe '#find' do
|
68
84
|
it 'returns an error if name is nil' do
|
69
|
-
expect {opsview_rest.find}.to raise_error ArgumentError,
|
85
|
+
expect { opsview_rest.find }.to raise_error ArgumentError, 'Need to specify the name of the object.'
|
70
86
|
end
|
71
87
|
end
|
72
88
|
|
73
89
|
describe '#purge' do
|
74
90
|
it 'returns an error if name is nil' do
|
75
|
-
expect {opsview_rest.purge}.to raise_error ArgumentError,
|
91
|
+
expect { opsview_rest.purge }.to raise_error ArgumentError, 'Need to specify the name of the object.'
|
76
92
|
end
|
77
93
|
end
|
78
|
-
|
79
|
-
end
|
94
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Paredes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,92 +16,94 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 11.3.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 11.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.5.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: yard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.9.5
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.9.5
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 2.1.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 2.1.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: json
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.0.2
|
76
76
|
type: :runtime
|
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:
|
82
|
+
version: 2.0.2
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rest-client
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 2.0.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 2.0.0
|
97
97
|
description: Update configuration on Opsview server via REST API
|
98
|
-
email:
|
98
|
+
email: cp@redbluemagenta.com
|
99
99
|
executables: []
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
103
|
- ".gitignore"
|
104
104
|
- ".rspec"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- ".rubocop_todo.yml"
|
105
107
|
- ".travis.yml"
|
106
108
|
- Gemfile
|
107
109
|
- LICENSE
|
@@ -133,7 +135,7 @@ files:
|
|
133
135
|
- spec/spec_helper.rb
|
134
136
|
homepage: http://github.com/cparedes/opsview_rest
|
135
137
|
licenses:
|
136
|
-
- Apache
|
138
|
+
- Apache-2.0
|
137
139
|
metadata: {}
|
138
140
|
post_install_message:
|
139
141
|
rdoc_options: []
|
@@ -151,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
153
|
version: '0'
|
152
154
|
requirements: []
|
153
155
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.6.11
|
155
157
|
signing_key:
|
156
158
|
specification_version: 4
|
157
159
|
summary: Opsview REST API library
|