#!/bin/bash # LeCoffre Node - Script de vérification des URLs de santé # Vérifie tous les endpoints internes et externes du système # Utilisé par les scripts de backup et de production set -e # Couleurs pour l'affichage RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' CYAN='\033[0;36m' NC='\033[0m' # No Color # Compteurs TOTAL_URLS=0 ACCESSIBLE_URLS=0 FAILED_URLS=0 # Fonction pour afficher un message avec timestamp print_message() { echo -e "${BLUE}[$(date '+%H:%M:%S')]${NC} $1" } # Fonction pour tester une URL test_url() { local url="$1" local description="$2" local expected_codes_csv="${3:-200}" local timeout="${4:-10}" TOTAL_URLS=$((TOTAL_URLS + 1)) print_message "Testing: $description" echo -e " ${CYAN}URL: $url${NC}" # Test de connectivité local response=$(curl -s -o /dev/null -w '%{http_code}' --max-time "$timeout" "$url" 2>/dev/null || echo "000") local curl_exit_code=$? # Support multiple acceptable codes, comma-separated local ok=false IFS=',' read -r -a expected_array <<< "$expected_codes_csv" for code in "${expected_array[@]}"; do if [ "$response" = "$code" ]; then ok=true break fi done if [ "$ok" = true ]; then echo -e " ${GREEN}✓${NC} Status: HTTP $response - Accessible" ACCESSIBLE_URLS=$((ACCESSIBLE_URLS + 1)) return 0 else echo -e " ${RED}✗${NC} Status: HTTP $response - Not accessible" if [ $curl_exit_code -ne 0 ]; then echo -e " ${RED} Curl exit code: $curl_exit_code${NC}" fi FAILED_URLS=$((FAILED_URLS + 1)) return 1 fi } # Fonction pour tester un WebSocket test_websocket() { local ws_url="$1" local description="$2" local timeout="${3:-5}" TOTAL_URLS=$((TOTAL_URLS + 1)) print_message "Testing WebSocket: $description" echo -e " ${CYAN}URL: $ws_url${NC}" # Test WebSocket avec wscat local ws_test=$(timeout "$timeout" wscat -c "$ws_url" --no-color 2>/dev/null && echo "connected" || echo "failed") if [ "$ws_test" = "connected" ]; then echo -e " ${GREEN}✓${NC} Status: Connected" ACCESSIBLE_URLS=$((ACCESSIBLE_URLS + 1)) return 0 else echo -e " ${RED}✗${NC} Status: Not connected" FAILED_URLS=$((FAILED_URLS + 1)) return 1 fi } # Fonction pour tester un endpoint API avec POST test_api_post() { local url="$1" local description="$2" local post_data="$3" local expected_codes_csv="${4:-200}" local timeout="${5:-10}" TOTAL_URLS=$((TOTAL_URLS + 1)) print_message "Testing API POST: $description" echo -e " ${CYAN}URL: $url${NC}" echo -e " ${CYAN}Data: $post_data${NC}" # Test de l'endpoint avec POST local response=$(curl -s -o /dev/null -w '%{http_code}' --max-time "$timeout" -X POST \ -H "Content-Type: application/json" \ -d "$post_data" \ "$url" 2>/dev/null || echo "000") local curl_exit_code=$? # Support multiple acceptable codes, comma-separated local ok=false IFS=',' read -r -a expected_array <<< "$expected_codes_csv" for code in "${expected_array[@]}"; do if [ "$response" = "$code" ]; then ok=true break fi done if [ "$ok" = true ]; then echo -e " ${GREEN}✓${NC} Status: HTTP $response - API accessible" ACCESSIBLE_URLS=$((ACCESSIBLE_URLS + 1)) return 0 else echo -e " ${RED}✗${NC} Status: HTTP $response - API not accessible" if [ $curl_exit_code -ne 0 ]; then echo -e " ${RED} Curl exit code: $curl_exit_code${NC}" fi FAILED_URLS=$((FAILED_URLS + 1)) return 1 fi } echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} LeCoffre Node - URL Health Check${NC}" echo -e "${BLUE}========================================${NC}" echo print_message "Starting URL health check..." # ======================================== # URLs INTERNES (Services Docker) # ======================================== echo -e "${CYAN}=== URLs INTERNES (Services Docker) ===${NC}" # Services de base test_url "http://localhost:8000/tweaks/1" "BlindBit Oracle API" "200" 5 test_url "http://localhost:8081/health" "SDK Storage Health" "200" 5 test_url "http://localhost:8091/" "SDK Relay WebSocket Interface" "200" 5 test_url "http://localhost:8090/" "SDK Relay HTTP Interface" "200" 5 # Services applicatifs test_url "http://localhost:3004/" "LeCoffre Frontend (Root)" "200,301,302,307,308" 10 test_url "http://localhost:3004/login" "LeCoffre Frontend Login" "200,301,302,307,308" 10 test_url "http://localhost:3004/lecoffre/" "LeCoffre Frontend App" "200,301,302,307,308" 10 test_url "http://localhost:3003/" "IHM Client Interface" "200" 10 # Services de monitoring test_url "http://localhost:3005/api/health" "Grafana Health Check" "200" 5 test_url "http://localhost:3005/" "Grafana Dashboard" "200,301,302" 10 test_url "http://localhost:3100/ready" "Loki Health Check" "200" 5 test_url "http://localhost:3006/api" "Status API" "200" 5 echo # ======================================== # URLs EXTERNES (Domaine Public) # ======================================== echo -e "${CYAN}=== URLs EXTERNES (Domaine Public) ===${NC}" # URLs principales test_url "https://dev4.4nkweb.com/" "Site Principal" "200,301,302" 15 test_url "https://dev4.4nkweb.com/status/" "Page de Statut" "200" 15 test_url "https://dev4.4nkweb.com/grafana/" "Dashboard Grafana" "200,301,302" 15 test_url "https://dev4.4nkweb.com/lecoffre/" "Application LeCoffre" "200,301,302" 15 # URLs d'authentification test_url "https://dev4.4nkweb.com/lecoffre/login" "Page de Login LeCoffre" "200,301,302" 15 test_url "https://dev4.4nkweb.com/lecoffre/authorized-client" "Callback d'authentification" "200,301,302" 15 echo # ======================================== # APIs EXTERNES (Backend Services) # ======================================== echo -e "${CYAN}=== APIs EXTERNES (Backend Services) ===${NC}" # API Backend principal test_url "https://dev3.4nkweb.com/api/v1/health" "API Backend Health" "200" 10 test_url "https://dev3.4nkweb.com/api/v1/status" "API Backend Status" "200" 10 # API IdNot (authentification) test_api_post "https://dev3.4nkweb.com/api/v1/idnot/state" \ "IdNot State Endpoint" \ '{"next_url":"https://dev4.4nkweb.com/authorized-client"}' \ "200" 10 echo # ======================================== # WebSockets EXTERNES # ======================================== echo -e "${CYAN}=== WebSockets EXTERNES ===${NC}" test_websocket "wss://dev3.4nkweb.com/ws/" "Bootstrap Relay WebSocket" 5 echo # ======================================== # SERVICES EXTERNES (Dépendances) # ======================================== echo -e "${CYAN}=== SERVICES EXTERNES (Dépendances) ===${NC}" # Mempool externe test_url "https://mempool2.4nkweb.com/" "Mempool Signet Explorer" "200,301,302" 10 # IdNot Service (authentification) test_url "https://qual-connexion.idnot.fr/" "Service IdNot" "200,301,302" 10 test_url "https://qual-connexion.idnot.fr/IdPOAuth2/authorize/idnot_idp_v1" "IdNot Authorization Endpoint" "200,301,302" 10 echo # ======================================== # RÉSUMÉ FINAL # ======================================== echo -e "${CYAN}=== RÉSUMÉ FINAL ===${NC}" echo -e "${BLUE}Total URLs testées: $TOTAL_URLS${NC}" echo -e "${GREEN}URLs accessibles: $ACCESSIBLE_URLS${NC}" echo -e "${RED}URLs échouées: $FAILED_URLS${NC}" if [ $FAILED_URLS -eq 0 ]; then echo -e "${GREEN}🎉 Toutes les URLs sont accessibles !${NC}" exit 0 elif [ $FAILED_URLS -lt $((TOTAL_URLS / 2)) ]; then echo -e "${YELLOW}⚠️ Certaines URLs ne sont pas accessibles, mais la majorité fonctionne.${NC}" exit 1 else echo -e "${RED}❌ Trop d'URLs ne sont pas accessibles. Vérifiez la configuration.${NC}" exit 2 fi