-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Kibana Spaces #8045
Support Kibana Spaces #8045
Changes from all commits
3ad9745
287915d
47e9986
9ec545f
820bcf8
5dc34d2
a4d4d84
30ed549
1f3e578
c90c541
80b1b99
89dbafd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ urllib3==1.22 | |
websocket-client==0.47.0 | ||
parameterized==0.6.1 | ||
jsondiff==1.1.2 | ||
semver==2.8.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
import subprocess | ||
from nose.plugins.attrib import attr | ||
import unittest | ||
|
||
import requests | ||
import semver | ||
|
||
INTEGRATION_TESTS = os.environ.get('INTEGRATION_TESTS', False) | ||
|
||
|
@@ -36,6 +37,40 @@ def test_load_dashboard(self): | |
|
||
assert self.log_contains("Kibana dashboards successfully loaded") is True | ||
|
||
@unittest.skipUnless(INTEGRATION_TESTS, "integration test") | ||
@attr('integration') | ||
def test_load_dashboard_into_space(self, create_space=True): | ||
""" | ||
Test loading dashboards into Kibana space | ||
""" | ||
version = self.get_version() | ||
if semver.compare(version, "6.5.0") == -1: | ||
# Skip for Kibana versions < 6.5.0 as Kibana Spaces not available | ||
raise SkipTest | ||
|
||
self.render_config_template() | ||
if create_space: | ||
self.create_kibana_space() | ||
|
||
beat = self.start_beat( | ||
logging_args=["-e", "-d", "*"], | ||
extra_args=["setup", | ||
"--dashboards", | ||
"-E", "setup.dashboards.file=" + | ||
os.path.join(self.beat_path, "tests", "files", "testbeat-dashboards.zip"), | ||
"-E", "setup.dashboards.beat=testbeat", | ||
"-E", "setup.kibana.protocol=http", | ||
"-E", "setup.kibana.host=" + self.get_kibana_host(), | ||
"-E", "setup.kibana.port=" + self.get_kibana_port(), | ||
"-E", "setup.kibana.space.id=foo-bar", | ||
"-E", "output.elasticsearch.hosts=['" + self.get_host() + "']", | ||
"-E", "output.file.enabled=false"] | ||
) | ||
|
||
beat.check_wait(exit_code=0) | ||
|
||
assert self.log_contains("Kibana dashboards successfully loaded") is True | ||
|
||
@unittest.skipUnless(INTEGRATION_TESTS, "integration test") | ||
@attr('integration') | ||
def test_load_only_index_patterns(self): | ||
|
@@ -88,6 +123,36 @@ def test_export_dashboard(self): | |
|
||
os.remove("output.json") | ||
|
||
@unittest.skipUnless(INTEGRATION_TESTS, "integration test") | ||
@attr('integration') | ||
def test_export_dashboard_from_space(self): | ||
""" | ||
Test export dashboards from Kibana space and remove unsupported characters | ||
""" | ||
version = self.get_version() | ||
if semver.compare(version, "6.5.0") == -1: | ||
# Skip for Kibana versions < 6.5.0 as Kibana Spaces not available | ||
raise SkipTest | ||
|
||
self.test_load_dashboard_into_space(False) | ||
|
||
path = os.path.normpath(self.beat_path + "/../dev-tools/cmd/dashboards/export_dashboards.go") | ||
command = path + " -kibana http://" + self.get_kibana_host() + ":" + self.get_kibana_port() | ||
command = "go run " + command + " -dashboard Metricbeat-system-overview -space-id foo-bar" | ||
|
||
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
content, err = p.communicate() | ||
|
||
assert p.returncode == 0 | ||
|
||
assert os.path.isfile("output.json") is True | ||
|
||
with open('output.json') as f: | ||
content = f.read() | ||
assert "Metricbeat-system-overview" in content | ||
|
||
os.remove("output.json") | ||
|
||
def get_host(self): | ||
return os.getenv('ES_HOST', 'localhost') + ':' + os.getenv('ES_PORT', '9200') | ||
|
||
|
@@ -96,3 +161,28 @@ def get_kibana_host(self): | |
|
||
def get_kibana_port(self): | ||
return os.getenv('KIBANA_PORT', '5601') | ||
|
||
def create_kibana_space(self): | ||
url = "http://" + self.get_kibana_host() + ":" + self.get_kibana_port() + \ | ||
"/api/spaces/space" | ||
data = { | ||
"id": "foo-bar", | ||
"name": "Foo bar space" | ||
} | ||
|
||
headers = { | ||
"kbn-xsrf": "1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of curiosity: Why is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's for protecting against CSRF attacks: https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet#Protecting_REST_Services:_Use_of_Custom_Request_Headers |
||
} | ||
|
||
r = requests.post(url, json=data, headers=headers) | ||
assert r.status_code == 200 | ||
|
||
def get_version(self): | ||
url = "http://" + self.get_kibana_host() + ":" + self.get_kibana_port() + \ | ||
"/api/status" | ||
|
||
r = requests.get(url) | ||
body = r.json() | ||
version = body["version"]["number"] | ||
|
||
return version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function Export should have comment or be unexported