zenoss_client 0.6.1 → 0.10.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.
Files changed (30) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +9 -7
  3. data/README.rdoc +0 -0
  4. data/VERSION +1 -1
  5. data/lib/zenoss.rb +1 -1
  6. data/lib/zenoss/connection.rb +1 -0
  7. data/lib/zenoss/events/event.rb +14 -2
  8. data/lib/zenoss/jsonapi/device_router.rb +30 -2
  9. data/lib/zenoss/jsonapi/events_router.rb +12 -0
  10. data/lib/zenoss/jsonapi/report_router.rb +6 -2
  11. data/lib/zenoss/model/devices/device.rb +6 -1
  12. data/lib/zenoss/model/z_device_loader.rb +1 -1
  13. data/test/fixtures/vcr_cassettes/6_2_1_initial_connection.yml +232 -0
  14. data/test/fixtures/vcr_cassettes/6_2_1_test_0001_returns_an_Array_of_devices_when_searched_by_name.yml +107 -0
  15. data/test/fixtures/vcr_cassettes/6_2_1_test_0002_returns_device_uptime_when_asked.yml +131 -0
  16. data/test/fixtures/vcr_cassettes/6_2_1_test_0003_returns_an_Array_of_events_for_a_device.yml +100 -0
  17. data/test/fixtures/vcr_cassettes/6_2_1_test_0004_returns_an_Array_of_historical_events_for_a_device.yml +100 -0
  18. data/test/fixtures/vcr_cassettes/6_2_1_test_0005_returns_info_for_a_device_in_the_form_of_a_Hash.yml +265 -0
  19. data/test/fixtures/vcr_cassettes/6_2_1_test_0006_returns_an_Array_of_events_for_all_devices.yml +100 -0
  20. data/test/fixtures/vcr_cassettes/6_2_1_test_0007_fetches_the_report_tree.yml +164 -0
  21. data/test/fixtures/vcr_cassettes/6_2_1_test_0008_fetches_available_report_types_and_returns_a_Hash.yml +100 -0
  22. data/test/fixtures/vcr_cassettes/6_2_1_test_0009_renames_the_device.yml +184 -0
  23. data/test/fixtures/vcr_cassettes/6_2_1_test_0010_sets_info_for_a_device.yml +100 -0
  24. data/test/fixtures/vcr_cassettes/6_2_1_test_0011_sets_info_for_a_device_on_a_device_object.yml +100 -0
  25. data/test/fixtures/vcr_cassettes/6_2_1_test_0012_remodels_a_device.yml +99 -0
  26. data/test/test_helper.rb +14 -0
  27. data/test/zenoss_client_test.rb +89 -3
  28. data/test/zenoss_model_device_test.rb +25 -0
  29. data/zenoss_client.gemspec +3 -3
  30. metadata +38 -115
@@ -0,0 +1,100 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8080/zport/dmd/zport/dmd/device_router
6
+ body:
7
+ encoding: UTF-8
8
+ string: '[{"action":"DeviceRouter","method":"getDevices","data":[{"uid":"/zport/dmd/Devices","params":{"name":"UnitTestDevice"}}],"type":"rpc","tid":15}]'
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.3 (2016-11-21))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Mon, 25 Feb 2019 23:20:07 GMT
16
+ Content-Type:
17
+ - application/json; charset=utf-8
18
+ Cookie: ''
19
+ response:
20
+ status:
21
+ code: 200
22
+ message: OK
23
+ headers:
24
+ Content-Type:
25
+ - application/json
26
+ Date:
27
+ - Mon, 25 Feb 2019 23:20:08 GMT
28
+ Server: ''
29
+ Strict-Transport-Security:
30
+ - max-age=31536000
31
+ Vary:
32
+ - Accept-Encoding
33
+ X-Frame-Options:
34
+ - SAMEORIGIN
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ Content-Length:
38
+ - '1064'
39
+ Set-Cookie: ''
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"uuid": "6245a13a-8add-4ee0-a04d-8e6206b8d8c8", "action": "DeviceRouter",
43
+ "result": {"totalCount": 1, "hash": "1", "success": true, "devices": [{"ipAddressString":
44
+ null, "serialNumber": "", "pythonClass": "Products.ZenModel.Device", "hwManufacturer":
45
+ null, "collector": "zencollector01", "osModel": null, "productionState": -1,
46
+ "systems": [], "priority": 3, "hwModel": null, "tagNumber": "", "osManufacturer":
47
+ null, "location": null, "groups": [{"uid": "/zport/dmd/Groups/BackboneDevices",
48
+ "path": "/Groups/BackboneDevices", "uuid": "65142f38-df6e-482e-a74d-ec825af8e058",
49
+ "name": "/BackboneDevices"}], "uid": "/zport/dmd/Devices/Server/devices/UnitTestDevice",
50
+ "ipAddress": null, "events": {"info": {"count": 0, "acknowledged_count": 0},
51
+ "clear": {"count": 0, "acknowledged_count": 0}, "warning": {"count": 0, "acknowledged_count":
52
+ 0}, "critical": {"count": 0, "acknowledged_count": 0}, "error": {"count":
53
+ 0, "acknowledged_count": 0}, "debug": {"count": 0, "acknowledged_count": 0}},
54
+ "name": "UnitTestDevice"}]}, "tid": 15, "type": "rpc", "method": "getDevices"}'
55
+ http_version:
56
+ recorded_at: Mon, 25 Feb 2019 23:20:08 GMT
57
+ - request:
58
+ method: post
59
+ uri: http://localhost:8080/zport/dmd/zport/dmd/device_router
60
+ body:
61
+ encoding: UTF-8
62
+ string: '[{"action":"DeviceRouter","method":"setInfo","data":[{"uid":"/zport/dmd/Devices/Server/devices/UnitTestDevice","productionState":-1}],"type":"rpc","tid":16}]'
63
+ headers:
64
+ User-Agent:
65
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.3 (2016-11-21))
66
+ Accept:
67
+ - "*/*"
68
+ Date:
69
+ - Mon, 25 Feb 2019 23:20:08 GMT
70
+ Content-Type:
71
+ - application/json; charset=utf-8
72
+ Cookie: ''
73
+ response:
74
+ status:
75
+ code: 200
76
+ message: OK
77
+ headers:
78
+ Content-Type:
79
+ - application/json
80
+ Date:
81
+ - Mon, 25 Feb 2019 23:20:08 GMT
82
+ Server: ''
83
+ Strict-Transport-Security:
84
+ - max-age=31536000
85
+ Vary:
86
+ - Accept-Encoding
87
+ X-Frame-Options:
88
+ - SAMEORIGIN
89
+ X-Xss-Protection:
90
+ - 1; mode=block
91
+ Content-Length:
92
+ - '150'
93
+ Set-Cookie: ''
94
+ body:
95
+ encoding: UTF-8
96
+ string: '{"uuid": "7e7ea36e-b80b-4fa6-bb1f-3ba6ab104996", "action": "DeviceRouter",
97
+ "result": {"success": true}, "tid": 16, "type": "rpc", "method": "setInfo"}'
98
+ http_version:
99
+ recorded_at: Mon, 25 Feb 2019 23:20:08 GMT
100
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,100 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8080/zport/dmd/zport/dmd/device_router
6
+ body:
7
+ encoding: UTF-8
8
+ string: '[{"action":"DeviceRouter","method":"getDevices","data":[{"uid":"/zport/dmd/Devices","params":{"name":"UnitTestDevice"}}],"type":"rpc","tid":21}]'
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.3 (2016-11-21))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Mon, 25 Feb 2019 23:20:08 GMT
16
+ Content-Type:
17
+ - application/json; charset=utf-8
18
+ Cookie: ''
19
+ response:
20
+ status:
21
+ code: 200
22
+ message: OK
23
+ headers:
24
+ Content-Type:
25
+ - application/json
26
+ Date:
27
+ - Mon, 25 Feb 2019 23:20:08 GMT
28
+ Server: ''
29
+ Strict-Transport-Security:
30
+ - max-age=31536000
31
+ Vary:
32
+ - Accept-Encoding
33
+ X-Frame-Options:
34
+ - SAMEORIGIN
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ Content-Length:
38
+ - '1064'
39
+ Set-Cookie: ''
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"uuid": "9e2f968f-be4a-4cc2-836a-9e5687d3c86c", "action": "DeviceRouter",
43
+ "result": {"totalCount": 1, "hash": "1", "success": true, "devices": [{"ipAddressString":
44
+ null, "serialNumber": "", "pythonClass": "Products.ZenModel.Device", "hwManufacturer":
45
+ null, "collector": "zencollector01", "osModel": null, "productionState": -1,
46
+ "systems": [], "priority": 3, "hwModel": null, "tagNumber": "", "osManufacturer":
47
+ null, "location": null, "groups": [{"uid": "/zport/dmd/Groups/BackboneDevices",
48
+ "path": "/Groups/BackboneDevices", "uuid": "65142f38-df6e-482e-a74d-ec825af8e058",
49
+ "name": "/BackboneDevices"}], "uid": "/zport/dmd/Devices/Server/devices/UnitTestDevice",
50
+ "ipAddress": null, "events": {"info": {"count": 0, "acknowledged_count": 0},
51
+ "clear": {"count": 0, "acknowledged_count": 0}, "warning": {"count": 0, "acknowledged_count":
52
+ 0}, "critical": {"count": 0, "acknowledged_count": 0}, "error": {"count":
53
+ 0, "acknowledged_count": 0}, "debug": {"count": 0, "acknowledged_count": 0}},
54
+ "name": "UnitTestDevice"}]}, "tid": 21, "type": "rpc", "method": "getDevices"}'
55
+ http_version:
56
+ recorded_at: Mon, 25 Feb 2019 23:20:08 GMT
57
+ - request:
58
+ method: post
59
+ uri: http://localhost:8080/zport/dmd/zport/dmd/device_router
60
+ body:
61
+ encoding: UTF-8
62
+ string: '[{"action":"DeviceRouter","method":"setInfo","data":[{"uid":"/zport/dmd/Devices/Server/devices/UnitTestDevice","productionState":-1}],"type":"rpc","tid":22}]'
63
+ headers:
64
+ User-Agent:
65
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.3 (2016-11-21))
66
+ Accept:
67
+ - "*/*"
68
+ Date:
69
+ - Mon, 25 Feb 2019 23:20:08 GMT
70
+ Content-Type:
71
+ - application/json; charset=utf-8
72
+ Cookie: ''
73
+ response:
74
+ status:
75
+ code: 200
76
+ message: OK
77
+ headers:
78
+ Content-Type:
79
+ - application/json
80
+ Date:
81
+ - Mon, 25 Feb 2019 23:20:09 GMT
82
+ Server: ''
83
+ Strict-Transport-Security:
84
+ - max-age=31536000
85
+ Vary:
86
+ - Accept-Encoding
87
+ X-Frame-Options:
88
+ - SAMEORIGIN
89
+ X-Xss-Protection:
90
+ - 1; mode=block
91
+ Content-Length:
92
+ - '150'
93
+ Set-Cookie: ''
94
+ body:
95
+ encoding: UTF-8
96
+ string: '{"uuid": "25ba2f17-7cdd-4229-9a5f-7c4e1d0c240b", "action": "DeviceRouter",
97
+ "result": {"success": true}, "tid": 22, "type": "rpc", "method": "setInfo"}'
98
+ http_version:
99
+ recorded_at: Mon, 25 Feb 2019 23:20:09 GMT
100
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,99 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8080/zport/dmd/zport/dmd/device_router
6
+ body:
7
+ encoding: UTF-8
8
+ string: '[{"action":"DeviceRouter","method":"getDevices","data":[{"uid":"/zport/dmd/Devices","params":{"name":"UnitTestDevice"}}],"type":"rpc","tid":4}]'
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.3 (2016-11-21))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Wed, 15 Apr 2020 20:39:11 GMT
16
+ Content-Type:
17
+ - application/json; charset=utf-8
18
+ Cookie: ''
19
+ response:
20
+ status:
21
+ code: 200
22
+ message: OK
23
+ headers:
24
+ Content-Type:
25
+ - application/json
26
+ Date:
27
+ - Wed, 15 Apr 2020 20:39:11 GMT
28
+ Server: ''
29
+ Strict-Transport-Security:
30
+ - max-age=31536000
31
+ Vary:
32
+ - Accept-Encoding
33
+ X-Frame-Options:
34
+ - SAMEORIGIN
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ Content-Length:
38
+ - '905'
39
+ Set-Cookie: ''
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"uuid": "d7e1f3b6-bff3-4ac0-b915-974e7b57bd24", "action": "DeviceRouter",
43
+ "result": {"totalCount": 1, "hash": "1", "success": true, "devices": [{"ipAddressString":
44
+ null, "serialNumber": "", "pythonClass": "Products.ZenModel.Device", "hwManufacturer":
45
+ null, "collector": "localhost", "osModel": null, "productionState": 1000,
46
+ "systems": [], "priority": 3, "hwModel": null, "tagNumber": "", "osManufacturer":
47
+ null, "location": null, "groups": [], "uid": "/zport/dmd/Devices/Server/devices/UnitTestDevice",
48
+ "ipAddress": null, "events": {"info": {"count": 0, "acknowledged_count": 0},
49
+ "clear": {"count": 0, "acknowledged_count": 0}, "warning": {"count": 0, "acknowledged_count":
50
+ 0}, "critical": {"count": 0, "acknowledged_count": 0}, "error": {"count":
51
+ 0, "acknowledged_count": 0}, "debug": {"count": 0, "acknowledged_count": 0}},
52
+ "name": "UnitTestDevice"}]}, "tid": 4, "type": "rpc", "method": "getDevices"}'
53
+ http_version:
54
+ recorded_at: Wed, 15 Apr 2020 20:39:11 GMT
55
+ - request:
56
+ method: post
57
+ uri: http://localhost:8080/zport/dmd/zport/dmd/device_router
58
+ body:
59
+ encoding: UTF-8
60
+ string: '[{"action":"DeviceRouter","method":"remodel","data":[{"deviceUid":"/zport/dmd/Devices/Server/devices/UnitTestDevice","collectPlugins":"","background":false}],"type":"rpc","tid":5}]'
61
+ headers:
62
+ User-Agent:
63
+ - HTTPClient/1.0 (2.8.3, ruby 2.3.3 (2016-11-21))
64
+ Accept:
65
+ - "*/*"
66
+ Date:
67
+ - Wed, 15 Apr 2020 20:39:11 GMT
68
+ Content-Type:
69
+ - application/json; charset=utf-8
70
+ Cookie: ''
71
+ response:
72
+ status:
73
+ code: 200
74
+ message: OK
75
+ headers:
76
+ Content-Type:
77
+ - application/json
78
+ Date:
79
+ - Wed, 15 Apr 2020 20:40:46 GMT
80
+ Server: ''
81
+ Strict-Transport-Security:
82
+ - max-age=31536000
83
+ Vary:
84
+ - Accept-Encoding
85
+ X-Frame-Options:
86
+ - SAMEORIGIN
87
+ X-Xss-Protection:
88
+ - 1; mode=block
89
+ Content-Length:
90
+ - '166'
91
+ Set-Cookie: ''
92
+ body:
93
+ encoding: UTF-8
94
+ string: '{"uuid": "40e52e10-789f-4da0-b15a-b839dbce38ae", "action": "DeviceRouter",
95
+ "result": {"exitStatus": 0, "success": true}, "tid": 5, "type": "rpc", "method":
96
+ "remodel"}'
97
+ http_version:
98
+ recorded_at: Wed, 15 Apr 2020 20:40:46 GMT
99
+ recorded_with: VCR 4.0.0
@@ -17,4 +17,18 @@ WebMock.enable!
17
17
  VCR.configure do |config|
18
18
  config.cassette_library_dir = "test/fixtures/vcr_cassettes"
19
19
  config.hook_into :webmock
20
+
21
+ config.filter_sensitive_data('admin') { ZENOSS_USER }
22
+ config.filter_sensitive_data('http://localhost:8080/zport/dmd') { ZENOSS_URL }
23
+ config.filter_sensitive_data('zenoss') { ZENOSS_PASSWORD }
24
+
25
+ config.before_record do |interaction, cassette|
26
+ if cassette.name == '6.2.1_initial connection'
27
+ interaction.request.body = '__ac_name=admin&__ac_password=zenoss'\
28
+ '&submitted=true&came_from=https%3A%2F'\
29
+ '%2Fhttp:://localhost:8080/zport/dmd'\
30
+ '%2Fzport%2Fdmd'
31
+ end
32
+ end
20
33
  end
34
+
@@ -1,5 +1,4 @@
1
1
  require_relative './test_helper'
2
- require 'minitest/spec'
3
2
  require 'minitest/autorun'
4
3
  require 'logger'
5
4
 
@@ -12,7 +11,9 @@ describe Zenoss do
12
11
  def self.zen
13
12
  VCR.use_cassette "#{ZENOSS_VERSION}_initial connection", :match_requests_on => [:method, :path, :query] do
14
13
  @zen ||= begin
15
- connection = Zenoss.connect ZENOSS_URL, ZENOSS_USER, ZENOSS_PASSWORD
14
+ opts = {}
15
+ opts[:version] = ZENOSS_VERSION
16
+ connection = Zenoss.connect ZENOSS_URL, ZENOSS_USER, ZENOSS_PASSWORD, opts
16
17
  # We Need to Create A Device for testing
17
18
  # We do this here, so we can re-use the same device over and over
18
19
  # Without needing to create a new one per test
@@ -69,7 +70,7 @@ describe Zenoss do
69
70
  end
70
71
 
71
72
  before do
72
- VCR.insert_cassette gen_cassette_name, :match_requests_on => [:method, :path, :query]
73
+ VCR.insert_cassette gen_cassette_name, :match_requests_on => [:method, :path, :query], :allow_playback_repeats => true
73
74
  @zen = self.class.zen
74
75
  @dev = @zen.find_devices_by_name(TEST_DEVICE_NAME).first
75
76
  end
@@ -137,4 +138,89 @@ describe Zenoss do
137
138
  renamed_device.rename_device(TEST_DEVICE_NAME)
138
139
  end
139
140
  end
141
+
142
+ if ZENOSS_VERSION > '6'
143
+ it 'sets info for a device' do
144
+ opts = {}
145
+ opts[:uid] = @dev.uid
146
+ opts[:productionState] = -1
147
+ set_info = @zen.set_info(opts)
148
+ set_info.must_be_kind_of Hash
149
+ set_info.wont_be_empty
150
+ set_info['success'].must_equal true
151
+ end
152
+
153
+ it 'sets info for a device on a device object' do
154
+ opts = {}
155
+ opts[:productionState] = -1
156
+ set_info = @dev.set_info(opts)
157
+ set_info.must_be_kind_of Hash
158
+ set_info.wont_be_empty
159
+ set_info['success'].must_equal true
160
+ end
161
+
162
+ it 'remodels a device' do
163
+ uid = @dev.uid
164
+ remodel = @zen.remodel(uid)
165
+ remodel.must_be_kind_of Hash
166
+ remodel.wont_be_empty
167
+ remodel['success'].must_equal true
168
+ remodel['exitStatus'].must_equal 0
169
+ end
170
+ end
171
+ end
172
+
173
+ describe Zenoss::Events::Event do
174
+ it 'initializes an object with times as strings' do
175
+ @zenoss = Zenoss
176
+ firstTime = Time.new(2018, 10, 3, 1, 0, 0)
177
+ lastTime = Time.new(2018, 10, 3, 3, 0, 0)
178
+ zhash = {
179
+ firstTime: firstTime.to_s,
180
+ lastTime: lastTime.to_s
181
+ }
182
+ event = Zenoss::Events::Event.new(@zenoss, zhash)
183
+ event.must_be_kind_of Zenoss::Events::Event
184
+ event.firstTime.must_be_kind_of Time
185
+ event.lastTime.must_be_kind_of Time
186
+ end
187
+
188
+ it 'intializes an object with times as unix time' do
189
+ @zenoss = Zenoss
190
+ firstTime = Time.new(2018, 10, 3, 2, 0, 0)
191
+ lastTime = Time.new(2018, 10, 3, 5, 0, 0)
192
+ zhash = {
193
+ firstTime: firstTime.to_f,
194
+ lastTime: lastTime.to_f
195
+ }
196
+ event = Zenoss::Events::Event.new(@zenoss, zhash)
197
+ event.must_be_kind_of Zenoss::Events::Event
198
+ event.firstTime.class.must_equal Time
199
+ event.firstTime.must_be_kind_of Time
200
+ event.lastTime.must_be_kind_of Time
201
+ end
202
+
203
+ it 'intializes an object with times set to nil' do
204
+ @zenoss = Zenoss
205
+ zhash = {
206
+ firstTime: nil,
207
+ lastTime: nil
208
+ }
209
+ event = Zenoss::Events::Event.new(@zenoss, zhash)
210
+ event.must_be_kind_of Zenoss::Events::Event
211
+ assert_nil event.firstTime
212
+ assert_nil event.lastTime
213
+ end
214
+
215
+ it 'intializes an object with times set to false' do
216
+ @zenoss = Zenoss
217
+ zhash = {
218
+ firstTime: false,
219
+ lastTime: false
220
+ }
221
+ event = Zenoss::Events::Event.new(@zenoss, zhash)
222
+ event.must_be_kind_of Zenoss::Events::Event
223
+ event.firstTime.must_equal false
224
+ event.lastTime.must_equal false
225
+ end
140
226
  end
@@ -0,0 +1,25 @@
1
+ require_relative './test_helper'
2
+ require 'minitest/autorun'
3
+
4
+ describe Zenoss::Model::Device do
5
+ it 'raises error on #set_info when version is less than 6' do
6
+ opts = {}
7
+ opts[:version] = '4.2.5'
8
+ opts[:no_sign_in] = true
9
+ connection = Zenoss::Connection.new('http://localhost', 'admin', 'zenoss', opts)
10
+ zhash = {
11
+ productionState: 400,
12
+ priority: 3,
13
+ uid: '/zport/dmd/Devices/Server/devices/UnitTestDevice',
14
+ name: 'UnitTestDevice'
15
+ }
16
+
17
+ dev = Zenoss::Model::Device.new(connection, zhash)
18
+ options = {}
19
+ options[:productionState] = -1
20
+ exception = assert_raises Zenoss::ZenossError do
21
+ dev.set_info(options)
22
+ end
23
+ assert_equal('setInfo method on DeviceRouter is only allowed for version 6 and above', exception.message)
24
+ end
25
+ end