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 inherited from KibanaBase

#content_as_object, #to_s

Constructor Details

#initialize(import_path, content) ⇒ KibanaDashboards

content is a list of kibana file resources



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

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

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/logstash/modules/kibana_dashboards.rb', line 7

def content
  @content
end

#import_pathObject (readonly)

Returns the value of attribute import_path.



7
8
9
# File 'lib/logstash/modules/kibana_dashboards.rb', line 7

def import_path
  @import_path
end

Instance Method Details

#import(client) ⇒ Object



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

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