Skip to content

Commit

Permalink
Add dashboard test loading for auditbeat (#5938)
Browse files Browse the repository at this point in the history
* Add dashboard test loading for auditbeat

In combination with adding the dashboard loading a libbeat.yml.j2 was created so all beats can share the common config options and we do not have to add each option for each beat.

So far this is applied to metricbeat, auditbeat and filebeat. Other beats will follow in a follow up PR.

* Enable system tests and environment.
 Change testing.

* add kibana environment

* fix template variables

* fix filebeat tests with console
  • Loading branch information
ruflin authored and andrewkroh committed Mar 15, 2018
1 parent 4aebadc commit 3f1e877
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 186 deletions.
9 changes: 9 additions & 0 deletions auditbeat/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ services:
env_file:
- ${PWD}/build/test.env
working_dir: /go/src/github.com/elastic/beats/auditbeat
environment:
- KIBANA_HOST=kibana
- KIBANA_PORT=5601
volumes:
- ${PWD}/..:/go/src/github.com/elastic/beats/
command: make
Expand All @@ -17,8 +20,14 @@ services:
image: busybox
depends_on:
elasticsearch: { condition: service_healthy }
kibana: { condition: service_healthy }

elasticsearch:
extends:
file: ../testing/environments/${TESTING_ENVIRONMENT}.yml
service: elasticsearch

kibana:
extends:
file: ../testing/environments/${TESTING_ENVIRONMENT}.yml
service: kibana
9 changes: 1 addition & 8 deletions auditbeat/tests/system/config/auditbeat.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,4 @@ queue.mem:
flush.min_events: 8
flush.timeout: 0.1s

{%- if elasticsearch %}
output.elasticsearch:
hosts: ["{{ elasticsearch.host }}"]
{%- else %}
output.file:
path: '{{ output_file_path|default(beat.working_dir + "/output") }}'
filename: {{ output_file_filename|default("auditbeat") }}
{%- endif %}
{% include './tests/system/config/libbeat.yml.j2' %}
27 changes: 27 additions & 0 deletions auditbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re
import sys
import os
import shutil
import unittest
from auditbeat import BaseTest
from elasticsearch import Elasticsearch
Expand Down Expand Up @@ -49,3 +51,28 @@ def test_template(self):
assert exit_code == 0
assert self.log_contains('Loaded index template')
assert len(es.cat.templates(name='auditbeat-*', 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": "file_integrity",
"extras": {
"paths": ["file.example"],
}
}],
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.")
99 changes: 1 addition & 98 deletions filebeat/tests/system/config/filebeat.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -120,101 +120,4 @@ filebeat.autodiscover:
{%- endfor %}
{% endif %}

#================================ General =====================================

# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
# If this options is not defined, the hostname is used.
name: {{shipper_name}}

# The tags of the shipper are included in their own field with each
# transaction published. Tags make it easy to group servers by different
# logical properties.
tags: [
{%- if agent_tags -%}
{%- for tag in agent_tags -%}
"{{ tag }}"
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- endif -%}
]

{% if geoip_paths is not none %}
geoip:
paths: [
{%- for path in geoip_paths -%}
"{{ beat.working_dir + '/' + path }}"
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
]
{%- endif %}

{% if setup_template_name %}
setup.template.name: setup_template_name
setup.template.pattern: setup_template_pattern
{%- endif %}

{%- if processors %}

#================================ Filters =====================================

processors:
{%- for processor in processors %}
{%- for name, settings in processor.items() %}
- {{name}}:
{%- if settings %}
{%- for k, v in settings.items() %}
{{k}}:
{{v | default([])}}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endfor %}

{%- endif %}

#================================ Queue =====================================

queue.mem:
events: 4096
flush.min_events: 8
flush.timeout: 0.1s

#================================ Outputs =====================================

# Configure what outputs to use when sending the data collected by the beat.
# Multiple outputs may be used.

{%- if elasticsearch %}
#------------------------------- Elasticsearch output ----------------------------
output.elasticsearch:
hosts: ["{{ elasticsearch.host }}"]
{% if elasticsearch.pipeline %}
pipeline: {{elasticsearch.pipeline}}
{% endif %}
{% if elasticsearch.index %}
index: {{elasticsearch.index}}
{% endif %}
{%- elif logstash %}
#------------------------------- Logstash output ---------------------------------
output.logstash:
hosts: ["{{ logstash.host }}"]
{%- else %}
#------------------------------- File output ----------------------------------
output.file:
path: {{ output_file_path|default(beat.working_dir + "/output") }}
filename: "{{ output_file_filename|default("filebeat") }}"
rotate_every_kb: {{ rotate_every_kb | default(1000) }}
#number_of_files: 7
{%- endif %}

{% if path_data %}
#================================ Paths =====================================
path:
data: {{path_data}}
{% endif %}

{% if keystore_path %}
#================================ keystore =====================================
keystore.path: {{keystore_path}}
{% endif %}
{% include './tests/system/config/libbeat.yml.j2' %}
2 changes: 1 addition & 1 deletion filebeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_invalid_config_with_removed_settings(self):
"""
Checks if filebeat fails to load if removed settings have been used:
"""
self.render_config_template(console={"pretty": "false"})
self.render_config_template()

exit_code = self.run_beat(extra_args=[
"-E", "filebeat.spool_size=2048",
Expand Down
5 changes: 4 additions & 1 deletion libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ def copy_files(self, files, source_dir="files/"):
def setUp(self):

self.template_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(self.beat_path)
loader=jinja2.FileSystemLoader([
self.beat_path,
os.path.abspath(os.path.join(self.beat_path, "../libbeat"))
])
)

# create working dir
Expand Down
93 changes: 93 additions & 0 deletions libbeat/tests/system/config/libbeat.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#================================ General =====================================

# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
# If this options is not defined, the hostname is used.
name: {{shipper_name}}

# The tags of the shipper are included in their own field with each
# transaction published. Tags make it easy to group servers by different
# logical properties.
tags: [
{%- if agent_tags -%}
{%- for tag in agent_tags -%}
"{{ tag }}"
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- endif -%}
]

{% if setup_template_name %}
setup.template.name: "{{setup_template_name}}"
setup.template.pattern: "{{setup_template_pattern}}"
{%- endif %}

#================================ Processors =====================================

{%- if processors %}
processors:
{%- for processor in processors %}
{%- for name, settings in processor.items() %}
- {{name}}:
{%- if settings %}
{%- for k, v in settings.items() %}
{{k}}:
{{v | default([])}}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endfor %}

{%- endif %}

#================================ Queue =====================================

queue.mem:
events: 4096
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.
# Multiple outputs may be used.

{% if elasticsearch -%}
output:
elasticsearch:
hosts: ["{{ elasticsearch.host }}"]
{% if elasticsearch.pipeline %}
pipeline: {{elasticsearch.pipeline}}
{% endif %}
{% if elasticsearch.index %}
index: {{elasticsearch.index}}
{% endif %}
{%- endif %}

{% if logstash %}
output.logstash:
hosts: ["{{ logstash.host }}"]
{%- endif %}

{% if not (console or elasticsearch or logstash) -%}
output.file:
path: {{ output_file_path|default(beat.working_dir + "/output") }}
filename: "{{ output_file_filename|default(beat.beat_name) }}"
rotate_every_kb: {{ rotate_every_kb | default(1000) }}
#number_of_files: 7
{%- endif %}

{% if path_data %}
#================================ Paths =====================================
path:
data: {{path_data}}
{%endif%}

{% if keystore_path %}
#================================ keystore =====================================
keystore.path: {{keystore_path}}
{% endif %}
79 changes: 1 addition & 78 deletions metricbeat/tests/system/config/metricbeat.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -101,43 +101,6 @@ metricbeat.config.modules:
# Disable random start delay for metricsets.
metricbeat.max_start_delay: 0

#================================ General =====================================

# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
# If this options is not defined, the hostname is used.
name: {{shipper_name}}

# The tags of the shipper are included in their own field with each
# transaction published. Tags make it easy to group servers by different
# logical properties.
tags: [
{%- if agent_tags -%}
{%- for tag in agent_tags -%}
"{{ tag }}"
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- endif -%}
]


#================================ Processors =====================================

{%- if processors %}
processors:
{%- for processor in processors %}
{%- for name, settings in processor.items() %}
- {{name}}:
{%- if settings %}
{%- for k, v in settings.items() %}
{{k}}:
{{v | default([])}}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endfor %}

{%- endif %}

#============================== Autodiscover ==================================

Expand All @@ -155,44 +118,4 @@ metricbeat.autodiscover:
{%- endfor %}
{% endif %}

#================================ Queue =====================================

queue.mem:
events: 4096
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.
# Multiple outputs may be used.

output:
{% if elasticsearch -%}
elasticsearch:
hosts: ["{{ elasticsearch.host }}"]
{%- endif %}

# File as output
# Options
# path: where to save the files
# filename: name of the files
# rotate_every_kb: maximum size of the files in path
# number of files: maximum number of files in path
{% if not (console or elasticsearch) -%}
file:
path: {{ output_file_path|default(beat.working_dir + "/output") }}
filename: "{{ output_file_filename|default("metricbeat") }}"
rotate_every_kb: 1000
#number_of_files: 7
{%- endif %}

{% if path_data %}
#================================ Paths =====================================
path:
data: {{path_data}}
{%endif%}
{% include './tests/system/config/libbeat.yml.j2' %}

0 comments on commit 3f1e877

Please sign in to comment.