life-noc/Makefile

103 lines
4.5 KiB
Makefile

SHELL := /bin/bash
.DEFAULT_GOAL := help
PYTHON ?= python3
ANSIBLE_PLAYBOOK ?= ansible-playbook
INVENTORY ?= ansible/inventory
PLAYBOOK ?= ansible/site.yml
ARCHIVE ?= life-noc-from-scratch-debian12.zip
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
ICINGA_FILES := $(wildcard icinga/commands/*.conf) $(wildcard icinga/hosts/*.conf) $(wildcard icinga/templates/*.conf) $(wildcard icinga/services/*.conf) $(wildcard icinga/servicegroups/*.conf)
.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
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"
@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"
@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"
@echo " make inventory-example Rappelle comment préparer l'inventaire"
@echo " make vars-example Rappelle comment préparer les variables"
@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"
validate-generated: $(ICINGA_FILES) bpm/Life-NOC.conf
@grep -R 'check_life_noc_mock' icinga/templates icinga/commands icinga/services >/dev/null
@$(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")'
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
bootstrap: check
$(ANSIBLE_PLAYBOOK) -i $(INVENTORY) $(PLAYBOOK)
deploy: bootstrap
deploy-no-bpm: bootstrap
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:
rm -f $(ARCHIVE) bpm/Life-NOC.conf
inventory-example:
@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."
info:
@echo "PROJECT_NAME=$(PROJECT_NAME)"
@echo "PYTHON=$(PYTHON)"
@echo "ANSIBLE_PLAYBOOK=$(ANSIBLE_PLAYBOOK)"
@echo "INVENTORY=$(INVENTORY)"
@echo "PLAYBOOK=$(PLAYBOOK)"
@echo "ARCHIVE=$(ARCHIVE)"