Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch committed Aug 31, 2021
1 parent 4d91ae7 commit bc5503f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libbeat/dashboards/kibana_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions libbeat/dashboards/modify_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
12 changes: 4 additions & 8 deletions libbeat/dashboards/modify_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-*\"}}"}}}`),
},
}

Expand Down

0 comments on commit bc5503f

Please sign in to comment.