zenoss_api 0.2.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02ea431c2beadc81cf178cdd7b1a8986fa0d0d3d
4
- data.tar.gz: 6df145478e48b9e4cdec8bd5e38b40bb16ed6d5b
3
+ metadata.gz: 268afdc946036a964e71a205ae5dc00c8fbf4082
4
+ data.tar.gz: 0eff486cdeacf9d2b876ea6c8c973437fad79aac
5
5
  SHA512:
6
- metadata.gz: 912a9fe207ca7021244f94a23a74585310b03597e09101b96d4358fd5c47dd017172abfec1a69dbb4bca5b032345a0fdbd01feaccd35529ca468369f54dbabcf
7
- data.tar.gz: 3af7d6c35a9588277cafdeb43795d2d21588b679808ff554c1c8586a226512ac47a579a2ec903e93d05f37b40fc23909eac9a98564562b6449c7b16d92d054df
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 getDevices -p name:admin01.ctl.gdl.englab.netapp.com | jq '.devices[]'
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/CTL' --limit 30 | jq '.devices[] | .name'
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:admin01.ctl.gdl.englab.netapp.com
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
- :filters => {},
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('-f', '--filters key:value', 'method filter: default is none') do |filters|
47
- filters_hash = {}
48
- if filters.match /^({.*})$/
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
- filters_array = filters.split(",")
52
- filters_array.each do |i|
53
- e = i.split(":")
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', '--args arg1:val1,arg2:val2', Array, 'arugments:values passed to api method') do |arguments|
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 = ZenossAPI::Client.new(options[:zenoss_instance], options[:username], options[:password], options[:verify_ssl])
143
+ z = ZenossApi::Client.new(options[:zenoss_instance], options[:username], options[:password], options[:verify_ssl])
144
144
 
145
- method_params = {}
145
+ api_method_args = {}
146
146
 
147
- if ZenossAPI::METHOD_PARAMS.key? options[:router].to_sym
148
- default_method_parms = ZenossAPI::METHOD_PARAMS[options[:router].to_sym][options[:method].to_sym]
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 default_method_parms
152
- default_method_parms.each do |k,v|
153
- # options override default params
154
- method_params[k] = options[k.to_sym] || v
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
- method_params['uid'] = z.validateUids(options[:uid]) unless not options[:uid]
159
- method_params['uids'] = z.validateUids(options[:uids]) unless not options[:uids]
160
- method_params['keys'] = options[:keys] unless not options[:keys]
161
- method_params['limit'] = options[:limit] unless not options[:limit]
162
- method_params['hashcheck'] = options[:hashcheck] unless not options[:hashcheck]
163
- method_params['action'] = options[:action] unless not options[:action]
164
- method_params['start'] = options[:offset] unless not options[:offset]
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
- method_params.merge! arg
168
+ api_method_args.merge! arg
169
169
  end
170
170
 
171
- # filters set in method parameter 'params' from key:value hash
172
- method_params['params'] = options[:filters] unless options[:filters].empty?
173
- #method_params['params'] = { 'productionState' => 1000 }
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], method_params, options)
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'] = method_params
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
+
@@ -1,3 +1,3 @@
1
1
  module ZenossApi
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.2"
3
3
  end
data/lib/zenoss_api.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "zenoss_api/version"
2
2
 
3
- module ZenossAPI
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
- METHOD_PARAMS = {
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
- 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
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.0
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: 2017-09-25 00:00:00.000000000 Z
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.0.14.1
124
+ rubygems_version: 2.5.2.1
126
125
  signing_key:
127
126
  specification_version: 4
128
127
  summary: Zenoss API via command line.