2013-07-03 17:04:58 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
require 'fog/rackspace/models/monitoring/base'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Rackspace
|
|
|
|
class Monitoring
|
|
|
|
class Entity < Fog::Rackspace::Monitoring::Base
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :label
|
|
|
|
attribute :metadata
|
|
|
|
attribute :ip_addresses
|
|
|
|
attribute :agent_id
|
|
|
|
attribute :managed, :default => false
|
|
|
|
attribute :uri
|
|
|
|
|
2013-07-24 16:18:02 -04:00
|
|
|
def params
|
2013-07-03 17:04:58 -04:00
|
|
|
options = {
|
|
|
|
'label' => label,
|
|
|
|
'metadata' => metadata,
|
|
|
|
'ip_addresses'=> ip_addresses,
|
|
|
|
'agent_id' => agent_id
|
|
|
|
}
|
2013-07-24 16:18:02 -04:00
|
|
|
options.reject {|key, value| value.nil?}
|
2013-07-03 17:04:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2013-07-24 16:18:02 -04:00
|
|
|
if identity
|
|
|
|
data = service.update_entity(identity, params)
|
2013-07-03 17:04:58 -04:00
|
|
|
else
|
2013-07-24 16:18:02 -04:00
|
|
|
data = service.create_entity(params)
|
2013-07-26 15:06:32 -04:00
|
|
|
self.id = data.headers['X-Object-ID']
|
2013-07-03 17:04:58 -04:00
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def checks
|
|
|
|
@checks ||= begin
|
|
|
|
Fog::Rackspace::Monitoring::Checks.new(
|
|
|
|
:entity => self,
|
|
|
|
:service => service
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def alarms
|
|
|
|
@alarms ||= begin
|
|
|
|
Fog::Rackspace::Monitoring::Alarms.new(
|
|
|
|
:entity => self,
|
|
|
|
:service => service
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :id
|
|
|
|
service.delete_entity(id)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|