mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
added DescribeAlarmHistory request and parser
This commit is contained in:
parent
519376f635
commit
a3ba1a035c
9 changed files with 132 additions and 26 deletions
1
Rakefile
1
Rakefile
|
@ -2,6 +2,7 @@ require 'rubygems'
|
|||
require 'bundler/setup'
|
||||
require 'date'
|
||||
require File.dirname(__FILE__) + '/lib/fog'
|
||||
require 'rake'
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
|
|
|
@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|||
## the sub! line in the Rakefile
|
||||
s.name = 'fog'
|
||||
s.version = '0.11.0'
|
||||
s.date = '2011-09-29'
|
||||
s.date = '2011-09-30'
|
||||
s.rubyforge_project = 'fog'
|
||||
|
||||
## Make sure your summary is short. The description may be as long
|
||||
|
|
|
@ -14,9 +14,10 @@ module Fog
|
|||
request :describe_alarms
|
||||
request :put_metric_alarm
|
||||
request :delete_alarms
|
||||
request :describe_alarm_history
|
||||
request :enable_alarm_actions
|
||||
request :disable_alarm_actions
|
||||
request :describe_alarm_history
|
||||
request :enable_alarm_actions
|
||||
request :disable_alarm_actions
|
||||
request :describe_alarms_for_metric
|
||||
|
||||
model_path 'fog/aws/models/cloud_watch'
|
||||
model :metric
|
||||
|
|
|
@ -19,14 +19,17 @@ module Fog
|
|||
end
|
||||
|
||||
def end_element(name)
|
||||
@dimension[name] = value
|
||||
#@alarm_history[name] = value
|
||||
case name
|
||||
#when 'Name', 'Value'
|
||||
#@dimension[name] = value
|
||||
when 'RequestId'
|
||||
when 'AlarmName', 'HistoryItemType', 'HistorySummary'
|
||||
@alarm_history[name] = value
|
||||
when 'Timestamp'
|
||||
@alarm_history[name] = Time.parse value
|
||||
when 'RequestId'
|
||||
@response['ResponseMetadata'][name] = value
|
||||
when 'member'
|
||||
@response['DescribeAlarmHistoryResult']['AlarmHistory'] << @metric_alarms
|
||||
@response['DescribeAlarmHistoryResult']['AlarmHistory'] << @alarm_history
|
||||
reset_alarm_history
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module CloudWatch
|
||||
|
||||
class DescribeAlarmsForMetric < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'DescribeAlarmsForMetricResult' => {'AlarmsForMetric' => []}, 'ResponseMetadata' => {} }
|
||||
reset_alarms_for_metric
|
||||
end
|
||||
|
||||
def reset_alarms_for_metric
|
||||
@alarms_for_metric = {'Dimensions' => []}
|
||||
end
|
||||
|
||||
def reset_dimension
|
||||
@dimension = {}
|
||||
end
|
||||
|
||||
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 'Period', 'EvaluationPeriods'
|
||||
@alarms_for_metric[name] = value.to_i
|
||||
when 'Threshold'
|
||||
@alarms_for_metric[name] = value.to_f
|
||||
when 'AlarmActions', 'OKActions', 'InsufficientDataActions'
|
||||
@alarms_for_metric[name] = value.to_s.strip
|
||||
when 'AlarmName', 'Namespace', 'MetricName', 'AlarmDescription', 'AlarmArn',
|
||||
'StateValue', 'Statistic', 'ComparisonOperator', 'StateReason', 'ActionsEnabled'
|
||||
@alarms_for_metric[name] = value
|
||||
when 'Dimensions'
|
||||
@in_dimensions = false
|
||||
when 'RequestId'
|
||||
@response['ResponseMetadata'][name] = value
|
||||
when 'member'
|
||||
if !@in_dimensions
|
||||
@response['DescribeAlarmsForMetricResult']['AlarmsForMetric'] << @alarms_for_metric
|
||||
reset_alarms_for_metric
|
||||
else
|
||||
@alarms_for_metric['Dimensions'] << @dimension
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,19 +3,18 @@ module Fog
|
|||
class CloudWatch
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/cloud_watch/describe_alarms'
|
||||
require 'fog/aws/parsers/cloud_watch/describe_alarms_for_metric'
|
||||
|
||||
# Fetch datapoints for a metric. At most 1440 datapoints will be returned, the most datapoints that can be queried is 50850
|
||||
# StartTime is capped to 2 weeks ago
|
||||
# Retrieves all alarms for a single metric
|
||||
# ==== Options
|
||||
# * ActionPrefix<~String>: The action name prefix
|
||||
# * AlarmNamePrefix<~String>: The alarm name prefix.
|
||||
# AlarmNames cannot be specified if this parameter is specified
|
||||
# * AlarmNames<~Array>: An array of alarm names to retrieve information for.
|
||||
# * MaxRecords<~Integer>: The maximum number of alarm descriptions to retrieve
|
||||
# * NextToken<~String>: The token returned by a previous call to indicate that there is more data available
|
||||
# * NextToken<~String> The token returned by a previous call to indicate that there is more data available
|
||||
# * StateValue<~String>: The state value to be used in matching alarms
|
||||
# * Dimensions<~Array>: a list of dimensions to filter against
|
||||
# Name : The name of the dimension
|
||||
# Value : The value to filter against
|
||||
# * MetricName<~String>: The name of the metric
|
||||
# * Namespace<~String>: The namespace of the metric
|
||||
# * Period<~Integer>: The period in seconds over which the statistic is applied
|
||||
# * Statistics<~String>: The statistic for the metric
|
||||
# * Unit<~String> The unit for the metric
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
@ -25,13 +24,14 @@ module Fog
|
|||
#
|
||||
|
||||
|
||||
def describe_alarms(options={})
|
||||
if alarm_names = options.delete('AlarmNames')
|
||||
options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names]))
|
||||
def describe_alarms_for_metric(options)
|
||||
if dimensions = options.delete('Dimensions')
|
||||
options.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.collect {|dimension| dimension['Name']}))
|
||||
options.merge!(AWS.indexed_param('Dimensions.member.%d.Value', dimensions.collect {|dimension| dimension['Value']}))
|
||||
end
|
||||
request({
|
||||
'Action' => 'DescribeAlarms',
|
||||
:parser => Fog::Parsers::AWS::CloudWatch::DescribeAlarms.new
|
||||
:parser => Fog::Parsers::AWS::CloudWatch::DescribeAlarmsForMetric.new
|
||||
}.merge(options))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class CloudWatch
|
||||
class Real
|
||||
|
||||
require 'fog/aws/parsers/cloud_watch/describe_alarms'
|
||||
|
||||
# Retrieves alarms with the specified names
|
||||
# ==== Options
|
||||
# * ActionPrefix<~String>: The action name prefix
|
||||
# * AlarmNamePrefix<~String>: The alarm name prefix.
|
||||
# AlarmNames cannot be specified if this parameter is specified
|
||||
# * AlarmNames<~Array>: An array of alarm names to retrieve information for.
|
||||
# * MaxRecords<~Integer>: The maximum number of alarm descriptions to retrieve
|
||||
# * NextToken<~String>: The token returned by a previous call to indicate that there is more data available
|
||||
# * NextToken<~String> The token returned by a previous call to indicate that there is more data available
|
||||
# * StateValue<~String>: The state value to be used in matching alarms
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
#
|
||||
# ==== See Also
|
||||
# http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DescribeAlarms.html
|
||||
#
|
||||
|
||||
|
||||
def describe_alarms(options={})
|
||||
if alarm_names = options.delete('AlarmNames')
|
||||
options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names]))
|
||||
end
|
||||
request({
|
||||
'Action' => 'DescribeAlarms',
|
||||
:parser => Fog::Parsers::AWS::CloudWatch::DescribeAlarms.new
|
||||
}.merge(options))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -6,7 +6,6 @@ module Fog
|
|||
require 'fog/aws/parsers/cloud_watch/disable_alarm_actions'
|
||||
|
||||
# Disables actions for the specified alarms
|
||||
# StartTime is capped to 2 weeks ago
|
||||
# ==== Options
|
||||
# * AlarmNames<~Array>: The names of the alarms to disable actions for
|
||||
#
|
||||
|
|
|
@ -6,7 +6,6 @@ module Fog
|
|||
require 'fog/aws/parsers/cloud_watch/enable_alarm_actions'
|
||||
|
||||
# Enables actions for the specified alarms
|
||||
# StartTime is capped to 2 weeks ago
|
||||
# ==== Options
|
||||
# * AlarmNames<~Array>: The names of the alarms to enable actions for
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue