-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement(#5219): Adding port tests
- Loading branch information
Showing
8 changed files
with
381 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,10 @@ | |
# 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 | ||
import time | ||
|
||
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: | ||
|
||
|
@@ -21,9 +16,12 @@ def get_indexer_version(inventory_path) -> str: | |
Args: | ||
inventory_path (str): host's inventory path | ||
Returns: | ||
- str: Version of the indexer. | ||
""" | ||
|
||
return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-indexer/VERSION') | ||
return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-indexer/VERSION').strip() | ||
|
||
|
||
@staticmethod | ||
|
@@ -33,6 +31,9 @@ def areIndexer_internalUsers_complete(inventory_path) -> bool: | |
Args: | ||
inventory_path (str): host's inventory path | ||
Returns: | ||
- bool: True/False depending on the status. | ||
""" | ||
|
||
users_to_check = [ | ||
|
@@ -49,4 +50,64 @@ def areIndexer_internalUsers_complete(inventory_path) -> bool: | |
|
||
return False | ||
|
||
return True | ||
return True | ||
|
||
|
||
@staticmethod | ||
def areIndexes_working(wazuh_api: WazuhAPI, inventory_path) -> bool: | ||
""" | ||
Returns True/False depending on the working status of the indexes | ||
Args: | ||
inventory_path (str): host's inventory path | ||
Returns: | ||
- bool: True/False depending on the status. | ||
""" | ||
indexes = Executor.execute_command(inventory_path, f"curl -k -u {wazuh_api.username}:{wazuh_api.password} {wazuh_api.api_url}/_cat/indices/?pretty").strip().split('\n') | ||
for index in indexes: | ||
if 'red' not in index: | ||
|
||
return True | ||
return False | ||
|
||
|
||
@staticmethod | ||
def isIndexCluster_working(wazuh_api: WazuhAPI, inventory_path) -> bool: | ||
""" | ||
Returns True/False depending on the status of the indexer Cluster | ||
Args: | ||
inventory_path (str): host's inventory path | ||
Returns: | ||
- bool: True/False depending on the status. | ||
""" | ||
response = Executor.execute_command(inventory_path, f"curl -k -u {wazuh_api.username}:{wazuh_api.password} {wazuh_api.api_url}/_cat/health") | ||
return 'green' in response | ||
|
||
|
||
@staticmethod | ||
def isIndexer_port_opened(inventory_path, wait=0, cycles=10): | ||
""" | ||
Check if indexer port is open | ||
Args: | ||
inventory_path (str): Indexer inventory. | ||
Returns: | ||
str: Os name. | ||
""" | ||
wait_cycles = 0 | ||
while wait_cycles < cycles: | ||
ports = Executor.execute_command(inventory_path, 'ss -t -a -n | grep ":9200"').strip().split('\n') | ||
for port in ports: | ||
if 'ESTAB' in port or 'LISTEN' in port: | ||
continue | ||
else: | ||
time.sleep(wait) | ||
wait_cycles += 1 | ||
break | ||
else: | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.