zenoss_client 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/README.textile +12 -0
- data/Rakefile +7 -0
- data/VERSION +1 -1
- data/test/test_helper.rb +11 -0
- data/test/zenoss_client_test.rb +114 -0
- data/zenoss_client.gemspec +3 -1
- metadata +44 -10
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#https://github.com/github/gitignore/blob/master/Ruby.gitignore
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
coverage
|
7
|
+
InstalledFiles
|
8
|
+
lib/bundler/man
|
9
|
+
pkg
|
10
|
+
rdoc
|
11
|
+
spec/reports
|
12
|
+
test/tmp
|
13
|
+
test/version_tmp
|
14
|
+
tmp
|
15
|
+
|
16
|
+
# YARD artifacts
|
17
|
+
.yardoc
|
18
|
+
_yardoc
|
19
|
+
doc/
|
20
|
+
|
21
|
+
|
22
|
+
# Extra's not part of the template
|
23
|
+
.buildpath
|
24
|
+
.project
|
data/README.textile
CHANGED
@@ -68,3 +68,15 @@ A gem is now available. 'gem install zenoss_client'
|
|
68
68
|
</pre>
|
69
69
|
|
70
70
|
Have fun and let me know what needs to be fixed / added.
|
71
|
+
|
72
|
+
== Testing
|
73
|
+
You can invoke a series of minitest based spec test using the supplied
|
74
|
+
tests and rake task. Simply run the following to kick off the tests
|
75
|
+
@rake test@
|
76
|
+
|
77
|
+
You should see output similar to the following (The number of tests will
|
78
|
+
of course grow over time):
|
79
|
+
@3 tests, 6 assertions, 0 failures, 0 errors, 0 skips@
|
80
|
+
|
81
|
+
If you get any failures, you should of course address them
|
82
|
+
|
data/Rakefile
CHANGED
@@ -2,6 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'rake/gempackagetask'
|
4
4
|
require 'rake/rdoctask'
|
5
|
+
require 'rake/testtask'
|
5
6
|
|
6
7
|
CLEAN.include("pkg")
|
7
8
|
CLEAN.include("doc")
|
@@ -70,3 +71,9 @@ def up_min_version
|
|
70
71
|
f.write(ver)
|
71
72
|
ver
|
72
73
|
end
|
74
|
+
|
75
|
+
Rake::TestTask.new do |t|
|
76
|
+
t.libs.push "lib"
|
77
|
+
t.test_files = FileList['test/*_test.rb']
|
78
|
+
t.verbose = true
|
79
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.4
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
#http://net.tutsplus.com/tutorials/ruby/ruby-for-newbies-testing-with-rspec/
|
3
|
+
require_relative '../lib/zenoss'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
|
7
|
+
ZENOSS_URL = ENV['zenoss_client_url'] || "http://localhost:8080/zport/dmd"
|
8
|
+
ZENOSS_USER = ENV['zenoss_client_username'] || "admin"
|
9
|
+
ZENOSS_PASSWORD = ENV['zenoss_client_password'] || "zenoss"
|
10
|
+
|
11
|
+
TEST_DEVICE_NAME = "UnitTestDevice"
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require_relative './test_helper'
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
LOG = Logger.new(STDOUT)
|
6
|
+
LOG.level = Logger::INFO
|
7
|
+
|
8
|
+
|
9
|
+
describe Zenoss do
|
10
|
+
#Simulate some "before all" type of setup
|
11
|
+
#https://github.com/seattlerb/minitest/issues/61#issuecomment-4581115
|
12
|
+
def self.zen
|
13
|
+
@zen ||= begin
|
14
|
+
connection = Zenoss.connect ZENOSS_URL, ZENOSS_USER, ZENOSS_PASSWORD
|
15
|
+
#We Need to Create A Device for testing
|
16
|
+
#We do this here, so we can re-use the same device over and over
|
17
|
+
#Without needing to create a new one per test
|
18
|
+
LOG.info("Creating a Fresh Device For Testing")
|
19
|
+
new_device_rsp = connection.json_request(
|
20
|
+
'DeviceRouter', 'addDevice',
|
21
|
+
[{:deviceName => TEST_DEVICE_NAME, :deviceClass => '/Devices/Server'}]
|
22
|
+
)
|
23
|
+
|
24
|
+
#Now we need to wait until the device is present before we proceed.
|
25
|
+
#Once we issue the create command, it takes
|
26
|
+
if new_device_rsp.has_key?("success") && new_device_rsp['success'] == true
|
27
|
+
#Our job was accepted
|
28
|
+
retries = 20
|
29
|
+
retry_delay = 15 #seconds
|
30
|
+
found_device = false
|
31
|
+
LOG.info("Waiting for the newly created device to be available. " +
|
32
|
+
"This might take a minute or two")
|
33
|
+
while found_device == false
|
34
|
+
if retries > 0
|
35
|
+
#This will return an Array, so we wait until the array has
|
36
|
+
#something, or we give up after a while
|
37
|
+
devs = connection.find_devices_by_name(TEST_DEVICE_NAME)
|
38
|
+
if devs.empty?
|
39
|
+
retries -= 1
|
40
|
+
LOG.info("#{TEST_DEVICE_NAME} not available yet")
|
41
|
+
sleep(retry_delay)
|
42
|
+
else
|
43
|
+
found_device = true
|
44
|
+
LOG.info("#{TEST_DEVICE_NAME} is available. Proceeding with " +
|
45
|
+
"testing")
|
46
|
+
end
|
47
|
+
else
|
48
|
+
raise ZenossError, "Unable to Create A New Device For Unit Tests"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
else
|
52
|
+
#We failed to create a new device....
|
53
|
+
end
|
54
|
+
#Return the connection object
|
55
|
+
connection
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
before do
|
60
|
+
@zen = self.class.zen
|
61
|
+
@dev = @zen.find_devices_by_name(TEST_DEVICE_NAME).first
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
it "returns an Array of devices when searched by name" do
|
66
|
+
x = @zen.find_devices_by_name(TEST_DEVICE_NAME)
|
67
|
+
x.must_be_kind_of Array
|
68
|
+
x.first.must_be_kind_of Zenoss::Model::Device
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns device uptime when asked" do
|
72
|
+
@dev.sys_uptime.wont_be_nil
|
73
|
+
@dev.sys_uptime.wont_be_empty
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns an Array of events for a device" do
|
77
|
+
#There could be 0 or more, events so an empty Array is OK
|
78
|
+
@dev.get_events.must_be_kind_of Array
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns an Array of historical events for a device" do
|
82
|
+
#There could be 0 or more, events so an empty Array is OK
|
83
|
+
@dev.get_event_history.must_be_kind_of Array
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns info for a device in the form of a Hash" do
|
87
|
+
@dev.get_info().wont_be_nil
|
88
|
+
@dev.get_info().wont_be_empty
|
89
|
+
@dev.get_info().must_be_kind_of Hash
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns an Array of events for all devices" do
|
93
|
+
events = @zen.query_events
|
94
|
+
events.must_be_kind_of Array
|
95
|
+
events.first.must_be_kind_of Zenoss::Events::ZEvent
|
96
|
+
end
|
97
|
+
|
98
|
+
it "fetches the report tree" do
|
99
|
+
report_tree = @zen.get_report_tree
|
100
|
+
report_tree.must_be_kind_of Array
|
101
|
+
report_tree.first.must_be_kind_of Hash
|
102
|
+
report_tree.wont_be_empty
|
103
|
+
end
|
104
|
+
|
105
|
+
it "fetches available report types and returns a Hash" do
|
106
|
+
report_types = @zen.get_report_types
|
107
|
+
report_types.must_be_kind_of Hash
|
108
|
+
report_types.wont_be_empty
|
109
|
+
report_types.has_key?("reportTypes").must_equal true
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
|
data/zenoss_client.gemspec
CHANGED
@@ -30,5 +30,7 @@ Gem::Specification.new do |gem|
|
|
30
30
|
gem.required_ruby_version = '>= 1.8.7'
|
31
31
|
gem.add_runtime_dependency 'httpclient', '~> 2.2.0'
|
32
32
|
gem.add_runtime_dependency 'tzinfo', '~> 0.3.20'
|
33
|
-
gem.add_runtime_dependency 'json', '~> 1.5
|
33
|
+
gem.add_runtime_dependency 'json', '~> 1.5'
|
34
|
+
|
35
|
+
gem.add_development_dependency('minitest')
|
34
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zenoss_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httpclient
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 2.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.2.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: tzinfo
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,18 +37,44 @@ dependencies:
|
|
32
37
|
version: 0.3.20
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.3.20
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: json
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version: 1.5
|
53
|
+
version: '1.5'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: minitest
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
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: '0'
|
47
78
|
description: ! " This is a wrapper around the Zenoss JSON and REST APIs. For the
|
48
79
|
most things it\n should feel very familiar to zendmd, but there are some changes
|
49
80
|
do to the merging\n of the JSON and REST APIs. Please read the API docs for Zenoss
|
@@ -55,6 +86,7 @@ extra_rdoc_files:
|
|
55
86
|
- README.textile
|
56
87
|
- COPYING.txt
|
57
88
|
files:
|
89
|
+
- .gitignore
|
58
90
|
- COPYING.txt
|
59
91
|
- Gemfile
|
60
92
|
- README.textile
|
@@ -96,6 +128,8 @@ files:
|
|
96
128
|
- lib/zenoss/restapi.rb
|
97
129
|
- lib/zenoss_client.rb
|
98
130
|
- preamble
|
131
|
+
- test/test_helper.rb
|
132
|
+
- test/zenoss_client_test.rb
|
99
133
|
- tools/callZenossMethod.py
|
100
134
|
- zenoss_client.gemspec
|
101
135
|
homepage: http://github.com/zenchild/zenoss_client
|
@@ -122,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
156
|
version: '0'
|
123
157
|
requirements: []
|
124
158
|
rubyforge_project:
|
125
|
-
rubygems_version: 1.8.
|
159
|
+
rubygems_version: 1.8.24
|
126
160
|
signing_key:
|
127
161
|
specification_version: 3
|
128
162
|
summary: A wrapper around the Zenoss JSON and REST APIs
|