#!/usr/bin/env bash set -euo pipefail ROOT="${1:-.}" need_file() { local f="$1" if [[ ! -f "$ROOT/$f" ]]; then echo "Fichier introuvable: $f" >&2 exit 1 fi } echo "==> Vérification" need_file "domains.yaml" need_file "icinga/commands/check_life_noc_probe.conf" need_file "scripts/generate_services.py" need_file "Makefile" echo "==> Sauvegarde minimale" mkdir -p "$ROOT/.backup-days-until-due-pilot" cp -a "$ROOT/domains.yaml" "$ROOT/.backup-days-until-due-pilot/domains.yaml.bak" echo "==> Création du store d'intrants" mkdir -p "$ROOT/data/inputs" cat > "$ROOT/data/inputs/obligations-legales-personnelles.yaml" <<'EOF' renouvellement-permis-conduire: value: "2026-09-20" captured_at: "2026-03-14T23:30:00Z" origin: manual EOF echo "==> Mise à jour de domains.yaml" python3 - "$ROOT/domains.yaml" <<'PY' from pathlib import Path import sys import yaml path = Path(sys.argv[1]) data = yaml.safe_load(path.read_text(encoding="utf-8")) domains = data.get("domains") if not isinstance(domains, dict): raise SystemExit("domains.yaml invalide: clé racine 'domains' absente ou invalide") domain_name = "obligations-legales-personnelles" items = domains.get(domain_name) if not isinstance(items, list): raise SystemExit(f"Domaine introuvable ou invalide: {domain_name}") target = None for item in items: if isinstance(item, dict) and item.get("name") == "renouvellement-permis-conduire": target = item break if target is None: raise SystemExit("Item 'renouvellement-permis-conduire' introuvable dans domains.yaml") target["date"] = "2026-09-20" target["notes"] = "Vérifier la proximité de l’échéance du permis" target["probe"] = { "type": "days_until_due", "source": { "type": "manual_date", "inputs_file": "/opt/life-noc/data/inputs/obligations-legales-personnelles.yaml", "item_key": "renouvellement-permis-conduire", }, "metric": { "unit": "days", }, "thresholds": { "critical_lt": 7, "warning_lt": 30, "ok_lt": 90, "unknown_gte": 90, }, "policy": { "on_error": "critical", }, } path.write_text(yaml.safe_dump(data, sort_keys=False, allow_unicode=True), encoding="utf-8") print("domains.yaml mis à jour") PY echo "==> Vérification rapide de la commande Icinga" for needle in \ '--unknown-gte' \ '--ok-lt' \ '--warning-lt' \ '--critical-lt' do if ! grep -q -- "$needle" "$ROOT/icinga/commands/check_life_noc_probe.conf"; then echo "ERREUR: argument manquant dans icinga/commands/check_life_noc_probe.conf : $needle" >&2 exit 1 fi done echo "==> Génération" ( cd "$ROOT" python3 scripts/generate_services.py ) echo "==> Validation" ( cd "$ROOT" make check ) echo "==> Déploiement" ( cd "$ROOT" make deploy-with-bpm ) echo echo "Terminé." echo "Test utile ensuite :" echo " python3 scripts/life_noc_input.py set obligations-legales-personnelles renouvellement-permis-conduire 2026-03-20"