1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/parsers/cloud_watch/describe_alarms.rb

72 lines
2.5 KiB
Ruby
Raw Normal View History

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
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'
@in_dimensions = false
2011-10-03 19:12:45 -04:00
when 'RequestId'
@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