#!/usr/bin/env bash # Local test (Phase 4 ยง29): renders prometheus.yml.j2 with dummy values and validates it plus # the alert rules with the REAL promtool (via the official Prometheus Docker image, no local # install needed). Also validates alertmanager.yml.j2 with amtool if the image supports it. set -euo pipefail cd "$(dirname "$0")" TMPDIR="$(mktemp -d)" trap 'rm -rf "$TMPDIR"' EXIT mkdir -p "$TMPDIR/rules" sed -e 's/{{ lab_host_ip }}/10.10.10.20/g' prometheus/prometheus.yml.j2 > "$TMPDIR/prometheus.yml" cp prometheus/rules/*.yml "$TMPDIR/rules/" chmod -R a+rX "$TMPDIR" echo "==> promtool check config" docker run --rm -v "$TMPDIR:/etc/prometheus:ro" --entrypoint promtool prom/prometheus:latest \ check config /etc/prometheus/prometheus.yml echo echo "==> amtool check-config (Alertmanager)" TMPDIR2="$(mktemp -d)" trap 'rm -rf "$TMPDIR" "$TMPDIR2"' EXIT sed -e "s/{{ vault_alertmanager_webhook_url | default('http:\/\/example.invalid\/webhook') }}/http:\/\/example.invalid\/webhook/g" \ alertmanager/alertmanager.yml.j2 > "$TMPDIR2/alertmanager.yml" chmod -R a+rX "$TMPDIR2" docker run --rm -v "$TMPDIR2:/etc/alertmanager:ro" --entrypoint amtool prom/alertmanager:latest \ check-config /etc/alertmanager/alertmanager.yml echo echo "OK: monitoring configs are valid"