# Validate an SLO doc (Markdown or YAML): every SLO has an explicit SLI +
# numeric target + error-budget window, and every alert references a runbook
# link and a paired dashboard/panel mention. Pure text/regex parsing
# (python3 stdlib, no deps) — there is no off-the-shelf tool for "does this
# SLO doc have complete fields", so this check is 100% custom, honestly
# labeled as such below. `yamllint` is used as a bonus structural check when
# the target is a .yaml/.yml file and yamllint is on PATH — degrades to a
# skipped warning if absent, same pattern as helm/scripts/lint_chart.sh.
# lint_slo_doc.sh [slo-doc.md|slo-doc.yaml]
# scripts/lint_slo_doc.sh ./slo.md
warn() { printf '⚠️ %s\n' "$1"; }
error() { printf '❌ %s\n' "$1"; fail=1; }
ok() { printf '✅ %s\n' "$1"; }
if [[ ! -f "$DOC" ]]; then
echo "Usage: $0 [slo-doc.md|slo-doc.yaml]" >&2
echo "File not found: $DOC" >&2
echo "== yamllint (bonus structural check on YAML) =="
if command -v yamllint >/dev/null 2>&1; then
error "yamllint reported errors"
warn "yamllint not on PATH — skipped (install: pip install yamllint)"
echo "== SLI + numeric target + error-budget window, per SLO; runbook + dashboard, per alert =="
py_out=$(python3 "$(dirname "$0")/_lint_slo_doc.py" "$DOC")
while IFS= read -r line; do
OK::*) ok "${line#OK::}" ;;
ERROR::*) error "${line#ERROR::}" ;;
*) [[ -n "$line" ]] && echo "$line" ;;
if [[ "$py_status" -ne 0 ]]; then
if [[ "$fail" -eq 0 ]]; then
echo "All checks passed."
echo "One or more checks failed — see ❌ lines above."