Class: Fog::Rackspace::Monitoring::Alarm

Inherits:
Base
  • Object
show all
Defined in:
lib/fog/rackspace/models/monitoring/alarm.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Base

#compare?, #hash

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#check=(obj) ⇒ Object



22
23
24
# File 'lib/fog/rackspace/models/monitoring/alarm.rb', line 22

def check=(obj)
  attributes[:check] = obj.is_a?(String) ? Check.new(:id => obj) : obj
end

#destroyObject



50
51
52
53
# File 'lib/fog/rackspace/models/monitoring/alarm.rb', line 50

def destroy
  requires :id
  service.delete_alarm(entity.id, id)
end

#entity=(obj) ⇒ Object



18
19
20
# File 'lib/fog/rackspace/models/monitoring/alarm.rb', line 18

def entity=(obj)
 attributes[:entity] = obj.is_a?(String) ? Entity.new(:id => obj) : obj
end

#params(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/fog/rackspace/models/monitoring/alarm.rb', line 26

def params(options={})
  h = {
    'label'                => label,
    'criteria'             => criteria,
    'notification_plan_id' => notification_plan_id,
  }.merge(options)
  h.reject {|key, value| value.nil?}
end

#saveObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/rackspace/models/monitoring/alarm.rb', line 35

def save
  requires :notification_plan_id
  requires :entity
  requires :check

  if identity
    data = service.update_alarm(entity.id, identity, params)
  else
    options = params('check_type' => check_type, 'check_id' => check.id)
    data = service.create_alarm(entity.id, options)
    self.id = data.headers['X-Object-ID']
  end
  true
end