You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::CloudWatch::Alarm

Inherits:
AWS::Core::Resource
  • Object
show all
Defined in:
lib/aws/cloud_watch/alarm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alarm_actionsArray<String> (readonly) Also known as: actions

The list of actions to execute when this alarm transitions into an ALARM state from any other state.

Returns:

  • (Array<String>)

    the current value of alarm_actions



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def alarm_actions
  @alarm_actions
end

#alarm_nameString (readonly) Also known as: name

Returns:

  • (String)


79
80
81
# File 'lib/aws/cloud_watch/alarm.rb', line 79

def alarm_name
  @alarm_name
end

#comparison_operatorString (readonly)

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

Returns:

  • (String)

    the current value of comparison_operator



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def comparison_operator
  @comparison_operator
end

#dimensionsArray<Hash> (readonly)

Returns the current value of dimensions

Returns:

  • (Array<Hash>)

    the current value of dimensions



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def dimensions
  @dimensions
end

#evaluation_periodsInteger (readonly)

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

Returns:

  • (Integer)

    the current value of evaluation_periods



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def evaluation_periods
  @evaluation_periods
end

#insufficient_data_actionsArray<Hash> (readonly)

The list of actions to execute when this alarm transitions into an INSUFFICIENT_DATA state

Returns:

  • (Array<Hash>)

    the current value of insufficient_data_actions



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def insufficient_data_actions
  @insufficient_data_actions
end

#metric_nameString (readonly)

Returns the current value of metric_name

Returns:

  • (String)

    the current value of metric_name



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def metric_name
  @metric_name
end

#namespaceString (readonly)

Returns the current value of namespace

Returns:

  • (String)

    the current value of namespace



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def namespace
  @namespace
end

#ok_actionsArray<Hash> (readonly)

The list of actions to execute when this alarm transitions into an OK state.

Returns:

  • (Array<Hash>)

    the current value of ok_actions



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def ok_actions
  @ok_actions
end

#periodInteger (readonly)

The period in seconds over which the statistic is applied.

Returns:

  • (Integer)

    the current value of period



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def period
  @period
end

#state_reasonString (readonly)

A human-readable explanation for the alarm's state.

Returns:

  • (String)

    the current value of state_reason



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def state_reason
  @state_reason
end

#state_reason_dataString (readonly)

An explanation for the alarm's state in machine-readable JSON format.

Returns:

  • (String)

    the current value of state_reason_data



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def state_reason_data
  @state_reason_data
end

#state_updated_timestampTime (readonly)

When the alarm's state last updated.

Returns:

  • (Time)

    the current value of state_updated_timestamp



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def state_updated_timestamp
  @state_updated_timestamp
end

#state_valueString (readonly)

The state value for the alarm.

Returns:

  • (String)

    the current value of state_value



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def state_value
  @state_value
end

#thresholdFloat (readonly)

The value against which the specified statistic is compared.

Returns:

  • (Float)

    the current value of threshold



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def threshold
  @threshold
end

#unitString (readonly)

The unit of the alarm's associated metric.

Returns:

  • (String)

    the current value of unit



70
71
72
# File 'lib/aws/cloud_watch/alarm.rb', line 70

def unit
  @unit
end

Instance Method Details

#deletenil

Deletes the current alarm.

Returns:

  • (nil)


224
225
226
227
# File 'lib/aws/cloud_watch/alarm.rb', line 224

def delete
  client.delete_alarms(:alarm_names => [ alarm_name ])
  nil
end

#disablenil

Disable the current alarm actions.

Returns:

  • (nil)


231
232
233
234
# File 'lib/aws/cloud_watch/alarm.rb', line 231

def disable
  client.disable_alarm_actions(:alarm_names => [ alarm_name ])
  nil
end

#enablenil

Enable the current alarm actions.

Returns:

  • (nil)


238
239
240
241
# File 'lib/aws/cloud_watch/alarm.rb', line 238

def enable
  client.enable_alarm_actions(:alarm_names => [ alarm_name ])
  nil
end

#exists?Boolean

Returns true if this alarm exists.

Returns:

  • (Boolean)

    Returns true if this alarm exists.



244
245
246
# File 'lib/aws/cloud_watch/alarm.rb', line 244

def exists?
  !get_resource.data[:metric_alarms].empty?
end

#history_items(options = {}) ⇒ AlarmHistoryItemCollection Also known as: history, histories

Returns a collection of the history items for current alarm.



250
251
252
# File 'lib/aws/cloud_watch/alarm.rb', line 250

def history_items options = {}
  AlarmHistoryItemCollection.new(:config => config).with_alarm_name(name)
end

#metricMetric

Returns:



145
146
147
148
149
150
# 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 = {}) ⇒ nil

Temporarily sets the state of current alarm.

Parameters:

  • reason (String)

    The reason that this alarm is set to this specific state (in human-readable text format).

  • value (String)

    Valid values include:

    • 'OK'
    • 'ALARM'
    • 'INSUFFICIENT_DATA'
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :state_reason_data (String)

    The reason that this

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

Returns:

  • (nil)


273
274
275
276
277
278
279
# 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 = {}) ⇒ nil

Updates the metric alarm.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :comparison_operator (String, required)

    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'
  • :namespace (String, required)

    The namespace for the alarm's associated metric.

  • :evaluation_periods (Integer, required)

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

  • :period (Integer, required)

    The period in seconds over which the specified statistic is applied.

  • :statistic (String, required)

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

    • 'SampleCount'
    • 'Average'
    • 'Sum'
    • 'Minimum'
    • 'Maximum'
  • :threshold (Number, required)

    The value against which the specified statistic is compared.

  • :insufficient_data_actions (Array<String>)

    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.

  • :ok_actions (Array<String>)

    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.

  • :actions_enabled (Boolean)

    Indicates whether or not actions should be executed during any changes to the alarm's state.

  • :alarm_actions (Array<String>)

    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.

  • :alarm_description (String)

    The description for the alarm.

  • :unit (String)

    The unit for the alarm's associated metric.

Returns:

  • (nil)


216
217
218
219
220
# File 'lib/aws/cloud_watch/alarm.rb', line 216

def update options = {}
  options[:alarm_name] = alarm_name
  client.put_metric_alarm(options)
  nil
end