2011-09-29 17:55:48 -04:00
|
|
|
module Fog
|
|
|
|
module Parsers
|
|
|
|
module AWS
|
|
|
|
module CloudWatch
|
|
|
|
class DescribeAlarms < Fog::Parsers::Base
|
|
|
|
def reset
|
|
|
|
@response = { 'DescribeAlarmsResult' => {'MetricAlarms' => []}, 'ResponseMetadata' => {} }
|
|
|
|
reset_metric_alarms
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_metric_alarms
|
|
|
|
@metric_alarms = {'Dimensions' => []}
|
|
|
|
end
|
2011-09-30 14:49:10 -04:00
|
|
|
|
2011-09-29 17:55:48 -04:00
|
|
|
def reset_dimension
|
|
|
|
@dimension = {}
|
|
|
|
end
|
2011-09-30 14:49:10 -04:00
|
|
|
|
2011-09-29 17:55:48 -04:00
|
|
|
def start_element(name, attrs = [])
|
|
|
|
super
|
|
|
|
case name
|
|
|
|
when 'Dimensions'
|
|
|
|
@in_dimensions = true
|
|
|
|
when 'member'
|
|
|
|
if @in_dimensions
|
|
|
|
reset_dimension
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_element(name)
|
|
|
|
case name
|
|
|
|
when 'Name', 'Value'
|
|
|
|
@dimension[name] = value
|
|
|
|
when 'AlarmConfigurationUpdatedTimestamp', 'StateUpdatedTimestamp'
|
|
|
|
@metric_alarms[name] = Time.parse value
|
|
|
|
when 'Period', 'EvaluationPeriods'
|
|
|
|
@metric_alarms[name] = value.to_i
|
|
|
|
when 'Threshold'
|
|
|
|
@metric_alarms[name] = value.to_f
|
|
|
|
when 'AlarmActions', 'OKActions', 'InsufficientDataActions'
|
|
|
|
@metric_alarms[name] = value.to_s.strip
|
2011-10-03 16:18:45 -04:00
|
|
|
when 'AlarmName', 'Namespace', 'MetricName', 'AlarmDescription', 'AlarmArn', 'Unit',
|
2011-10-03 19:12:45 -04:00
|
|
|
'StateValue', 'Statistic', 'ComparisonOperator', 'StateReason', 'ActionsEnabled'
|
2011-09-29 17:55:48 -04:00
|
|
|
@metric_alarms[name] = value
|
2011-09-30 17:10:40 -04:00
|
|
|
when 'StateUpdatedTimestamp', 'AlarmConfigurationUpdatedTimestamp'
|
2011-10-03 19:12:45 -04:00
|
|
|
@metric_alarms[name] = Time.parse value
|
2011-09-29 17:55:48 -04:00
|
|
|
when 'Dimensions'
|
2011-09-30 17:10:40 -04:00
|
|
|
@in_dimensions = false
|
2011-10-03 19:12:45 -04:00
|
|
|
when 'RequestId'
|
2011-09-30 17:10:40 -04:00
|
|
|
@response['ResponseMetadata'][name] = value
|
|
|
|
when 'NextToken'
|
|
|
|
@response['ResponseMetadata'][name] = value
|
2011-09-29 17:55:48 -04:00
|
|
|
when 'member'
|
|
|
|
if !@in_dimensions
|
2011-10-03 16:18:45 -04:00
|
|
|
if @metric_alarms.has_key?('AlarmName')
|
2011-10-03 19:12:45 -04:00
|
|
|
@response['DescribeAlarmsResult']['MetricAlarms'] << @metric_alarms
|
|
|
|
reset_metric_alarms
|
2011-10-03 16:18:45 -04:00
|
|
|
elsif @response['DescribeAlarmsResult']['MetricAlarms'].last != nil
|
|
|
|
@response['DescribeAlarmsResult']['MetricAlarms'].last.merge!( @metric_alarms)
|
2011-09-29 17:55:48 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
@metric_alarms['Dimensions'] << @dimension
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-03 18:34:59 -04:00
|
|
|
end
|