Class: CWA::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cwa/client.rb

Overview

AWS client class

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
# File 'lib/cwa/client.rb', line 11

def initialize(opts)
  if opts[:assume_role]
    role = opts.delete(:assume_role)
    opts[:credentials] = assume_role(role)
  end

  @client = Aws::CloudWatch::Client.new(opts)
end

Instance Method Details

#alarms(query) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/cwa/client.rb', line 20

def alarms(query)
  @alarms ||= Alarms.new(@client)
  alms      = @alarms.filter(query)
  alms.each { |alm| yield alm } if block_given?

  @query_cache = query
  alms
end

#disable(alm) ⇒ Object



42
43
44
45
# File 'lib/cwa/client.rb', line 42

def disable(alm)
  alm = alm[:alarm_name]
  @client.disable_alarm_actions({ alarm_names: [alm] })
end

#enable(alm) ⇒ Object



37
38
39
40
# File 'lib/cwa/client.rb', line 37

def enable(alm)
  alm = alm[:alarm_name]
  @client.enable_alarm_actions({ alarm_names: [alm] })
end

#update(cache: true) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/cwa/client.rb', line 29

def update(cache: true)
  if cache
    @alarms.refresh(@query_cache)
  else
    @alarms.refresh
  end
end