| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- #!/usr/bin/env bash
- set -euo pipefail
- ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- export SOC_SHARED_NETWORK="${SOC_SHARED_NETWORK:-soc_shared}"
- export IRIS_HTTPS_PORT="${IRIS_HTTPS_PORT:-8443}"
- export INTERFACE_HTTPS_PORT="${IRIS_HTTPS_PORT}"
- export SHUFFLE_OPENSEARCH_PORT="${SHUFFLE_OPENSEARCH_PORT:-9201}"
- export PAGERDUTY_STUB_PORT="${PAGERDUTY_STUB_PORT:-18080}"
- export SOC_INTEGRATOR_PORT="${SOC_INTEGRATOR_PORT:-8088}"
- if ! docker network inspect "${SOC_SHARED_NETWORK}" >/dev/null 2>&1; then
- docker network create "${SOC_SHARED_NETWORK}" >/dev/null
- fi
- if [[ $# -eq 0 ]]; then
- COMMAND="up"
- ARGS=(-d)
- else
- COMMAND="$1"
- shift
- ARGS=("$@")
- fi
- if [[ "${COMMAND}" == "status" ]]; then
- exec "${ROOT_DIR}/soc-status.sh"
- fi
- run_wazuh() {
- docker compose \
- --project-name wazuh-single \
- --project-directory "${ROOT_DIR}/wazuh-docker/single-node" \
- -f "${ROOT_DIR}/wazuh-docker/single-node/docker-compose.yml" \
- -f "${ROOT_DIR}/compose-overrides/wazuh.shared-network.yml" \
- "${COMMAND}" "${ARGS[@]}"
- }
- run_iris() {
- docker compose \
- --project-name iris-web \
- --project-directory "${ROOT_DIR}/iris-web" \
- -f "${ROOT_DIR}/iris-web/docker-compose.yml" \
- -f "${ROOT_DIR}/compose-overrides/iris.shared-network.yml" \
- "${COMMAND}" "${ARGS[@]}"
- }
- run_shuffle() {
- docker compose \
- --project-name shuffle \
- --project-directory "${ROOT_DIR}/Shuffle" \
- -f "${ROOT_DIR}/Shuffle/docker-compose.yml" \
- -f "${ROOT_DIR}/compose-overrides/shuffle.shared-network.yml" \
- "${COMMAND}" "${ARGS[@]}"
- }
- run_pagerduty_stub() {
- docker compose \
- --project-name pagerduty-stub \
- --project-directory "${ROOT_DIR}" \
- -f "${ROOT_DIR}/compose-overrides/pagerduty.stub.yml" \
- "${COMMAND}" "${ARGS[@]}"
- }
- run_soc_integrator() {
- docker compose \
- --project-name soc-integrator \
- --project-directory "${ROOT_DIR}/compose-overrides" \
- -f "${ROOT_DIR}/compose-overrides/soc-integrator.yml" \
- "${COMMAND}" "${ARGS[@]}"
- }
- run_target() {
- local target="$1"
- case "${target}" in
- wazuh)
- run_wazuh
- ;;
- iris)
- run_iris
- ;;
- shuffle)
- run_shuffle
- ;;
- pagerduty)
- run_pagerduty_stub
- ;;
- integrator)
- run_soc_integrator
- ;;
- *)
- echo "Unknown target: ${target}"
- echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator"
- exit 1
- ;;
- esac
- }
- run_all() {
- local mode="$1"
- if [[ "${mode}" == "down" ]]; then
- run_soc_integrator
- run_pagerduty_stub
- run_shuffle
- run_iris
- run_wazuh
- else
- run_wazuh
- run_iris
- run_shuffle
- run_pagerduty_stub
- run_soc_integrator
- fi
- }
- follow_all_logs() {
- COMMAND="logs"
- ARGS=("-f" "--tail" "${LOG_TAIL:-100}")
- run_wazuh &
- run_iris &
- run_shuffle &
- run_pagerduty_stub &
- run_soc_integrator &
- trap 'kill 0' INT TERM
- wait
- }
- run_logs_for_target() {
- local target="${1:-all}"
- case "${target}" in
- wazuh)
- run_wazuh
- ;;
- iris)
- run_iris
- ;;
- shuffle)
- run_shuffle
- ;;
- pagerduty)
- run_pagerduty_stub
- ;;
- integrator)
- run_soc_integrator
- ;;
- all|--all)
- run_wazuh
- run_iris
- run_shuffle
- run_pagerduty_stub
- run_soc_integrator
- ;;
- *)
- echo "Unknown logs target: ${target}"
- echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator"
- exit 1
- ;;
- esac
- }
- if [[ "${COMMAND}" == "down" ]]; then
- TARGET="${1:-all}"
- case "${TARGET}" in
- wazuh|iris|shuffle|pagerduty|integrator)
- ARGS=("${ARGS[@]:1}")
- run_target "${TARGET}"
- ;;
- all|--all)
- ARGS=("${ARGS[@]:1}")
- run_all "down"
- ;;
- *)
- run_all "down"
- ;;
- esac
- elif [[ "${COMMAND}" == "logs" ]]; then
- LOGS_TARGET="${1:-all}"
- case "${LOGS_TARGET}" in
- wazuh|iris|shuffle|pagerduty|integrator)
- ARGS=("${ARGS[@]:1}")
- run_logs_for_target "${LOGS_TARGET}"
- ;;
- all|--all)
- ARGS=("${ARGS[@]:1}")
- run_logs_for_target "all"
- ;;
- *)
- for arg in "${ARGS[@]}"; do
- if [[ "${arg}" == "-f" || "${arg}" == "--follow" ]]; then
- echo "For follow mode, specify one target:"
- echo "./run-combined-stack.sh logs <wazuh|iris|shuffle|pagerduty|integrator> -f"
- exit 1
- fi
- done
- run_logs_for_target "all"
- ;;
- esac
- elif [[ "${COMMAND}" == "up" ]]; then
- TARGET="${1:-all}"
- case "${TARGET}" in
- wazuh|iris|shuffle|pagerduty|integrator)
- ARGS=("${ARGS[@]:1}")
- run_target "${TARGET}"
- ;;
- all|--all)
- ARGS=("${ARGS[@]:1}")
- HAS_DETACH="false"
- for arg in "${ARGS[@]}"; do
- if [[ "${arg}" == "-d" || "${arg}" == "--detach" ]]; then
- HAS_DETACH="true"
- break
- fi
- done
- if [[ "${HAS_DETACH}" == "true" ]]; then
- run_all "up"
- else
- ARGS+=("-d")
- run_all "up"
- follow_all_logs
- fi
- ;;
- *)
- run_all "up"
- ;;
- esac
- else
- run_all "up"
- fi
|