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
|
|
|
|
recognizes :rackspace_service_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
|
|
|
|
|
|
|
|
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-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_options[:headers] ||= {}
|
|
|
|
@connection_options[:headers].merge!({ 'Content-Type' => 'application/json', 'X-Auth-Token' => auth_token })
|
|
|
|
|
|
|
|
@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-19 14:04:37 -04:00
|
|
|
private
|
2013-07-03 17:04:58 -04:00
|
|
|
|
|
|
|
def request(params)
|
|
|
|
begin
|
2013-07-19 14:04:37 -04:00
|
|
|
response = @connection.request(params.merge!({
|
|
|
|
:path => "#{endpoint_uri.path}/#{params[:path]}"
|
|
|
|
}))
|
|
|
|
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-03 17:04:58 -04:00
|
|
|
end
|
2013-07-19 14:04:37 -04:00
|
|
|
unless response.body.empty?
|
|
|
|
response.body = Fog::JSON.decode(response.body)
|
|
|
|
end
|
|
|
|
response
|
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
|