Class: AWS::CloudWatch::AlarmCollection
- Inherits:
-
Object
- Object
- AWS::CloudWatch::AlarmCollection
- Defined in:
- lib/aws/cloud_watch/alarm_collection.rb
Overview
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 AWS::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| ... }
Direct Known Subclasses
Instance Method Summary collapse
- #[](alarm_name) ⇒ Alarm
-
#create(alarm_name, options = {}) ⇒ Alarm
Creates an alarm and associates it with the specified metric.
-
#delete(*alarm_names) ⇒ nil
Delete one or more alarms by name.
-
#filter(name, value) ⇒ Alarm
Returns a new collection with the given filter.
-
#initialize(options = {}) ⇒ AlarmCollection
constructor
A new instance of AlarmCollection.
- #with_action_prefix(prefix) ⇒ MetricAlarmCollection
- #with_name(*names) ⇒ MetricAlarmCollection
- #with_name_prefix(prefix) ⇒ MetricAlarmCollection
- #with_state_value(state) ⇒ MetricAlarmCollection
Methods included from AWS::Core::Collection
#each, #each_batch, #enum, #first, #in_groups_of, #page
Constructor Details
#initialize(options = {}) ⇒ AlarmCollection
Returns a new instance of AlarmCollection.
49 50 51 52 |
# File 'lib/aws/cloud_watch/alarm_collection.rb', line 49 def initialize = {} @filters = [:filters] || {} super end |
Instance Method Details
#[](alarm_name) ⇒ Alarm
56 57 58 |
# File 'lib/aws/cloud_watch/alarm_collection.rb', line 56 def [] alarm_name Alarm.new(alarm_name, :config => config) end |
#create(alarm_name, options = {}) ⇒ Alarm
Creates an alarm and associates it with the specified metric.
74 75 76 77 78 |
# File 'lib/aws/cloud_watch/alarm_collection.rb', line 74 def create alarm_name, = {} [:alarm_name] = alarm_name client.put_metric_alarm() self[alarm_name] end |
#delete(*alarm_names) ⇒ nil
Delete one or more alarms by name.
cloud_watch.alarms.delete('alarm1', 'alarm2')
86 87 88 89 |
# File 'lib/aws/cloud_watch/alarm_collection.rb', line 86 def delete *alarm_names client.delete_alarms(:alarm_names => alarm_names.flatten) nil end |
#filter(name, value) ⇒ Alarm
Returns a new collection with the given filter.
95 96 97 98 |
# 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 |
#with_action_prefix(prefix) ⇒ MetricAlarmCollection
102 103 104 |
# File 'lib/aws/cloud_watch/alarm_collection.rb', line 102 def with_action_prefix prefix filter(:action_prefix, prefix) end |
#with_name(*names) ⇒ MetricAlarmCollection
115 116 117 |
# File 'lib/aws/cloud_watch/alarm_collection.rb', line 115 def with_name *names filter(:alarm_names, names.flatten) end |
#with_name_prefix(prefix) ⇒ MetricAlarmCollection
108 109 110 |
# File 'lib/aws/cloud_watch/alarm_collection.rb', line 108 def with_name_prefix prefix filter(:alarm_name_prefix, prefix) end |
#with_state_value(state) ⇒ MetricAlarmCollection
121 122 123 |
# File 'lib/aws/cloud_watch/alarm_collection.rb', line 121 def with_state_value state filter(:state_value, state) end |