Skip to content
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

System Test: Module (WAZUH-DB) - Sync of agents registered on nodes after seconds #2761

Merged
merged 9 commits into from
Apr 11, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Wazuh commit: TBD \
Release report: TBD

### Added
- Add System test cluster sync group with 40 agents ([#2761](https:/wazuh/wazuh-qa/pull/2761))
- Add test fim with file currently open ([#2300](https:/wazuh/wazuh-qa/pull/2300))
- Test manager sends AR log format as expected ([#2347](https:/wazuh/wazuh-qa/pull/2347))
- Syscollector deltas IT ([#2146](https:/wazuh/wazuh-qa/pull/2146))
Expand Down
8 changes: 4 additions & 4 deletions tests/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def clean_cluster_logs(hosts_list, host_manager):
def remove_cluster_agents(wazuh_master, agents_list, host_manager):
# Removes a list of agents from the cluster using manage_agents
agent_id = get_agent_id(host_manager)
for agent in agents_list:
host_manager.control_service(host=agent, service='wazuh', state="stopped")
host_manager.clear_file(agent, file_path=os.path.join(WAZUH_PATH, 'etc', 'client.keys'))
while (agent_id != ''):
host_manager.get_host(wazuh_master).ansible("command", f'{WAZUH_PATH}/bin/manage_agents -r {agent_id}',
check=False)
agent_id = get_agent_id(host_manager)
for agent in agents_list:
host_manager.control_service(host=agent, service='wazuh', state="stopped")
host_manager.clear_file(agent, file_path=os.path.join(WAZUH_PATH, 'etc', 'client.keys'))


def get_agents_in_cluster(host, host_manager):
Expand Down Expand Up @@ -91,7 +91,7 @@ def check_agent_groups(agent_id, group_to_check, hosts_list, host_manager):
# Check the expected group is in the group data for the agent
for host in hosts_list:
group_data = host_manager.run_command(host, f'{WAZUH_PATH}/bin/agent_groups -s -i {agent_id}')
assert group_to_check in group_data
assert group_to_check in group_data, f"Did not find the expected group {group_to_check} in data: {group_data} in host: {host}"


def check_agent_status(agent_id, agent_name, agent_ip, status, host_manager, hosts_list):
Expand Down
93 changes: 93 additions & 0 deletions tests/system/provisioning/big_cluster_40_agents/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# wazuh-qa

Wazuh - Big cluster - Forty agents provisioning

## Setting up the provisioning

To run this provisioning we need to use a **Linux** machine and install the following tools:

- [Docker](https://docs.docker.com/install/)
- [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)

## Structure

```bash
basic_cluster
├── ansible.cfg
├── destroy.yml
├── inventory.yml
├── playbook.yml
├── README.md
├── roles
│   ├── agent-role
│   │   ├── files
│   │   │   └── ossec.conf
│   │   └── tasks
│   │   └── main.yml
│   ├── master-role
│   │   ├── files
│   │   │   └── ossec.conf
│   │   └── tasks
│   │   └── main.yml
│   └── worker-role
│   ├── files
│   │   └── ossec.conf
│   └── tasks
│   └── main.yml
└── vars
├── configurations.yml
└── main.yml
```

#### ansible.cfg

Ansible configuration file in the current directory. In this file, we setup the configuration of Ansible for this
provisioning.

#### destroy.yml

In this file we will specify that we want to shut down the docker machines in our environment.

##### inventory.yml

File containing the inventory of machines in our environment. In this file we will set the connection method and its
python interpreter

##### playbook.yml

Here we will write the commands to be executed in order to use our environment

##### roles

Folder with all the general roles that could be used for start our environment. Within each role we can find the
following structure:

- **files**: Configuration files to be applied when the environment is setting up.
- **tasks**: Main tasks to be performed for each role

#### Vars

This folder contains the variables used to configure our environment. Variables like the cluster key or the agent key.

## Environment

The base environment defined for Docker provisioning is

- A master node
- Two workers nodes
- Forty agents, all connected to master node by default, stopped and not registered.


## Environment management

For running the docker provisioning we must execute the following command:

```shell script
ansible-playbook -i inventory.yml playbook.yml --extra-vars='{"wazuh_branch": "PUT YOUT wazuh/wazuh BRANCH HERE"}'
```

To destroy it, the command is:

```shell script
ansible-playbook -i inventory.yml destroy.yml
```
12 changes: 12 additions & 0 deletions tests/system/provisioning/big_cluster_40_agents/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[defaults]
hash_behaviour = merge
gather_timeout = 300
stdout_callback = yaml
callback_whitelist = profile_tasks, timer, mail
timeout = 60
log_path = ./ansible.log

[ssh_connection]
ssh_args = -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
pipelining = True
retries = 10
54 changes: 54 additions & 0 deletions tests/system/provisioning/big_cluster_40_agents/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
- hosts: localhost
tasks:
- docker_container:
name: "{{item}}"
state: absent
force_kill: yes
with_items:
- "wazuh-master"
- "wazuh-worker1"
- "wazuh-worker2"
- "wazuh-agent1"
- "wazuh-agent2"
- "wazuh-agent3"
- "wazuh-agent4"
- "wazuh-agent5"
- "wazuh-agent6"
- "wazuh-agent7"
- "wazuh-agent8"
- "wazuh-agent9"
- "wazuh-agent10"
- "wazuh-agent11"
- "wazuh-agent12"
- "wazuh-agent13"
- "wazuh-agent14"
- "wazuh-agent15"
- "wazuh-agent16"
- "wazuh-agent17"
- "wazuh-agent18"
- "wazuh-agent19"
- "wazuh-agent20"
- "wazuh-agent21"
- "wazuh-agent22"
- "wazuh-agent23"
- "wazuh-agent24"
- "wazuh-agent25"
- "wazuh-agent26"
- "wazuh-agent27"
- "wazuh-agent28"
- "wazuh-agent29"
- "wazuh-agent30"
- "wazuh-agent31"
- "wazuh-agent32"
- "wazuh-agent33"
- "wazuh-agent34"
- "wazuh-agent35"
- "wazuh-agent36"
- "wazuh-agent37"
- "wazuh-agent38"
- "wazuh-agent39"
- "wazuh-agent40"



157 changes: 157 additions & 0 deletions tests/system/provisioning/big_cluster_40_agents/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
all:
hosts:
wazuh-master:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-worker1:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-worker2:
ansible_connection: docker
ansible_python_interpreter: python
managers:
hosts:
wazuh-master:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-worker1:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-worker2:
ansible_connection: docker
ansible_python_interpreter: python
master:
hosts:
wazuh-master:
ansible_connection: docker
ansible_python_interpreter: python
workers:
hosts:
wazuh-worker1:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-worker2:
ansible_connection: docker
ansible_python_interpreter: python
agents:
hosts:
wazuh-agent1:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent2:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent3:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent4:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent5:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent6:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent7:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent8:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent9:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent10:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent11:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent12:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent13:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent14:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent15:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent16:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent17:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent18:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent19:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent20:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent21:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent22:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent23:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent24:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent25:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent26:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent27:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent28:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent29:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent30:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent31:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent32:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent33:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent34:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent35:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent36:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent37:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent38:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent39:
ansible_connection: docker
ansible_python_interpreter: python
wazuh-agent40:
ansible_connection: docker
ansible_python_interpreter: python
Loading