From f5bfc4644cfb6d11e097ab19e2817e1eafa1064e Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Sun, 21 Sep 2025 14:38:21 +0000 Subject: [PATCH] align for IA agents + grafana --- conf/nginx/dev4.4nkweb.com.conf | 22 +++++++++++----------- web/status/api.js | 30 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/conf/nginx/dev4.4nkweb.com.conf b/conf/nginx/dev4.4nkweb.com.conf index 42aa24e..b47c118 100644 --- a/conf/nginx/dev4.4nkweb.com.conf +++ b/conf/nginx/dev4.4nkweb.com.conf @@ -118,20 +118,20 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; - + # Configuration spécifique pour Grafana proxy_set_header X-Grafana-Org-Id 1; - + # Support des WebSockets pour les live updates proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; - + # Timeouts proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; - + # Buffer settings proxy_buffering off; proxy_request_buffering off; @@ -144,12 +144,12 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; - + # CORS pour les requêtes depuis Grafana add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods "GET, POST, OPTIONS"; add_header Access-Control-Allow-Headers "Content-Type, Authorization"; - + if ($request_method = 'OPTIONS') { return 204; } @@ -161,12 +161,12 @@ server { root /var/www/lecoffre/status; index index.html; try_files $uri $uri/ =404; - + # Headers de sécurité add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; - + # Cache pour les assets statiques location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg)$ { expires 1h; @@ -181,17 +181,17 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; - + # CORS pour les requêtes AJAX add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods "GET, POST, OPTIONS"; add_header Access-Control-Allow-Headers "Content-Type, Authorization"; - + # Timeouts proxy_connect_timeout 10s; proxy_send_timeout 10s; proxy_read_timeout 10s; - + if ($request_method = 'OPTIONS') { return 204; } diff --git a/web/status/api.js b/web/status/api.js index 7b4978b..41009ff 100644 --- a/web/status/api.js +++ b/web/status/api.js @@ -61,7 +61,7 @@ async function getContainerInfo(containerName) { async function getServiceHealth(containerName, port) { if (!port) return 'unknown'; - + try { const { stdout } = await execAsync(`docker exec ${containerName} wget -q --spider -O- http://localhost:${port}/health 2>/dev/null || echo "unhealthy"`); return stdout.trim() === 'unhealthy' ? 'unhealthy' : 'healthy'; @@ -80,12 +80,12 @@ async function checkExternalService(url) { response_time: 'N/A (WebSocket)' }; } - + const http = require('http'); const https = require('https'); const urlObj = new URL(url); const client = urlObj.protocol === 'https:' ? https : http; - + return new Promise((resolve) => { const req = client.get(url, { timeout: 5000 }, (res) => { resolve({ @@ -93,14 +93,14 @@ async function checkExternalService(url) { response_time: `${Date.now() - start}ms` }); }); - + req.on('error', () => { resolve({ status: 'error', response_time: 'N/A' }); }); - + req.on('timeout', () => { resolve({ status: 'timeout', @@ -118,16 +118,16 @@ async function checkExternalService(url) { function calculateUptime(startedAt) { if (!startedAt || startedAt === 'N/A') return 'N/A'; - + try { const start = new Date(startedAt); const now = new Date(); const diff = now - start; - + const days = Math.floor(diff / (1000 * 60 * 60 * 24)); const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); - + if (days > 0) return `${days}j ${hours}h ${minutes}m`; if (hours > 0) return `${hours}h ${minutes}m`; return `${minutes}m`; @@ -138,15 +138,15 @@ function calculateUptime(startedAt) { async function getServicesStatus() { const servicesStatus = []; - + for (const service of services) { const containerInfo = await getContainerInfo(service.container); const [status, startedAt, image, ip, ports] = containerInfo.split('|'); - + const portsArray = ports ? ports.split(' ').filter(p => p.trim()) : []; const health = await getServiceHealth(service.container, service.port); const uptime = calculateUptime(startedAt); - + servicesStatus.push({ name: service.name, status: status === 'running' ? 'running' : 'stopped', @@ -159,13 +159,13 @@ async function getServicesStatus() { port: service.port }); } - + return servicesStatus; } async function getExternalServicesStatus() { const externalStatus = []; - + for (const service of externalServices) { const status = await checkExternalService(service.url); externalStatus.push({ @@ -175,7 +175,7 @@ async function getExternalServicesStatus() { ...status }); } - + return externalStatus; } @@ -183,7 +183,7 @@ app.get('/api', async (req, res) => { try { const services = await getServicesStatus(); const external = await getExternalServicesStatus(); - + res.json({ timestamp: new Date().toISOString(), services: services,