class AWS::CloudWatch::Alarm

@attr_reader [String] metric_name

@attr_reader [String] namespace

@attr_reader [Array<Hash>] dimensions

@attr_reader [Boolean] enabled Indicates whether actions

should be executed during any changes to the alarm's state.

@attr_reader [Array<String>] alarm_actions The list of actions to execute

when this alarm transitions into an ALARM state from any other
state.

@attr_reader [String] arn The Amazon Resource Name (ARN) of the alarm.

@attr_reader [Time] configuration_updated_timestamp

The time stamp of the last update to the alarm configuration.

@attr_reader [String] description The description for the alarm.

@attr_reader [String] comparison_operator The arithmetic operation to

use when comparing the specified Statistic and Threshold. The
specified Statistic value is used as the first operand.

@attr_reader [Integer] evaluation_periods The number of periods over

which data is compared to the specified threshold.

@attr_reader [Array<Hash>] insufficient_data_actions The list of

actions to execute when this alarm transitions into an
INSUFFICIENT_DATA state

@attr_reader [Array<Hash>] ok_actions The list of actions to execute

when this alarm transitions into an OK state.

@attr_reader [Integer] period The period in seconds over which the

statistic is applied.

@attr_reader [String] state_reason A human-readable explanation for

the alarm's state.

@attr_reader [String] state_reason_data An explanation for the alarm’s

state in machine-readable JSON format.

@attr_reader [Time] state_updated_timestamp When the alarm’s state

last updated.

@attr_reader [String] state_value The state value for the alarm.

@attr_reader [Float] threshold The value against which the specified

statistic is compared.

@attr_reader [String] unit The unit of the alarm’s associated metric.

Attributes

alarm_name[R]

@return [String]

name[R]

@return [String]

Public Class Methods

new(alarm_name, options = {}) click to toggle source

@api private

Calls superclass method
# File lib/aws/cloud_watch/alarm.rb, line 73
def initialize alarm_name, options = {}
  @alarm_name = alarm_name
  super
end

Public Instance Methods

delete() click to toggle source

Deletes the current alarm. @return [nil]

# File lib/aws/cloud_watch/alarm.rb, line 224
def delete
  client.delete_alarms(:alarm_names => [ alarm_name ])
  nil
end
disable() click to toggle source

Disable the current alarm actions. @return [nil]

# File lib/aws/cloud_watch/alarm.rb, line 231
def disable
  client.disable_alarm_actions(:alarm_names => [ alarm_name ])
  nil
end
enable() click to toggle source

Enable the current alarm actions. @return [nil]

# File lib/aws/cloud_watch/alarm.rb, line 238
def enable
  client.enable_alarm_actions(:alarm_names => [ alarm_name ])
  nil
end
exists?() click to toggle source

@return [Boolean] Returns true if this alarm exists.

# File lib/aws/cloud_watch/alarm.rb, line 244
def exists?
  !get_resource.data[:metric_alarms].empty?
end
histories(options = {})
Alias for: history_items
history(options = {})
Alias for: history_items
history_items(options = {}) click to toggle source

Returns a collection of the history items for current alarm. @return [AlarmHistoryItemCollection]

# File lib/aws/cloud_watch/alarm.rb, line 250
def history_items options = {}
  AlarmHistoryItemCollection.new(:config => config).with_alarm_name(name)
end
Also aliased as: history, histories
metric() click to toggle source

@return [Metric]

# File lib/aws/cloud_watch/alarm.rb, line 145
def metric
  options = {}
  options[:dimensions] = dimensions unless dimensions.empty?
  options[:config] = config
  Metric.new(namespace, metric_name, options)
end
set_state(reason, value, options = {}) click to toggle source

Temporarily sets the state of current alarm. @param [String] reason The reason that this alarm is set to this

specific state (in human-readable text format).

@param [String] value Valid values include:

* 'OK'
* 'ALARM'
* 'INSUFFICIENT_DATA'

@param [Hash] options @option options [String] :state_reason_data The reason that this

alarm is set to this specific state (in machine-readable JSON
format)

@return [nil]

# File lib/aws/cloud_watch/alarm.rb, line 273
def set_state reason, value, options = {}
  options[:alarm_name] = alarm_name
  options[:state_reason] = reason
  options[:state_value] = value
  client.set_alarm_state(options)
  nil
end
update(options = {}) click to toggle source

Updates the metric alarm.

@option options [String,required] :comparison_operator The arithmetic

operation to use when comparing the specified Statistic and
Threshold. The specified Statistic value is used as the first
operand.  Valid values include:

  * 'GreaterThanOrEqualToThreshold'
  * 'GreaterThanThreshold'
  * 'LessThanThreshold'
  * 'LessThanOrEqualToThreshold'

@option options [String,required] :namespace The namespace for the

alarm's associated metric.

@option options [Integer,required] :evaluation_periods The number

of periods over which data is compared to the specified threshold.

@option options [Integer,required] :period The period in seconds

over which the specified statistic is applied.

@option options [String,required] :statistic The statistic to apply

to the alarm's associated metric. Valid values include:

  * 'SampleCount'
  * 'Average'
  * 'Sum'
  * 'Minimum'
  * 'Maximum'

@option options [Number,required] :threshold The value against which

the specified statistic is compared.

@option options [Array<String>] :insufficient_data_actions

The list of actions to execute when this alarm transitions into an
INSUFFICIENT_DATA state from any other state. Each action is
specified as an Amazon Resource Number (ARN). Currently the only
action supported is publishing to an Amazon SNS topic or an
Amazon Auto Scaling policy.

@option options [Array<String>] :ok_actions The list of actions to

execute when this alarm transitions into an OK state from any
other state. Each action is specified as an Amazon Resource
Number (ARN). Currently the only action supported is publishing to
an Amazon SNS topic or an Amazon Auto Scaling policy.

@option options [Boolean] :actions_enabled Indicates whether or not

actions should be executed during any changes to the alarm's
state.

@option options [Array<String>] :alarm_actions The list of actions

to execute when this alarm transitions into an ALARM state from
any other state. Each action is specified as an Amazon Resource
Number (ARN). Currently the only action supported is publishing
to an Amazon SNS topic or an Amazon Auto Scaling policy.
Maximum of 5 alarm actions.

@option options [String] :alarm_description The description for

the alarm.

@option options [String] :unit The unit for the alarm’s associated

metric.

@return [nil]

# File lib/aws/cloud_watch/alarm.rb, line 216
def update options = {}
  options[:alarm_name] = alarm_name
  client.put_metric_alarm(options)
  nil
end

Protected Instance Methods

get_resource(attr_name = nil) click to toggle source
# File lib/aws/cloud_watch/alarm.rb, line 287
def get_resource attr_name = nil
  client.describe_alarms(:alarm_names => [ alarm_name ])
end
resource_identifiers() click to toggle source
# File lib/aws/cloud_watch/alarm.rb, line 283
def resource_identifiers
  [[:alarm_name, alarm_name]]
end