From 75a1fc823c78fb89da98675c64ac303179dcf07e Mon Sep 17 00:00:00 2001 From: Nicolas Ruflin Date: Thu, 30 Nov 2017 22:08:11 +1100 Subject: [PATCH] Adds system test to Metricbeat to load dashboards (#5770) This adds a test to the system tests to load all dashboards into Kibana throught the Kibana API. In a follow up PR this should be added to all Beats. --- .../tests/system/config/metricbeat.yml.j2 | 4 +++ metricbeat/tests/system/test_base.py | 28 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/metricbeat/tests/system/config/metricbeat.yml.j2 b/metricbeat/tests/system/config/metricbeat.yml.j2 index dffe0e6879f..3ed3879fc49 100644 --- a/metricbeat/tests/system/config/metricbeat.yml.j2 +++ b/metricbeat/tests/system/config/metricbeat.yml.j2 @@ -162,6 +162,10 @@ queue.mem: flush.min_events: {{ flush_min_events|default(8) }} flush.timeout: 0.1s +{% if kibana -%} +setup.kibana.host: "{{ kibana.host }}" +{%- endif %} + #================================ Outputs ===================================== # Configure what outputs to use when sending the data collected by the beat. diff --git a/metricbeat/tests/system/test_base.py b/metricbeat/tests/system/test_base.py index ae8151b005c..a731edc5cf1 100644 --- a/metricbeat/tests/system/test_base.py +++ b/metricbeat/tests/system/test_base.py @@ -2,6 +2,8 @@ import sys import unittest import time +import os +import shutil from metricbeat import BaseTest from elasticsearch import Elasticsearch from beat.beat import INTEGRATION_TESTS @@ -9,7 +11,7 @@ class Test(BaseTest): - COMPOSE_SERVICES = ['elasticsearch'] + COMPOSE_SERVICES = ['elasticsearch', 'kibana'] @unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd|openbsd", sys.platform), "os") def test_start_stop(self): @@ -50,3 +52,27 @@ def test_template(self): assert exit_code == 0 assert self.log_contains('Loaded index template') assert len(es.cat.templates(name='metricbeat-*', h='name')) > 0 + + @unittest.skipUnless(INTEGRATION_TESTS, "integration test") + def test_dashboards(self): + """ + Test that the dashboards can be loaded with `setup --dashboards` + """ + + kibana_dir = os.path.join(self.beat_path, "_meta", "kibana") + shutil.copytree(kibana_dir, os.path.join(self.working_dir, "kibana")) + + es = Elasticsearch([self.get_elasticsearch_url()]) + self.render_config_template( + modules=[{ + "name": "apache", + "metricsets": ["status"], + "hosts": ["localhost"], + }], + elasticsearch={"host": self.get_elasticsearch_url()}, + kibana={"host": self.get_kibana_url()}, + ) + exit_code = self.run_beat(extra_args=["setup", "--dashboards"]) + + assert exit_code == 0 + assert self.log_contains("Kibana dashboards successfully loaded.")