Use this script can import kibana dashboards by json files.
Signed-off-by: Wu Zhende wuzhende666@163.com --- container/kibana/dashboard_import | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 container/kibana/dashboard_import
diff --git a/container/kibana/dashboard_import b/container/kibana/dashboard_import new file mode 100755 index 0000000..e20e8ff --- /dev/null +++ b/container/kibana/dashboard_import @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'set' +require 'pathname' +require_relative '../defconfig.rb' + +names = Set.new %w[ + KIBANA_HOST + KIBANA_PORT + ES_USER + ES_PASSWORD +] + +defaults = relevant_defaults(names) +KIBANA_HOST = defaults['KIBANA_HOST'] || '172.17.0.1' +KIBANA_PORT = defaults['KIBANA_PORT'] || '20017' + +service_authentication = relevant_service_authentication(names) + +files = ARGV +if files.empty? + profile = Pathname.new(File.dirname(__FILE__)).realpath + files << profile + 'data.json' + files << profile + 'resource.json' + files << profile + 'all.json' +end + +cmd = "curl -XPOST -u #{service_authentication['ES_USER']}:#{service_authentication['ES_PASSWORD']}" +cmd += " http://#%7BKIBANA_HOST%7D:#%7BKIBANA_PORT%7D/api/kibana/dashboards/import" +cmd += " -H 'Content-Type: application/json' -H 'kbn-xsrf: reporting'" + +files.each do |f| + new_cmd = cmd + new_cmd += " -d @#{f}" + puts new_cmd + system new_cmd +end
This script has so many reused code with dashboard_export, why not define a common lib?
-------- Thanks, Xijian
On Wed, Apr 28, 2021 at 02:19:08PM +0800, Wu Zhende wrote:
Use this script can import kibana dashboards by json files.
Signed-off-by: Wu Zhende wuzhende666@163.com
container/kibana/dashboard_import | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 container/kibana/dashboard_import
diff --git a/container/kibana/dashboard_import b/container/kibana/dashboard_import new file mode 100755 index 0000000..e20e8ff --- /dev/null +++ b/container/kibana/dashboard_import @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'set' +require 'pathname' +require_relative '../defconfig.rb'
+names = Set.new %w[
- KIBANA_HOST
- KIBANA_PORT
- ES_USER
- ES_PASSWORD
+]
+defaults = relevant_defaults(names) +KIBANA_HOST = defaults['KIBANA_HOST'] || '172.17.0.1' +KIBANA_PORT = defaults['KIBANA_PORT'] || '20017'
+service_authentication = relevant_service_authentication(names)
+files = ARGV +if files.empty?
- profile = Pathname.new(File.dirname(__FILE__)).realpath
- files << profile + 'data.json'
- files << profile + 'resource.json'
- files << profile + 'all.json'
+end
+cmd = "curl -XPOST -u #{service_authentication['ES_USER']}:#{service_authentication['ES_PASSWORD']}" +cmd += " http://#%7BKIBANA_HOST%7D:#%7BKIBANA_PORT%7D/api/kibana/dashboards/import" +cmd += " -H 'Content-Type: application/json' -H 'kbn-xsrf: reporting'"
+files.each do |f|
- new_cmd = cmd
- new_cmd += " -d @#{f}"
- puts new_cmd
- system new_cmd
+end
2.23.0