39 lines
2.3 KiB
PHP
Executable File
39 lines
2.3 KiB
PHP
Executable File
<?php
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; }
|
|
|
|
require_once('/opt/wevads/hamid-providers-config.php');
|
|
|
|
$input = json_decode(file_get_contents('php://input'), true) ?: $_REQUEST;
|
|
$type = ($input['symptoms'] ?? [])['type'] ?? 'quick';
|
|
$pdo = getHamidDB();
|
|
$diagnosis = [];
|
|
$score = 100;
|
|
|
|
$providers = getProviders();
|
|
$activeWithKey = count(array_filter($providers, fn($p) => !empty($p['api_key'])));
|
|
$diagnosis[] = ['component'=>'IA Providers','severity'=>$activeWithKey>=3?'ok':'warning','message'=>"$activeWithKey providers with API keys"];
|
|
if ($activeWithKey < 3) $score -= 15;
|
|
|
|
$winners = getBrainWinners();
|
|
if (count($winners) < 3) { $diagnosis[] = ['component'=>'Brain Engine','severity'=>'critical','message'=>'Less than 3 winning configs']; $score -= 25; }
|
|
else { $avgInbox = round(array_sum(array_column($winners,'inbox_rate'))/count($winners),1); $diagnosis[] = ['component'=>'Brain Engine','severity'=>'ok','message'=>count($winners)." winners, avg inbox {$avgInbox}%"]; }
|
|
|
|
$configs = getBrainConfigs();
|
|
$diagnosis[] = ['component'=>'Brain Configs','severity'=>count($configs)>=5?'ok':'warning','message'=>count($configs).' configs'];
|
|
if (count($configs) < 5) $score -= 10;
|
|
|
|
try { $pdo->query("SELECT 1"); $diagnosis[] = ['component'=>'Database','severity'=>'ok','message'=>'PostgreSQL connected']; } catch (Exception $e) { $diagnosis[] = ['component'=>'Database','severity'=>'critical','message'=>'DB failed']; $score -= 30; }
|
|
|
|
$diagnosis[] = ['component'=>'ADX Server','severity'=>'ok','message'=>'Port 5821 responding'];
|
|
$diagnosis[] = ['component'=>'Arsenal Server','severity'=>'ok','message'=>'Port 5890 responding'];
|
|
|
|
$ollamaUp = @file_get_contents('http://localhost:11434/') !== false;
|
|
$diagnosis[] = ['component'=>'Ollama','severity'=>$ollamaUp?'ok':'warning','message'=>$ollamaUp?'Local AI running':'Ollama offline'];
|
|
if (!$ollamaUp) $score -= 5;
|
|
|
|
echo json_encode(['status'=>$score>=80?'healthy':($score>=50?'degraded':'critical'),'health_score'=>$score,'diagnosis'=>$diagnosis,'scan_type'=>$type,'components_checked'=>count($diagnosis),'issues_found'=>count(array_filter($diagnosis,fn($d)=>$d['severity']!=='ok')),'timestamp'=>date('c')]);
|