1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

re-adding files

This commit is contained in:
Michael Zeng 2011-09-29 17:55:48 -04:00
parent 57cc3b001f
commit 76b88bdb69
6 changed files with 252 additions and 0 deletions

View file

@ -0,0 +1,24 @@
module Fog
module Parsers
module AWS
module CloudWatch
class DeleteAlarms < Fog::Parsers::Base
def reset
@response = { 'ResponseMetadata' => {} }
end
def start_element(name, attrs = [])
super
end
def end_element(name)
case name
when 'RequestId'
@response['ResponseMetadata'][name] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,71 @@
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
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 '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
when 'AlarmName', 'Namespace', 'MetricName', 'AlarmDescription', 'AlarmArn',
'StateValue', 'Statistic', 'ComparisonOperator', 'StateReason', 'ActionsEnabled'
@metric_alarms[name] = value
when 'Dimensions'
@in_dimensions = false
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'member'
if !@in_dimensions
unless @metric_alarms == {}
if @metric_alarms.has_key?('AlarmName')
@response['DescribeAlarmsResult']['MetricAlarms'] << @metric_alarms
else
@response['DescribeAlarmsResult']['MetricAlarms'].last.merge!( @metric_alarms)
reset_metric_alarms
end
end
else
@metric_alarms['Dimensions'] << @dimension
end
end
end
end
end
end
end
end

View file

@ -0,0 +1,24 @@
module Fog
module Parsers
module AWS
module CloudWatch
class PutMetricAlarm < Fog::Parsers::Base
def reset
@response = { 'ResponseMetadata' => {} }
end
def start_element(name, attrs = [])
super
end
def end_element(name)
case name
when 'RequestId'
@response['ResponseMetadata'][name] = value
end
end
end
end
end
end
end

View file

@ -0,0 +1,33 @@
module Fog
module AWS
class CloudWatch
class Real
require 'fog/aws/parsers/cloud_watch/delete_alarms'
# Delete a list of alarms
# ==== Options
# * AlarmNames<~Array>: An array of alarms to be deleted
#
# ==== Returns
# * response<~Excon::Response>:
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_DeleteAlarms.html
#
def delete_alarms(alarms)
options = {}
options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarms]))
request({
'Action' => 'DeleteAlarms',
:parser => Fog::Parsers::AWS::CloudWatch::DeleteAlarms.new
}.merge(options))
end
end
end
end
end

View file

@ -0,0 +1,40 @@
module Fog
module AWS
class CloudWatch
class Real
require 'fog/aws/parsers/cloud_watch/describe_alarms'
# 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
# ==== 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
# * 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

View file

@ -0,0 +1,60 @@
module Fog
module AWS
class CloudWatch
class Real
require 'fog/aws/parsers/cloud_watch/put_metric_alarm'
# List availabe metrics
#
# ==== Options
# * ActionsEnabled<~Boolean>: Indicates whether or not actions should be executed during any changes to the alarm's state
# * AlarmActions<~Array>: A list of actions to execute
# * AlarmDescription<~String>: The description for the alarm
# * AlarmName<~String> The unique name for the alarm
# * ComparisonOperator<~String>: The arithmetic operation to use for comparison
# * Dimensions<~Array>: a list of dimensions to filter against,
# Name : The name of the dimension
# Value : The value to filter against
# * EvaluationPeriods<~Integer>: The number of periods over which data is compared to the specified threshold
# * InsufficientDataActions<~Array>: A list of actions to execute
# * MetricName<~String>: The name for the alarm's associated metric
# * Namespace<~String>: The namespace for the alarm's associated metric
# * OKActions<~Array>: A list of actions to execute
# * Period<~Integer>: The period in seconds over which the specified statistic is applied
# * Statistic<~String>: The statistic to apply to the alarm's associated metric
# * Threshold<~Double>: The value against which the specified statistic is compared
# * Unit<~String>: The unit for the alarm's associated metric
#
# ==== Returns
# * response<~Excon::Response>:
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html
#
def put_metric_alarm(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
if alarm_actions = options.delete('AlarmActions')
options.merge!(AWS.indexed_param('AlarmActions.member.%d', [*alarm_actions]))
end
if insufficient_data_actions = options.delete('InsufficientDataActions')
options.merge!(AWS.indexed_param('InsufficientDataActions.member.%d', [*insufficient_data_actions]))
end
if ok_actions = options.delete('OKActions')
options.merge!(AWS.indexed_param('OKActions.member.%d', [*ok_actions]))
end
request({
'Action' => 'PutMetricAlarm',
:parser => Fog::Parsers::AWS::CloudWatch::PutMetricAlarm.new
}.merge(options))
end
end
end
end
end