Skip to content

Commit

Permalink
enhancement(#5219): Preparing additional dashboard and indexer valida…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
pro-akim committed Apr 24, 2024
1 parent eb44df7 commit 587dd76
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 26 deletions.
71 changes: 71 additions & 0 deletions deployability/modules/testing/tests/helpers/dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (C) 2015, Wazuh Inc.
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import requests
import socket

from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT
from .executor import Executor, WazuhAPI
from .generic import HostInformation, CheckFiles
from modules.testing.utils import logger
from .utils import Utils


class WazuhDashboard:

@staticmethod
def get_dashboard_version(inventory_path) -> str:
"""
Returns dashboard version
Args:
inventory_path (str): host's inventory path
"""

return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-dashboard/VERSION')


@staticmethod
def isDashboard_active(inventory_path) -> bool:
"""
Returns True/False depending if the dashboard is active or not
Args:
inventory_path (str): host's inventory path
"""

return '200' in Executor.execute_command(inventory_path, 'curl -Is -k https://localhost/app/login?nextUrl=%2F | head -n 1')


@staticmethod
def isDashboardKeystore_working(inventory_path) -> bool:
"""
Returns True/False depending if the dashboard keystore is active or not
Args:
inventory_path (str): host's inventory path
"""

return 'No such file or directory' not in Executor.execute_command(inventory_path, '/usr/share/wazuh-dashboard/bin/opensearch-dashboards-keystore list --allow-root')


@staticmethod
def areIndexes_working(wazuh_api: WazuhAPI) -> str:
"""
Function to get the status of an agent given its name.
Args:
- agents_data (list): List of dictioconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaanaries conaaaaa.
- agent_name (str): Name of the agent whoseconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaa status is to be obtained.
Returns:
- str: Status of the agent if found in the daconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaa, otherwise returns None.
"""
logger.error(wazuh_api.api_url)
logger.error(wazuh_api.password)
logger.error(wazuh_api.username)
response = requests.get(f"{wazuh_api.api_url}/_cat/indices/?pretty", auth=(wazuh_api.username, wazuh_api.password), verify=False)


return response
24 changes: 22 additions & 2 deletions deployability/modules/testing/tests/helpers/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ def execute_commands(inventory_path, commands=[]) -> dict:


class WazuhAPI:
def __init__(self, inventory_path):
def __init__(self, inventory_path, component=None):
self.inventory_path = inventory_path
self.api_url = None
self.headers = None
self.component = component
self.username = None
self.password = None
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
self._authenticate()

Expand All @@ -80,8 +83,25 @@ def _authenticate(self):

token = json.loads(requests.post(login_url, headers=login_headers, verify=False).content.decode())['data']['token']

self.api_url = f'https://{host}:{port}'
self.headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {token}'
}

self.api_url = f'https://{host}:{port}'

if self.component == 'dashboard':
self.username = 'admin'
file_path = Executor.execute_command(self.inventory_path, 'pwd').replace("\n","") + '/wazuh-install-files/wazuh-passwords.txt'
if not 'true' in Executor.execute_command(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"'):
Executor.execute_command(self.inventory_path, 'tar -xvf wazuh-install-files.tar')
self.password = Executor.execute_command(self.inventory_path, "grep indexer_password wazuh-install-files/wazuh-passwords.txt | head -n 1 | awk '{print $NF}'").replace("'","").replace("\n","")
self.api_url = f'https://localhost'

if self.component == 'indexer':
self.username = 'admin'
file_path = Executor.execute_command(self.inventory_path, 'pwd').replace("\n","") + '/wazuh-install-files/wazuh-passwords.txt'
if not 'true' in Executor.execute_command(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"'):
Executor.execute_command(self.inventory_path, 'tar -xvf wazuh-install-files.tar')
self.password = Executor.execute_command(self.inventory_path, "").replace("'","").replace("\n","")
self.api_url = f'https://localhost:9200'
Empty file.
52 changes: 52 additions & 0 deletions deployability/modules/testing/tests/helpers/indexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (C) 2015, Wazuh Inc.
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import requests
import socket

from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT
from .executor import Executor, WazuhAPI
from .generic import HostInformation, CheckFiles
from modules.testing.utils import logger
from .utils import Utils


class WazuhIndexer:

@staticmethod
def get_indexer_version(inventory_path) -> str:
"""
Returns indexer version
Args:
inventory_path (str): host's inventory path
"""

return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-indexer/VERSION')


@staticmethod
def areIndexer_internalUsers_complete(inventory_path) -> bool:
"""
Returns True/False depending on the existance of all the expected internal users
Args:
inventory_path (str): host's inventory path
"""

users_to_check = [
'admin',
'kibanaserver',
'kibanaro',
'logstash',
'readall',
'snapshotrestore'
]
report_of_users = Executor.execute_command(inventory_path, "cat /etc/wazuh-indexer/opensearch-security/internal_users.yml | grep '^[a-z]'")
for user in users_to_check:
if user not in report_of_users:

return False

return True
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from ..helpers.executor import WazuhAPI
from ..helpers.generic import HostConfiguration, HostInformation, GeneralComponentActions
from ..helpers.manager import WazuhManager
from ..helpers.indexer import WazuhIndexer
from ..helpers.dashboard import WazuhDashboard
from ..helpers.central import WazuhCentralComponents
from modules.testing.utils import logger
from ..helpers.utils import Utils
Expand Down Expand Up @@ -48,7 +50,23 @@ def setup_test_environment(wazuh_params):

wazuh_params['managers'] = {key: value for key, value in targets_dict.items() if key.startswith('wazuh-')}

def test_installation(wazuh_params):

def test_parametros(wazuh_params):
#logger.error(WazuhDashboard.get_dashboard_version(wazuh_params['dashboard']))
#for indexer_params in wazuh_params['indexers']:
# logger.error(WazuhIndexer.get_indexer_version(indexer_params))

#logger.error(WazuhDashboard.isDashboard_active(wazuh_params['dashboard']))


#logger.error(WazuhDashboard.isDashboardKeystore_working(wazuh_params['dashboard']))
#for indexer_params in wazuh_params['indexers']:
# logger.error(WazuhIndexer.areIndexer_internalUsers_complete(indexer_params))

wazuh_api = WazuhAPI(wazuh_params['dashboard'], component='dashboard')
logger.error(WazuhDashboard.areIndexes_working(wazuh_api))

""" def test_installation(wazuh_params):
# Disabling firewall for all managers
for manager_name, manager_params in wazuh_params['managers'].items():
Utils.check_inventory_connection(manager_params)
Expand Down Expand Up @@ -93,3 +111,4 @@ def test_manager_revision(wazuh_params):
def test_manager_installed_directory(wazuh_params):
for manager in wazuh_params['managers'].values():
assert HostInformation.dir_exists(manager, WAZUH_ROOT), logger.error(f'The {WAZUH_ROOT} is not present in {HostInformation.get_os_name_and_version_from_inventory(manager)}')
"""
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ description: This workflow is used to test manager deployment for DDT1 PoC
variables:
central_components-os:
- linux-ubuntu-20.04-amd64
#- linux-ubuntu-22.04-amd64
#- linux-oracle-9-amd64
#- linux-amazon-2-amd64
#- linux-redhat-7-amd64
#- linux-redhat-8-amd64
#- linux-redhat-9-amd64
#- linux-centos-7-amd64
#- linux-centos-8-amd64
#- linux-debian-10-amd64
#- linux-debian-11-amd64
#- linux-debian-12-amd64
- linux-ubuntu-22.04-amd64
- linux-amazon-2-amd64
- linux-redhat-7-amd64
- linux-redhat-8-amd64
- linux-redhat-9-amd64
- linux-centos-7-amd64
- linux-centos-8-amd64
- linux-debian-10-amd64
- linux-debian-11-amd64
- linux-debian-12-amd64
infra-provider: aws
working-dir: /tmp/dtt1-poc

Expand All @@ -39,6 +38,14 @@ tasks:
foreach:
- variable: central_components-os
as: central_components
cleanup:
this: process
with:
path: python3
args:
- modules/allocation/main.py
- action: delete
- track-output: "{working-dir}/central_components-{central_components-os}/track.yaml"

# Generic manager test task
- task: "run-central_components-{central_components}-tests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ description: This workflow is used to test manager deployment for DDT1 PoC
variables:
central_components-os:
- linux-ubuntu-20.04-amd64
#- linux-ubuntu-22.04-amd64
#- linux-oracle-9-amd64
#- linux-amazon-2-amd64
#- linux-redhat-7-amd64
#- linux-redhat-8-amd64
#- linux-redhat-9-amd64
#- linux-centos-7-amd64
#- linux-centos-8-amd64
#- linux-debian-10-amd64
#- linux-debian-11-amd64
#- linux-debian-12-amd64
- linux-ubuntu-22.04-amd64
- linux-oracle-9-amd64
- linux-amazon-2-amd64
- linux-redhat-7-amd64
- linux-redhat-8-amd64
- linux-redhat-9-amd64
- linux-centos-7-amd64
- linux-centos-8-amd64
- linux-debian-10-amd64
- linux-debian-11-amd64
- linux-debian-12-amd64
infra-provider: vagrant
working-dir: /tmp/dtt1-poc

Expand Down Expand Up @@ -49,7 +49,7 @@ tasks:
- modules/testing/main.py
- targets:
- wazuh-1: "{working-dir}/central_components-{central_components}/inventory.yaml"
- tests: "install,stop,restart,uninstall"
- tests: "install"
- component: "central_components"
- wazuh-version: "4.7.3"
- wazuh-revision: "40714"
Expand Down

0 comments on commit 587dd76

Please sign in to comment.