Added tests for Logstash
This commit is contained in:
parent
6e3b92bcc4
commit
e5b0e2b40e
14
molecule/logstash/Dockerfile.j2
Normal file
14
molecule/logstash/Dockerfile.j2
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Molecule managed
|
||||||
|
|
||||||
|
{% if item.registry is defined %}
|
||||||
|
FROM {{ item.registry.url }}/{{ item.image }}
|
||||||
|
{% else %}
|
||||||
|
FROM {{ item.image }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
|
||||||
|
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
|
||||||
|
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
|
||||||
|
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
|
||||||
|
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
|
||||||
|
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
|
||||||
22
molecule/logstash/INSTALL.rst
Normal file
22
molecule/logstash/INSTALL.rst
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
*******
|
||||||
|
Docker driver installation guide
|
||||||
|
*******
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
============
|
||||||
|
|
||||||
|
* Docker Engine
|
||||||
|
|
||||||
|
Install
|
||||||
|
=======
|
||||||
|
|
||||||
|
Please refer to the `Virtual environment`_ documentation for installation best
|
||||||
|
practices. If not using a virtual environment, please consider passing the
|
||||||
|
widely recommended `'--user' flag`_ when invoking ``pip``.
|
||||||
|
|
||||||
|
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
|
||||||
|
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
$ pip install 'molecule[docker]'
|
||||||
56
molecule/logstash/molecule.yml
Normal file
56
molecule/logstash/molecule.yml
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
lint:
|
||||||
|
name: yamllint
|
||||||
|
platforms:
|
||||||
|
- name: bionic
|
||||||
|
image: solita/ubuntu-systemd:bionic
|
||||||
|
command: /sbin/init
|
||||||
|
ulimits:
|
||||||
|
- nofile:262144:262144
|
||||||
|
privileged: True
|
||||||
|
memory_reservation: 1024m
|
||||||
|
- name: xenial
|
||||||
|
image: solita/ubuntu-systemd:xenial
|
||||||
|
privileged: true
|
||||||
|
memory_reservation: 1024m
|
||||||
|
command: /sbin/init
|
||||||
|
ulimits:
|
||||||
|
- nofile:262144:262144
|
||||||
|
- name: centos6
|
||||||
|
image: geerlingguy/docker-centos6-ansible
|
||||||
|
privileged: true
|
||||||
|
memory_reservation: 1024m
|
||||||
|
command: /sbin/init
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||||
|
ulimits:
|
||||||
|
- nofile:262144:262144
|
||||||
|
- name: centos7
|
||||||
|
image: milcom/centos7-systemd
|
||||||
|
memory_reservation: 1024m
|
||||||
|
privileged: true
|
||||||
|
ulimits:
|
||||||
|
- nofile:262144:262144
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
playbooks:
|
||||||
|
docker:
|
||||||
|
create: ../default/create.yml
|
||||||
|
destroy: ../default/destroy.yml
|
||||||
|
env:
|
||||||
|
ANSIBLE_ROLES_PATH: ../../roles
|
||||||
|
lint:
|
||||||
|
name: ansible-lint
|
||||||
|
enabled: true
|
||||||
|
inventory:
|
||||||
|
group_vars:
|
||||||
|
all:
|
||||||
|
elasticsearch_jvm_xms: 256
|
||||||
|
verifier:
|
||||||
|
name: testinfra
|
||||||
|
lint:
|
||||||
|
name: flake8
|
||||||
5
molecule/logstash/playbook.yml
Normal file
5
molecule/logstash/playbook.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
roles:
|
||||||
|
- role: elastic-stack/ansible-logstash
|
||||||
41
molecule/logstash/prepare.yml
Normal file
41
molecule/logstash/prepare.yml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
---
|
||||||
|
- name: Prepare
|
||||||
|
hosts: all
|
||||||
|
gather_facts: true
|
||||||
|
pre_tasks:
|
||||||
|
|
||||||
|
- name: "Install Python packages for Trusty to solve trust issues"
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- python-setuptools
|
||||||
|
- python-pip
|
||||||
|
state: latest
|
||||||
|
register: wazuh_manager_trusty_packages_installed
|
||||||
|
until: wazuh_manager_trusty_packages_installed is succeeded
|
||||||
|
when:
|
||||||
|
- ansible_distribution == "Ubuntu"
|
||||||
|
- ansible_distribution_major_version | int == 14
|
||||||
|
|
||||||
|
- name: "Install dependencies"
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- curl
|
||||||
|
- net-tools
|
||||||
|
state: latest
|
||||||
|
register: wazuh_manager_dependencies_packages_installed
|
||||||
|
until: wazuh_manager_dependencies_packages_installed is succeeded
|
||||||
|
|
||||||
|
- name: "Install (RedHat) dependencies"
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- initscripts
|
||||||
|
state: latest
|
||||||
|
register: wazuh_manager_dependencies_packages_installed
|
||||||
|
until: wazuh_manager_dependencies_packages_installed is succeeded
|
||||||
|
when:
|
||||||
|
- ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: wazuh/ansible-wazuh-manager
|
||||||
|
- role: elastic-stack/ansible-elasticsearch
|
||||||
|
elasticsearch_network_host: 'localhost'
|
||||||
30
molecule/logstash/tests/test_default.py
Normal file
30
molecule/logstash/tests/test_default.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||||
|
|
||||||
|
|
||||||
|
def test_logstash_is_installed(host):
|
||||||
|
logstash = host.package("logstash")
|
||||||
|
assert logstash.is_installed
|
||||||
|
|
||||||
|
distribution = host.system_info.distribution.lower()
|
||||||
|
if distribution == 'ubuntu':
|
||||||
|
assert logstash.version.startswith('1:6.7.1')
|
||||||
|
else:
|
||||||
|
assert logstash.version.startswith('6.7.1')
|
||||||
|
|
||||||
|
|
||||||
|
def test_logstash_is_running(host):
|
||||||
|
"""Test if the services are enabled and running."""
|
||||||
|
logstash = host.service("logstash")
|
||||||
|
assert logstash.is_enabled
|
||||||
|
assert logstash.is_running
|
||||||
|
|
||||||
|
|
||||||
|
def test_find_correct_logentry(host):
|
||||||
|
logfile = host.file("//var/log/logstash/logstash-plain.log")
|
||||||
|
assert logfile.contains("Successfully started Logstash API endpoint")
|
||||||
|
assert logfile.contains("Restored connection to ES instance")
|
||||||
@ -1,7 +1,9 @@
|
|||||||
---
|
---
|
||||||
- name: Debian/Ubuntu | Install apt-transport-https and ca-certificates
|
- name: Debian/Ubuntu | Install apt-transport-https and ca-certificates
|
||||||
apt:
|
apt:
|
||||||
name: ['apt-transport-https', 'ca-certificates']
|
name:
|
||||||
|
- apt-transport-https
|
||||||
|
- ca-certificates
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- when: logstash_install_java
|
- when: logstash_install_java
|
||||||
@ -20,6 +22,7 @@
|
|||||||
repo: 'deb https://artifacts.elastic.co/packages/6.x/apt stable main'
|
repo: 'deb https://artifacts.elastic.co/packages/6.x/apt stable main'
|
||||||
state: present
|
state: present
|
||||||
filename: 'elastic_repo'
|
filename: 'elastic_repo'
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Debian/Ubuntu | Install Logstash
|
- name: Debian/Ubuntu | Install Logstash
|
||||||
apt:
|
apt:
|
||||||
@ -31,7 +34,8 @@
|
|||||||
- name: Debian/Ubuntu | Checking if wazuh-manager is installed
|
- name: Debian/Ubuntu | Checking if wazuh-manager is installed
|
||||||
command: dpkg -l wazuh-manager
|
command: dpkg -l wazuh-manager
|
||||||
register: wazuh_manager_check_deb
|
register: wazuh_manager_check_deb
|
||||||
when: logstash_input_beats == false
|
when: not logstash_input_beats
|
||||||
|
changed_when: false
|
||||||
args:
|
args:
|
||||||
warn: false
|
warn: false
|
||||||
|
|
||||||
@ -41,5 +45,5 @@
|
|||||||
groups: ossec
|
groups: ossec
|
||||||
append: true
|
append: true
|
||||||
when:
|
when:
|
||||||
- logstash_input_beats == false
|
- not logstash_input_beats
|
||||||
- wazuh_manager_check_deb.rc == 0
|
- wazuh_manager_check_deb.rc == 0
|
||||||
|
|||||||
@ -3,3 +3,4 @@
|
|||||||
apt_repository:
|
apt_repository:
|
||||||
repo: deb https://artifacts.elastic.co/packages/5.x/apt stable main
|
repo: deb https://artifacts.elastic.co/packages/5.x/apt stable main
|
||||||
state: absent
|
state: absent
|
||||||
|
changed_when: false
|
||||||
|
|||||||
@ -3,3 +3,4 @@
|
|||||||
yum_repository:
|
yum_repository:
|
||||||
name: elastic_repo
|
name: elastic_repo
|
||||||
state: absent
|
state: absent
|
||||||
|
changed_when: false
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
baseurl: https://artifacts.elastic.co/packages/6.x/yum
|
baseurl: https://artifacts.elastic.co/packages/6.x/yum
|
||||||
gpgkey: https://artifacts.elastic.co/GPG-KEY-elasticsearch
|
gpgkey: https://artifacts.elastic.co/GPG-KEY-elasticsearch
|
||||||
gpgcheck: true
|
gpgcheck: true
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: RedHat/CentOS/Fedora | Install Logstash
|
- name: RedHat/CentOS/Fedora | Install Logstash
|
||||||
package: name=logstash-{{ elastic_stack_version }} state=present
|
package: name=logstash-{{ elastic_stack_version }} state=present
|
||||||
@ -22,7 +23,8 @@
|
|||||||
- name: RedHat/CentOS/Fedora | Checking if wazuh-manager is installed
|
- name: RedHat/CentOS/Fedora | Checking if wazuh-manager is installed
|
||||||
command: rpm -q wazuh-manager
|
command: rpm -q wazuh-manager
|
||||||
register: wazuh_manager_check_rpm
|
register: wazuh_manager_check_rpm
|
||||||
when: logstash_input_beats == false
|
when: not logstash_input_beats
|
||||||
|
changed_when: false
|
||||||
args:
|
args:
|
||||||
warn: false
|
warn: false
|
||||||
|
|
||||||
@ -32,12 +34,14 @@
|
|||||||
groups: ossec
|
groups: ossec
|
||||||
append: true
|
append: true
|
||||||
when:
|
when:
|
||||||
- logstash_input_beats == false
|
- not logstash_input_beats
|
||||||
- wazuh_manager_check_rpm.rc == 0
|
- wazuh_manager_check_rpm.rc == 0
|
||||||
|
|
||||||
- name: Amazon Linux change startup group
|
- name: Amazon Linux change startup group
|
||||||
shell: sed -i 's/.*LS_GROUP=logstash.*/LS_GROUP=ossec/' /etc/logstash/startup.options
|
shell: sed -i 's/.*LS_GROUP=logstash.*/LS_GROUP=ossec/' /etc/logstash/startup.options
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
when:
|
when:
|
||||||
- logstash_input_beats == false
|
- not logstash_input_beats
|
||||||
- wazuh_manager_check_rpm.rc == 0
|
- wazuh_manager_check_rpm.rc == 0
|
||||||
- ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA"
|
- ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA"
|
||||||
|
|||||||
@ -15,10 +15,23 @@
|
|||||||
- not (ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA")
|
- not (ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA")
|
||||||
- not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('15.04', '<'))
|
- not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('15.04', '<'))
|
||||||
- not (ansible_distribution == "Debian" and ansible_distribution_version is version('8', '<'))
|
- not (ansible_distribution == "Debian" and ansible_distribution_version is version('8', '<'))
|
||||||
|
- not (ansible_os_family == "RedHat" and ansible_distribution_version is version('7', '<'))
|
||||||
|
|
||||||
- name: Amazon Linux create service
|
- name: Amazon Linux create service
|
||||||
shell: /usr/share/logstash/bin/system-install /etc/logstash/startup.options
|
shell: /usr/share/logstash/bin/system-install /etc/logstash/startup.options
|
||||||
when: ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA"
|
when: ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA"
|
||||||
|
args:
|
||||||
|
creates: /etc/default/logstash
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|
||||||
|
- name: Amazon Linux create service
|
||||||
|
shell: /usr/share/logstash/bin/system-install /etc/logstash/startup.options
|
||||||
|
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
|
||||||
|
args:
|
||||||
|
creates: /etc/default/logstash
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|
||||||
- name: Ensure Logstash started and enabled
|
- name: Ensure Logstash started and enabled
|
||||||
service:
|
service:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user