Sha256: b5cb089efe4adf3aea47f5adf58f5590dc97ddf0663dc6f46c152b2878523da8

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

require 'aws-sdk-cloudwatch'
require 'cfn_manage/aws_credentials'

module CfnManage
  module StartStopHandler
    class Alarm

      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

      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

      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

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

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cfn_manage-0.8.3 lib/cfn_manage/handlers/alarm.rb
cfn_manage-0.8.2 lib/cfn_manage/handlers/alarm.rb
cfn_manage-0.8.1 lib/cfn_manage/handlers/alarm.rb
cfn_manage-0.8.0 lib/cfn_manage/handlers/alarm.rb