From a9b814d107483e2c7350745c11af5dde2d8fe904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Mag=C3=A1n?= <80041853+juliamagan@users.noreply.github.com> Date: Wed, 25 Jan 2023 11:46:12 +0100 Subject: [PATCH] feat(#3112): add API statistics format test --- CHANGELOG.md | 4 +- deps/wazuh_testing/wazuh_testing/api.py | 15 +- .../test_config/test_rbac/test_rbac_mode.py | 6 +- .../test_response_postprocessing.py | 3 + .../test_set_secure_headers.py | 3 + .../test_rbac/test_add_old_resource.py | 3 + .../test_rbac/test_admin_resources.py | 3 + .../test_rbac/test_policy_position.py | 4 + .../test_rbac/test_remove_relationship.py | 3 + .../test_rbac/test_remove_resource.py | 3 + ...nfiguration_manager_statistics_format.yaml | 11 + .../wazuh-analysisd_template.json | 260 ++++ .../wazuh-remoted_template.json | 168 +++ .../wazuh-analysisd_template.json | 683 ++++++++++ .../wazuh-db_template.json | 1159 +++++++++++++++++ .../wazuh-remoted_template.json | 215 +++ .../cases_agent_statistics_format.yaml | 13 + .../cases_manager_statistics_format.yaml | 20 + .../test_statistics/test_statistics_format.py | 149 +++ 19 files changed, 2714 insertions(+), 11 deletions(-) create mode 100644 tests/integration/test_api/test_statistics/data/configuration_template/configuration_manager_statistics_format.yaml create mode 100644 tests/integration/test_api/test_statistics/data/statistics_template/agent_statistics_format_test_module/wazuh-analysisd_template.json create mode 100644 tests/integration/test_api/test_statistics/data/statistics_template/agent_statistics_format_test_module/wazuh-remoted_template.json create mode 100644 tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-analysisd_template.json create mode 100644 tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-db_template.json create mode 100644 tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-remoted_template.json create mode 100644 tests/integration/test_api/test_statistics/data/test_cases/agent_statistics_format_test_module/cases_agent_statistics_format.yaml create mode 100644 tests/integration/test_api/test_statistics/data/test_cases/manager_statistics_format_test_module/cases_manager_statistics_format.yaml create mode 100644 tests/integration/test_api/test_statistics/test_statistics_format.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 03c818687f..30dfb373ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,9 @@ Release report: TBD ### Added +- Add integration test to check statistics format ([#3813](https://github.com/wazuh/wazuh-qa/pull/3813)) \- (Framework + Tests) - Add new test to check vulnerable packages with triaged null([#3587](https://github.com/wazuh/wazuh-qa/pull/3587)) \- (Framework + Tests) -- Add new tests analysid handling of invalid/empty rule signature IDs ([#3649] -(https://github.com/wazuh/wazuh-qa/pull/3649)) \- (Framework + Tests) +- Add new tests analysid handling of invalid/empty rule signature IDs ([#3649](https://github.com/wazuh/wazuh-qa/pull/3649)) \- (Framework + Tests) - Add integration test to check agent database version ([#3768](https://github.com/wazuh/wazuh-qa/pull/3768)) \- (Tests) - Fix Yara and VirusTotal E2E basic usage tests ([#3660](https://github.com/wazuh/wazuh-qa/pull/3660)) - Add new test to check if syslog message are parsed correctrly in the `archives.json` file ([#3609](https://github.com/wazuh/wazuh-qa/pull/3609)) \- (Framework + Tests) diff --git a/deps/wazuh_testing/wazuh_testing/api.py b/deps/wazuh_testing/wazuh_testing/api.py index 435fdf8d85..489f842a19 100644 --- a/deps/wazuh_testing/wazuh_testing/api.py +++ b/deps/wazuh_testing/wazuh_testing/api.py @@ -113,7 +113,8 @@ def compare_config_api_response(configuration, section): def get_manager_configuration(section=None, field=None): """Get Wazuh manager configuration response from API using GET /manager/configuration - References: https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.manager_controller.get_configuration + References: https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/ + api.controllers.manager_controller.get_configuration Args: section (str): wazuh configuration section, E.g: "active-response", "ruleset"... @@ -180,8 +181,8 @@ def wait_until_api_ready(protocol=API_PROTOCOL, host=API_HOST, port=API_PORT, us get_token_login_api(protocol, host, port, user, password, login_endpoint, timeout, attempts, 1) -def make_api_call(port=55000, method='GET', endpoint='/', headers=None, request_json=None, params=None, verify=False, - token=None): +def make_api_call(manager_address=API_HOST, port=55000, method='GET', endpoint='/', headers=None, request_json=None, + params=None, verify=False, token=None): """Make an API call Args: @@ -206,16 +207,16 @@ def make_api_call(port=55000, method='GET', endpoint='/', headers=None, request_ response = None if method == 'POST': - response = requests.post(f'https://localhost:{port}{endpoint}', headers=headers, json=request_json, + response = requests.post(f'https://{manager_address}:{port}{endpoint}', headers=headers, json=request_json, params=params, verify=verify) elif method == 'DELETE': - response = requests.delete(f'https://localhost:{port}{endpoint}', headers=headers, json=request_json, + response = requests.delete(f'https://{manager_address}:{port}{endpoint}', headers=headers, json=request_json, params=params, verify=verify) elif method == 'PUT': - response = requests.put(f'https://localhost:{port}{endpoint}', headers=headers, json=request_json, + response = requests.put(f'https://{manager_address}:{port}{endpoint}', headers=headers, json=request_json, params=params, verify=verify) else: - response = requests.get(f'https://localhost:{port}{endpoint}', headers=headers, json=request_json, + response = requests.get(f'https://{manager_address}:{port}{endpoint}', headers=headers, json=request_json, params=params, verify=verify) return response diff --git a/tests/integration/test_api/test_config/test_rbac/test_rbac_mode.py b/tests/integration/test_api/test_config/test_rbac/test_rbac_mode.py index 7597f32730..a14207cfc6 100644 --- a/tests/integration/test_api/test_config/test_rbac/test_rbac_mode.py +++ b/tests/integration/test_api/test_config/test_rbac/test_rbac_mode.py @@ -66,8 +66,6 @@ path = os.path.dirname(os.path.abspath(__file__)) rbac_sql_path = os.path.join(WAZUH_PATH, 'api', 'configuration', 'security', 'rbac.db') -con = sqlite3.connect(rbac_sql_path) -cur = con.cursor() # Configurations @@ -88,6 +86,8 @@ def get_configuration(request): def extra_configuration_before_yield(): # Add a new user in the RBAC database. + con = sqlite3.connect(rbac_sql_path) + cur = con.cursor() with open(os.path.join(test_data_path, 'schema_add_user.sql')) as f: sql = f.read() cur.executescript(sql) @@ -95,6 +95,8 @@ def extra_configuration_before_yield(): def extra_configuration_after_yield(): # Delete the test_user created in the RBAC database. + con = sqlite3.connect(rbac_sql_path) + cur = con.cursor() with open(os.path.join(test_data_path, 'schema_delete_user.sql')) as f: sql = f.read() cur.executescript(sql) diff --git a/tests/integration/test_api/test_middlewares/test_response_postprocessing.py b/tests/integration/test_api/test_middlewares/test_response_postprocessing.py index 62afd7e743..fd92f858ce 100644 --- a/tests/integration/test_api/test_middlewares/test_response_postprocessing.py +++ b/tests/integration/test_api/test_middlewares/test_response_postprocessing.py @@ -58,6 +58,9 @@ import requests from wazuh_testing import api +# Marks +pytestmark = [pytest.mark.server] + # Tests diff --git a/tests/integration/test_api/test_middlewares/test_set_secure_headers.py b/tests/integration/test_api/test_middlewares/test_set_secure_headers.py index f6631779c1..4bc4e22273 100644 --- a/tests/integration/test_api/test_middlewares/test_set_secure_headers.py +++ b/tests/integration/test_api/test_middlewares/test_set_secure_headers.py @@ -55,6 +55,9 @@ import pytest import requests +# Marks +pytestmark = [pytest.mark.server] + # Tests diff --git a/tests/integration/test_api/test_rbac/test_add_old_resource.py b/tests/integration/test_api/test_rbac/test_add_old_resource.py index b35982c8df..1f0c98292f 100644 --- a/tests/integration/test_api/test_rbac/test_add_old_resource.py +++ b/tests/integration/test_api/test_rbac/test_add_old_resource.py @@ -52,6 +52,9 @@ import pytest from wazuh_testing.api import get_security_resource_information +# Marks +pytestmark = [pytest.mark.server] + # Variables user_id, role_id, policy_id, rule_id = None, None, None, None diff --git a/tests/integration/test_api/test_rbac/test_admin_resources.py b/tests/integration/test_api/test_rbac/test_admin_resources.py index d56883d929..827b826045 100644 --- a/tests/integration/test_api/test_rbac/test_admin_resources.py +++ b/tests/integration/test_api/test_rbac/test_admin_resources.py @@ -51,6 +51,9 @@ import pytest import requests +# Marks +pytestmark = [pytest.mark.server] + @pytest.fixture(scope='module') def get_configuration(): diff --git a/tests/integration/test_api/test_rbac/test_policy_position.py b/tests/integration/test_api/test_rbac/test_policy_position.py index 341255921f..3b71ee8d1b 100644 --- a/tests/integration/test_api/test_rbac/test_policy_position.py +++ b/tests/integration/test_api/test_rbac/test_policy_position.py @@ -52,6 +52,10 @@ import requests from wazuh_testing.api import get_security_resource_information +# Marks + +pytestmark = [pytest.mark.server] + # Variables user_id, role_id, policy_id, rule_id = None, None, None, None policy_positions = list() diff --git a/tests/integration/test_api/test_rbac/test_remove_relationship.py b/tests/integration/test_api/test_rbac/test_remove_relationship.py index 55f5c9713a..e4a334a20a 100644 --- a/tests/integration/test_api/test_rbac/test_remove_relationship.py +++ b/tests/integration/test_api/test_rbac/test_remove_relationship.py @@ -52,6 +52,9 @@ import pytest from wazuh_testing.api import get_security_resource_information +# Marks +pytestmark = [pytest.mark.server] + # Variables user_id, role_id, policy_id, rule_id = None, None, None, None diff --git a/tests/integration/test_api/test_rbac/test_remove_resource.py b/tests/integration/test_api/test_rbac/test_remove_resource.py index a031e47ad8..8230357cd3 100644 --- a/tests/integration/test_api/test_rbac/test_remove_resource.py +++ b/tests/integration/test_api/test_rbac/test_remove_resource.py @@ -52,6 +52,9 @@ import pytest from wazuh_testing.api import get_security_resource_information +# Marks +pytestmark = [pytest.mark.server] + # Variables user_id, role_id, policy_id, rule_id = None, None, None, None diff --git a/tests/integration/test_api/test_statistics/data/configuration_template/configuration_manager_statistics_format.yaml b/tests/integration/test_api/test_statistics/data/configuration_template/configuration_manager_statistics_format.yaml new file mode 100644 index 0000000000..7caeb6e73e --- /dev/null +++ b/tests/integration/test_api/test_statistics/data/configuration_template/configuration_manager_statistics_format.yaml @@ -0,0 +1,11 @@ +- sections: + - section: global + elements: + - limits: + elements: + - eps: + elements: + - maximum: + value: 500 + - timeframe: + value: 10 diff --git a/tests/integration/test_api/test_statistics/data/statistics_template/agent_statistics_format_test_module/wazuh-analysisd_template.json b/tests/integration/test_api/test_statistics/data/statistics_template/agent_statistics_format_test_module/wazuh-analysisd_template.json new file mode 100644 index 0000000000..e56d481c29 --- /dev/null +++ b/tests/integration/test_api/test_statistics/data/statistics_template/agent_statistics_format_test_module/wazuh-analysisd_template.json @@ -0,0 +1,260 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "affected_items": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "timestamp": { + "type": "string" + }, + "name": { + "type": "string", + "pattern": "^wazuh-analysisd$" + }, + "agents": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "uptime": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "metrics": { + "type": "object", + "properties": { + "events": { + "type": "object", + "properties": { + "processed": { + "type": "integer" + }, + "received_breakdown": { + "type": "object", + "properties": { + "decoded_breakdown": { + "type": "object", + "properties": { + "agent": { + "type": "integer" + }, + "dbsync": { + "type": "integer" + }, + "integrations_breakdown": { + "type": "object", + "properties": { + "virustotal": { + "type": "integer" + } + }, + "required": [ + "virustotal" + ] + }, + "modules_breakdown": { + "type": "object", + "properties": { + "aws": { + "type": "integer" + }, + "azure": { + "type": "integer" + }, + "ciscat": { + "type": "integer" + }, + "command": { + "type": "integer" + }, + "docker": { + "type": "integer" + }, + "gcp": { + "type": "integer" + }, + "github": { + "type": "integer" + }, + "logcollector_breakdown": { + "type": "object", + "properties": { + "eventchannel": { + "type": "integer" + }, + "eventlog": { + "type": "integer" + }, + "macos": { + "type": "integer" + }, + "others": { + "type": "integer" + } + }, + "required": [ + "eventchannel", + "eventlog", + "macos", + "others" + ] + }, + "office365": { + "type": "integer" + }, + "oscap": { + "type": "integer" + }, + "osquery": { + "type": "integer" + }, + "rootcheck": { + "type": "integer" + }, + "sca": { + "type": "integer" + }, + "syscheck": { + "type": "integer" + }, + "syscollector": { + "type": "integer" + }, + "upgrade": { + "type": "integer" + }, + "vulnerability": { + "type": "integer" + } + }, + "required": [ + "aws", + "azure", + "ciscat", + "command", + "docker", + "gcp", + "github", + "logcollector_breakdown", + "office365", + "oscap", + "osquery", + "rootcheck", + "sca", + "syscheck", + "syscollector", + "upgrade", + "vulnerability" + ] + }, + "monitor": { + "type": "integer" + }, + "remote": { + "type": "integer" + } + }, + "required": [ + "agent", + "dbsync", + "integrations_breakdown", + "modules_breakdown", + "monitor", + "remote" + ] + } + }, + "required": [ + "decoded_breakdown" + ] + }, + "written_breakdown": { + "type": "object", + "properties": { + "alerts": { + "type": "integer" + }, + "archives": { + "type": "integer" + }, + "firewall": { + "type": "integer" + } + }, + "required": [ + "alerts", + "archives", + "firewall" + ] + } + }, + "required": [ + "processed", + "received_breakdown", + "written_breakdown" + ] + } + }, + "required": [ + "events" + ] + } + }, + "required": [ + "uptime", + "id", + "metrics" + ] + } + ] + } + }, + "required": [ + "timestamp", + "name", + "agents" + ] + } + ] + }, + "total_affected_items": { + "type": "integer" + }, + "total_failed_items": { + "type": "integer" + }, + "failed_items": { + "type": "array", + "items": {} + } + }, + "required": [ + "affected_items", + "total_affected_items", + "total_failed_items", + "failed_items" + ] + }, + "message": { + "type": "string" + }, + "error": { + "type": "integer" + } + }, + "required": [ + "data", + "message", + "error" + ] + } diff --git a/tests/integration/test_api/test_statistics/data/statistics_template/agent_statistics_format_test_module/wazuh-remoted_template.json b/tests/integration/test_api/test_statistics/data/statistics_template/agent_statistics_format_test_module/wazuh-remoted_template.json new file mode 100644 index 0000000000..58d207ff13 --- /dev/null +++ b/tests/integration/test_api/test_statistics/data/statistics_template/agent_statistics_format_test_module/wazuh-remoted_template.json @@ -0,0 +1,168 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "affected_items": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "timestamp": { + "type": "string" + }, + "name": { + "type": "string", + "pattern": "^wazuh-remoted$" + }, + "agents": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "uptime": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "metrics": { + "type": "object", + "properties": { + "messages": { + "type": "object", + "properties": { + "received_breakdown": { + "type": "object", + "properties": { + "control": { + "type": "integer" + }, + "control_breakdown": { + "type": "object", + "properties": { + "keepalive": { + "type": "integer" + }, + "request": { + "type": "integer" + }, + "shutdown": { + "type": "integer" + }, + "startup": { + "type": "integer" + } + }, + "required": [ + "keepalive", + "request", + "shutdown", + "startup" + ] + }, + "event": { + "type": "integer" + } + }, + "required": [ + "control", + "control_breakdown", + "event" + ] + }, + "sent_breakdown": { + "type": "object", + "properties": { + "ack": { + "type": "integer" + }, + "ar": { + "type": "integer" + }, + "discarded": { + "type": "integer" + }, + "request": { + "type": "integer" + }, + "sca": { + "type": "integer" + }, + "shared": { + "type": "integer" + } + }, + "required": [ + "ack", + "ar", + "discarded", + "request", + "sca", + "shared" + ] + } + }, + "required": [ + "received_breakdown", + "sent_breakdown" + ] + } + }, + "required": [ + "messages" + ] + } + }, + "required": [ + "uptime", + "id", + "metrics" + ] + } + ] + } + }, + "required": [ + "timestamp", + "name", + "agents" + ] + } + ] + }, + "total_affected_items": { + "type": "integer" + }, + "total_failed_items": { + "type": "integer" + }, + "failed_items": { + "type": "array", + "items": {} + } + }, + "required": [ + "affected_items", + "total_affected_items", + "total_failed_items", + "failed_items" + ] + }, + "message": { + "type": "string" + }, + "error": { + "type": "integer" + } + }, + "required": [ + "data", + "message", + "error" + ] + } diff --git a/tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-analysisd_template.json b/tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-analysisd_template.json new file mode 100644 index 0000000000..d8df1a2f4b --- /dev/null +++ b/tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-analysisd_template.json @@ -0,0 +1,683 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "affected_items": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "uptime": { + "type": "string" + }, + "timestamp": { + "type": "string" + }, + "name": { + "type": "string", + "pattern": "^wazuh-analysisd$" + }, + "metrics": { + "type": "object", + "properties": { + "bytes": { + "type": "object", + "properties": { + "received": { + "type": "integer" + } + }, + "required": [ + "received" + ] + }, + "eps":{ + "type": "object", + "properties": { + "available_credits": { + "type": "number" + }, + "events_dropped": { + "type": "number" + }, + "seconds_over_limit": { + "type": "number" + } + }, + "required": [ + "available_credits", + "events_dropped", + "seconds_over_limit" + ] + }, + "events": { + "type": "object", + "properties": { + "processed": { + "type": "integer" + }, + "received": { + "type": "integer" + }, + "received_breakdown": { + "type": "object", + "properties": { + "decoded_breakdown": { + "type": "object", + "properties": { + "agent": { + "type": "integer" + }, + "agentless": { + "type": "integer" + }, + "dbsync": { + "type": "integer" + }, + "integrations_breakdown": { + "type": "object", + "properties": { + "virustotal": { + "type": "integer" + } + }, + "required": [ + "virustotal" + ] + }, + "modules_breakdown": { + "type": "object", + "properties": { + "aws": { + "type": "integer" + }, + "azure": { + "type": "integer" + }, + "ciscat": { + "type": "integer" + }, + "command": { + "type": "integer" + }, + "docker": { + "type": "integer" + }, + "gcp": { + "type": "integer" + }, + "github": { + "type": "integer" + }, + "logcollector_breakdown": { + "type": "object", + "properties": { + "eventchannel": { + "type": "integer" + }, + "eventlog": { + "type": "integer" + }, + "macos": { + "type": "integer" + }, + "others": { + "type": "integer" + } + }, + "required": [ + "eventchannel", + "eventlog", + "macos", + "others" + ] + }, + "office365": { + "type": "integer" + }, + "oscap": { + "type": "integer" + }, + "osquery": { + "type": "integer" + }, + "rootcheck": { + "type": "integer" + }, + "sca": { + "type": "integer" + }, + "syscheck": { + "type": "integer" + }, + "syscollector": { + "type": "integer" + }, + "upgrade": { + "type": "integer" + }, + "vulnerability": { + "type": "integer" + } + }, + "required": [ + "aws", + "azure", + "ciscat", + "command", + "docker", + "gcp", + "github", + "logcollector_breakdown", + "office365", + "oscap", + "osquery", + "rootcheck", + "sca", + "syscheck", + "syscollector", + "upgrade", + "vulnerability" + ] + }, + "monitor": { + "type": "integer" + }, + "remote": { + "type": "integer" + }, + "syslog": { + "type": "integer" + } + }, + "required": [ + "agent", + "agentless", + "dbsync", + "integrations_breakdown", + "modules_breakdown", + "monitor", + "remote", + "syslog" + ] + }, + "dropped_breakdown": { + "type": "object", + "properties": { + "agent": { + "type": "integer" + }, + "agentless": { + "type": "integer" + }, + "dbsync": { + "type": "integer" + }, + "integrations_breakdown": { + "type": "object", + "properties": { + "virustotal": { + "type": "integer" + } + }, + "required": [ + "virustotal" + ] + }, + "modules_breakdown": { + "type": "object", + "properties": { + "aws": { + "type": "integer" + }, + "azure": { + "type": "integer" + }, + "ciscat": { + "type": "integer" + }, + "command": { + "type": "integer" + }, + "docker": { + "type": "integer" + }, + "gcp": { + "type": "integer" + }, + "github": { + "type": "integer" + }, + "logcollector_breakdown": { + "type": "object", + "properties": { + "eventchannel": { + "type": "integer" + }, + "eventlog": { + "type": "integer" + }, + "macos": { + "type": "integer" + }, + "others": { + "type": "integer" + } + }, + "required": [ + "eventchannel", + "eventlog", + "macos", + "others" + ] + }, + "office365": { + "type": "integer" + }, + "oscap": { + "type": "integer" + }, + "osquery": { + "type": "integer" + }, + "rootcheck": { + "type": "integer" + }, + "sca": { + "type": "integer" + }, + "syscheck": { + "type": "integer" + }, + "syscollector": { + "type": "integer" + }, + "upgrade": { + "type": "integer" + }, + "vulnerability": { + "type": "integer" + } + }, + "required": [ + "aws", + "azure", + "ciscat", + "command", + "docker", + "gcp", + "github", + "logcollector_breakdown", + "office365", + "oscap", + "osquery", + "rootcheck", + "sca", + "syscheck", + "syscollector", + "upgrade", + "vulnerability" + ] + }, + "monitor": { + "type": "integer" + }, + "remote": { + "type": "integer" + }, + "syslog": { + "type": "integer" + } + }, + "required": [ + "agent", + "agentless", + "dbsync", + "integrations_breakdown", + "modules_breakdown", + "monitor", + "remote", + "syslog" + ] + } + }, + "required": [ + "decoded_breakdown", + "dropped_breakdown" + ] + }, + "written_breakdown": { + "type": "object", + "properties": { + "alerts": { + "type": "integer" + }, + "archives": { + "type": "integer" + }, + "firewall": { + "type": "integer" + }, + "fts": { + "type": "integer" + }, + "stats": { + "type": "integer" + } + }, + "required": [ + "alerts", + "archives", + "firewall", + "fts", + "stats" + ] + } + }, + "required": [ + "processed", + "received", + "received_breakdown", + "written_breakdown" + ] + }, + "queues": { + "type": "object", + "properties": { + "alerts": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "archives": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "dbsync": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "eventchannel": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "firewall": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "fts": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "hostinfo": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "others": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "processed": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "rootcheck": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "sca": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "stats": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "syscheck": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "syscollector": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + }, + "upgrade": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + } + }, + "required": [ + "alerts", + "archives", + "dbsync", + "eventchannel", + "firewall", + "fts", + "hostinfo", + "others", + "processed", + "rootcheck", + "sca", + "stats", + "syscheck", + "syscollector", + "upgrade" + ] + } + }, + "required": [ + "bytes", + "eps", + "events", + "queues" + ] + } + }, + "required": [ + "uptime", + "timestamp", + "name", + "metrics" + ] + } + ] + }, + "total_affected_items": { + "type": "integer" + }, + "total_failed_items": { + "type": "integer" + }, + "failed_items": { + "type": "array", + "items": {} + } + }, + "required": [ + "affected_items", + "total_affected_items", + "total_failed_items", + "failed_items" + ] + }, + "message": { + "type": "string" + }, + "error": { + "type": "integer" + } + }, + "required": [ + "data", + "message", + "error" + ] + } diff --git a/tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-db_template.json b/tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-db_template.json new file mode 100644 index 0000000000..3bc83ddca6 --- /dev/null +++ b/tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-db_template.json @@ -0,0 +1,1159 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "affected_items": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "uptime": { + "type": "string" + }, + "timestamp": { + "type": "string" + }, + "name": { + "type": "string", + "pattern": "^wazuh-db$" + }, + "metrics": { + "type": "object", + "properties": { + "queries": { + "type": "object", + "properties": { + "received": { + "type": "integer" + }, + "received_breakdown": { + "type": "object", + "properties": { + "agent": { + "type": "integer" + }, + "agent_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "begin": { + "type": "integer" + }, + "close": { + "type": "integer" + }, + "commit": { + "type": "integer" + }, + "remove": { + "type": "integer" + }, + "sql": { + "type": "integer" + }, + "vacuum": { + "type": "integer" + }, + "get_fragmentation": { + "type": "integer" + } + }, + "required": [ + "begin", + "close", + "commit", + "remove", + "sql", + "vacuum", + "get_fragmentation" + ] + }, + "tables": { + "type": "object", + "properties": { + "ciscat": { + "type": "object", + "properties": { + "ciscat": { + "type": "integer" + } + }, + "required": [ + "ciscat" + ] + }, + "rootcheck": { + "type": "object", + "properties": { + "rootcheck": { + "type": "integer" + } + }, + "required": [ + "rootcheck" + ] + }, + "sca": { + "type": "object", + "properties": { + "sca": { + "type": "integer" + } + }, + "required": [ + "sca" + ] + }, + "sync": { + "type": "object", + "properties": { + "dbsync": { + "type": "integer" + } + }, + "required": [ + "dbsync" + ] + }, + "syscheck": { + "type": "object", + "properties": { + "fim_file": { + "type": "integer" + }, + "fim_registry": { + "type": "integer" + }, + "syscheck": { + "type": "integer" + } + }, + "required": [ + "fim_file", + "fim_registry", + "syscheck" + ] + }, + "syscollector": { + "type": "object", + "properties": { + "syscollector_hotfixes": { + "type": "integer" + }, + "syscollector_hwinfo": { + "type": "integer" + }, + "syscollector_network_address": { + "type": "integer" + }, + "syscollector_network_iface": { + "type": "integer" + }, + "syscollector_network_protocol": { + "type": "integer" + }, + "syscollector_osinfo": { + "type": "integer" + }, + "syscollector_packages": { + "type": "integer" + }, + "syscollector_ports": { + "type": "integer" + }, + "syscollector_processes": { + "type": "integer" + }, + "deprecated": { + "type": "object", + "properties": { + "hardware": { + "type": "integer" + }, + "hotfix": { + "type": "integer" + }, + "netaddr": { + "type": "integer" + }, + "netinfo": { + "type": "integer" + }, + "netproto": { + "type": "integer" + }, + "osinfo": { + "type": "integer" + }, + "package": { + "type": "integer" + }, + "port": { + "type": "integer" + }, + "process": { + "type": "integer" + } + }, + "required": [ + "hardware", + "hotfix", + "netaddr", + "netinfo", + "netproto", + "osinfo", + "package", + "port", + "process" + ] + } + }, + "required": [ + "syscollector_hotfixes", + "syscollector_hwinfo", + "syscollector_network_address", + "syscollector_network_iface", + "syscollector_network_protocol", + "syscollector_osinfo", + "syscollector_packages", + "syscollector_ports", + "syscollector_processes", + "deprecated" + ] + }, + "vulnerability": { + "type": "object", + "properties": { + "vuln_cves": { + "type": "integer" + } + }, + "required": [ + "vuln_cves" + ] + } + }, + "required": [ + "ciscat", + "rootcheck", + "sca", + "sync", + "syscheck", + "syscollector", + "vulnerability" + ] + } + }, + "required": [ + "db", + "tables" + ] + }, + "global": { + "type": "integer" + }, + "global_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "backup": { + "type": "integer" + }, + "sql": { + "type": "integer" + }, + "vacuum": { + "type": "integer" + }, + "get_fragmentation": { + "type": "integer" + } + }, + "required": [ + "backup", + "sql", + "vacuum", + "get_fragmentation" + ] + }, + "tables": { + "type": "object", + "properties": { + "agent": { + "type": "object", + "properties": { + "delete-agent": { + "type": "integer" + }, + "disconnect-agents": { + "type": "integer" + }, + "find-agent": { + "type": "integer" + }, + "get-agent-info": { + "type": "integer" + }, + "get-agents-by-connection-status": { + "type": "integer" + }, + "get-all-agents": { + "type": "integer" + }, + "get-groups-integrity": { + "type": "integer" + }, + "insert-agent": { + "type": "integer" + }, + "reset-agents-connection": { + "type": "integer" + }, + "select-agent-group": { + "type": "integer" + }, + "select-agent-name": { + "type": "integer" + }, + "set-agent-groups": { + "type": "integer" + }, + "sync-agent-groups-get": { + "type": "integer" + }, + "sync-agent-info-get": { + "type": "integer" + }, + "sync-agent-info-set": { + "type": "integer" + }, + "update-agent-data": { + "type": "integer" + }, + "update-agent-name": { + "type": "integer" + }, + "update-connection-status": { + "type": "integer" + }, + "update-keepalive": { + "type": "integer" + } + }, + "required": [ + "delete-agent", + "disconnect-agents", + "find-agent", + "get-agent-info", + "get-agents-by-connection-status", + "get-all-agents", + "get-groups-integrity", + "insert-agent", + "reset-agents-connection", + "select-agent-group", + "select-agent-name", + "set-agent-groups", + "sync-agent-groups-get", + "sync-agent-info-get", + "sync-agent-info-set", + "update-agent-data", + "update-agent-name", + "update-connection-status", + "update-keepalive" + ] + }, + "belongs": { + "type": "object", + "properties": { + "get-group-agents": { + "type": "integer" + }, + "select-group-belong": { + "type": "integer" + } + }, + "required": [ + "get-group-agents", + "select-group-belong" + ] + }, + "group": { + "type": "object", + "properties": { + "delete-group": { + "type": "integer" + }, + "find-group": { + "type": "integer" + }, + "insert-agent-group": { + "type": "integer" + }, + "select-groups": { + "type": "integer" + } + }, + "required": [ + "delete-group", + "find-group", + "insert-agent-group", + "select-groups" + ] + }, + "labels": { + "type": "object", + "properties": { + "get-labels": { + "type": "integer" + } + }, + "required": [ + "get-labels" + ] + } + }, + "required": [ + "agent", + "belongs", + "group", + "labels" + ] + } + }, + "required": [ + "db", + "tables" + ] + }, + "mitre": { + "type": "integer" + }, + "mitre_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "sql": { + "type": "integer" + } + }, + "required": [ + "sql" + ] + } + }, + "required": [ + "db" + ] + }, + "task": { + "type": "integer" + }, + "task_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "sql": { + "type": "integer" + } + }, + "required": [ + "sql" + ] + }, + "tables": { + "type": "object", + "properties": { + "tasks": { + "type": "object", + "properties": { + "delete_old": { + "type": "integer" + }, + "set_timeout": { + "type": "integer" + }, + "upgrade": { + "type": "integer" + }, + "upgrade_cancel_tasks": { + "type": "integer" + }, + "upgrade_custom": { + "type": "integer" + }, + "upgrade_get_status": { + "type": "integer" + }, + "upgrade_result": { + "type": "integer" + }, + "upgrade_update_status": { + "type": "integer" + } + }, + "required": [ + "delete_old", + "set_timeout", + "upgrade", + "upgrade_cancel_tasks", + "upgrade_custom", + "upgrade_get_status", + "upgrade_result", + "upgrade_update_status" + ] + } + }, + "required": [ + "tasks" + ] + } + }, + "required": [ + "db", + "tables" + ] + }, + "wazuhdb": { + "type": "integer" + }, + "wazuhdb_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "remove": { + "type": "integer" + } + }, + "required": [ + "remove" + ] + } + }, + "required": [ + "db" + ] + } + }, + "required": [ + "agent", + "agent_breakdown", + "global", + "global_breakdown", + "mitre", + "mitre_breakdown", + "task", + "task_breakdown", + "wazuhdb", + "wazuhdb_breakdown" + ] + } + }, + "required": [ + "received", + "received_breakdown" + ] + }, + "time": { + "type": "object", + "properties": { + "execution": { + "type": "integer" + }, + "execution_breakdown": { + "type": "object", + "properties": { + "agent": { + "type": "integer" + }, + "agent_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "begin": { + "type": "integer" + }, + "close": { + "type": "integer" + }, + "commit": { + "type": "integer" + }, + "remove": { + "type": "integer" + }, + "sql": { + "type": "integer" + }, + "vacuum": { + "type": "integer" + }, + "get_fragmentation": { + "type": "integer" + } + }, + "required": [ + "begin", + "close", + "commit", + "remove", + "sql", + "vacuum", + "get_fragmentation" + ] + }, + "tables": { + "type": "object", + "properties": { + "ciscat": { + "type": "object", + "properties": { + "ciscat": { + "type": "integer" + } + }, + "required": [ + "ciscat" + ] + }, + "rootcheck": { + "type": "object", + "properties": { + "rootcheck": { + "type": "integer" + } + }, + "required": [ + "rootcheck" + ] + }, + "sca": { + "type": "object", + "properties": { + "sca": { + "type": "integer" + } + }, + "required": [ + "sca" + ] + }, + "sync": { + "type": "object", + "properties": { + "dbsync": { + "type": "integer" + } + }, + "required": [ + "dbsync" + ] + }, + "syscheck": { + "type": "object", + "properties": { + "fim_file": { + "type": "integer" + }, + "fim_registry": { + "type": "integer" + }, + "syscheck": { + "type": "integer" + } + }, + "required": [ + "fim_file", + "fim_registry", + "syscheck" + ] + }, + "syscollector": { + "type": "object", + "properties": { + "syscollector_hotfixes": { + "type": "integer" + }, + "syscollector_hwinfo": { + "type": "integer" + }, + "syscollector_network_address": { + "type": "integer" + }, + "syscollector_network_iface": { + "type": "integer" + }, + "syscollector_network_protocol": { + "type": "integer" + }, + "syscollector_osinfo": { + "type": "integer" + }, + "syscollector_packages": { + "type": "integer" + }, + "syscollector_ports": { + "type": "integer" + }, + "syscollector_processes": { + "type": "integer" + }, + "deprecated": { + "type": "object", + "properties": { + "hardware": { + "type": "integer" + }, + "hotfix": { + "type": "integer" + }, + "netaddr": { + "type": "integer" + }, + "netinfo": { + "type": "integer" + }, + "netproto": { + "type": "integer" + }, + "osinfo": { + "type": "integer" + }, + "package": { + "type": "integer" + }, + "port": { + "type": "integer" + }, + "process": { + "type": "integer" + } + }, + "required": [ + "hardware", + "hotfix", + "netaddr", + "netinfo", + "netproto", + "osinfo", + "package", + "port", + "process" + ] + } + }, + "required": [ + "syscollector_hotfixes", + "syscollector_hwinfo", + "syscollector_network_address", + "syscollector_network_iface", + "syscollector_network_protocol", + "syscollector_osinfo", + "syscollector_packages", + "syscollector_ports", + "syscollector_processes", + "deprecated" + ] + }, + "vulnerability": { + "type": "object", + "properties": { + "vuln_cves": { + "type": "integer" + } + }, + "required": [ + "vuln_cves" + ] + } + }, + "required": [ + "ciscat", + "rootcheck", + "sca", + "sync", + "syscheck", + "syscollector", + "vulnerability" + ] + } + }, + "required": [ + "db", + "tables" + ] + }, + "global": { + "type": "integer" + }, + "global_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "backup": { + "type": "integer" + }, + "sql": { + "type": "integer" + }, + "vacuum": { + "type": "integer" + }, + "get_fragmentation": { + "type": "integer" + } + }, + "required": [ + "backup", + "sql", + "vacuum", + "get_fragmentation" + ] + }, + "tables": { + "type": "object", + "properties": { + "agent": { + "type": "object", + "properties": { + "delete-agent": { + "type": "integer" + }, + "disconnect-agents": { + "type": "integer" + }, + "find-agent": { + "type": "integer" + }, + "get-agent-info": { + "type": "integer" + }, + "get-agents-by-connection-status": { + "type": "integer" + }, + "get-all-agents": { + "type": "integer" + }, + "get-groups-integrity": { + "type": "integer" + }, + "insert-agent": { + "type": "integer" + }, + "reset-agents-connection": { + "type": "integer" + }, + "select-agent-group": { + "type": "integer" + }, + "select-agent-name": { + "type": "integer" + }, + "set-agent-groups": { + "type": "integer" + }, + "sync-agent-groups-get": { + "type": "integer" + }, + "sync-agent-info-get": { + "type": "integer" + }, + "sync-agent-info-set": { + "type": "integer" + }, + "update-agent-data": { + "type": "integer" + }, + "update-agent-name": { + "type": "integer" + }, + "update-connection-status": { + "type": "integer" + }, + "update-keepalive": { + "type": "integer" + } + }, + "required": [ + "delete-agent", + "disconnect-agents", + "find-agent", + "get-agent-info", + "get-agents-by-connection-status", + "get-all-agents", + "get-groups-integrity", + "insert-agent", + "reset-agents-connection", + "select-agent-group", + "select-agent-name", + "set-agent-groups", + "sync-agent-groups-get", + "sync-agent-info-get", + "sync-agent-info-set", + "update-agent-data", + "update-agent-name", + "update-connection-status", + "update-keepalive" + ] + }, + "belongs": { + "type": "object", + "properties": { + "get-group-agents": { + "type": "integer" + }, + "select-group-belong": { + "type": "integer" + } + }, + "required": [ + "get-group-agents", + "select-group-belong" + ] + }, + "group": { + "type": "object", + "properties": { + "delete-group": { + "type": "integer" + }, + "find-group": { + "type": "integer" + }, + "insert-agent-group": { + "type": "integer" + }, + "select-groups": { + "type": "integer" + } + }, + "required": [ + "delete-group", + "find-group", + "insert-agent-group", + "select-groups" + ] + }, + "labels": { + "type": "object", + "properties": { + "get-labels": { + "type": "integer" + } + }, + "required": [ + "get-labels" + ] + } + }, + "required": [ + "agent", + "belongs", + "group", + "labels" + ] + } + }, + "required": [ + "db", + "tables" + ] + }, + "mitre": { + "type": "integer" + }, + "mitre_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "sql": { + "type": "integer" + } + }, + "required": [ + "sql" + ] + } + }, + "required": [ + "db" + ] + }, + "task": { + "type": "integer" + }, + "task_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "sql": { + "type": "integer" + } + }, + "required": [ + "sql" + ] + }, + "tables": { + "type": "object", + "properties": { + "tasks": { + "type": "object", + "properties": { + "delete_old": { + "type": "integer" + }, + "set_timeout": { + "type": "integer" + }, + "upgrade": { + "type": "integer" + }, + "upgrade_cancel_tasks": { + "type": "integer" + }, + "upgrade_custom": { + "type": "integer" + }, + "upgrade_get_status": { + "type": "integer" + }, + "upgrade_result": { + "type": "integer" + }, + "upgrade_update_status": { + "type": "integer" + } + }, + "required": [ + "delete_old", + "set_timeout", + "upgrade", + "upgrade_cancel_tasks", + "upgrade_custom", + "upgrade_get_status", + "upgrade_result", + "upgrade_update_status" + ] + } + }, + "required": [ + "tasks" + ] + } + }, + "required": [ + "db", + "tables" + ] + }, + "wazuhdb": { + "type": "integer" + }, + "wazuhdb_breakdown": { + "type": "object", + "properties": { + "db": { + "type": "object", + "properties": { + "remove": { + "type": "integer" + } + }, + "required": [ + "remove" + ] + } + }, + "required": [ + "db" + ] + } + }, + "required": [ + "agent", + "agent_breakdown", + "global", + "global_breakdown", + "mitre", + "mitre_breakdown", + "task", + "task_breakdown", + "wazuhdb", + "wazuhdb_breakdown" + ] + } + }, + "required": [ + "execution", + "execution_breakdown" + ] + } + }, + "required": [ + "queries", + "time" + ] + } + }, + "required": [ + "uptime", + "timestamp", + "name", + "metrics" + ] + } + ] + }, + "total_affected_items": { + "type": "integer" + }, + "total_failed_items": { + "type": "integer" + }, + "failed_items": { + "type": "array", + "items": {} + } + }, + "required": [ + "affected_items", + "total_affected_items", + "total_failed_items", + "failed_items" + ] + }, + "message": { + "type": "string" + }, + "error": { + "type": "integer" + } + }, + "required": [ + "data", + "message", + "error" + ] + } diff --git a/tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-remoted_template.json b/tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-remoted_template.json new file mode 100644 index 0000000000..07195b2e4b --- /dev/null +++ b/tests/integration/test_api/test_statistics/data/statistics_template/manager_statistics_format_test_module/wazuh-remoted_template.json @@ -0,0 +1,215 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "data": { + "type": "object", + "properties": { + "affected_items": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "uptime": { + "type": "string" + }, + "timestamp": { + "type": "string" + }, + "name": { + "type": "string", + "pattern": "^wazuh-remoted$" + }, + "metrics": { + "type": "object", + "properties": { + "bytes": { + "type": "object", + "properties": { + "received": { + "type": "integer" + }, + "sent": { + "type": "integer" + } + }, + "required": [ + "received", + "sent" + ] + }, + "keys_reload_count": { + "type": "integer" + }, + "messages": { + "type": "object", + "properties": { + "received_breakdown": { + "type": "object", + "properties": { + "control": { + "type": "integer" + }, + "control_breakdown": { + "type": "object", + "properties": { + "keepalive": { + "type": "integer" + }, + "request": { + "type": "integer" + }, + "shutdown": { + "type": "integer" + }, + "startup": { + "type": "integer" + } + }, + "required": [ + "keepalive", + "request", + "shutdown", + "startup" + ] + }, + "dequeued_after": { + "type": "integer" + }, + "discarded": { + "type": "integer" + }, + "event": { + "type": "integer" + }, + "ping": { + "type": "integer" + }, + "unknown": { + "type": "integer" + } + }, + "required": [ + "control", + "control_breakdown", + "dequeued_after", + "discarded", + "event", + "ping", + "unknown" + ] + }, + "sent_breakdown": { + "type": "object", + "properties": { + "ack": { + "type": "integer" + }, + "ar": { + "type": "integer" + }, + "discarded": { + "type": "integer" + }, + "request": { + "type": "integer" + }, + "sca": { + "type": "integer" + }, + "shared": { + "type": "integer" + } + }, + "required": [ + "ack", + "ar", + "discarded", + "request", + "sca", + "shared" + ] + } + }, + "required": [ + "received_breakdown", + "sent_breakdown" + ] + }, + "queues": { + "type": "object", + "properties": { + "received": { + "type": "object", + "properties": { + "size": { + "type": "integer" + }, + "usage": { + "type": "integer" + } + }, + "required": [ + "size", + "usage" + ] + } + }, + "required": [ + "received" + ] + }, + "tcp_sessions": { + "type": "integer" + } + }, + "required": [ + "bytes", + "keys_reload_count", + "messages", + "queues", + "tcp_sessions" + ] + } + }, + "required": [ + "uptime", + "timestamp", + "name", + "metrics" + ] + } + ] + }, + "total_affected_items": { + "type": "integer" + }, + "total_failed_items": { + "type": "integer" + }, + "failed_items": { + "type": "array", + "items": {} + } + }, + "required": [ + "affected_items", + "total_affected_items", + "total_failed_items", + "failed_items" + ] + }, + "message": { + "type": "string" + }, + "error": { + "type": "integer" + } + }, + "required": [ + "data", + "message", + "error" + ] + } diff --git a/tests/integration/test_api/test_statistics/data/test_cases/agent_statistics_format_test_module/cases_agent_statistics_format.yaml b/tests/integration/test_api/test_statistics/data/test_cases/agent_statistics_format_test_module/cases_agent_statistics_format.yaml new file mode 100644 index 0000000000..1d8a4ffcd2 --- /dev/null +++ b/tests/integration/test_api/test_statistics/data/test_cases/agent_statistics_format_test_module/cases_agent_statistics_format.yaml @@ -0,0 +1,13 @@ +- name: remoted_endpoint + description: remoted statistics endpoint + configuration_parameters: + ENDPOINT: wazuh-remoted + metadata: + endpoint: wazuh-remoted + +- name: analysisd_endpoint + description: analysisd statistics endpoint + configuration_parameters: + ENDPOINT: wazuh-analysisd + metadata: + endpoint: wazuh-analysisd diff --git a/tests/integration/test_api/test_statistics/data/test_cases/manager_statistics_format_test_module/cases_manager_statistics_format.yaml b/tests/integration/test_api/test_statistics/data/test_cases/manager_statistics_format_test_module/cases_manager_statistics_format.yaml new file mode 100644 index 0000000000..fbae59c3d5 --- /dev/null +++ b/tests/integration/test_api/test_statistics/data/test_cases/manager_statistics_format_test_module/cases_manager_statistics_format.yaml @@ -0,0 +1,20 @@ +- name: remoted_endpoint + description: remoted statistics endpoint + configuration_parameters: + ENDPOINT: wazuh-remoted + metadata: + endpoint: wazuh-remoted + +- name: analysisd_endpoint + description: analysisd statistics endpoint + configuration_parameters: + ENDPOINT: wazuh-analysisd + metadata: + endpoint: wazuh-analysisd + +- name: wazuh-db_endpoint + description: wazuh-db statistics endpoint + configuration_parameters: + ENDPOINT: wazuh-db + metadata: + endpoint: wazuh-db diff --git a/tests/integration/test_api/test_statistics/test_statistics_format.py b/tests/integration/test_api/test_statistics/test_statistics_format.py new file mode 100644 index 0000000000..ac6ef03f34 --- /dev/null +++ b/tests/integration/test_api/test_statistics/test_statistics_format.py @@ -0,0 +1,149 @@ +import jsonschema +import os +import pytest + +from wazuh_testing.api import make_api_call +from wazuh_testing.tools import agent_simulator as ag +from wazuh_testing.tools.configuration import load_configuration_template, get_test_cases_data +from wazuh_testing.tools.file import read_json_file +from wazuh_testing.tools.wazuh_manager import remove_agents + +pytestmark = [pytest.mark.server] + + +# Generic vars +TEST_DATA_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') +CONFIGURATIONS_PATH = os.path.join(TEST_DATA_PATH, 'configuration_template') +TEST_CASES_PATH = os.path.join(TEST_DATA_PATH, 'test_cases') +STATISTICS_TEMPLATE_PATH = os.path.join(TEST_DATA_PATH, 'statistics_template') + +# ------------------------------------------- TEST_MANAGER_STATISTICS_FORMAT ------------------------------------------- +# Configuration and cases data +t1_configurations_path = os.path.join(CONFIGURATIONS_PATH, 'configuration_manager_statistics_format.yaml') +t1_cases_path = os.path.join(TEST_CASES_PATH, 'manager_statistics_format_test_module', + 'cases_manager_statistics_format.yaml') +t1_statistics_template_path = os.path.join(STATISTICS_TEMPLATE_PATH, 'manager_statistics_format_test_module') + +# Manager statistics format test configurations (t1) +t1_configuration_parameters, t1_configuration_metadata, t1_case_ids = get_test_cases_data(t1_cases_path) +t1_configurations = load_configuration_template(t1_configurations_path, t1_configuration_parameters, + t1_configuration_metadata) + +# -------------------------------------------- TEST_AGENT_STATISTICS_FORMAT -------------------------------------------- +# Configuration and cases data +t2_cases_path = os.path.join(TEST_CASES_PATH, 'agent_statistics_format_test_module', + 'cases_agent_statistics_format.yaml') +t2_statistics_template_path = os.path.join(STATISTICS_TEMPLATE_PATH, 'agent_statistics_format_test_module') + +# Agent statistics format test configurations (t2) +t2_configuration_parameters, t2_configuration_metadata, t2_case_ids = get_test_cases_data(t2_cases_path) + + +@pytest.mark.tier(level=0) +@pytest.mark.filterwarnings('ignore::urllib3.exceptions.InsecureRequestWarning') +@pytest.mark.parametrize('configuration, metadata', zip(t1_configurations, t1_configuration_metadata), ids=t1_case_ids) +def test_manager_statistics_format(configuration, metadata, load_wazuh_basic_configuration, set_wazuh_configuration, + get_api_details, restart_wazuh_daemon_function): + """ + description: Check if the statistics returned by the API have the expected format. + + test_phases: + - setup: + - Load Wazuh light configuration. + - Apply ossec.conf configuration changes according to the configuration template and use case. + - Truncate wazuh logs. + - Restart wazuh-manager service to apply configuration changes. + - test: + - Request the statistics of a particular daemon from the API. + - Compare the obtained statistics with the json schema. + - tierdown: + - Restore initial configuration. + + wazuh_min_version: 4.4.0 + + parameters: + - configuration: + type: dict + brief: Get configurations from the module. + - metadata: + type: dict + brief: Get metadata from the module. + - load_wazuh_basic_configuration: + type: fixture + brief: Load basic wazuh configuration. + - set_wazuh_configuration: + type: fixture + brief: Apply changes to the ossec.conf configuration. + - get_api_details: + type: fixture + brief: Get API information. + - restart_wazuh_daemon_function: + type: fixture + brief: Restart the wazuh service and truncate wazuh logs. + + assertions: + - Check if the statistics returned by the API have the expected format. + + input_description: + - The `configuration_manager_statistics_format` file provides the module configuration for this test. + - The `cases_manager_statistics_format` file provides the test cases. + """ + endpoint = f"/manager/daemons/stats?daemons_list={metadata['endpoint']}" + api_details = get_api_details() + response = make_api_call(endpoint=endpoint, headers=api_details['auth_headers']) + stats_schema = read_json_file(os.path.join(t1_statistics_template_path, f"{metadata['endpoint']}_template.json")) + + # Check if the API statistics response data meets the expected schema. Raise an exception if not. + jsonschema.validate(instance=response.json(), schema=stats_schema) + + +@pytest.mark.tier(level=0) +@pytest.mark.filterwarnings('ignore::urllib3.exceptions.InsecureRequestWarning') +@pytest.mark.parametrize('metadata', t2_configuration_metadata, ids=t2_case_ids) +def test_agent_statistics_format(metadata, restart_wazuh_daemon_function, get_api_details): + """ + description: Check if the statistics returned by the API have the expected format. + + test_phases: + - setup: + - Truncate wazuh logs. + - Restart wazuh-manager service to apply configuration changes. + - test: + - Simulate and connect an agent. + - Request the statistics of a particular daemon and agent from the API. + - Compare the obtained statistics with the json schema. + - Stop and delete the simulated agent. + + wazuh_min_version: 4.4.0 + + parameters: + - metadata: + type: dict + brief: Get metadata from the module. + - get_api_details: + type: fixture + brief: Get API information. + - restart_wazuh_daemon_function: + type: fixture + brief: Restart the wazuh service and truncate wazuh logs. + + assertions: + - Check if the statistics returned by the API have the expected format. + + input_description: + - The `cases_agent_statistics_format` file provides the test cases. + """ + agents = ag.create_agents(1, 'localhost') + sender, injector = ag.connect(agents[0]) + + endpoint = f"/agents/{agents[0].id}/daemons/stats?daemons_list={metadata['endpoint']}" + api_details = get_api_details() + response = make_api_call(endpoint=endpoint, headers=api_details['auth_headers']) + stats_schema = read_json_file(os.path.join(t2_statistics_template_path, f"{metadata['endpoint']}_template.json")) + + # Check if the API statistics response data meets the expected schema. Raise an exception if not. + jsonschema.validate(instance=response.json(), schema=stats_schema) + + # Stop and delete simulated agent + injector.stop_receive() + remove_agents(agents[0].id, 'api')