class AWS::CloudWatch::AlarmCollection
AlarmCollection
¶ ↑
Represents alarms for an AWS
account.
Getting an alarm by name¶ ↑
If you know the name of the alarm, you can get a reference using the {#[]} method.
cw = AWS::CloudWatch.new alarm = cw.alarms['alarm-name']
Enumerating Alarms¶ ↑
You can enumerate all alarms using each (or any of the methods defined in {Core::Collection}).
cw.alarms.each do |alarm| puts alarm.name end
Filtering Alarms¶ ↑
Use one of the filtering methods to reduce the number of alarms returned.
cw.alarms.with_name_prefix('some-prefix-').each {|alarm| ... }
Public Class Methods
# File lib/aws/cloud_watch/alarm_collection.rb, line 49 def initialize options = {} @filters = options[:filters] || {} super end
Public Instance Methods
@param [String] alarm_name @return [Alarm]
# File lib/aws/cloud_watch/alarm_collection.rb, line 56 def [] alarm_name Alarm.new(alarm_name, :config => config) end
Creates an alarm and associates it with the specified metric.
@param [String] alarm_name The descriptive name for the alarm.
This name must be unique within the user's AWS account.
@param [Hash] options @option options [String,required] :namespace The namespace for the
alarm's associated metric.
@option options [String,required] :metric_name The name for the
alarm's associated metric.
@option options [Array<Hash>] :dimensions The dimensions for the
alarm's associated metric. Each dimension must specify a +:name+ and a +:value+.
@option (see Alarm#update
) @return [Alarm]
# File lib/aws/cloud_watch/alarm_collection.rb, line 74 def create alarm_name, options = {} options[:alarm_name] = alarm_name client.put_metric_alarm(options) self[alarm_name] end
Delete one or more alarms by name.
cloud_watch.alarms.delete('alarm1', 'alarm2')
@param [String,Array<String>] alarm_names @return [nil]
# File lib/aws/cloud_watch/alarm_collection.rb, line 86 def delete *alarm_names client.delete_alarms(:alarm_names => alarm_names.flatten) nil end
Returns a new collection with the given filter. @param [String,Symbol] name @param [String,Integer] value @return [Alarm]
# File lib/aws/cloud_watch/alarm_collection.rb, line 95 def filter name, value filters = @filters.merge(name.to_s.to_sym => value) AlarmCollection.new(:filters => filters, :config => config) end
@param [String] prefix @return [MetricAlarmCollection]
# File lib/aws/cloud_watch/alarm_collection.rb, line 102 def with_action_prefix prefix filter(:action_prefix, prefix) end
@param [String,Array<String>] names A list of alarm names to
retrieve information for.
@return [MetricAlarmCollection]
# File lib/aws/cloud_watch/alarm_collection.rb, line 115 def with_name *names filter(:alarm_names, names.flatten) end
@param [String] prefix The alarm name prefix. @return [MetricAlarmCollection]
# File lib/aws/cloud_watch/alarm_collection.rb, line 108 def with_name_prefix prefix filter(:alarm_name_prefix, prefix) end
@param [String] state The state value to be used in matching alarms. @return [MetricAlarmCollection]
# File lib/aws/cloud_watch/alarm_collection.rb, line 121 def with_state_value state filter(:state_value, state) end
Protected Instance Methods
# File lib/aws/cloud_watch/alarm_collection.rb, line 127 def _each_item next_token, limit, options = {}, &block options = @filters.merge(options) options[:next_token] = next_token if next_token options[:max_records] = limit if limit resp = client.describe_alarms(options) resp.data[:metric_alarms].each do |details| alarm = Alarm.new_from( :describe_alarms, details, details[:alarm_name], :config => config) yield(alarm) end resp.data[:next_token] end