Skip to content

Commit

Permalink
Merge pull request #57 from wazuh/bug/51-manager-check-change-order
Browse files Browse the repository at this point in the history
Changed command order execution to get the TOKEN
  • Loading branch information
davidcr01 authored Sep 24, 2024
2 parents dcca470 + 12d7a37 commit a1b03c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
- 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))
- Fixed manager check in distributed deployment ([#52](https://github.com/wazuh/wazuh-installation-assistant/pull/52))
- Changed command order execution to get the TOKEN ([#57](https://github.com/wazuh/wazuh-installation-assistant/pull/57))

## [4.9.1]

Expand Down
24 changes: 13 additions & 11 deletions install_functions/manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,30 @@ function manager_startCluster() {

function manager_checkService() {
common_logger "Checking Wazuh API connection"

max_attempts=15
attempt=0
seconds=5
api_password="wazuh-wui"
token_command="curl -k -s -X POST -u \"wazuh-wui:${api_password}\" 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}")

# Wait for the API to be ready
while [[ -z "${TOKEN}" && "${attempt}" -lt "${max_attempts}" ]]; do
attempt=$((attempt+1))
common_logger "Attempt $attempt: Checking the Wazuh API to be ready"
sleep "${seconds}"
TOKEN=$(eval "${token_command}")
done
common_logger "Wazuh API is ready to receive requests."

# Change curl credentials in case the master node has changed the passwords
if [[ "${TOKEN}" =~ "Invalid credentials" && "${server_node_types[pos]}" == "worker" ]]; then
api_password=$(tar -axf "${tar_file}" wazuh-install-files/wazuh-passwords.txt -O | grep -P "'wazuh-wui'" -A 1 | awk 'NR==2 { print $2 }' | sed "s/'//g")
token_command="curl -k -s -X POST -u \"wazuh-wui:${api_password}\" 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}")
fi

max_attempts=15
attempt=0
seconds=5

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
Expand Down

0 comments on commit a1b03c3

Please sign in to comment.