Class: Cumulus::AutoScaling::AlarmDiff

Inherits:
Common::Diff show all
Includes:
AlarmChange
Defined in:
lib/autoscaling/models/AlarmDiff.rb

Overview

Public: Represents a single difference between local configuration and AWS configuration of Cloudwatch alarms

Constant Summary

Constants included from AlarmChange

Cumulus::AutoScaling::AlarmChange::ALARM, Cumulus::AutoScaling::AlarmChange::COMPARISON, Cumulus::AutoScaling::AlarmChange::DESCRIPTION, Cumulus::AutoScaling::AlarmChange::DIMENSIONS, Cumulus::AutoScaling::AlarmChange::ENABLED, Cumulus::AutoScaling::AlarmChange::EVALUATION, Cumulus::AutoScaling::AlarmChange::INSUFFICIENT, Cumulus::AutoScaling::AlarmChange::METRIC, Cumulus::AutoScaling::AlarmChange::NAMESPACE, Cumulus::AutoScaling::AlarmChange::OK, Cumulus::AutoScaling::AlarmChange::PERIOD, Cumulus::AutoScaling::AlarmChange::STATISTIC, Cumulus::AutoScaling::AlarmChange::THRESHOLD, Cumulus::AutoScaling::AlarmChange::UNIT

Constants included from Common::DiffChange

Common::DiffChange::ADD, Common::DiffChange::MODIFIED, Common::DiffChange::UNMANAGED

Instance Attribute Summary collapse

Attributes inherited from Common::Diff

#aws, #changes, #info_only, #local, #type

Instance Method Summary collapse

Methods included from Common::DiffChange

next_change_id

Methods inherited from Common::Diff

#add_string, added, #initialize, #local_name, modified, #to_s, unmanaged, #unmanaged_string

Constructor Details

This class inherits a constructor from Cumulus::Common::Diff

Instance Attribute Details

#policy_arnObject

Returns the value of attribute policy_arn.



31
32
33
# File 'lib/autoscaling/models/AlarmDiff.rb', line 31

def policy_arn
  @policy_arn
end

Instance Method Details

#alarm_actions_to_addObject

Public: Get the alarm actions that will be added

Returns an array of arns to add



104
105
106
# File 'lib/autoscaling/models/AlarmDiff.rb', line 104

def alarm_actions_to_add
  local_actions("alarm") - @aws.alarm_actions
end

#alarm_actions_to_removeObject

Public: Get the alarm actions that will be removed

Returns an array of arns to remove



97
98
99
# File 'lib/autoscaling/models/AlarmDiff.rb', line 97

def alarm_actions_to_remove
  @aws.alarm_actions - local_actions("alarm")
end

#asset_typeObject



86
87
88
# File 'lib/autoscaling/models/AlarmDiff.rb', line 86

def asset_type
  "Alarm"
end

#aws_nameObject



90
91
92
# File 'lib/autoscaling/models/AlarmDiff.rb', line 90

def aws_name
  @aws.alarm_name
end

#diff_stringObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/autoscaling/models/AlarmDiff.rb', line 33

def diff_string
  diff_lines = [@local.name]

  case @type
  when ALARM
    lines = ["\tAlarm actions:"]
    lines << alarm_actions_to_remove.map { |a| "\t\t#{Colors.removed(a)}" }
    lines << alarm_actions_to_add.map { |a| "\t\t#{Colors.added(a)}" }
    diff_lines << lines.flatten.join("\n")
  when COMPARISON
    diff_lines << "\tComparison type: AWS - #{Colors.aws_changes(@aws.comparison_operator)}, Local - #{Colors.local_changes(@local.comparison)}"
  when DESCRIPTION
    diff_lines << [
      "\tDescription:",
      Colors.aws_changes("\t\tAWS - #{@aws.alarm_description}"),
      Colors.local_changes("\t\tLocal - #{@local.description}")
    ].join("\n")
  when DIMENSIONS
    lines = ["\tDimensions:"]
    lines << dimensions_to_remove.map { |d| "\t\t#{Colors.removed(d)}" }
    lines << dimensions_to_add.map { |d| "\t\t#{Colors.added(d)}" }
    diff_lines << lines.flatten.join("\n")
  when ENABLED
    diff_lines << "\tActions enabled: AWS - #{Colors.aws_changes(@aws.actions_enabled)}, Local - #{Colors.local_changes(@local.actions_enabled)}"
  when EVALUATION
    diff_lines << "\tEvaluation periods: AWS - #{Colors.aws_changes(@aws.evaluation_periods)}, Local - #{Colors.local_changes(@local.evaluation_periods)}"
  when INSUFFICIENT
    lines = ["\tInsufficient data actions:"]
    lines << insufficient_actions_to_remove.map { |i| "\t\t#{Colors.removed(i)}" }
    lines << insufficient_actions_to_add.map { |i| "\t\t#{Colors.added(i)}" }
    diff_lines << lines.flatten.join("\n")
  when METRIC
    diff_lines << "\tMetric: AWS - #{Colors.aws_changes(@aws.metric_name)}, Local - #{Colors.local_changes(@local.metric)}"
  when NAMESPACE
    diff_lines << "\tNamespace: AWS - #{Colors.aws_changes(@aws.namespace)}, Local - #{Colors.local_changes(@local.namespace)}"
  when OK
    lines = ["\tOk actions:"]
    lines << ok_actions_to_remove.map { |o| "\t\t#{Colors.removed(o)}" }
    lines << ok_actions_to_add.map { |o| "\t\t#{Colors.added(o)}" }
    diff_lines << lines.flatten.join("\n")
  when PERIOD
    diff_lines << "\tPeriod seconds: AWS - #{Colors.aws_changes(@aws.period)}, Local - #{Colors.local_changes(@local.period)}"
  when STATISTIC
    diff_lines << "\tStatistic: AWS - #{Colors.aws_changes(@aws.statistic)}, Local - #{Colors.local_changes(@local.statistic)}"
  when THRESHOLD
    diff_lines << "\tThreshold: AWS - #{Colors.aws_changes(@aws.threshold)}, Local - #{Colors.local_changes(@local.threshold)}"
  when UNIT
    diff_lines << "\tUnit: AWS - #{Colors.aws_changes(@aws.unit)}, Local - #{Colors.local_changes(@local.unit)}"
  end

  diff_lines.flatten.join("\n")
end

#dimensions_to_addObject

Public: Get the dimensions that will be added

Returns a hash of key value pairs to add



118
119
120
# File 'lib/autoscaling/models/AlarmDiff.rb', line 118

def dimensions_to_add
  @local.dimensions.reject { |k, v| aws_dimensions.include?(k) and aws_dimensions[k] == v }
end

#dimensions_to_removeObject

Public: Get the dimensions that will be removed

Returns a hash of key value pairs to be removed



111
112
113
# File 'lib/autoscaling/models/AlarmDiff.rb', line 111

def dimensions_to_remove
  aws_dimensions.reject { |k, v| @local.dimensions.include?(k) and @local.dimensions[k] == v }
end

#insufficient_actions_to_addObject

Public: Get the insufficient data actions that will be added

Returns an array of arns to add



132
133
134
# File 'lib/autoscaling/models/AlarmDiff.rb', line 132

def insufficient_actions_to_add
  local_actions("insufficient-data") - @aws.insufficient_data_actions
end

#insufficient_actions_to_removeObject

Public: Get the insufficient data actions that will be removed

Returns an array of arns to remove



125
126
127
# File 'lib/autoscaling/models/AlarmDiff.rb', line 125

def insufficient_actions_to_remove
  @aws.insufficient_data_actions - local_actions("insufficient-data")
end

#ok_actions_to_addObject

Public: Get the ok actions that will be added

Returns an array of arns to add



146
147
148
# File 'lib/autoscaling/models/AlarmDiff.rb', line 146

def ok_actions_to_add
  local_actions("ok") - @aws.ok_actions
end

#ok_actions_to_removeObject

Public: Get the ok actions that will be removed

Returns an array of arns to remove



139
140
141
# File 'lib/autoscaling/models/AlarmDiff.rb', line 139

def ok_actions_to_remove
  @aws.ok_actions - local_actions("ok")
end