2026-03-13 16:13:37 -04:00
SHELL := /bin/bash
.DEFAULT_GOAL := help
PYTHON ?= python3
ANSIBLE_PLAYBOOK ?= ansible-playbook
INVENTORY ?= ansible/inventory
2026-03-13 16:57:50 -04:00
PLAYBOOK ?= ansible/site.yml
ARCHIVE ?= life-noc-from-scratch-debian12.zip
2026-03-13 16:13:37 -04:00
PROJECT_NAME ?= life-noc
GENERATORS := scripts/generate_services.py scripts/generate_bpm.py
CHECKS := checks/check_life_noc_mock.sh checks/check_echeance_vie.sh
2026-03-14 15:31:28 -04:00
ICINGA_FILES := $( wildcard icinga/commands/*.conf) $( wildcard icinga/hosts/*.conf) $( wildcard icinga/templates/*.conf) $( wildcard icinga/services/*.conf) $( wildcard icinga/servicegroups/*.conf)
2026-03-13 16:13:37 -04:00
2026-03-13 16:57:50 -04:00
.PHONY : help all generate regen services bpm validate validate -yaml validate -python validate -shell validate -generated check mock -ok mock -warning mock -critical clean bootstrap deploy deploy -no -bpm deploy -with -bpm package inventory -example vars -example info
2026-03-13 16:13:37 -04:00
help :
@echo "Life-NOC - cibles disponibles"
@echo
@echo " make generate Génère services Icinga + BPM"
@echo " make validate Valide YAML, Python, shell et artefacts générés"
@echo " make check Génère puis valide"
2026-03-13 16:57:50 -04:00
@echo " make bootstrap Déploie la plateforme complète depuis Debian 12 vanille"
@echo " make deploy Alias de bootstrap"
@echo " make deploy-with-bpm Déploie explicitement avec artefact BPM"
2026-03-13 16:13:37 -04:00
@echo " make mock-ok Teste la sonde mock en état OK"
@echo " make mock-warning Teste la sonde mock en état WARNING"
@echo " make mock-critical Teste la sonde mock en état CRITICAL"
@echo " make package Crée une archive zip du dépôt"
2026-03-13 16:57:50 -04:00
@echo " make inventory-example Rappelle comment préparer l'inventaire"
@echo " make vars-example Rappelle comment préparer les variables"
2026-03-13 16:13:37 -04:00
@echo " make info Affiche les variables utiles"
@echo
@echo "Variables surchargables : INVENTORY=..., PLAYBOOK=..., ARCHIVE=..."
all : check
regen : generate
generate : services bpm
services : domains .yaml scripts /generate_services .py
$( PYTHON) scripts/generate_services.py
bpm : domains .yaml scripts /generate_bpm .py
$( PYTHON) scripts/generate_bpm.py
validate : validate -yaml validate -python validate -shell validate -generated
validate-yaml : domains .yaml
@$( PYTHON) -c 'import yaml, pathlib; p = pathlib.Path("domains.yaml"); data = yaml.safe_load(p.read_text(encoding="utf-8")); assert isinstance(data, dict) and isinstance(data.get("domains"), dict), "domains.yaml invalide: clé racine domains requise"; print("YAML valide: domains.yaml")'
validate-python : $( GENERATORS )
@$( PYTHON) -m py_compile $( GENERATORS)
@echo "Python OK"
validate-shell : $( CHECKS )
@bash -n $( CHECKS)
@echo "Shell OK"
2026-03-14 15:31:28 -04:00
validate-generated : $( ICINGA_FILES ) bpm /Life -NOC .conf
2026-03-13 16:13:37 -04:00
@grep -R 'check_life_noc_mock' icinga/templates icinga/commands icinga/services >/dev/null
2026-03-14 15:31:28 -04:00
@$( PYTHON) -c 'import pathlib; p = pathlib.Path("bpm/Life-NOC.conf"); text = p.read_text(encoding="utf-8"); lines = [l.strip() for l in text.splitlines() if l.strip()]; assert any(l == "### Business Process Config File ###" for l in lines), "bpm/Life-NOC.conf invalide: en-tête BPM absent"; assert any(l.startswith("display 1;") for l in lines), "bpm/Life-NOC.conf invalide: aucun display absent"; print("Artefacts générés valides")'
2026-03-13 16:13:37 -04:00
2026-03-15 14:43:50 -04:00
check : generate validate
2026-03-13 16:13:37 -04:00
mock-ok :
@bash checks/check_life_noc_mock.sh --state OK --message "Sous contrôle" --item-name "demo" --date "2026-03-13"
mock-warning :
@bash checks/check_life_noc_mock.sh --state WARNING --message "Attention requise" --item-name "demo" --date "2026-03-13" ; test $$ ? -eq 1
mock-critical :
@bash checks/check_life_noc_mock.sh --state CRITICAL --message "Action requise" --item-name "demo" --date "2026-03-13" ; test $$ ? -eq 2
2026-03-13 16:57:50 -04:00
bootstrap : check
$( ANSIBLE_PLAYBOOK) -i $( INVENTORY) $( PLAYBOOK)
deploy : bootstrap
2026-03-13 16:13:37 -04:00
2026-03-13 16:57:50 -04:00
deploy-no-bpm : bootstrap
2026-03-13 16:13:37 -04:00
deploy-with-bpm : check
$( ANSIBLE_PLAYBOOK) -i $( INVENTORY) $( PLAYBOOK) -e life_noc_bpm_deploy_enabled = true
package : check
@rm -f $( ARCHIVE)
@zip -qr $( ARCHIVE) . -x '*.git*' -x '__pycache__/*' -x '*.pyc' -x '$(ARCHIVE)'
@echo " Archive créée: $( ARCHIVE) "
clean :
2026-03-14 15:31:28 -04:00
rm -f $( ARCHIVE) bpm/Life-NOC.conf
2026-03-13 16:13:37 -04:00
inventory-example :
2026-03-13 16:57:50 -04:00
@echo "Copier ansible/inventory.example vers ansible/inventory puis ajuster l'hôte, l'adresse et l'utilisateur ansible."
vars-example :
@echo "Copier ansible/group_vars/all.yml.example vers ansible/group_vars/all.yml puis remplacer TOUS les mots de passe par les tiens."
2026-03-13 16:13:37 -04:00
info :
@echo " PROJECT_NAME= $( PROJECT_NAME) "
@echo " PYTHON= $( PYTHON) "
@echo " ANSIBLE_PLAYBOOK= $( ANSIBLE_PLAYBOOK) "
@echo " INVENTORY= $( INVENTORY) "
@echo " PLAYBOOK= $( PLAYBOOK) "
@echo " ARCHIVE= $( ARCHIVE) "