zenoss_api 0.2.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -5
- data/bin/zenapi +39 -34
- data/lib/zenoss_api/version.rb +1 -1
- data/lib/zenoss_api.rb +3 -2
- data/zenoss_api.gemspec +6 -6
- metadata +17 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 268afdc946036a964e71a205ae5dc00c8fbf4082
|
4
|
+
data.tar.gz: 0eff486cdeacf9d2b876ea6c8c973437fad79aac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb7b5b69304243c9bc2b05ea309049621ff12650f053b4e7cb769ca1312a20b3268d0968fd29f4b08dfabf6dcea34c92ccbe57c4b31d0d6256b19f30f272b9d9
|
7
|
+
data.tar.gz: ef4ada9af5a98ec50a1c2157ca1745a7bdf540ce76c6b4a2eeb02a72676303738daf0e9345f3ab3035827b0fa48da4db8cf2a724af563f2cddba4ae4295842e7
|
data/README.md
CHANGED
@@ -4,8 +4,6 @@ Command line interface abstraction of zenoss api method calls.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
*Not currently published to rubygems.org, see Development*
|
8
|
-
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
@@ -25,7 +23,7 @@ Or install it yourself as:
|
|
25
23
|
Get all device classes:
|
26
24
|
|
27
25
|
```bash
|
28
|
-
zenapi -m
|
26
|
+
zenapi -m getDeviceClasses | jq '.devices[]'
|
29
27
|
```
|
30
28
|
|
31
29
|
Get all groups:
|
@@ -37,12 +35,12 @@ zenapi -m getGroups | jq '.groups[] | .name'
|
|
37
35
|
Get devices in device class, limit to 30:
|
38
36
|
|
39
37
|
```bash
|
40
|
-
zenapi --uid '/Devices/Server/Linux
|
38
|
+
zenapi --uid '/Devices/Server/Linux' --limit 30 | jq '.devices[] | .name'
|
41
39
|
```
|
42
40
|
Get device by name:
|
43
41
|
|
44
42
|
```bash
|
45
|
-
zenapi -m getDevices -a name:
|
43
|
+
zenapi -m getDevices -a name:hostname.fqdn
|
46
44
|
```
|
47
45
|
|
48
46
|
Get most recent events, limit to 10:
|
data/bin/zenapi
CHANGED
@@ -18,7 +18,7 @@ options = {
|
|
18
18
|
:zenoss_instance => zenrc['url'],
|
19
19
|
:router => 'DeviceRouter',
|
20
20
|
:method => 'getDevices',
|
21
|
-
:
|
21
|
+
:zenoss_params_arg => [],
|
22
22
|
:limit => nil,
|
23
23
|
:uid => nil,
|
24
24
|
:keys => nil,
|
@@ -43,18 +43,14 @@ opts_parser = OptionParser.new do |opts|
|
|
43
43
|
opts.on('-m', '--method method', 'method: default is getDevices') do |method|
|
44
44
|
options[:method] = method
|
45
45
|
end
|
46
|
-
opts.on('-
|
47
|
-
|
48
|
-
|
49
|
-
filters_hash = JSON.parse(filters)
|
46
|
+
opts.on('-p', '--params key=value', Array, 'zenoss method params: default is none') do |params|
|
47
|
+
if params[0].match /^({.*})$/
|
48
|
+
params_hash = JSON.parse(params)
|
50
49
|
else
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
filters_hash[e[0]] = e[1]
|
55
|
-
end
|
50
|
+
key_pairs = params.map { |x| x.split('=') }
|
51
|
+
key_hashes = key_pairs.map { |y| { y[0] => y[1] } }
|
52
|
+
key_hashes.each { |k| options[:zenoss_params_arg].push k }
|
56
53
|
end
|
57
|
-
options[:filters] = filters_hash
|
58
54
|
end
|
59
55
|
opts.on('-l', '--limit integer', 'limit results: default 50') do |limit|
|
60
56
|
options[:limit] = limit.to_i
|
@@ -68,8 +64,8 @@ opts_parser = OptionParser.new do |opts|
|
|
68
64
|
opts.on('-k', '--keys key1,key2,key3', Array, 'list of keys to return: defaull all') do |keys|
|
69
65
|
options[:keys] = keys
|
70
66
|
end
|
71
|
-
opts.on('-a', '--
|
72
|
-
key_pairs = arguments.map { |x| x.split('
|
67
|
+
opts.on('-a', '--arg arg1=val1', Array, 'arugment=value passed to api method') do |arguments|
|
68
|
+
key_pairs = arguments.map { |x| x.split('=') }
|
73
69
|
key_hashes = key_pairs.map { |y| { y[0] => y[1] } }
|
74
70
|
key_hashes.each { |k| options[:arguments].push k }
|
75
71
|
end
|
@@ -111,6 +107,10 @@ opts_parser = OptionParser.new do |opts|
|
|
111
107
|
json = JSON.parse(uids)
|
112
108
|
options[:uids_file] = json
|
113
109
|
end
|
110
|
+
opts.on('-v', '--version') do
|
111
|
+
puts ZenossApi::VERSION
|
112
|
+
exit 0
|
113
|
+
end
|
114
114
|
end
|
115
115
|
|
116
116
|
opts_parser.parse!
|
@@ -140,40 +140,44 @@ if options[:password].nil?
|
|
140
140
|
STDOUT.flush
|
141
141
|
end
|
142
142
|
|
143
|
-
z =
|
143
|
+
z = ZenossApi::Client.new(options[:zenoss_instance], options[:username], options[:password], options[:verify_ssl])
|
144
144
|
|
145
|
-
|
145
|
+
api_method_args = {}
|
146
146
|
|
147
|
-
if
|
148
|
-
|
147
|
+
if ZenossApi::DEFAULT_API_METHOD_ARGS.key? options[:router].to_sym
|
148
|
+
default_api_method_args = ZenossApi::DEFAULT_API_METHOD_ARGS[options[:router].to_sym][options[:method].to_sym]
|
149
149
|
end
|
150
150
|
|
151
|
-
if
|
152
|
-
|
153
|
-
# options override default
|
154
|
-
|
151
|
+
if default_api_method_args
|
152
|
+
default_api_method_args.each do |k,v|
|
153
|
+
# args passed as options override default api method args
|
154
|
+
api_method_args[k] = options[k.to_sym] || v
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
158
|
+
api_method_args['uid'] = z.validateUids(options[:uid]) unless not options[:uid]
|
159
|
+
api_method_args['uids'] = z.validateUids(options[:uids]) unless not options[:uids]
|
160
|
+
api_method_args['keys'] = options[:keys] unless not options[:keys]
|
161
|
+
api_method_args['limit'] = options[:limit] unless not options[:limit]
|
162
|
+
api_method_args['hashcheck'] = options[:hashcheck] unless not options[:hashcheck]
|
163
|
+
api_method_args['action'] = options[:action] unless not options[:action]
|
164
|
+
api_method_args['start'] = options[:offset] unless not options[:offset]
|
165
165
|
|
166
166
|
|
167
167
|
options[:arguments].each do |arg|
|
168
|
-
|
168
|
+
api_method_args.merge! arg
|
169
169
|
end
|
170
170
|
|
171
|
-
#
|
172
|
-
|
173
|
-
|
171
|
+
# zenoss method params parameter from options[:params] array of hashes
|
172
|
+
if not options[:zenoss_params_arg].empty?
|
173
|
+
api_method_args['params'] = {}
|
174
|
+
options[:zenoss_params_arg].each do |param|
|
175
|
+
api_method_args['params'].merge! param
|
176
|
+
end
|
177
|
+
end
|
174
178
|
|
175
179
|
if options[:command] == "api"
|
176
|
-
response = z.router(options[:router], options[:method],
|
180
|
+
response = z.router(options[:router], options[:method], api_method_args, options)
|
177
181
|
|
178
182
|
if options[:paginate]
|
179
183
|
response.each do |x|
|
@@ -184,7 +188,7 @@ if options[:command] == "api"
|
|
184
188
|
p response.headers.to_json
|
185
189
|
end
|
186
190
|
|
187
|
-
response['query'] =
|
191
|
+
response['query'] = api_method_args
|
188
192
|
puts response.to_hash.to_json
|
189
193
|
end
|
190
194
|
end
|
@@ -203,3 +207,4 @@ exit 0
|
|
203
207
|
#########################################
|
204
208
|
#[{"tid": 1, "type": "rpc", "method_params": [], "method": "getDeviceClasses", "action": "DeviceRouter"}]
|
205
209
|
|
210
|
+
|
data/lib/zenoss_api/version.rb
CHANGED
data/lib/zenoss_api.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "zenoss_api/version"
|
2
2
|
|
3
|
-
module
|
3
|
+
module ZenossApi
|
4
4
|
require 'json'
|
5
5
|
require 'httparty'
|
6
6
|
|
@@ -21,9 +21,10 @@ module ZenossAPI
|
|
21
21
|
:JobsRouter => 'jobs',
|
22
22
|
:IntrospectionRouter => 'introspection',
|
23
23
|
:UsersRouter => 'users',
|
24
|
+
:EventClassesRouter => 'Events/evclasses',
|
24
25
|
}
|
25
26
|
|
26
|
-
|
27
|
+
DEFAULT_API_METHOD_ARGS = {
|
27
28
|
:DeviceRouter => {
|
28
29
|
:getDevices => {
|
29
30
|
'uid' => nil,
|
data/zenoss_api.gemspec
CHANGED
@@ -16,12 +16,12 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
18
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
if spec.respond_to?(:metadata)
|
20
|
-
|
21
|
-
else
|
22
|
-
|
23
|
-
|
24
|
-
end
|
19
|
+
#if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
#else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
#end
|
25
25
|
|
26
26
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
27
|
f.match(%r{^(test|spec|features)/})
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zenoss_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Stoll
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
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
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.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
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: io-console
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: httparty
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
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
82
|
version: '0'
|
83
83
|
description: Execute api calls given the router, method, and parameters. Returns response
|
@@ -89,7 +89,7 @@ executables:
|
|
89
89
|
extensions: []
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
92
|
-
- .gitignore
|
92
|
+
- ".gitignore"
|
93
93
|
- CODE_OF_CONDUCT.md
|
94
94
|
- Gemfile
|
95
95
|
- LICENSE.txt
|
@@ -104,25 +104,24 @@ files:
|
|
104
104
|
homepage: ''
|
105
105
|
licenses:
|
106
106
|
- MIT
|
107
|
-
metadata:
|
108
|
-
allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
|
107
|
+
metadata: {}
|
109
108
|
post_install_message:
|
110
109
|
rdoc_options: []
|
111
110
|
require_paths:
|
112
111
|
- lib
|
113
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
113
|
requirements:
|
115
|
-
- -
|
114
|
+
- - ">="
|
116
115
|
- !ruby/object:Gem::Version
|
117
116
|
version: '0'
|
118
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
118
|
requirements:
|
120
|
-
- -
|
119
|
+
- - ">="
|
121
120
|
- !ruby/object:Gem::Version
|
122
121
|
version: '0'
|
123
122
|
requirements: []
|
124
123
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.5.2.1
|
126
125
|
signing_key:
|
127
126
|
specification_version: 4
|
128
127
|
summary: Zenoss API via command line.
|