|
| 1 | +import os |
| 2 | +import metricbeat |
| 3 | +import json |
| 4 | +from nose.plugins.skip import SkipTest |
| 5 | + |
| 6 | + |
| 7 | +class Test(metricbeat.BaseTest): |
| 8 | + |
| 9 | + def test_export_template(self): |
| 10 | + """ |
| 11 | + Test export template works and contains all fields |
| 12 | + """ |
| 13 | + |
| 14 | + if os.name == "nt": |
| 15 | + raise SkipTest |
| 16 | + |
| 17 | + self.render_config_template("metricbeat", |
| 18 | + os.path.join(self.working_dir, |
| 19 | + "metricbeat.yml"), |
| 20 | + ) |
| 21 | + |
| 22 | + # Remove fields.yml to make sure template is built from internal binary data |
| 23 | + os.remove(os.path.join(self.working_dir, "fields.yml")) |
| 24 | + |
| 25 | + exit_code = self.run_beat( |
| 26 | + logging_args=[], |
| 27 | + extra_args=["export", "template"], |
| 28 | + config="metricbeat.yml", |
| 29 | + output="template.json" |
| 30 | + ) |
| 31 | + assert exit_code == 0 |
| 32 | + |
| 33 | + template_path = os.path.join(self.working_dir, "template.json") |
| 34 | + template_content = "" |
| 35 | + |
| 36 | + # Read in all json lines and discard the coverage info |
| 37 | + with open(template_path) as f: |
| 38 | + for line in f: |
| 39 | + template_content += line |
| 40 | + if line.startswith("}"): |
| 41 | + break |
| 42 | + |
| 43 | + t = json.loads(template_content) |
| 44 | + |
| 45 | + properties = t["mappings"]["doc"]["properties"] |
| 46 | + |
| 47 | + # Check libbeat fields |
| 48 | + assert properties["@timestamp"] == {"type": "date"} |
| 49 | + assert properties["host"]["properties"]["name"] == {"type": "keyword", "ignore_above": 1024} |
| 50 | + |
| 51 | + # Check metricbeat generic field |
| 52 | + assert properties["metricset"]["properties"]["host"] == {"type": "keyword", "ignore_above": 1024} |
| 53 | + |
| 54 | + # Check module specific field |
| 55 | + assert properties["system"]["properties"]["cpu"]["properties"]["cores"] == {"type": "long"} |
0 commit comments