Files
wevads-platform/scripts/analyse-brain.php
2026-02-26 04:53:11 +01:00

130 lines
4.3 KiB
PHP
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once '/opt/wevads-arsenal/public/api/db-connect.php';
require_once '/opt/wevads-arsenal/public/api/hamid-engine.php';
echo "=== 🧠 ANALYSE DU BRAIN ===\n\n";
try {
$pdo = getDB();
// 1. État des tables Brain
echo "📊 TABLES BRAIN EN BASE DE DONNÉES:\n";
$tables = ['brain_winners', 'brain_configs', 'brain_tests', 'brain_results'];
foreach ($tables as $table) {
try {
$stmt = $pdo->query("SELECT COUNT(*) FROM admin.$table");
$count = $stmt->fetchColumn();
echo " - $table: $count lignes\n";
} catch (Exception $e) {
echo " - $table: ❌ Table inexistante ou erreur\n";
}
}
echo "\n";
// 2. Analyse des brain_winners
echo "🏆 BRAIN WINNERS ACTIFS:\n";
$stmt = $pdo->query("
SELECT id, config_name, success_rate, total_sends, inbox_rate,
bounce_rate, spam_rate, is_active, created_at
FROM admin.brain_winners
WHERE is_active = true
ORDER BY success_rate DESC
LIMIT 5
");
$winners = $stmt->fetchAll();
if (empty($winners)) {
echo " ❌ Aucun brain winner actif\n";
} else {
foreach ($winners as $winner) {
echo " - {$winner['config_name']}: {$winner['success_rate']}% succès, ";
echo "{$winner['inbox_rate']}% inbox, {$winner['total_sends']} envois\n";
}
}
echo "\n";
// 3. Derniers tests Brain
echo "🧪 DERNIERS TESTS BRAIN:\n";
try {
$stmt = $pdo->query("
SELECT test_type, result_status, created_at, error_message
FROM admin.brain_tests
ORDER BY created_at DESC
LIMIT 5
");
$tests = $stmt->fetchAll();
if (empty($tests)) {
echo " Aucun test récent trouvé\n";
} else {
foreach ($tests as $test) {
$status = $test['result_status'] === 'success' ? '✅' : '❌';
echo " $status {$test['test_type']} le {$test['created_at']}";
if ($test['error_message']) {
echo " - Erreur: " . substr($test['error_message'], 0, 50) . "...";
}
echo "\n";
}
}
} catch (Exception $e) {
echo " ❌ Impossible de lire les tests: " . $e->getMessage() . "\n";
}
echo "\n";
// 4. Vérifier les permissions et dépendances
echo "🔧 VÉRIFICATION SYSTÈME:\n";
// PMTA installé ?
$pmta = shell_exec("which pmta 2>/dev/null");
if ($pmta) {
echo " ✅ PMTA installé: " . trim($pmta) . "\n";
// Vérifier si PMTA tourne
$pmta_status = trim(shell_exec("systemctl is-active pmta 2>/dev/null"));
echo " - PMTA status: " . ($pmta_status === 'active' ? '✅ Actif' : "$pmta_status") . "\n";
} else {
echo " ❌ PMTA non installé\n";
}
// PHP memory limit
$memory = ini_get('memory_limit');
echo " - PHP memory_limit: $memory\n";
// Database connections
$db_conns = $pdo->query("SELECT count(*) FROM pg_stat_activity WHERE datname = 'adx_system'")->fetchColumn();
echo " - Connexions DB actives: $db_conns\n";
echo "\n";
// 5. Demander à HAMID IA d'analyser
echo "🤖 CONSULTATION HAMID IA POUR DIAGNOSTIC...\n";
$prompt = "Problème Brain sur serveur 89.167.40.150 (Backend ADX port 5821).
Données actuelles:
- Brain winners actifs: " . count($winners) . "
- Derniers tests: " . (!empty($tests) ? count($tests) . " disponibles" : "aucun") . "
- PMTA: " . ($pmta ? "installé" : "non installé") . "
- Memory PHP: $memory
Le Brain plante seulement sur le backend (hamid.php) mais pas sur le front (Arsenal port 5890).
Quelles pourraient être les causes et comment debugger ?";
$response = hamidAsk($prompt, [], 'Ollama-Local');
if (!$response['error']) {
echo "📝 RECOMMANDATIONS HAMID:\n";
echo str_replace("\n", "\n ", $response['response']) . "\n";
echo "\n (Provider: {$response['provider']}, Latence: {$response['latency_ms']}ms)\n";
} else {
echo "❌ Impossible de contacter HAMID IA\n";
}
} catch (Exception $e) {
echo "❌ ERREUR D'ANALYSE: " . $e->getMessage() . "\n";
}