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

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

Instance Method Summary collapse

Methods inherited from Base

#compare?, #hash

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



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

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
34
# File 'lib/fog/rackspace/models/monitoring/alarm.rb', line 26

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

#saveObject



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

def save
  requires :notification_plan_id
  requires :entity
  requires :check

  if identity
    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