Class: Lbrt::Alert

Inherits:
Object
  • Object
show all
Includes:
Logger::Helper
Defined in:
lib/lbrt/alert.rb

Defined Under Namespace

Classes: DSL, Exporter

Constant Summary collapse

DEFAULT_CONCURRENCY =
32

Instance Method Summary collapse

Methods included from Logger::Helper

#log

Constructor Details

#initialize(client, options = {}) ⇒ Alert



6
7
8
9
10
# File 'lib/lbrt/alert.rb', line 6

def initialize(client, options = {})
  @client = client
  @options = options
  @driver = Lbrt::Driver.new(@client, @options)
end

Instance Method Details

#apply(file) ⇒ Object



53
54
55
# File 'lib/lbrt/alert.rb', line 53

def apply(file)
  walk(file)
end

#export(export_options = {}) ⇒ Object



48
49
50
51
# File 'lib/lbrt/alert.rb', line 48

def export(export_options = {})
  exported = Lbrt::Alert::Exporter.export(@client, @options)
  Lbrt::Alert::DSL.convert(exported, @options)
end

#listObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lbrt/alert.rb', line 12

def list
  json = {}
  alert_by_name = build_alert_by_name

  alert_by_name.select {|name, alrt|
    @options[:status].nil? or @options[:status] == alrt[:status]
  }.each {|name, alrt|
    alert_id = alrt[:id]

    json[alert_id] = {
      name: name,
      url: alert_url(alert_id),
      status: alrt[:status],
    }
  }

  puts JSON.pretty_generate(json)
end

#pecoObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lbrt/alert.rb', line 31

def peco
  alert_id_by_name = {}

  build_alert_by_name.select {|name, alrt|
    @options[:status].nil? or @options[:status] == alrt[:status]
  }.map {|name, alrt| alert_id_by_name[name] = alrt[:id] }

  unless alert_id_by_name.empty?
    result = PecoSelector.select_from(alert_id_by_name)

    result.each do |alert_id|
      url = alert_url(alert_id)
      Lbrt::Utils.open(url)
    end
  end
end