Skip to content

Commit

Permalink
fix(#5215): Adding missing part
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-akim committed Apr 18, 2024
1 parent 5045ba3 commit 852bbe5
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions deployability/modules/testing/tests/helpers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,42 @@ def get_agent_ip_status_and_name_by_id(wazuh_api: WazuhAPI, identifier):
logger.error(f"Unexpected error: {e}")
return [None, None, None]

def get_agent_os_version_by_name(wazuh_api: WazuhAPI, agent_name):
"""
Get Agent os version by Agent name
Args:
agent_name (str): Agent name.
Returns:
str: Os version.
"""
response = requests.get(f"{wazuh_api.api_url}/agents", headers=wazuh_api.headers, verify=False)
try:
for agent_data in eval(response.text)['data']['affected_items']:
if agent_data.get('name') == agent_name:
return agent_data.get('os', {}).get('version')
except Exception as e:
logger.error(f"Unexpected error: {e}")
return f"Unexpected error: {e}"


def get_agent_os_name_by_name(wazuh_api: WazuhAPI, agent_name):
"""
Get Agent os name by Agent name
Args:
agent_name (str): Agent name.
Returns:
str: Os name.
"""
response = requests.get(f"{wazuh_api.api_url}/agents", headers=wazuh_api.headers, verify=False)
try:
for agent_data in eval(response.text)['data']['affected_items']:
if agent_data.get('name') == agent_name:
return 'suse' if agent_data.get('os', {}).get('name', '').lower() == 'sles' else agent_data.get('os', {}).get('name', '').lower()
except Exception as e:
logger.error(f"Unexpected error: {e}")
return f"Unexpected error: {e}"
return None


def get_agent_ip_status_and_name_by_id(wazuh_api: WazuhAPI, identifier):
"""
Expand All @@ -389,6 +425,43 @@ def get_agent_ip_status_and_name_by_id(wazuh_api: WazuhAPI, identifier):
return [None, None, None]


def get_agent_os_version_by_name(wazuh_api: WazuhAPI, agent_name):
"""
Get Agent os version by Agent name
Args:
agent_name (str): Agent name.
Returns:
str: Os version.
"""
response = requests.get(f"{wazuh_api.api_url}/agents", headers=wazuh_api.headers, verify=False)
try:
for agent_data in eval(response.text)['data']['affected_items']:
if agent_data.get('name') == agent_name:
return agent_data.get('os', {}).get('version')
except Exception as e:
logger.error(f"Unexpected error: {e}")
return f"Unexpected error: {e}"


def get_agent_os_name_by_name(wazuh_api: WazuhAPI, agent_name):
"""
Get Agent os name by Agent name
Args:
agent_name (str): Agent name.
Returns:
str: Os name.
"""
response = requests.get(f"{wazuh_api.api_url}/agents", headers=wazuh_api.headers, verify=False)
try:
for agent_data in eval(response.text)['data']['affected_items']:
if agent_data.get('name') == agent_name:
return 'suse' if agent_data.get('os', {}).get('name', '').lower() == 'sles' else agent_data.get('os', {}).get('name', '').lower()
except Exception as e:
logger.error(f"Unexpected error: {e}")
return f"Unexpected error: {e}"
return None


def add_agent_to_manager(wazuh_api: WazuhAPI, name, ip) -> str:
"""
Add an agent to the manager.
Expand Down

0 comments on commit 852bbe5

Please sign in to comment.