From bc5503f25675f36d14be0a7179a4562d0f2a22f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Tue, 31 Aug 2021 18:41:20 +0200 Subject: [PATCH] minor fixes --- libbeat/dashboards/kibana_loader.go | 2 +- libbeat/dashboards/modify_json.go | 8 +++----- libbeat/dashboards/modify_json_test.go | 12 ++++-------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/libbeat/dashboards/kibana_loader.go b/libbeat/dashboards/kibana_loader.go index 129e2e3f248..aec0b56c5bf 100644 --- a/libbeat/dashboards/kibana_loader.go +++ b/libbeat/dashboards/kibana_loader.go @@ -154,7 +154,7 @@ func (loader KibanaLoader) ImportDashboard(file string) error { } content = ReplaceIndexInDashboardObject(loader.config.Index, content) - content = ConvertToStr(content) + content = EncodeJSONObjects(content) content = ReplaceStringInDashboard("CHANGEME_HOSTNAME", loader.hostname, content) err = loader.importReferences(file, content) diff --git a/libbeat/dashboards/modify_json.go b/libbeat/dashboards/modify_json.go index 8fcb90c6b59..3178d6b2382 100644 --- a/libbeat/dashboards/modify_json.go +++ b/libbeat/dashboards/modify_json.go @@ -192,13 +192,11 @@ func ReplaceIndexInDashboardObject(index string, content []byte) []byte { } if kibanaSavedObject, ok := attributes["kibanaSavedObjectMeta"].(map[string]interface{}); ok { - ba := ReplaceIndexInSavedObject(logger, index, kibanaSavedObject) - attributes["kibanaSavedObjectMeta"] = ba + attributes["kibanaSavedObjectMeta"] = ReplaceIndexInSavedObject(logger, index, kibanaSavedObject) } if visState, ok := attributes["visState"].(string); ok { - nya := ReplaceIndexInVisState(logger, index, visState) - attributes["visState"] = nya + attributes["visState"] = ReplaceIndexInVisState(logger, index, visState) } b, err := json.Marshal(objectMap) @@ -210,7 +208,7 @@ func ReplaceIndexInDashboardObject(index string, content []byte) []byte { return b } -func ConvertToStr(content []byte) []byte { +func EncodeJSONObjects(content []byte) []byte { logger := logp.NewLogger("dashboards") if len(bytes.TrimSpace(content)) == 0 { diff --git a/libbeat/dashboards/modify_json_test.go b/libbeat/dashboards/modify_json_test.go index 367b07f2b3d..48f0fe972c9 100644 --- a/libbeat/dashboards/modify_json_test.go +++ b/libbeat/dashboards/modify_json_test.go @@ -72,18 +72,14 @@ func TestReplaceIndexInDashboardObject(t *testing.T) { expected []byte }{ { - []byte(`{"attributes":{"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"index\":\"metricbeat-*\"}"}}} -`), + []byte(`{"attributes":{"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"index\":\"metricbeat-*\"}"}}}`), "otherindex-*", - []byte(`{"attributes":{"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"index\":\"otherindex-*\"}"}}} -`), + []byte(`{"attributes":{"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"index\":\"otherindex-*\"}"}}}`), }, { - []byte(`{"attributes":{"kibanaSavedObjectMeta":{"visState":"{\"params\":{\"index_pattern\":\"metricbeat-*\"}}"}}} -`), + []byte(`{"attributes":{"kibanaSavedObjectMeta":{"visState":"{\"params\":{\"index_pattern\":\"metricbeat-*\"}}"}}}`), "otherindex-*", - []byte(`{"attributes":{"kibanaSavedObjectMeta":{"visState":"{\"params\":{\"index_pattern\":\"otherindex-*\"}}"}}} -`), + []byte(`{"attributes":{"kibanaSavedObjectMeta":{"visState":"{\"params\":{\"index_pattern\":\"otherindex-*\"}}"}}}`), }, }