rackspace-monitoring 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "fog", ">= 0"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", ">= 1.0.0"
13
+ gem "jeweler", "~> 1.8.3"
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = Rackspace Cloud Monitoring Ruby Bindings
2
+
3
+ This project contains the Ruby bindings for the Rackspace Cloud Monitoring product.
4
+
5
+ == Contributing
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Rackspace Hosting Inc See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rackspace-monitoring"
18
+ gem.homepage = "http://github.com/racker/rackspace-monitoring-rb"
19
+ gem.license = "APACHE"
20
+ gem.summary = %Q{Rackspace Cloud Monitoring Ruby Bindings}
21
+ gem.description = %Q{Rackspace Cloud Monitoring Ruby Bindings, built on top of fog.}
22
+ gem.email = "dan.dispaltro@gmail.com"
23
+ gem.authors = ["Dan Di Spaltro"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+ rescue LoadError
43
+ task :rcov do
44
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
45
+ end
46
+ end
47
+
48
+ task :default => :test
49
+
50
+ require 'rdoc/task'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "rackspace-monitoring #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,118 @@
1
+ require 'fog/core'
2
+ require 'fog/rackspace'
3
+ require 'multi_json'
4
+
5
+ module Fog
6
+ module Monitoring
7
+ class Rackspace < Fog::Service
8
+
9
+ ENDPOINT = 'https://monitoring.api.rackspacecloud.com/v1.0'
10
+
11
+ requires :rackspace_api_key, :rackspace_username
12
+ recognizes :rackspace_auth_url, :persistent
13
+ recognizes :rackspace_auth_token, :rackspace_service_url, :rackspace_account_id
14
+
15
+ model_path 'rackspace-monitoring/monitoring/models'
16
+ model :entity
17
+ collection :entities
18
+ model :check
19
+ collection :checks
20
+ model :alarm
21
+ collection :alarms
22
+
23
+ request_path 'rackspace-monitoring/monitoring/requests'
24
+ request :list_entities
25
+ request :list_checks
26
+ request :list_alarms
27
+ request :list_overview
28
+ request :get_entity
29
+ request :create_entity
30
+ request :get_check
31
+ request :create_check
32
+ request :get_alarm
33
+ request :create_alarm
34
+
35
+
36
+ class Mock
37
+
38
+ end
39
+
40
+ class Real
41
+ def initialize(options={})
42
+ @rackspace_api_key = options[:rackspace_api_key]
43
+ @rackspace_username = options[:rackspace_username]
44
+ @rackspace_auth_url = options[:rackspace_auth_url]
45
+ @rackspace_auth_token = options[:rackspace_auth_token]
46
+ @rackspace_account_id = options[:rackspace_account_id]
47
+ @rackspace_service_url = options[:rackspace_service_url] || ENDPOINT
48
+ @rackspace_must_reauthenticate = false
49
+ @connection_options = options[:connection_options] || {}
50
+ authenticate
51
+ @persistent = options[:persistent] || false
52
+ @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
53
+ end
54
+
55
+ def reload
56
+ @connection.reset
57
+ end
58
+
59
+ def request(params)
60
+ print params
61
+ begin
62
+ response = @connection.request(params.merge({
63
+ :headers => {
64
+ 'Content-Type' => 'application/json',
65
+ 'X-Auth-Token' => @auth_token
66
+ }.merge!(params[:headers] || {}),
67
+ :host => @host,
68
+ :path => "#{@path}/#{params[:path]}"
69
+ }))
70
+ rescue Excon::Errors::Unauthorized => error
71
+ if error.response.body != 'Bad username or password' # token expiration
72
+ @rackspace_must_reauthenticate = true
73
+ authenticate
74
+ retry
75
+ else # bad credentials
76
+ raise error
77
+ end
78
+ rescue Excon::Errors::HTTPStatusError => error
79
+ raise case error
80
+ when Excon::Errors::NotFound
81
+ Fog::Monitoring::Rackspace::NotFound.slurp(error)
82
+ else
83
+ error
84
+ end
85
+ end
86
+ unless response.body.empty?
87
+ response.body = MultiJson.decode(response.body)
88
+ end
89
+ response
90
+ end
91
+
92
+ private
93
+
94
+ def authenticate
95
+ if @rackspace_must_reauthenticate || @rackspace_auth_token.nil? || @account_id.nil?
96
+ options = {
97
+ :rackspace_api_key => @rackspace_api_key,
98
+ :rackspace_username => @rackspace_username,
99
+ :rackspace_auth_url => @rackspace_auth_url
100
+ }
101
+ credentials = Fog::Rackspace.authenticate(options, @connection_options)
102
+ @auth_token = credentials['X-Auth-Token']
103
+ @account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
104
+ else
105
+ @auth_token = @rackspace_auth_token
106
+ @account_id = @rackspace_account_id
107
+ end
108
+ uri = URI.parse("#{@rackspace_service_url}/#{@account_id}")
109
+ @host = uri.host
110
+ @path = uri.path
111
+ @port = uri.port
112
+ @scheme = uri.scheme
113
+ end
114
+
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,37 @@
1
+ require 'fog/core/model'
2
+ require 'rackspace-monitoring/monitoring/models/base'
3
+
4
+ module Fog
5
+ module Monitoring
6
+ class Rackspace
7
+ class Alarm < Fog::Monitoring::Rackspace::Base
8
+
9
+ identity :id
10
+ attribute :entity
11
+
12
+ attribute :label
13
+ attribute :criteria
14
+ attribute :check_type
15
+ attribute :check_id
16
+ attribute :notification_plan_id
17
+
18
+ def save
19
+ raise Fog::Errors::Error.new('Update not implemented yet.') if identity
20
+ requires :notification_plan_id
21
+ requires :entity
22
+ options = {
23
+ 'label' => label,
24
+ 'criteria' => criteria,
25
+ 'check_type' => check_type,
26
+ 'check_id' => check_id,
27
+ }
28
+ options = options.reject {|key, value| value.nil?}
29
+ data = connection.create_alarm(entity.identity, notification_plan_id, options)
30
+ true
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,40 @@
1
+ require 'fog/core/collection'
2
+ require 'rackspace-monitoring/monitoring/models/alarm'
3
+
4
+ module Fog
5
+ module Monitoring
6
+ class Rackspace
7
+ class Alarms < Fog::Collection
8
+
9
+ attribute :entity
10
+
11
+ model Fog::Monitoring::Rackspace::Alarm
12
+
13
+ def all
14
+ requires :entity
15
+ data = connection.list_alarms(entity.identity).body['values']
16
+ load(data)
17
+ end
18
+
19
+ def get(alarm_id)
20
+ requires :entity
21
+ data = connection.get_alarm(entity.identity, alarm_id).body
22
+ new(data)
23
+ rescue Fog::Monitoring::Rackspace::NotFound
24
+ nil
25
+ end
26
+
27
+ def new(attributes = {})
28
+ requires :entity
29
+ super({ :entity => entity }.merge!(attributes))
30
+ end
31
+
32
+ def create(attributes = {})
33
+ requires :entity
34
+ super({ :entity => entity }.merge!(attributes))
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,22 @@
1
+ require 'digest/md5'
2
+
3
+ module Fog
4
+ module Monitoring
5
+ class Rackspace
6
+ class Base < Fog::Model
7
+
8
+ attribute :created_at
9
+ attribute :updated_at
10
+
11
+ def hash
12
+ attrs = attributes.dup
13
+ attrs.delete_if {|key, value| [:created_at, :updated_at].include?(key)}
14
+ attrs.delete_if {|key, value| value.kind_of?(Base) }
15
+ keys = attrs.keys.map{|sym| sym.to_s}.sort.join ''
16
+ values = attrs.values.map{|sym| sym.to_s}.sort.join ''
17
+ Digest::MD5.hexdigest(keys + values)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ require 'fog/core/model'
2
+ require 'rackspace-monitoring/monitoring/models/base'
3
+
4
+ module Fog
5
+ module Monitoring
6
+ class Rackspace
7
+ class Check < Fog::Monitoring::Rackspace::Base
8
+
9
+ identity :id
10
+ attribute :entity
11
+
12
+ attribute :label
13
+ attribute :metadata
14
+ attribute :target_alias
15
+ attribute :target_resolver
16
+ attribute :target_hostname
17
+ attribute :period
18
+ attribute :timeout
19
+ attribute :type
20
+ attribute :details
21
+ attribute :disabled
22
+ attribute :monitoring_zones_poll
23
+
24
+ def save
25
+ raise Fog::Errors::Error.new('Update not implemented yet.') if identity
26
+ requires :type
27
+ requires :entity
28
+ options = {
29
+ 'label' => label,
30
+ 'metadata' => metadata,
31
+ 'target_alias'=> target_alias,
32
+ 'target_resolver' => target_resolver,
33
+ 'target_hostname' => target_hostname,
34
+ 'period' => period,
35
+ 'timeout'=> timeout,
36
+ 'details'=> details,
37
+ 'monitoring_zones_poll'=> monitoring_zones_poll,
38
+ 'disabled'=> disabled
39
+ }
40
+ options = options.reject {|key, value| value.nil?}
41
+ data = connection.create_check(entity.identity, type, options)
42
+ true
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,40 @@
1
+ require 'fog/core/collection'
2
+ require 'rackspace-monitoring/monitoring/models/check'
3
+
4
+ module Fog
5
+ module Monitoring
6
+ class Rackspace
7
+ class Checks < Fog::Collection
8
+
9
+ attribute :entity
10
+
11
+ model Fog::Monitoring::Rackspace::Check
12
+
13
+ def all
14
+ requires :entity
15
+ data = connection.list_checks(entity.identity).body['values']
16
+ load(data)
17
+ end
18
+
19
+ def get(check_id)
20
+ requires :entity
21
+ data = connection.get_check(entity.identity, check_id).body
22
+ new(data)
23
+ rescue Fog::Monitoring::Rackspace::NotFound
24
+ nil
25
+ end
26
+
27
+ def new(attributes = {})
28
+ requires :entity
29
+ super({ :entity => entity }.merge!(attributes))
30
+ end
31
+
32
+ def create(attributes = {})
33
+ requires :entity
34
+ super({ :entity => entity }.merge!(attributes))
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,42 @@
1
+ require 'fog/core/collection'
2
+ require 'rackspace-monitoring/monitoring/models/entity'
3
+ require 'rackspace-monitoring/monitoring/models/check'
4
+
5
+ module Fog
6
+ module Monitoring
7
+ class Rackspace
8
+ class Entities < Fog::Collection
9
+
10
+ model Fog::Monitoring::Rackspace::Entity
11
+
12
+ def all
13
+ data = connection.list_entities.body['values']
14
+ load(data)
15
+ end
16
+
17
+ def get(entity_id)
18
+ data = connection.get_entity(entity_id).body
19
+ new(data)
20
+ rescue Fog::Monitoring::Rackspace::NotFound
21
+ nil
22
+ end
23
+
24
+ def overview
25
+ data = connection.list_overview.body['values']
26
+ loadAll(data)
27
+ end
28
+
29
+ def loadAll(objects)
30
+ clear
31
+ for object in objects
32
+ en = new(object['entity'])
33
+ self << en
34
+ en.checks.load(object['checks'])
35
+ en.alarms.load(object['alarms'])
36
+ end
37
+ self
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,49 @@
1
+ require 'fog/core/model'
2
+ require 'rackspace-monitoring/monitoring/models/base'
3
+
4
+ module Fog
5
+ module Monitoring
6
+ class Rackspace
7
+ class Entity < Fog::Monitoring::Rackspace::Base
8
+
9
+ identity :id
10
+
11
+ attribute :label
12
+ attribute :metadata
13
+ attribute :ip_addresses
14
+ attribute :agent_id
15
+
16
+ def save
17
+ raise Fog::Errors::Error.new('Update not implemented yet.') if identity
18
+ requires :label
19
+ options = {
20
+ 'metadata' => metadata,
21
+ 'ip_addresses'=> ip_addresses,
22
+ 'agent_id' => agent_id
23
+ }
24
+ options = options.reject {|key, value| value.nil?}
25
+ data = connection.create_entity(label, options)
26
+ true
27
+ end
28
+
29
+ def checks
30
+ @checks ||= begin
31
+ Fog::Monitoring::Rackspace::Checks.new(
32
+ :entity => self,
33
+ :connection => connection
34
+ )
35
+ end
36
+ end
37
+
38
+ def alarms
39
+ @alarms ||= begin
40
+ Fog::Monitoring::Rackspace::Alarms.new(
41
+ :entity => self,
42
+ :connection => connection
43
+ )
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+ # attribute :label
7
+ # attribute :criteria
8
+ # attribute :check_type
9
+ # attribute :check_id
10
+ # attribute :notification_plan_id
11
+
12
+
13
+ def create_alarm(entity_id, notification_plan_id, options = {})
14
+ data = {}
15
+ data['label'] = options['label'] if options['label']
16
+ data['criteria'] = options['criteria'] if options['criteria']
17
+ data['check_type'] = options['check_type'] if options['check_type']
18
+ data['check_id'] = options['check_id'] if options['check_id']
19
+ data['notification_plan_id'] = notification_plan_id
20
+ request(
21
+ :body => MultiJson.encode(options),
22
+ :expects => [201],
23
+ :method => 'POST',
24
+ :path => "entities/#{entity_id}/alarms"
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,66 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+
7
+ def process_options(options)
8
+ data = {}
9
+ if options['label'] then
10
+ data['label'] = options['label']
11
+ end
12
+ if options['metadata'] then
13
+ data['metadata'] = options['metadata']
14
+ end
15
+ if options['target_alias'] then
16
+ data['target_alias'] = options['target_alias']
17
+ end
18
+ if options['target_resolver'] then
19
+ data['target_resolver'] = options['target_resolver']
20
+ end
21
+ if options['target_hostname'] then
22
+ data['target_hostname'] = options['target_hostname']
23
+ end
24
+ if options['period'] then
25
+ data['period'] = options['period']
26
+ end
27
+ if options['timeout'] then
28
+ data['timeout'] = options['timeout']
29
+ end
30
+ if options['details'] then
31
+ data['details'] = options['details']
32
+ end
33
+ if options['monitoring_zones_poll'] then
34
+ data['monitoring_zones_poll'] = options['monitoring_zones_poll']
35
+ end
36
+ if options['disabled'] then
37
+ data['disabled'] = options['disabled']
38
+ end
39
+ data
40
+ end
41
+
42
+ def update_check(id, entity_id, options = {})
43
+ data = process_options options
44
+ request(
45
+ :body => MultiJson.encode(data),
46
+ :expects => [201],
47
+ :method => 'PUT',
48
+ :path => "entities/#{entity_id}/checks/#{id}"
49
+ )
50
+ end
51
+
52
+ def create_check(entity_id, type, options = {})
53
+ data = process_options options
54
+ data['type'] = type
55
+ request(
56
+ :body => MultiJson.encode(data),
57
+ :expects => [201],
58
+ :method => 'POST',
59
+ :path => "entities/#{entity_id}/checks"
60
+ )
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+ def create_entity(label, options = {})
7
+ data = {}
8
+ data['label'] = label
9
+ if options['metadata']
10
+ data['metadata'] = options['metadata']
11
+ end
12
+ if options['ip_addresses']
13
+ data['ip_addresses'] = options['ip_addresses']
14
+ end
15
+ request(
16
+ :body => MultiJson.encode(data),
17
+ :expects => [201],
18
+ :method => 'POST',
19
+ :path => 'entities'
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+ def get_alarm(entity_id, alarm_id)
7
+ request(
8
+ :expects => [200, 203],
9
+ :method => 'GET',
10
+ :path => "entities/#{entity_id}/alarms/#{alarm_id}"
11
+ )
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+ def get_check(entity_id, check_id)
7
+ request(
8
+ :expects => [200, 203],
9
+ :method => 'GET',
10
+ :path => "entities/#{entity_id}/checks/#{check_id}"
11
+ )
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+ def get_entity(entity_id)
7
+ request(
8
+ :expects => [200, 203],
9
+ :method => 'GET',
10
+ :path => "entities/#{entity_id}"
11
+ )
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+ def list_alarms(entity_id)
7
+ request(
8
+ :expects => [200, 203],
9
+ :method => 'GET',
10
+ :path => "entities/#{entity_id}/alarms"
11
+ )
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+ def list_checks(entity_id)
7
+ request(
8
+ :expects => [200, 203],
9
+ :method => 'GET',
10
+ :path => "entities/#{entity_id}/checks"
11
+ )
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+ def list_entities
7
+ request(
8
+ :expects => [200, 203],
9
+ :method => 'GET',
10
+ :path => 'entities'
11
+ )
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Monitoring
3
+ class Rackspace
4
+ class Real
5
+
6
+ def list_overview
7
+ request(
8
+ :expects => [200, 203],
9
+ :method => 'GET',
10
+ :path => 'views/overview'
11
+ )
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'rackspace-monitoring'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRackspaceMonitoring < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rackspace-monitoring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dan Di Spaltro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fog
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: shoulda
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.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: 1.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.3
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.3
94
+ description: Rackspace Cloud Monitoring Ruby Bindings, built on top of fog.
95
+ email: dan.dispaltro@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.rdoc
101
+ files:
102
+ - .document
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.rdoc
106
+ - Rakefile
107
+ - VERSION
108
+ - lib/rackspace-monitoring.rb
109
+ - lib/rackspace-monitoring/monitoring/models/alarm.rb
110
+ - lib/rackspace-monitoring/monitoring/models/alarms.rb
111
+ - lib/rackspace-monitoring/monitoring/models/base.rb
112
+ - lib/rackspace-monitoring/monitoring/models/check.rb
113
+ - lib/rackspace-monitoring/monitoring/models/checks.rb
114
+ - lib/rackspace-monitoring/monitoring/models/entities.rb
115
+ - lib/rackspace-monitoring/monitoring/models/entity.rb
116
+ - lib/rackspace-monitoring/monitoring/requests/create_alarm.rb
117
+ - lib/rackspace-monitoring/monitoring/requests/create_check.rb
118
+ - lib/rackspace-monitoring/monitoring/requests/create_entity.rb
119
+ - lib/rackspace-monitoring/monitoring/requests/get_alarm.rb
120
+ - lib/rackspace-monitoring/monitoring/requests/get_check.rb
121
+ - lib/rackspace-monitoring/monitoring/requests/get_entity.rb
122
+ - lib/rackspace-monitoring/monitoring/requests/list_alarms.rb
123
+ - lib/rackspace-monitoring/monitoring/requests/list_checks.rb
124
+ - lib/rackspace-monitoring/monitoring/requests/list_entities.rb
125
+ - lib/rackspace-monitoring/monitoring/requests/list_overview.rb
126
+ - test/helper.rb
127
+ - test/test_rackspace-monitoring.rb
128
+ homepage: http://github.com/racker/rackspace-monitoring-rb
129
+ licenses:
130
+ - APACHE
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ segments:
142
+ - 0
143
+ hash: 1660523492308502531
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 1.8.24
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: Rackspace Cloud Monitoring Ruby Bindings
156
+ test_files: []