Class: Cumulus::AutoScaling::AlarmConfig
- Inherits:
-
Object
- Object
- Cumulus::AutoScaling::AlarmConfig
- Defined in:
- lib/autoscaling/models/AlarmConfig.rb
Overview
Public: A class that encapsulates data about configuration for an autoscaling Cloudwatch alarm.
The action to be taken is inferred to be activating the policy that contains the alarm. As such, we don’t keep arrays of actions to take when various alarm states are triggered. We just apply the action (activating the policy) to the states contained in the ‘action_states` array. Valid values are “alarm”, “ok”, and “insufficient-data”.
Instance Attribute Summary collapse
-
#action_states ⇒ Object
readonly
Returns the value of attribute action_states.
-
#actions_enabled ⇒ Object
readonly
Returns the value of attribute actions_enabled.
-
#comparison ⇒ Object
readonly
Returns the value of attribute comparison.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#dimensions ⇒ Object
readonly
Returns the value of attribute dimensions.
-
#evaluation_periods ⇒ Object
readonly
Returns the value of attribute evaluation_periods.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#statistic ⇒ Object
readonly
Returns the value of attribute statistic.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
-
#diff(aws, policy_arn) ⇒ Object
Public: Produce the differences between this local configuration and the configuration in AWS.
-
#hash ⇒ Object
Public: Get the configuration as a hash.
-
#initialize(json = nil) ⇒ AlarmConfig
constructor
Public: Constructor.
-
#populate(policy_arn, resource) ⇒ Object
Public: Populate the AlarmConfig from an existing AWS cloudwatch alarm.
Constructor Details
#initialize(json = nil) ⇒ AlarmConfig
Public: Constructor
json - a hash containing the JSON configuration for the alarm
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 31 def initialize(json = nil) if !json.nil? @action_states = json["action-states"] @actions_enabled = json["actions-enabled"] @comparison = json["comparison"] @description = json["description"] @dimensions = json["dimensions"] @evaluation_periods = json["evaluation-periods"] @metric = json["metric"] @name = json["name"] @namespace = json["namespace"] @period = json["period-seconds"] @statistic = json["statistic"] @threshold = json["threshold"] @unit = json["unit"] end end |
Instance Attribute Details
#action_states ⇒ Object (readonly)
Returns the value of attribute action_states.
14 15 16 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 14 def action_states @action_states end |
#actions_enabled ⇒ Object (readonly)
Returns the value of attribute actions_enabled.
15 16 17 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 15 def actions_enabled @actions_enabled end |
#comparison ⇒ Object (readonly)
Returns the value of attribute comparison.
16 17 18 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 16 def comparison @comparison end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
17 18 19 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 17 def description @description end |
#dimensions ⇒ Object (readonly)
Returns the value of attribute dimensions.
18 19 20 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 18 def dimensions @dimensions end |
#evaluation_periods ⇒ Object (readonly)
Returns the value of attribute evaluation_periods.
19 20 21 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 19 def evaluation_periods @evaluation_periods end |
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
20 21 22 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 20 def metric @metric end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 21 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
22 23 24 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 22 def namespace @namespace end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
23 24 25 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 23 def period @period end |
#statistic ⇒ Object (readonly)
Returns the value of attribute statistic.
24 25 26 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 24 def statistic @statistic end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
25 26 27 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 25 def threshold @threshold end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
26 27 28 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 26 def unit @unit end |
Instance Method Details
#diff(aws, policy_arn) ⇒ Object
Public: Produce the differences between this local configuration and the configuration in AWS
aws - the alarm in AWS policy_arn - the policy arn is the action this alarm should take
Returns an array of AlarmDiff objects representing the differences
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 102 def diff(aws, policy_arn) diffs = [] if @description != aws.alarm_description diffs << AlarmDiff.new(AlarmChange::DESCRIPTION, aws, self) end if @actions_enabled != aws.actions_enabled diffs << AlarmDiff.new(AlarmChange::ENABLED, aws, self) end if @comparison != aws.comparison_operator diffs << AlarmDiff.new(AlarmChange::COMPARISON, aws, self) end if @evaluation_periods != aws.evaluation_periods diffs << AlarmDiff.new(AlarmChange::EVALUATION, aws, self) end if @metric != aws.metric_name diffs << AlarmDiff.new(AlarmChange::METRIC, aws, self) end if @namespace != aws.namespace diffs << AlarmDiff.new(AlarmChange::NAMESPACE, aws, self) end if @period != aws.period diffs << AlarmDiff.new(AlarmChange::PERIOD, aws, self) end if @statistic != aws.statistic diffs << AlarmDiff.new(AlarmChange::STATISTIC, aws, self) end if @threshold != aws.threshold diffs << AlarmDiff.new(AlarmChange::THRESHOLD, aws, self) end if @unit != aws.unit diffs << AlarmDiff.new(AlarmChange::UNIT, aws, self) end aws_dimensions = Hash[aws.dimensions.map { |d| [d.name, d.value] }] if @dimensions != aws_dimensions diffs << AlarmDiff.new(AlarmChange::DIMENSIONS, aws, self) end ["ok", "alarm", "insufficient-data"].each do |state| case state when "ok" actions = aws.ok_actions change_type = AlarmChange::OK when "alarm" actions = aws.alarm_actions change_type = AlarmChange::ALARM when "insufficient-data" actions = aws.insufficient_data_actions change_type = AlarmChange::INSUFFICIENT end if (!@action_states.include?(state) and actions.size != 0) or (@action_states.include?(state) and (actions.size != 1 or actions[0] != policy_arn)) diff = AlarmDiff.new(change_type, aws, self) diff.policy_arn = policy_arn diffs << diff end end diffs end |
#hash ⇒ Object
Public: Get the configuration as a hash
Returns the hash
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 52 def hash { "name" => @name, "action-states" => @action_states, "actions-enabled" => @actions_enabled, "comparison" => @comparison, "description" => @description, "dimensions" => @dimensions, "evaluation-periods" => @evaluation_periods, "metric" => @metric, "namespace" => @namespace, "period-seconds" => @period, "statistic" => @statistic, "threshold" => @threshold, "unit" => @unit }.reject { |k, v| v.nil? } end |
#populate(policy_arn, resource) ⇒ Object
Public: Populate the AlarmConfig from an existing AWS cloudwatch alarm
policy_arn - the arn of the policy the alarm should be attached to resource - the aws resource to populate from
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/autoscaling/models/AlarmConfig.rb', line 74 def populate(policy_arn, resource) action_states = [] if resource.ok_actions.include?(policy_arn) then action_states << "ok" end if resource.alarm_actions.include?(policy_arn) then action_states << "alarm" end if resource.insufficient_data_actions.include?(policy_arn) then action_states << "insufficient-data" end @action_states = action_states @actions_enabled = resource.actions_enabled @comparison = resource.comparison_operator @description = resource.alarm_description @dimensions = Hash[resource.dimensions.map { |d| [d.name, d.value] }] @evaluation_periods = resource.evaluation_periods @metric = resource.metric_name @name = resource.alarm_name @namespace = resource.namespace @period = resource.period @statistic = resource.statistic @threshold = resource.threshold @unit = resource.unit end |