Class: CfnManage::StartStopHandler::Alarm

Inherits:
Object
  • Object
show all
Defined in:
lib/cfn_manage/handlers/alarm.rb

Instance Method Summary collapse

Constructor Details

#initialize(alarm_name, options = {}) ⇒ Alarm

Returns a new instance of Alarm.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cfn_manage/handlers/alarm.rb', line 8

def initialize(alarm_name,options = {})
  @alarm_id = alarm_name
  credentials = CfnManage::AWSCredentials.get_session_credentials("startstopalarm_#{@asg_name}")
  @cwclient = Aws::CloudWatch::Client.new(retry_limit: 20)
  if credentials != nil
    @cwclient = Aws::CloudWatch::Client.new(credentials: credentials, retry_limit: 20)
  end

  @cwresource = Aws::CloudWatch::Resource.new(client: @cwclient)
  @alarm = @cwresource.alarm(alarm_name)
end

Instance Method Details

#start(configuration) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/cfn_manage/handlers/alarm.rb', line 20

def start(configuration)
  if @alarm.actions_enabled
    $log.info("Alarm #{@alarm.alarm_arn} actions already enabled")
    return
  end
  $log.info("Enabling alarm #{@alarm.alarm_arn}")
  @alarm.enable_actions({})
end

#stopObject



29
30
31
32
33
34
35
36
37
# File 'lib/cfn_manage/handlers/alarm.rb', line 29

def stop
  if not @alarm.actions_enabled
    $log.info("Alarm #{@alarm.alarm_arn} actions already disabled")
    return {}
  end
  $log.info("Disabling actions on alarm #{@alarm.alarm_arn}")
  @alarm.disable_actions({})
  return {}
end

#wait(wait_states = []) ⇒ Object



39
40
41
# File 'lib/cfn_manage/handlers/alarm.rb', line 39

def wait(wait_states=[])
  $log.debug("Not waiting for alarm #{@alarm_id}")
end