Class: LogStash::Modules::KibanaDashboards

Inherits:
KibanaBase
  • Object
show all
Includes:
Util::Loggable
Defined in:
lib/logstash/modules/kibana_dashboards.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Loggable

included, #logger, #slow_logger

Methods inherited from KibanaBase

#content_as_object, #to_s

Constructor Details

#initialize(import_path, content) ⇒ KibanaDashboards

content is a list of kibana file resources



12
13
14
# File 'lib/logstash/modules/kibana_dashboards.rb', line 12

def initialize(import_path, content)
  @import_path, @content = import_path, content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



9
10
11
# File 'lib/logstash/modules/kibana_dashboards.rb', line 9

def content
  @content
end

#import_pathObject (readonly)

Returns the value of attribute import_path.



9
10
11
# File 'lib/logstash/modules/kibana_dashboards.rb', line 9

def import_path
  @import_path
end

Instance Method Details

#import(client) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/logstash/modules/kibana_dashboards.rb', line 16

def import(client)
  # e.g. curl "http://localhost:5601/api/kibana/dashboards/import"
  # extract and prepare all objects
  objects = []
  content.each do |resource|
    hash = {
      "id" => resource.content_id,
      "type" => resource.content_type,
      "version" => 1,
      "attributes" => resource.content_as_object
    }
    objects << hash
  end
  body = {"version": client.version, "objects": objects}
  response = client.post(import_path, body)
  if response.failed?
    logger.error("Attempted POST failed", :url_path => import_path, :response => response.body)
  end
  response
end