#!/bin/sh
set -eu

: "${PROBER_SITE_ID:?PROBER_SITE_ID is required}"
: "${PROBER_CONTROL_API_URL:?PROBER_CONTROL_API_URL is required}"

export PROBER_POLL_INTERVAL_SECONDS="${PROBER_POLL_INTERVAL_SECONDS:-5}"
export PROBER_TCP_TIMEOUT_SECONDS="${PROBER_TCP_TIMEOUT_SECONDS:-5}"
export PROBER_ICMP_TIMEOUT_SECONDS="${PROBER_ICMP_TIMEOUT_SECONDS:-5}"
export PROBER_ICMP_COUNT="${PROBER_ICMP_COUNT:-3}"

# Tokens/passwords (CONTROL_API_AGENT_TOKEN, ADMIN_DASHBOARD_*) are deliberately
# NOT templated into the YAML: the binary reads them straight from this
# container's environment (names default in the config loader), so secrets
# never land in a file inside the container.
envsubst '${PROBER_SITE_ID} ${PROBER_CONTROL_API_URL} ${PROBER_POLL_INTERVAL_SECONDS} ${PROBER_TCP_TIMEOUT_SECONDS} ${PROBER_ICMP_TIMEOUT_SECONDS} ${PROBER_ICMP_COUNT}' \
    < /etc/prober/prober.yaml.tmpl > /etc/prober/prober.yaml

exec /usr/local/bin/prober -config /etc/prober/prober.yaml
