From 948f4d9a63758fb19968cad866d4878f13e81c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Fri, 30 Aug 2024 13:03:41 +0200 Subject: [PATCH] Added not empty token variable check --- install_functions/manager.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/install_functions/manager.sh b/install_functions/manager.sh index 862f76b..0d83620 100644 --- a/install_functions/manager.sh +++ b/install_functions/manager.sh @@ -45,6 +45,24 @@ function manager_startCluster() { function manager_checkService() { common_logger "Checking Wazuh API connection" eval "TOKEN=$(curl -k -s -X POST -u "wazuh-wui:wazuh-wui" https://127.0.0.1:55000/security/user/authenticate/run_as?raw=true -d '{"user_name":"wzread"}' -H "content-type:application/json")" + + max_attempts=5 + attempt=0 + seconds=3 + + while [[ -z "${TOKEN}" && "${attempt}" -lt "${max_attempts}" ]]; do + attempt=$((attempt+1)) + common_logger "Attempt $attempt: Trying to get Wazuh API token" + sleep "${seconds}" + TOKEN=$(curl -k -s -X POST -u "wazuh-wui:wazuh-wui" https://127.0.0.1:55000/security/user/authenticate/run_as?raw=true -d '{"user_name":"wzread"}' -H "content-type:application/json") + done + + if [[ -z "${TOKEN}" ]]; then + common_logger -e "Failed to obtain Wazuh API token after $max_attempts attempts." + installCommon_rollBack + exit 1 + fi + wm_error=$(curl -k -s -X GET "https://127.0.0.1:55000/agents/outdated?pretty=true" -H "Authorization: Bearer ${TOKEN}") if [[ ${wm_error,,} =~ '"error": 0' ]]; then