diff --git a/CHANGELOG.md b/CHANGELOG.md index 85e2091..7fe0fd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Fixed Wazuh API validation ([#29](https://github.com/wazuh/wazuh-installation-assistant/pull/29)) +- Fixed token variable empty in Wazuh manager check ([#45](https://github.com/wazuh/wazuh-installation-assistant/pull/45)) ## [4.9.1] diff --git a/install_functions/manager.sh b/install_functions/manager.sh index 862f76b..edc7bd5 100644 --- a/install_functions/manager.sh +++ b/install_functions/manager.sh @@ -44,7 +44,26 @@ 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")" + token_command="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\"" + TOKEN=$(eval "${token_command}") + + 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=$(eval "${token_command}") + 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