zenoss_client 0.1.0 → 0.5.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 (40) hide show
  1. data/README.textile +67 -0
  2. data/VERSION +1 -1
  3. data/lib/{events/zevent.rb → ext/ipaddr.rb} +11 -8
  4. data/lib/zenoss.rb +13 -89
  5. data/lib/zenoss/connection.rb +62 -0
  6. data/lib/{model/events/event_class.rb → zenoss/events.rb} +2 -0
  7. data/lib/{model/rrd_view.rb → zenoss/events/event.rb} +25 -19
  8. data/lib/zenoss/events/zevent.rb +25 -0
  9. data/lib/zenoss/exceptions.rb +25 -0
  10. data/lib/zenoss/jsonapi.rb +84 -0
  11. data/lib/zenoss/jsonapi/device_router.rb +93 -0
  12. data/lib/{events/event.rb → zenoss/jsonapi/events_router.rb} +24 -12
  13. data/lib/{model/events/mysql_event_manager.rb → zenoss/jsonapi/report_router.rb} +10 -12
  14. data/lib/{model → zenoss}/model.rb +6 -10
  15. data/lib/{model → zenoss/model}/devices.rb +4 -4
  16. data/lib/{model → zenoss/model}/devices/device.rb +20 -21
  17. data/lib/{model → zenoss/model}/devices/device_class.rb +0 -0
  18. data/lib/{model → zenoss/model}/devices/device_hw.rb +0 -0
  19. data/lib/{model → zenoss/model}/devices/operating_system.rb +0 -0
  20. data/lib/{model → zenoss/model}/event_view.rb +0 -0
  21. data/lib/{model → zenoss/model}/manufacturers/manufacturers.rb +0 -0
  22. data/lib/{model → zenoss/model}/processes/os_process_organizer.rb +0 -0
  23. data/lib/{model → zenoss/model}/rrd/rrd_data_point.rb +10 -7
  24. data/lib/zenoss/model/rrd_view.rb +93 -0
  25. data/lib/{model → zenoss/model}/services.rb +5 -5
  26. data/lib/{model → zenoss/model}/services/ip_service.rb +0 -0
  27. data/lib/{model → zenoss/model}/services/service.rb +0 -0
  28. data/lib/{model → zenoss/model}/services/service_class.rb +0 -0
  29. data/lib/{model → zenoss/model}/services/service_organizer.rb +0 -0
  30. data/lib/{model → zenoss/model}/services/win_service.rb +0 -0
  31. data/lib/{model → zenoss/model}/systems.rb +1 -1
  32. data/lib/{model → zenoss/model}/systems/system.rb +0 -0
  33. data/lib/{model → zenoss/model}/z_device_loader.rb +0 -0
  34. data/lib/{model → zenoss/model}/zenpack/zenpack_manager.rb +0 -0
  35. data/lib/zenoss/restapi.rb +80 -0
  36. data/lib/zenoss_client.rb +3 -0
  37. data/zenoss_client.gemspec +34 -0
  38. metadata +69 -51
  39. data/README.rdoc +0 -58
  40. data/lib/model/events/event_manager_base.rb +0 -66
File without changes
@@ -17,4 +17,4 @@
17
17
  # You should have received a copy of the GNU General Public License along
18
18
  # with zenoss_client. If not, see <http://www.gnu.org/licenses/>.
19
19
  #############################################################################
20
- require 'model/systems/system'
20
+ require 'zenoss/model/systems/system'
File without changes
File without changes
@@ -0,0 +1,80 @@
1
+ #############################################################################
2
+ # Copyright © 2010 Dan Wanek <dwanek@nd.gov>
3
+ #
4
+ #
5
+ # This file is part of zenoss_client.
6
+ #
7
+ # zenoss_client is free software: you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or (at
10
+ # your option) any later version.
11
+ #
12
+ # zenoss_client is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15
+ # Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License along
18
+ # with zenoss_client. If not, see <http://www.gnu.org/licenses/>.
19
+ #############################################################################
20
+
21
+ module Zenoss
22
+ module RESTAPI
23
+
24
+ # Prepend the appropriate path and call the REST method on the URL set with Zenoss#uri
25
+ #
26
+ # @param [String] req_path the request path of the REST method
27
+ # @return [String] the response body of the REST call
28
+ def rest(req_path)
29
+ resp = @httpcli.get "#{@zenoss_uri}#{req_path}"
30
+ parse_rest(resp)
31
+ end
32
+
33
+ # Call a custom Zope method to work around some issues of unsupported or bad behaving
34
+ # REST methods.
35
+ # @see http://gist.github.com/343627 for more info.
36
+ #
37
+ # @param [String] req_path the request path of the REST method ( as if it wasn't misbehaving )
38
+ # @example req_path
39
+ # getRRDValues?dsnames=['ProcessorTotalUserTime_ProcessorTotalUserTime','MemoryPagesOutputSec_MemoryPagesOutputSec']
40
+ # @param [String] callback_func the name of the function to be called on the returned object before giving it back to Ruby
41
+ # @param [String] callback_attr the name of the attribute to fetch on the returned object before giving it back to Ruby
42
+ # @return [String] the response body of the REST call
43
+ def custom_rest(dev_path, req_path, callback_func = nil, callback_attr=nil)
44
+ puts "ORIGINAL: #{req_path}" if $DEBUG
45
+ meth,args = req_path.split('?')
46
+ meth = "callZenossMethod?methodName=#{meth}"
47
+ unless args.nil?
48
+ meth << '&args=['
49
+ # Remove the named parameters because we can't dynamically call named parameters in Python.
50
+ # This method uses positional parameters via the passed Array (Python List).
51
+ meth << args.split('&').inject('') do |parms,arg|
52
+ arg.gsub!(/'/, "'''") # This may cause problems if the passed argument is already triple quoted.
53
+ parms << '===' unless parms.empty?
54
+ parms << arg.split('=').last
55
+ end
56
+ meth << ']'
57
+ end
58
+ meth << "&filterFunc=#{callback_func}" unless callback_func.nil?
59
+ meth << "&filterAttr=#{callback_attr}" unless callback_attr.nil?
60
+ meth = "#{URI.encode(dev_path)}/#{meth}"
61
+ puts "METHOD: #{meth}" if $DEBUG
62
+ rest(meth)
63
+ end
64
+
65
+
66
+ private
67
+
68
+ # Check the HTTP and REST response for errors and return appropriate response
69
+ def parse_rest(resp)
70
+ begin
71
+ if(resp.status >= 300)
72
+ raise ZenossError, "Bad HTTP Response #{resp.status}: Cound not make REST call"
73
+ end
74
+
75
+ resp.body.content
76
+ end
77
+ end
78
+
79
+ end # RESTAPI
80
+ end # Zenoss
@@ -0,0 +1,3 @@
1
+ # You should actually load it with require 'zenoss' but this is here to stay
2
+ # consistent with the gem name
3
+ require 'zenoss'
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+ require 'date'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "zenoss_client"
8
+ gem.version = File.open('VERSION').readline.chomp
9
+ gem.date = Date.today.to_s
10
+ gem.platform = Gem::Platform::RUBY
11
+ gem.rubyforge_project = nil
12
+
13
+ gem.author = "Dan Wanek"
14
+ gem.email = "dan.wanek@gmail.com"
15
+ gem.homepage = "http://github.com/zenchild/zenoss_client"
16
+
17
+ gem.summary = "A wrapper around the Zenoss JSON and REST APIs"
18
+ gem.description = <<-EOF
19
+ This is a wrapper around the Zenoss JSON and REST APIs. For the most things it
20
+ should feel very familiar to zendmd, but there are some changes do to the merging
21
+ of the JSON and REST APIs. Please read the API docs for Zenoss and the YARDDoc for
22
+ this gem (rdoc.info).
23
+ EOF
24
+
25
+ gem.files = `git ls-files`.split(/\n/)
26
+ gem.require_path = "lib"
27
+ gem.rdoc_options = %w(-x test/ -x examples/)
28
+ gem.extra_rdoc_files = %w(README.textile COPYING.txt)
29
+
30
+ gem.required_ruby_version = '>= 1.8.7'
31
+ gem.add_runtime_dependency 'httpclient'
32
+ gem.add_runtime_dependency 'tzinfo'
33
+ gem.add_runtime_dependency 'json'
34
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zenoss_client
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
4
+ prerelease:
5
+ version: 0.5.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Dan Wanek
@@ -14,101 +10,123 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-04-28 00:00:00 -05:00
13
+ date: 2011-03-28 00:00:00 -05:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
- name: tzinfo
17
+ name: httpclient
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
24
21
  requirements:
25
22
  - - ">="
26
23
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
24
  version: "0"
30
25
  type: :runtime
31
26
  version_requirements: *id001
32
- description: " \tThis is a Ruby library for accessing Zenoss through its REST interface. It is a work in progress and as functionality is testing\n\
33
- \tit will be added. For documentation on what the method calls do see the official Zenoss API docs.\n"
27
+ - !ruby/object:Gem::Dependency
28
+ name: tzinfo
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: json
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ description: " This is a wrapper around the Zenoss JSON and REST APIs. For the most things it\n should feel very familiar to zendmd, but there are some changes do to the merging\n of the JSON and REST APIs. Please read the API docs for Zenoss and the YARDDoc for\n this gem (rdoc.info).\n"
34
50
  email: dan.wanek@gmail.com
35
51
  executables: []
36
52
 
37
53
  extensions: []
38
54
 
39
55
  extra_rdoc_files:
40
- - README.rdoc
56
+ - README.textile
41
57
  - COPYING.txt
42
58
  files:
43
59
  - COPYING.txt
44
- - README.rdoc
60
+ - README.textile
45
61
  - Rakefile
46
62
  - VERSION
47
- - lib/events/event.rb
48
- - lib/events/zevent.rb
49
- - lib/model/devices.rb
50
- - lib/model/devices/device.rb
51
- - lib/model/devices/device_class.rb
52
- - lib/model/devices/device_hw.rb
53
- - lib/model/devices/operating_system.rb
54
- - lib/model/event_view.rb
55
- - lib/model/events/event_class.rb
56
- - lib/model/events/event_manager_base.rb
57
- - lib/model/events/mysql_event_manager.rb
58
- - lib/model/manufacturers/manufacturers.rb
59
- - lib/model/model.rb
60
- - lib/model/processes/os_process_organizer.rb
61
- - lib/model/rrd/rrd_data_point.rb
62
- - lib/model/rrd_view.rb
63
- - lib/model/services.rb
64
- - lib/model/services/ip_service.rb
65
- - lib/model/services/service.rb
66
- - lib/model/services/service_class.rb
67
- - lib/model/services/service_organizer.rb
68
- - lib/model/services/win_service.rb
69
- - lib/model/systems.rb
70
- - lib/model/systems/system.rb
71
- - lib/model/z_device_loader.rb
72
- - lib/model/zenpack/zenpack_manager.rb
63
+ - lib/ext/ipaddr.rb
73
64
  - lib/zenoss.rb
65
+ - lib/zenoss/connection.rb
66
+ - lib/zenoss/events.rb
67
+ - lib/zenoss/events/event.rb
68
+ - lib/zenoss/events/zevent.rb
69
+ - lib/zenoss/exceptions.rb
70
+ - lib/zenoss/jsonapi.rb
71
+ - lib/zenoss/jsonapi/device_router.rb
72
+ - lib/zenoss/jsonapi/events_router.rb
73
+ - lib/zenoss/jsonapi/report_router.rb
74
+ - lib/zenoss/model.rb
75
+ - lib/zenoss/model/devices.rb
76
+ - lib/zenoss/model/devices/device.rb
77
+ - lib/zenoss/model/devices/device_class.rb
78
+ - lib/zenoss/model/devices/device_hw.rb
79
+ - lib/zenoss/model/devices/operating_system.rb
80
+ - lib/zenoss/model/event_view.rb
81
+ - lib/zenoss/model/manufacturers/manufacturers.rb
82
+ - lib/zenoss/model/processes/os_process_organizer.rb
83
+ - lib/zenoss/model/rrd/rrd_data_point.rb
84
+ - lib/zenoss/model/rrd_view.rb
85
+ - lib/zenoss/model/services.rb
86
+ - lib/zenoss/model/services/ip_service.rb
87
+ - lib/zenoss/model/services/service.rb
88
+ - lib/zenoss/model/services/service_class.rb
89
+ - lib/zenoss/model/services/service_organizer.rb
90
+ - lib/zenoss/model/services/win_service.rb
91
+ - lib/zenoss/model/systems.rb
92
+ - lib/zenoss/model/systems/system.rb
93
+ - lib/zenoss/model/z_device_loader.rb
94
+ - lib/zenoss/model/zenpack/zenpack_manager.rb
95
+ - lib/zenoss/restapi.rb
96
+ - lib/zenoss_client.rb
74
97
  - preamble
75
98
  - tools/callZenossMethod.py
99
+ - zenoss_client.gemspec
76
100
  has_rdoc: true
77
101
  homepage: http://github.com/zenchild/zenoss_client
78
102
  licenses: []
79
103
 
80
- post_install_message: See README.rdoc
104
+ post_install_message:
81
105
  rdoc_options:
82
106
  - -x
83
- - wsdl/
84
- - -x
85
107
  - test/
86
108
  - -x
87
109
  - examples/
88
110
  require_paths:
89
111
  - lib
90
112
  required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
91
114
  requirements:
92
115
  - - ">="
93
116
  - !ruby/object:Gem::Version
94
- segments:
95
- - 1
96
- - 8
97
- - 7
98
117
  version: 1.8.7
99
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
100
120
  requirements:
101
121
  - - ">="
102
122
  - !ruby/object:Gem::Version
103
- segments:
104
- - 0
105
123
  version: "0"
106
124
  requirements: []
107
125
 
108
126
  rubyforge_project:
109
- rubygems_version: 1.3.6
127
+ rubygems_version: 1.5.0
110
128
  signing_key:
111
129
  specification_version: 3
112
- summary: A Ruby API for accessing Zenoss via REST
130
+ summary: A wrapper around the Zenoss JSON and REST APIs
113
131
  test_files: []
114
132
 
data/README.rdoc DELETED
@@ -1,58 +0,0 @@
1
- = zenoss_client: A Ruby library for REST access to Zenoss
2
-
3
- This is a work-in-progress to create an easy to use client REST API for
4
- Zenoss (http://www.zenoss.com) written in Ruby. I love Zenoss as a
5
- product, but I am much more efficient in Ruby than Python so I decided
6
- to start hacking this library together. It is very incomplete and I am
7
- just adding functionality as I need it or it is requested.
8
-
9
- Cheers,
10
-
11
- Dan Wanek
12
-
13
- == REQUIREMENTS:
14
- Gems:
15
-
16
- * tzinfo: For Python DateTime to Ruby DateTime conversion
17
-
18
-
19
- == UNSUPPORTED REST METHODS:
20
- Some methods within Zope are unsupported due to type conversion issues.
21
- I have created a work-around but you must add a custom Python script
22
- to Zope in order to do this. Please see this blog post for information
23
- on how add the custom script:
24
-
25
- http://distributed-frostbite.blogspot.com/2010/04/using-ruby-with-zenoss-part-1.html
26
-
27
- UPDATE: The script itself is now part of the source tree and can be found here: tools/callZenossMethod.py
28
- It should still be installed in the same fashion as the blog post steps through.
29
-
30
- == TO USE:
31
- A gem is now available. 'gem install zenoss_client'
32
-
33
- require 'zenoss'
34
-
35
- # You must set the URI before doing anything else
36
- Zenoss.uri 'https://zenhost:port/zport/dmd/'
37
-
38
- # Add the appropriate credentials
39
- Zenoss.set_auth('user','pass')
40
-
41
- # This returns the base DeviceClass '/zport/dmd/Devices'
42
- # It is the equivilent in zendmd of 'dmd.Devices'
43
- devices = Zenoss.devices
44
-
45
- # Search for a device
46
- dev = devices.find_device_path('devname')
47
-
48
- # List all implemented REST methods for this object
49
- puts dev.zenoss_methods.sort.join(', ')
50
-
51
- # Get the uptime of the device
52
- dev.sys_uptime
53
-
54
- # Get a list of events for this system
55
- dev.get_events
56
-
57
-
58
- Have fun and let me know what needs to be fixed / added.
@@ -1,66 +0,0 @@
1
- #############################################################################
2
- # Copyright © 2010 Dan Wanek <dwanek@nd.gov>
3
- #
4
- #
5
- # This file is part of zenoss_client.
6
- #
7
- # zenoss_client is free software: you can redistribute it and/or
8
- # modify it under the terms of the GNU General Public License as published
9
- # by the Free Software Foundation, either version 3 of the License, or (at
10
- # your option) any later version.
11
- #
12
- # zenoss_client is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15
- # Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License along
18
- # with zenoss_client. If not, see <http://www.gnu.org/licenses/>.
19
- #############################################################################
20
- require 'uri'
21
- module Zenoss
22
- module Model
23
- module Events
24
- class EventManagerBase
25
- include Zenoss::Model
26
-
27
- def initialize(manager_base)
28
- @manager = manager_base.sub(/^(\/zport\/dmd\/)?([^\/]+)$/,'\2')
29
-
30
- # Initialize common things from Model
31
- model_init
32
- end
33
-
34
-
35
- # ------------------ REST Calls ------------------ #
36
-
37
- def get_event_list(resultFields=nil, where=nil, orderby=nil, severity=nil, state=2, startdate=nil, enddate=nil, offset=0, rows=0, get_total_count=false, filter=nil, filters=nil)
38
- method = "getEventList?"
39
- method << (resultFields.nil? ? "None&" : "#{resultFields.join(',')}&")
40
- method << (where.nil? ? "&" : URI.encode(where,'='))
41
- events = []
42
- (parse_array(custom_rest(method, 'getEventFields'))).each do |event|
43
- events << Zenoss::Event::ZEvent.new(Hash[event])
44
- end
45
- events
46
- end
47
-
48
- # Parameters:
49
- # * evid (string) - Event ID
50
- # * dedupid (string) - string used to determine duplicates
51
- # * better (boolean) - provide even more detail than normal?
52
- # Returns: EventDetail object fields from the event
53
- def get_event_detail(evid=nil, dedupid=nil, better=false)
54
- end
55
-
56
-
57
- private
58
-
59
- def rest(method)
60
- super("#{@manager}/#{method}")
61
- end
62
-
63
- end # EventManagerBase
64
- end # Events
65
- end # Model
66
- end # Zenoss