Class: CfFactory::CfCloudWatchAlarm

Inherits:
Object
  • Object
show all
Includes:
CfBase
Defined in:
lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb

Constant Summary collapse

GREATER_THAN_OR_EQUAL_TO_THRESHOLD =
"GreaterThanOrEqualToThreshold"
GREATER_THAN_THRESHOLD =
"GreaterThanThreshold"
LESS_THAN_THRESHOLD =
"LessThanThreshold"
LESS_THAN_OR_EQUAL_TO_THRESHOLD =
"LessThanOrEqualToThreshold"

Instance Method Summary collapse

Methods included from CfBase

#generate, #generate_ref, #get_deletion_policy, #get_name, #get_update_policy, #hash_to_string, #retrieve_attribute, #set_meta_data, #set_quotes, #set_tags

Constructor Details

#initialize(name, comparison_operator, evaluation_periods, metric_name, metric_name_space, period, statistic, threshold, options = {}) ⇒ CfCloudWatchAlarm

Returns a new instance of CfCloudWatchAlarm.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb', line 13

def initialize(name, comparison_operator, evaluation_periods, metric_name, metric_name_space, 
  period, statistic, threshold, options = {})
  @name = name
  @comparison_operator = comparison_operator
  @evaluation_periods = evaluation_periods
  @metric_name = metric_name
  @metric_name_space = metric_name_space
  @period = period
  @statistic = statistic
  @threshold = threshold
  #TODO: optional values
  @alarm_actions = options[:alarm_actions]
  validate()
end

Instance Method Details

#get_cf_attributesObject



41
42
43
# File 'lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb', line 41

def get_cf_attributes
  {}
end

#get_cf_propertiesObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb', line 45

def get_cf_properties
  result = {
    "ComparisonOperator" => @comparison_operator,
    "EvaluationPeriods" => @evaluation_periods,
    "MetricName" => @metric_name,
    "Namespace" => @metric_name_space,
    "Period" => @period,
    "Statistic" => @statistic,
    "Threshold" => @threshold
  }
  result["AlarmActions"] = CfHelper.generate_ref_array(@alarm_actions) unless @alarm_actions.nil?
  result
end

#get_cf_typeObject



37
38
39
# File 'lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb', line 37

def get_cf_type
  "AWS::CloudWatch::Alarm"
end

#validateObject



28
29
30
31
32
33
34
35
# File 'lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb', line 28

def validate
  if ![GREATER_THAN_OR_EQUAL_TO_THRESHOLD, GREATER_THAN_THRESHOLD, LESS_THAN_OR_EQUAL_TO_THRESHOLD, LESS_THAN_THRESHOLD].include?(@comparison_operator)
    raise Exception.new("comparison operator #{@comparison_operator} not valid")
  end
  if !["SampleCount", "Average", "Sum", "Minimum", "Maximum"].include?(@statistic)
    raise Exception.new("statistic #{@statistic} not a valid value")
  end
end