Skip to content

Commit

Permalink
Merge pull request #209 from wazuh/bug/202-wazuh-dashboard-shows-erro…
Browse files Browse the repository at this point in the history
…rs-in-4110-beta-1-ova

Fix Wazuh dashboard errors in OVA
  • Loading branch information
c-bordon authored Feb 13, 2025
2 parents f84fb3f + b15520c commit 07668aa
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.

### Fixed

- Fix Wazuh dashboard errors in OVA. ([#209](https://github.com/wazuh/wazuh-virtual-machines/pull/209))
- Fixed local build for OVA. ([#208](https://github.com/wazuh/wazuh-virtual-machines/pull/208))
- Fixed Wazuh Dashboard issues when the AMI boots up. ([#205](https://github.com/wazuh/wazuh-virtual-machines/pull/205))
- Fix Wazuh dashboard certificate verification failure ([#198](https://github.com/wazuh/wazuh-virtual-machines/pull/198))
Expand Down
19 changes: 19 additions & 0 deletions ova/assets/custom/wazuh-starter/wazuh-starter.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Wazuh AMI Customizer Service - Used to customize the Wazuh AMI with custom certificates and passwords
# Copyright (C) 2015, Wazuh Inc.
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.
#

[Unit]
Description=Starts Wazuh services in order
Wants=wazuh-starter.timer

[Service]
Type=oneshot
ExecStart=/etc/.wazuh-starter.sh

[Install]
WantedBy=multi-user.target
116 changes: 116 additions & 0 deletions ova/assets/custom/wazuh-starter/wazuh-starter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash
# This script is used to configure the Wazuh environment after the installation

# Variables
logfile="/var/log/wazuh-starter.log"
debug="| tee -a ${logfile}"

###########################################
# Utility Functions
###########################################
function logger(){
now=$(date +'%d/%m/%Y %H:%M:%S')
mtype="INFO:"
if [ -n "${1}" ]; then
while [ -n "${1}" ]; do
case ${1} in
"-e")
mtype="ERROR:"
shift 1
;;
"-w")
mtype="WARNING:"
shift 1
;;
*)
message="${1}"
shift 1
;;
esac
done
fi
printf "%s\n" "${now} ${mtype} ${message}" | tee -a "${logfile}"
}


###########################################
# Configuration Functions
###########################################

function starter_service() {
logger "Starting $1 service"
systemctl start $1
}

function verify_indexer() {
logger "Waiting for Wazuh indexer to be ready"
indexer_security_admin_comm="curl -XGET https://localhost:9200/ -uadmin:admin -k --max-time 120 --silent -w \"%{http_code}\" --output /dev/null"
http_status=$(eval "${indexer_security_admin_comm}")
retries=0
max_retries=5
while [ "${http_status}" -ne 200 ]; do
logger -w "Wazuh indexer is not ready yet, waiting 5 seconds"
sleep 5
retries=$((retries+1))
if [ "${retries}" -eq "${max_retries}" ]; then
logger -e "Wazuh indexer is not ready yet, trying to configure it again"
configure_indexer
fi
http_status=$(eval "${indexer_security_admin_comm}")
done
}

function verify_filebeat() {
logger "Waiting for Filebeat to be ready"
if filebeat test output | grep -q -i -w "ERROR"; then
logger -e "Filebeat is not ready yet, trying to configure it again"
eval "filebeat test output x ${debug}"
configure_filebeat
fi
}

function verify_dashboard() {
logger "Waiting for Wazuh dashboard to be ready"
dashboard_check_comm="curl -XGET https://localhost:443/status -uadmin:admin -k -w \"%{http_code}\" -s -o /dev/null"
http_code=$(eval "${dashboard_check_comm}")
retries=0
max_dashboard_initialize_retries=20
while [ "${http_code}" -ne "200" ];do
logger -w "Wazuh dashboard is not ready yet, waiting 15 seconds"
retries=$((retries+1))
sleep 15
if [ "${retries}" -eq "${max_dashboard_initialize_retries}" ]; then
logger -e "Wazuh dashboard is not ready yet, trying to configure it again"
configure_dashboard
fi
http_code=$(eval "${dashboard_check_comm}")
done
}

function clean_configuration(){
logger "Cleaning configuration files"
eval "rm -rf /var/log/wazuh-starter.log"
eval "rm -f /etc/.wazuh-starter.sh /etc/systemd/system/wazuh-starter.service /etc/systemd/system/wazuh-starter.timer"
}


###########################################
# Main
###########################################

logger "Starting Wazuh services in order"


starter_service wazuh-indexer
verify_indexer

starter_service wazuh-manager
starter_service filebeat
verify_filebeat

starter_service wazuh-dashboard
verify_dashboard
systemctl enable wazuh-manager
systemctl enable wazuh-dashboard

clean_configuration
19 changes: 19 additions & 0 deletions ova/assets/custom/wazuh-starter/wazuh-starter.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Wazuh AMI Customizer Service - Used to customize the Wazuh AMI with custom certificates and passwords
# Copyright (C) 2015, Wazuh Inc.
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.
#

[Unit]
Description=Starts Wazuh services in order
Requires=wazuh-starter.service

[Timer]
Unit=wazuh-starter.service
OnBootSec=10s

[Install]
WantedBy=timers.target
8 changes: 8 additions & 0 deletions ova/assets/steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ systemConfig() {
systemctl daemon-reload
systemctl enable updateIndexerHeap.service

# Add Wazuh starter service
mv ${CUSTOM_PATH}/wazuh-starter/wazuh-starter.service /etc/systemd/system/
mv ${CUSTOM_PATH}/wazuh-starter/wazuh-starter.timer /etc/systemd/system/
mv ${CUSTOM_PATH}/wazuh-starter/wazuh-starter.sh /etc/.wazuh-starter.sh
chmod 755 /etc/.wazuh-starter.sh
systemctl daemon-reload
systemctl enable wazuh-starter.timer
systemctl enable wazuh-starter.service

# Change root password (root:wazuh)
sed -i "s/root:.*:/root:\$1\$pNjjEA7K\$USjdNwjfh7A\.vHCf8suK41::0:99999:7:::/g" /etc/shadow
Expand Down
3 changes: 2 additions & 1 deletion ova/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ bash /usr/share/wazuh-indexer/bin/indexer-security-init.sh -ho 127.0.0.1

echo "Stopping Wazuh indexer and Wazuh dashboard"
systemctl stop wazuh-indexer wazuh-dashboard
systemctl enable wazuh-manager
systemctl disable wazuh-manager
systemctl disable wazuh-dashboard

echo "Cleaning system"
clean

0 comments on commit 07668aa

Please sign in to comment.