2013-08-01 15:21:28 -04:00
|
|
|
# This class originally came from the rackspace-monitoring gem located here:
|
|
|
|
# https://github.com/racker/rackspace-monitoring-rb
|
|
|
|
# It has been heavily modified for import into Fog master.
|
|
|
|
|
2013-07-03 17:04:58 -04:00
|
|
|
require 'fog'
|
|
|
|
require 'fog/core'
|
|
|
|
|
|
|
|
module Fog
|
2013-07-19 14:04:37 -04:00
|
|
|
module Rackspace
|
2013-07-03 17:04:58 -04:00
|
|
|
class Monitoring < Fog::Service
|
2013-07-11 18:30:37 -04:00
|
|
|
include Fog::Rackspace::Errors
|
|
|
|
|
|
|
|
class IdentifierTaken < Fog::Errors::Error; end
|
|
|
|
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
|
|
|
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
|
|
|
|
class BadRequest < Fog::Rackspace::Errors::BadRequest; end
|
2013-07-19 14:04:37 -04:00
|
|
|
class Conflict < Fog::Rackspace::Errors::Conflict; end
|
|
|
|
class ServiceUnavailable < Fog::Rackspace::Errors::ServiceUnavailable; end
|
2013-07-03 17:04:58 -04:00
|
|
|
|
|
|
|
requires :rackspace_api_key, :rackspace_username
|
2013-07-19 14:04:37 -04:00
|
|
|
recognizes :rackspace_auth_url
|
|
|
|
recognizes :persistent
|
2013-07-24 14:07:56 -04:00
|
|
|
recognizes :rackspace_monitoring_url
|
2013-07-24 12:22:16 -04:00
|
|
|
recognizes :rackspace_region
|
2013-07-03 17:04:58 -04:00
|
|
|
|
2013-07-11 18:30:37 -04:00
|
|
|
model_path 'fog/rackspace/models/monitoring'
|
2013-07-03 17:04:58 -04:00
|
|
|
model :entity
|
|
|
|
collection :entities
|
|
|
|
model :check
|
|
|
|
collection :checks
|
|
|
|
model :alarm
|
|
|
|
collection :alarms
|
|
|
|
model :alarm_example
|
|
|
|
collection :alarm_examples
|
|
|
|
model :agent_token
|
|
|
|
collection :agent_tokens
|
|
|
|
model :metric
|
|
|
|
collection :metrics
|
|
|
|
model :data_point
|
|
|
|
collection :data_points
|
|
|
|
model :check_type
|
|
|
|
collection :check_types
|
|
|
|
|
2013-07-11 18:30:37 -04:00
|
|
|
request_path 'fog/rackspace/requests/monitoring'
|
2013-07-03 17:04:58 -04:00
|
|
|
request :list_agent_tokens
|
|
|
|
request :list_alarms
|
|
|
|
request :list_alarm_examples
|
|
|
|
request :list_checks
|
|
|
|
request :list_entities
|
|
|
|
request :list_metrics
|
|
|
|
request :list_data_points
|
|
|
|
request :list_check_types
|
|
|
|
request :list_overview
|
2013-07-18 18:37:51 -04:00
|
|
|
request :list_notification_plans
|
2013-07-03 17:04:58 -04:00
|
|
|
|
|
|
|
request :get_agent_token
|
|
|
|
request :get_alarm
|
|
|
|
request :get_alarm_example
|
|
|
|
request :get_check
|
|
|
|
request :get_entity
|
|
|
|
|
|
|
|
request :create_agent_token
|
|
|
|
request :create_alarm
|
|
|
|
request :create_check
|
|
|
|
request :create_entity
|
|
|
|
|
|
|
|
request :update_check
|
|
|
|
request :update_entity
|
|
|
|
request :update_alarm
|
|
|
|
|
2013-07-24 13:48:05 -04:00
|
|
|
request :delete_agent_token
|
2013-07-24 14:09:46 -04:00
|
|
|
request :delete_alarm
|
2013-07-03 17:04:58 -04:00
|
|
|
request :delete_check
|
|
|
|
request :delete_entity
|
|
|
|
|
|
|
|
request :evaluate_alarm_example
|
|
|
|
|
|
|
|
|
2013-07-11 18:30:37 -04:00
|
|
|
class Mock < Fog::Rackspace::Service
|
|
|
|
def request(params)
|
|
|
|
Fog::Mock.not_implemented
|
|
|
|
end
|
2013-07-03 17:04:58 -04:00
|
|
|
end
|
|
|
|
|
2013-07-11 18:30:37 -04:00
|
|
|
class Real < Fog::Rackspace::Service
|
2013-07-19 14:04:37 -04:00
|
|
|
def service_name
|
|
|
|
:cloudMonitoring
|
|
|
|
end
|
|
|
|
|
|
|
|
def region
|
|
|
|
@rackspace_region
|
|
|
|
end
|
|
|
|
|
2013-07-03 17:04:58 -04:00
|
|
|
def initialize(options={})
|
|
|
|
@rackspace_api_key = options[:rackspace_api_key]
|
|
|
|
@rackspace_username = options[:rackspace_username]
|
|
|
|
@rackspace_auth_url = options[:rackspace_auth_url]
|
|
|
|
@connection_options = options[:connection_options] || {}
|
2013-07-24 14:07:56 -04:00
|
|
|
@rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_monitoring_url])
|
2013-07-03 17:04:58 -04:00
|
|
|
|
2013-07-19 14:04:37 -04:00
|
|
|
authenticate
|
2013-07-03 17:04:58 -04:00
|
|
|
|
|
|
|
@persistent = options[:persistent] || false
|
2013-07-19 14:04:37 -04:00
|
|
|
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
|
2013-07-03 17:04:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
2013-07-24 14:07:56 -04:00
|
|
|
def endpoint_uri(service_endpoint_url=nil)
|
|
|
|
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_monitoring_url)
|
|
|
|
end
|
|
|
|
|
2013-07-19 14:04:37 -04:00
|
|
|
private
|
2013-07-03 17:04:58 -04:00
|
|
|
|
2013-07-24 14:07:56 -04:00
|
|
|
def request(params, parse_json = true, &block)
|
|
|
|
super(params, parse_json, &block)
|
2013-07-19 14:04:37 -04:00
|
|
|
rescue Excon::Errors::BadRequest => error
|
|
|
|
raise BadRequest.slurp error
|
|
|
|
rescue Excon::Errors::Conflict => error
|
|
|
|
raise Conflict.slurp error
|
|
|
|
rescue Excon::Errors::NotFound => error
|
|
|
|
raise NotFound.slurp(error, region)
|
|
|
|
rescue Excon::Errors::ServiceUnavailable => error
|
|
|
|
raise ServiceUnavailable.slurp error
|
2013-07-24 14:07:56 -04:00
|
|
|
rescue Excon::Errors::InternalServerError => error
|
|
|
|
raise InternalServerError.slurp error
|
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
|
|
raise ServiceError.slurp error
|
2013-07-03 17:04:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authenticate
|
2013-07-19 14:04:37 -04:00
|
|
|
options = {
|
|
|
|
:rackspace_api_key => @rackspace_api_key,
|
|
|
|
:rackspace_username => @rackspace_username,
|
|
|
|
:rackspace_auth_url => @rackspace_auth_url,
|
|
|
|
:connection_options => @connection_options
|
|
|
|
}
|
|
|
|
super(options)
|
2013-07-03 17:04:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|