forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements and fixes to the Host Overview dashboard (elastic#5340) (e…
…lastic#5351) * Use `beat.name` instead of `beat.hostname` in visualizations. See elastic#5276 for the motivation * Add a "tip" widget that tells user how they can select another host. * Automatically set a search pattern of the form `beat.name: "HOSTNAME"` where HOSTNAME is the Beat name (hostname) that uploads the dashboards. The way the last point works is that I saved the dashbaord using this filter: `beat.name:"CHANGEME_HOSTNAME"`. The kibana loader code does a string replacement and replaces `CHANGEME_HOSTNAME` with the actual hostname. The disadvantage of this approach (vs doing JSON parsing) is that we must remember to always save that dashboard with the `CHANGEME_HOSTNAME` wildcard in place. I have added a unit test to the system module that checks for that, so it should be relatively hard for us to forget. Closes elastic#5276. (cherry picked from commit 4778c51)
- Loading branch information
Showing
10 changed files
with
167 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package dashboards | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
) | ||
|
||
func TestReplaceStringInDashboard(t *testing.T) { | ||
tests := []struct { | ||
content common.MapStr | ||
old string | ||
new string | ||
expected common.MapStr | ||
}{ | ||
{ | ||
content: common.MapStr{"test": "CHANGEME"}, | ||
old: "CHANGEME", | ||
new: "hostname", | ||
expected: common.MapStr{"test": "hostname"}, | ||
}, | ||
{ | ||
content: common.MapStr{"test": "hello"}, | ||
old: "CHANGEME", | ||
new: "hostname", | ||
expected: common.MapStr{"test": "hello"}, | ||
}, | ||
{ | ||
content: common.MapStr{"test": map[string]interface{}{"key": "\"CHANGEME\""}}, | ||
old: "CHANGEME", | ||
new: "hostname.local", | ||
expected: common.MapStr{"test": map[string]interface{}{"key": "\"hostname.local\""}}, | ||
}, | ||
{ | ||
content: common.MapStr{ | ||
"kibanaSavedObjectMeta": map[string]interface{}{ | ||
"searchSourceJSON": "{\"filter\":[],\"highlightAll\":true,\"version\":true,\"query\":{\"query\":\"beat.name:\\\"CHANGEME_HOSTNAME\\\"\",\"language\":\"lucene\"}}"}}, | ||
|
||
old: "CHANGEME_HOSTNAME", | ||
new: "hostname.local", | ||
expected: common.MapStr{ | ||
"kibanaSavedObjectMeta": map[string]interface{}{ | ||
"searchSourceJSON": "{\"filter\":[],\"highlightAll\":true,\"version\":true,\"query\":{\"query\":\"beat.name:\\\"hostname.local\\\"\",\"language\":\"lucene\"}}"}}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
result, err := ReplaceStringInDashboard(test.old, test.new, test.content) | ||
assert.NoError(t, err) | ||
assert.Equal(t, test.expected, result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.