1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/rackspace/monitoring.rb

139 lines
4.3 KiB
Ruby

require 'fog'
require 'fog/core'
module Fog
module Rackspace
class Monitoring < Fog::Service
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
class Conflict < Fog::Rackspace::Errors::Conflict; end
class ServiceUnavailable < Fog::Rackspace::Errors::ServiceUnavailable; end
requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url
recognizes :persistent
recognizes :rackspace_monitoring_url
recognizes :rackspace_region
model_path 'fog/rackspace/models/monitoring'
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
request_path 'fog/rackspace/requests/monitoring'
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
request :list_notification_plans
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
request :delete_check
request :delete_entity
request :evaluate_alarm_example
class Mock < Fog::Rackspace::Service
def request(params)
Fog::Mock.not_implemented
end
end
class Real < Fog::Rackspace::Service
def service_name
:cloudMonitoring
end
def region
@rackspace_region
end
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] || {}
@rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_monitoring_url])
authenticate
@persistent = options[:persistent] || false
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end
def reload
@connection.reset
end
def endpoint_uri(service_endpoint_url=nil)
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_monitoring_url)
end
private
def request(params, parse_json = true, &block)
super(params, parse_json, &block)
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
rescue Excon::Errors::InternalServerError => error
raise InternalServerError.slurp error
rescue Excon::Errors::HTTPStatusError => error
raise ServiceError.slurp error
end
def authenticate
options = {
:rackspace_api_key => @rackspace_api_key,
:rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url,
:connection_options => @connection_options
}
super(options)
end
end
end
end
end