zenoss_client 0.0.1 → 0.0.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.
- data/{README.markdown → README.rdoc} +21 -3
- data/Rakefile +8 -2
- data/VERSION +1 -1
- data/lib/model/device.rb +116 -28
- data/lib/model/device_hw.rb +42 -0
- data/lib/model/event_view.rb +56 -0
- data/lib/model/model.rb +13 -0
- data/lib/model/operating_system.rb +41 -0
- data/lib/zenoss.rb +0 -4
- metadata +8 -6
- data/lib/extensions.rb +0 -101
@@ -1,3 +1,5 @@
|
|
1
|
+
= zenoss_client: A Ruby library for REST access to Zenoss
|
2
|
+
|
1
3
|
This is a work-in-progress to create an easy to use client REST API for
|
2
4
|
Zenoss (http://www.zenoss.com) written in Ruby. I love Zenoss as a
|
3
5
|
product, but I am much more efficient in Ruby than Python so I decided
|
@@ -8,9 +10,26 @@ Cheers,
|
|
8
10
|
|
9
11
|
Dan Wanek
|
10
12
|
|
13
|
+
== REQUIREMENTS:
|
14
|
+
Gems:
|
15
|
+
|
16
|
+
* tzinfo: For Python DateTime to Ruby DateTime conversion
|
17
|
+
|
18
|
+
|
19
|
+
Zenoss Event Information:
|
20
|
+
|
21
|
+
If you want to access Zenoss event information via REST you may need the
|
22
|
+
following patch. The methods Zenoss::Model::EventView#get_status_img_src and
|
23
|
+
EventView#get_status_css_class depend on the 'status' parameter being an
|
24
|
+
integer. When the call is unmarshalled on the Zenoss side it is always a
|
25
|
+
string unless you apply this patch:
|
26
|
+
|
27
|
+
http://gist.github.com/328414
|
28
|
+
|
29
|
+
|
30
|
+
== TO USE:
|
31
|
+
A gem is now available. 'gem install zenoss_client'
|
11
32
|
|
12
|
-
TO USE:
|
13
|
-
-------
|
14
33
|
require 'zenoss'
|
15
34
|
|
16
35
|
# You must set the URI before doing anything else
|
@@ -32,6 +51,5 @@ TO USE:
|
|
32
51
|
# Get the uptime of the device
|
33
52
|
dev.sys_uptime
|
34
53
|
|
35
|
-
---------
|
36
54
|
|
37
55
|
Have fun and let me know what needs to be fixed / added.
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'rake/gempackagetask'
|
4
|
+
require 'rake/rdoctask'
|
4
5
|
|
5
6
|
CLEAN.include("pkg")
|
6
7
|
CLEAN.include("doc")
|
@@ -25,11 +26,11 @@ GEMSPEC = Gem::Specification.new do |gem|
|
|
25
26
|
gem.files = `git ls-files`.split(/\n/)
|
26
27
|
gem.require_path = "lib"
|
27
28
|
gem.rdoc_options = %w(-x wsdl/ -x test/ -x examples/)
|
28
|
-
gem.extra_rdoc_files = %w(README.
|
29
|
+
gem.extra_rdoc_files = %w(README.rdoc COPYING.txt)
|
29
30
|
|
30
31
|
gem.required_ruby_version = '>= 1.8.7'
|
31
32
|
gem.add_runtime_dependency 'tzinfo'
|
32
|
-
gem.post_install_message = "See README.
|
33
|
+
gem.post_install_message = "See README.rdoc"
|
33
34
|
end
|
34
35
|
|
35
36
|
Rake::GemPackageTask.new(GEMSPEC) do |pkg|
|
@@ -51,6 +52,11 @@ task :versionup do
|
|
51
52
|
puts "New version: #{ver}"
|
52
53
|
end
|
53
54
|
|
55
|
+
Rake::RDocTask.new do |rd|
|
56
|
+
rd.main = 'README.rdoc'
|
57
|
+
rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
|
58
|
+
end
|
59
|
+
|
54
60
|
|
55
61
|
def up_min_version
|
56
62
|
f = File.open('VERSION', 'r+')
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/model/device.rb
CHANGED
@@ -20,62 +20,154 @@
|
|
20
20
|
module Zenoss
|
21
21
|
module Model
|
22
22
|
class Device
|
23
|
-
include Zenoss
|
24
23
|
include Zenoss::Model
|
24
|
+
include Zenoss::Model::EventView
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
zenoss_list( {:get_device_group_names => 'getDeviceGroupNames', :get_system_names => 'getSystemNames'} )
|
29
|
-
zenoss_datetime( {:get_last_change => 'getLastChange', :get_snmp_last_collection => 'getSnmpLastCollection' } )
|
30
|
-
zenoss_string( {:sys_uptime => 'sysUpTime', :get_hw_product_name => 'getHWProductName', :get_location_link => 'getLocationLink',
|
31
|
-
:get_location_name => 'getLocationName', :get_data_for_json => 'getDataForJSON', :get_manage_ip => 'getManageIp',
|
32
|
-
:get_performance_server_name => 'getPerformanceServerName', :get_ping_status_string => 'getPingStatusString',
|
33
|
-
:get_pretty_link => 'getPrettyLink', :get_priority_string => 'getPriorityString',
|
34
|
-
:get_production_state_string => 'getProductionStateString', :get_snmp_status_string => 'getSnmpStatusString',
|
35
|
-
:uptime_str => 'uptimeStr'
|
36
|
-
} )
|
37
|
-
|
38
|
-
zenoss_int( {:get_priority => 'getPriority'} )
|
39
|
-
|
40
|
-
zenoss_boolean( {:monitor_device? => 'monitorDevice', :snmp_monitor_device? => 'snmpMonitorDevice' } )
|
41
|
-
|
26
|
+
attr_reader :path, :device, :os, :hw
|
42
27
|
|
43
28
|
def initialize(device_path)
|
44
29
|
device_path.sub(/^\/zport\/dmd\/(.*)\/([^\/]+)$/) do |m|
|
45
30
|
@path = $1
|
46
31
|
@device = $2
|
47
32
|
end
|
33
|
+
|
34
|
+
@os = OperatingSystem.new(self)
|
35
|
+
@hw = DeviceHW.new(self)
|
48
36
|
end
|
49
37
|
|
38
|
+
# ------------------ REST Calls ------------------ #
|
39
|
+
|
50
40
|
# Instead of calling the /getId REST method, this method simply returns
|
51
41
|
# the @device value since it is the same anyway.
|
52
42
|
def get_id()
|
53
43
|
@device
|
54
44
|
end
|
55
45
|
|
56
|
-
|
57
|
-
|
58
|
-
|
46
|
+
def sys_uptime
|
47
|
+
rest("sysUpTime")
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_hw_product_name
|
51
|
+
rest('getHWProductName')
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get the HTML formatted link to the Location that this devices exists at.
|
55
|
+
# If you are looking for just the name, use #get_location_name instead.
|
56
|
+
def get_location_link
|
57
|
+
rest('getLocationLink')
|
58
|
+
end
|
59
|
+
|
60
|
+
# Returns a String value of the Location that this device exists at. You can
|
61
|
+
# also issue #get_location_link if you want an HTML link to the location page.
|
62
|
+
def get_location_name
|
63
|
+
rest('getLocationName')
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns data ready for serialization
|
67
|
+
def get_data_for_json
|
68
|
+
plist_to_array( rest('getDataForJSON') )
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_device_group_names
|
72
|
+
plist_to_array( rest('getDeviceGroupNames') )
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns a DateTime instance when this device was last modified.
|
76
|
+
def get_last_change
|
77
|
+
pdatetime_to_datetime( rest('getLastChange') )
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return the management ip for this device.
|
81
|
+
def get_manage_ip
|
82
|
+
rest('getManageIp')
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns the name of the Zenoss Collector that this host currently belogs to.
|
86
|
+
def get_performance_server_name
|
87
|
+
rest('getPerformanceServerName')
|
88
|
+
end
|
89
|
+
|
90
|
+
# Return the pingStatus as a string
|
91
|
+
def get_ping_status_string
|
92
|
+
rest('getPingStatusString')
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_pretty_link
|
96
|
+
rest('getPrettyLink')
|
97
|
+
end
|
98
|
+
|
99
|
+
# Return the numeric device priority.
|
100
|
+
def get_priority
|
101
|
+
(rest('getPriority')).to_i
|
102
|
+
end
|
103
|
+
|
104
|
+
# Return the device priority as a string.
|
105
|
+
def get_priority_string
|
106
|
+
rest('getPriorityString')
|
107
|
+
end
|
108
|
+
|
109
|
+
# Return the prodstate as a string.
|
110
|
+
def get_production_state_string
|
111
|
+
rest('getProductionStateString')
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_rrd_templates
|
115
|
+
end
|
116
|
+
|
117
|
+
# Returns a DateTime instance when this device was last collected from.
|
118
|
+
def get_snmp_last_collection
|
119
|
+
pdatetime_to_datetime( rest('getSnmpLastCollection') )
|
120
|
+
end
|
121
|
+
|
122
|
+
# Return the snmpStatus as a string.
|
123
|
+
def get_snmp_status_string
|
124
|
+
rest('getSnmpStatusString')
|
125
|
+
end
|
126
|
+
|
127
|
+
# Returns an Array of Zenoss /Systems that this device belogs to.
|
128
|
+
def get_system_names
|
129
|
+
plist_to_array( rest('getSystemNames') )
|
130
|
+
end
|
131
|
+
|
132
|
+
# Returns true if the device production state >= zProdStateThreshold.
|
133
|
+
def monitor_device?
|
134
|
+
(rest('monitorDevice')).eql?('True') ? true : false
|
135
|
+
end
|
136
|
+
|
137
|
+
# Returns true if the device is subject to SNMP monitoring
|
138
|
+
def snmp_monitor_device?
|
139
|
+
(rest('snmpMonitorDevice')).eql?('True') ? true : false
|
140
|
+
end
|
141
|
+
|
142
|
+
# Return the SNMP uptime
|
143
|
+
def uptime_str
|
144
|
+
rest('uptimeStr')
|
145
|
+
end
|
146
|
+
|
147
|
+
# Update the devices hardware tag with the passed string
|
148
|
+
def set_hw_tag(asset_tag)
|
149
|
+
puts "No REST implementation yet."
|
150
|
+
#rest("setHWTag?assettag#{asset_tag}")
|
59
151
|
end
|
60
152
|
|
61
153
|
# Return list of monitored DeviceComponents on this device
|
62
154
|
def get_monitored_components(collector=nil, type=nil)
|
63
155
|
method = "getMonitoredComponents"
|
64
156
|
method << '?' unless(collector.nil? && type.nil?)
|
65
|
-
method << "collector=#{collector}" unless collector.nil?
|
157
|
+
method << "collector=#{collector}&" unless collector.nil?
|
66
158
|
method << "type=#{type}" unless type.nil?
|
67
159
|
components = rest(method)
|
68
160
|
|
69
161
|
# Turn the return string into an array of components
|
70
162
|
(components.gsub /[\[\]]/,'').split /,\s+/
|
71
163
|
end
|
72
|
-
|
164
|
+
|
73
165
|
# Return list of all DeviceComponents on this device
|
74
166
|
def get_device_components(monitored=nil, collector=nil, type=nil)
|
75
167
|
method = "getDeviceComponents"
|
76
168
|
method << '?' unless(monitored.nil? && collector.nil? && type.nil?)
|
77
|
-
method << "monitored=#{monitored}" unless monitored.nil?
|
78
|
-
method << "collector=#{collector}" unless collector.nil?
|
169
|
+
method << "monitored=#{monitored}&" unless monitored.nil?
|
170
|
+
method << "collector=#{collector}&" unless collector.nil?
|
79
171
|
method << "type=#{type}" unless type.nil?
|
80
172
|
components = rest(method)
|
81
173
|
|
@@ -89,10 +181,6 @@ module Zenoss
|
|
89
181
|
end
|
90
182
|
|
91
183
|
|
92
|
-
# -------- Methods from DeviceResultInt.DeviceResultInt -------- #
|
93
|
-
zenoss_string( {:get_device_class_name => 'getDeviceClassName'} )
|
94
|
-
|
95
|
-
|
96
184
|
private
|
97
185
|
|
98
186
|
def rest(method)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2009 Dan Wanek <dwanek@nd.gov>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Zenoss-RubyREST.
|
6
|
+
#
|
7
|
+
# Zenoss-RubyREST 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-RubyREST 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-RubyREST. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
module Zenoss
|
21
|
+
module Model
|
22
|
+
class DeviceHW
|
23
|
+
include Zenoss
|
24
|
+
include Zenoss::Model
|
25
|
+
|
26
|
+
@@zenoss_methods = []
|
27
|
+
|
28
|
+
|
29
|
+
def initialize(device)
|
30
|
+
@device = device
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def rest(method)
|
37
|
+
super("#{@device.path}/#{@device.device}/hw/#{method}")
|
38
|
+
end
|
39
|
+
|
40
|
+
end # Device
|
41
|
+
end # Model
|
42
|
+
end # Zenoss
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2009 Dan Wanek <dwanek@nd.gov>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Zenoss-RubyREST.
|
6
|
+
#
|
7
|
+
# Zenoss-RubyREST 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-RubyREST 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-RubyREST. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
|
21
|
+
module Zenoss
|
22
|
+
module Model
|
23
|
+
module EventView
|
24
|
+
|
25
|
+
def get_event_history
|
26
|
+
rest('getEventHistory')
|
27
|
+
end
|
28
|
+
|
29
|
+
# Fetches that status number for this device or component
|
30
|
+
def get_status(statusclass=nil)
|
31
|
+
method = 'getStatus'
|
32
|
+
method << "?statusclass=#{statusclass}" unless statusclass.nil?
|
33
|
+
|
34
|
+
# nil.to_i is 0 so we should be OK for nil returns
|
35
|
+
rest(method).to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
# Fetches the img src path for this status number. This is usually the
|
39
|
+
# output from the #get_status method. If this is not working you may
|
40
|
+
# need to apply this patch to Zenoss:
|
41
|
+
# http://gist.github.com/328414
|
42
|
+
def get_status_img_src(status_number)
|
43
|
+
rest("getStatusImgSrc?status=#{status_number}")
|
44
|
+
end
|
45
|
+
|
46
|
+
# Fetches the css class for this status number. This is usually the
|
47
|
+
# output from the #get_status method. If this is not working you may
|
48
|
+
# need to apply this patch to Zenoss:
|
49
|
+
# http://gist.github.com/328414
|
50
|
+
def get_status_css_class(status_number)
|
51
|
+
rest("getStatusCssClass?status=#{status_number}")
|
52
|
+
end
|
53
|
+
|
54
|
+
end # EventView
|
55
|
+
end # Model
|
56
|
+
end # Zenoss
|
data/lib/model/model.rb
CHANGED
@@ -24,8 +24,21 @@ module Zenoss
|
|
24
24
|
module Model
|
25
25
|
include Zenoss
|
26
26
|
|
27
|
+
|
28
|
+
# -------- Methods from DeviceResultInt.DeviceResultInt -------- #
|
29
|
+
|
30
|
+
def get_device_class_name
|
31
|
+
rest('getDeviceClassName')
|
32
|
+
end
|
33
|
+
|
27
34
|
end # Model
|
28
35
|
end # Zenoss
|
29
36
|
|
37
|
+
# Modules
|
38
|
+
require 'model/event_view'
|
39
|
+
|
40
|
+
# Classes
|
30
41
|
require 'model/device'
|
31
42
|
require 'model/device_class'
|
43
|
+
require 'model/device_hw'
|
44
|
+
require 'model/operating_system'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2009 Dan Wanek <dwanek@nd.gov>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Zenoss-RubyREST.
|
6
|
+
#
|
7
|
+
# Zenoss-RubyREST 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-RubyREST 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-RubyREST. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
module Zenoss
|
21
|
+
module Model
|
22
|
+
class OperatingSystem
|
23
|
+
include Zenoss
|
24
|
+
include Zenoss::Model
|
25
|
+
|
26
|
+
@@zenoss_methods = []
|
27
|
+
|
28
|
+
def initialize(device)
|
29
|
+
@device = device
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def rest(method)
|
36
|
+
super("#{@device.path}/#{@device.device}/os/#{method}")
|
37
|
+
end
|
38
|
+
|
39
|
+
end # Device
|
40
|
+
end # Model
|
41
|
+
end # Zenoss
|
data/lib/zenoss.rb
CHANGED
@@ -22,9 +22,6 @@ require 'date'
|
|
22
22
|
require 'tzinfo'
|
23
23
|
require 'uri'
|
24
24
|
|
25
|
-
# Include extensions to classes for helper methods
|
26
|
-
require 'extensions'
|
27
|
-
|
28
25
|
module Zenoss
|
29
26
|
|
30
27
|
# Set the Base URI of the Zenoss server
|
@@ -50,7 +47,6 @@ module Zenoss
|
|
50
47
|
end
|
51
48
|
|
52
49
|
|
53
|
-
|
54
50
|
private
|
55
51
|
|
56
52
|
# Prepend the appropriate path and call the REST method on the URL set with Zenoss#uri
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Wanek
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-11 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,24 +30,26 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
|
32
32
|
extra_rdoc_files:
|
33
|
-
- README.
|
33
|
+
- README.rdoc
|
34
34
|
- COPYING.txt
|
35
35
|
files:
|
36
36
|
- COPYING.txt
|
37
|
-
- README.
|
37
|
+
- README.rdoc
|
38
38
|
- Rakefile
|
39
39
|
- VERSION
|
40
|
-
- lib/extensions.rb
|
41
40
|
- lib/model/device.rb
|
42
41
|
- lib/model/device_class.rb
|
42
|
+
- lib/model/device_hw.rb
|
43
|
+
- lib/model/event_view.rb
|
43
44
|
- lib/model/model.rb
|
45
|
+
- lib/model/operating_system.rb
|
44
46
|
- lib/zenoss.rb
|
45
47
|
- preamble
|
46
48
|
has_rdoc: true
|
47
49
|
homepage: http://github.com/zenchild/zenoss_client
|
48
50
|
licenses: []
|
49
51
|
|
50
|
-
post_install_message: See README.
|
52
|
+
post_install_message: See README.rdoc
|
51
53
|
rdoc_options:
|
52
54
|
- -x
|
53
55
|
- wsdl/
|
data/lib/extensions.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
#############################################################################
|
2
|
-
# Copyright © 2010 Dan Wanek <dwanek@nd.gov>
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# This file is part of Zenoss-RubyREST.
|
6
|
-
#
|
7
|
-
# Zenoss-RubyREST 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-RubyREST 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-RubyREST. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
#############################################################################
|
20
|
-
require 'rubygems'
|
21
|
-
require 'date'
|
22
|
-
require 'tzinfo'
|
23
|
-
require 'uri'
|
24
|
-
|
25
|
-
# String is extended to for method renaming purposes
|
26
|
-
class String
|
27
|
-
def ruby_case
|
28
|
-
self.split(/(?=[A-Z])/).join('_').downcase
|
29
|
-
end
|
30
|
-
|
31
|
-
def camel_case
|
32
|
-
self.split(/_/).map {|word| word.capitalize}.join
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Class is extended in order to add Zenoss REST methods declaratively.
|
37
|
-
class Class
|
38
|
-
|
39
|
-
# Takes a Hash as an argument in the form {:ruby_name => 'RestName'}
|
40
|
-
def zenoss_list(methods)
|
41
|
-
methods.each_pair do |ruby_name,rest_name|
|
42
|
-
add_to_zenoss_methods(ruby_name)
|
43
|
-
|
44
|
-
define_method(ruby_name) do
|
45
|
-
plist_to_array( rest(rest_name) )
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def zenoss_datetime(methods)
|
51
|
-
methods.each_pair do |ruby_name,rest_name|
|
52
|
-
add_to_zenoss_methods(ruby_name)
|
53
|
-
|
54
|
-
define_method(ruby_name) do
|
55
|
-
pdatetime_to_datetime( rest(rest_name) )
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def zenoss_string(methods)
|
61
|
-
methods.each_pair do |ruby_name,rest_name|
|
62
|
-
add_to_zenoss_methods(ruby_name)
|
63
|
-
|
64
|
-
define_method(ruby_name) do
|
65
|
-
rest(rest_name)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def zenoss_int(methods)
|
71
|
-
methods.each_pair do |ruby_name,rest_name|
|
72
|
-
add_to_zenoss_methods(ruby_name)
|
73
|
-
|
74
|
-
define_method(ruby_name) do
|
75
|
-
retval = rest(rest_name)
|
76
|
-
retval.to_i unless retval.nil?
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def zenoss_boolean(methods)
|
82
|
-
methods.each_pair do |ruby_name,rest_name|
|
83
|
-
add_to_zenoss_methods(ruby_name)
|
84
|
-
|
85
|
-
define_method(ruby_name) do
|
86
|
-
(rest(rest_name)).eql?('True') ? true : false
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
private
|
94
|
-
|
95
|
-
# Update the class variable @@zenoss_methods with this method
|
96
|
-
def add_to_zenoss_methods(method_sym)
|
97
|
-
z_methods = class_variable_get(:@@zenoss_methods)
|
98
|
-
z_methods << method_sym.to_s
|
99
|
-
class_variable_set(:@@zenoss_methods, z_methods)
|
100
|
-
end
|
101
|
-
end
|