Skip to content

Commit

Permalink
fix(#5229): Adapting some validations
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-akim committed Apr 19, 2024
1 parent eb324d9 commit 1f80707
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
27 changes: 25 additions & 2 deletions deployability/modules/testing/tests/helpers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def install_agent(inventory_path, agent_name, wazuh_version, wazuh_revision, liv
"NET STATUS WazuhSvc"
])
elif 'macos' in os_type:
if 'x86_64' in architecture:
if 'amd64' in architecture:
commands.extend([
f'curl -so wazuh-agent.pkg https://{s3_url}.wazuh.com/{release}/macos/wazuh-agent-{wazuh_version}-1.intel64.pkg && echo "WAZUH_MANAGER=\'MANAGER_IP\' && WAZUH_AGENT_NAME=\'{agent_name}\'" > /tmp/wazuh_envs && sudo installer -pkg ./wazuh-agent.pkg -target /'
])
Expand Down Expand Up @@ -117,6 +117,25 @@ def register_agent(inventory_path, manager_path):
assert host_ip in Executor.execute_command(inventory_path, f'cat /Library/Ossec/etc/ossec.conf'), logger.error(f'Error configuring the Manager IP ({host_ip}) in: {HostInformation.get_os_name_and_version_from_inventory(inventory_path)} agent')


@staticmethod
def set_protocol_agent_connection(inventory_path, protocol):
os_type = HostInformation.get_os_type(inventory_path)
if 'linux' in os_type:
commands = [
f"sed -i 's/<protocol>[^<]*<\/protocol>/<protocol>{protocol}<\/protocol>/g' {WAZUH_CONF}",
"systemctl restart wazuh-agent"
]
Executor.execute_commands(inventory_path, commands)
assert protocol in Executor.execute_command(inventory_path, f'cat {WAZUH_CONF}'), logger.error(f'Error configuring the protocol ({protocol}) in: {HostInformation.get_os_name_and_version_from_inventory(inventory_path)} agent')
elif 'macos' in os_type:
commands = [
f"sed -i '' 's/<protocol>[^<]*<\/protocol>/<protocol>{protocol}<\/protocol>/g' /Library/Ossec/etc/ossec.conf",
"/Library/Ossec/bin/wazuh-control restart"
]
Executor.execute_commands(inventory_path, commands)
assert protocol in Executor.execute_command(inventory_path, f'cat /Library/Ossec/etc/ossec.conf'), logger.error(f'Error configuring the protocol ({protocol}) in: {HostInformation.get_os_name_and_version_from_inventory(inventory_path)} agent')


@staticmethod
def uninstall_agent(inventory_path, wazuh_version=None, wazuh_revision=None) -> None:
os_type = HostInformation.get_os_type(inventory_path)
Expand Down Expand Up @@ -328,7 +347,11 @@ def isAgent_port_open(agent_params):
Returns:
str: Os name.
"""
return 'ESTAB' in Executor.execute_command(agent_params, 'ss -t -a -n | grep ":1514" | grep ESTAB')
os_name = HostInformation.get_os_name_from_inventory(agent_params)
if os_name == 'linux':
return 'ESTAB' in Executor.execute_command(agent_params, 'ss -t -a -n | grep ":1514" | grep ESTAB')
elif os_name == 'macos':
return 'ESTABLISHED' in Executor.execute_command(agent_params, 'netstat -an | grep ".1514 " | grep ESTABLISHED')

def get_agents_information(wazuh_api: WazuhAPI) -> list:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_connection(wazuh_params):

def test_status(wazuh_params):
for agent in wazuh_params['agents'].values():
assert 'active' in GeneralComponentActions.get_component_status(agent, 'wazuh-agent'), logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(agent)} is not active')
assert 'active' in GeneralComponentActions.get_component_status(agent, 'wazuh-agent') or 'is running' in GeneralComponentActions.get_component_status(agent, 'wazuh-agent'), logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(agent)} is not active')


def test_service(wazuh_params):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ def test_installation(wazuh_params):
def test_status(wazuh_params):
for agent in wazuh_params['agents'].values():
agent_status = GeneralComponentActions.get_component_status(agent, 'wazuh-agent')
assert 'loaded' in agent_status, logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(agent)} status is not loaded')
assert 'loaded' in agent_status or 'not running' in agent_status, logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(agent)} status is not loaded')

0 comments on commit 1f80707

Please sign in to comment.