Skip to content

Commit

Permalink
Added not empty token variable check
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcr01 committed Aug 30, 2024
1 parent a2737f9 commit 948f4d9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions install_functions/manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 948f4d9

Please sign in to comment.