2011-09-30 17:10:40 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class CloudWatch
|
|
|
|
class Alarm < Fog::Model
|
2012-06-17 12:47:07 -04:00
|
|
|
identity :id, :aliases => 'AlarmName'
|
|
|
|
|
|
|
|
attribute :actions_enabled, :aliases => 'ActionsEnabled'
|
|
|
|
attribute :alarm_actions, :aliases => 'AlarmActions'
|
|
|
|
attribute :arn, :aliases => 'AlarmArn'
|
|
|
|
attribute :alarm_configuration_updated_timestamp, :aliases => 'AlarmConfigurationUpdatedTimestamp'
|
|
|
|
attribute :alarm_description, :aliases => 'AlarmDescription'
|
|
|
|
attribute :comparison_operator, :aliases => 'ComparisonOperator'
|
|
|
|
attribute :dimensions, :aliases => 'Dimensions'
|
|
|
|
attribute :evaluation_periods, :aliases => 'EvaluationPeriods'
|
|
|
|
attribute :insufficient_data_actions, :aliases => 'InsufficientDataActions'
|
|
|
|
attribute :metric_name, :aliases => 'MetricName'
|
|
|
|
attribute :namespace, :aliases => 'Namespace'
|
|
|
|
attribute :ok_actions, :aliases => 'OKActions'
|
2012-06-17 14:16:29 -04:00
|
|
|
attribute :period, :aliases => 'Period'
|
2012-06-17 12:47:07 -04:00
|
|
|
attribute :state_reason, :aliases => 'StateReason'
|
|
|
|
attribute :state_reason_data, :aliases => 'StateReasonData'
|
|
|
|
attribute :state_updated_timestamp, :aliases => 'StateUpdatedTimestamp'
|
|
|
|
attribute :state_value, :aliases => 'StateValue'
|
|
|
|
attribute :statistic, :aliases => 'Statistic'
|
|
|
|
attribute :threshold, :aliases => 'Threshold'
|
|
|
|
attribute :unit, :aliases => 'Unit'
|
|
|
|
|
2012-06-17 14:16:29 -04:00
|
|
|
def initialize(attributes)
|
|
|
|
attributes['EvaluationPeriods'] ||= 1
|
|
|
|
attributes['Namespace'] ||= 'AWS/EC2'
|
|
|
|
super
|
|
|
|
end
|
2012-06-17 12:47:07 -04:00
|
|
|
|
2012-06-17 14:16:29 -04:00
|
|
|
def save
|
|
|
|
requires :id
|
|
|
|
requires :comparison_operator
|
|
|
|
requires :evaluation_periods
|
|
|
|
requires :metric_name
|
|
|
|
requires :namespace
|
|
|
|
requires :period
|
|
|
|
requires :statistic
|
|
|
|
requires :threshold
|
2012-06-17 12:47:07 -04:00
|
|
|
|
2012-06-17 14:16:29 -04:00
|
|
|
options = Hash[self.class.aliases.map { |key, value| [key, send(value)] }]
|
|
|
|
options.delete_if { |key, value| value.nil? }
|
2012-06-17 12:47:07 -04:00
|
|
|
|
2012-12-22 18:31:48 -05:00
|
|
|
service.put_metric_alarm(options)
|
2012-06-17 14:16:29 -04:00
|
|
|
reload
|
|
|
|
end
|
2012-06-17 12:47:07 -04:00
|
|
|
|
2012-06-17 14:16:29 -04:00
|
|
|
def destroy
|
|
|
|
requires :id
|
2012-12-22 18:31:48 -05:00
|
|
|
service.delete_alarms(id)
|
2012-06-17 14:16:29 -04:00
|
|
|
end
|
2011-09-30 17:10:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-03 18:34:59 -04:00
|
|
|
end
|