Class: CWA::Alarms

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

Defined Under Namespace

Classes: Error

Constant Summary collapse

DEFAULT_OPTS =
{
  alarm_name_prefix: '*',
  max_records:       100
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(client, **opts) ⇒ Alarms

Returns a new instance of Alarms.



12
13
14
# File 'lib/cwa/alarms.rb', line 12

def initialize(client, **opts)
  @client        = client
end

Instance Method Details

#filter(query) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cwa/alarms.rb', line 16

def filter(query)
  @alms = alarms

  # querys
  name_query       = ->(alm) { alm.alarm_name == query[:name]        }
  regexp_query     = ->(alm) { alm.alarm_name =~ /#{query[:regexp]}/ }
  namespace_query  = ->(alm) { alm.namespace  == query[:namespace]   }

  @alms = @alms.select(&name_query)             if query[:name      ]
  @alms = @alms.select(&regexp_query)           if query[:regexp    ]
  @alms = @alms.select(&namespace_query)        if query[:namespace ]
  @alms = dimension?(@alms, query[:dimensions]) if query[:dimensions]

  @alms
end

#refresh(query = nil) ⇒ Object



32
33
34
35
# File 'lib/cwa/alarms.rb', line 32

def refresh(query = nil)
  @alms = nil
  query ? filter(query) : alarms
end