date('c'), 'actions'=>[]]; // Read blade-status $status = @json_decode(@file_get_contents('/var/www/html/api/blade-status.json'), true) ?: []; $last_seen = $status['last_seen'] ?? null; $last_age_sec = $last_seen ? (time() - strtotime($last_seen)) : 99999; $last_age_hours = round($last_age_sec / 3600, 1); $R['actions'][] = [ 'id' => 'diag', 'last_seen' => $last_seen, 'age_hours' => $last_age_hours, 'hostname' => $status['hostname'] ?? '?', 'ip' => $status['ip'] ?? '?', 'user' => $status['user'] ?? '?', 'cpu' => $status['cpu'] ?? '?', 'ram' => $status['ram'] ?? '?', 'status' => $last_age_hours < 1 ? 'HEALTHY' : ($last_age_hours < 24 ? 'STALE' : 'DEAD'), 'root_cause_hypothesis' => $last_age_hours > 24 ? 'PS1 Sentinel Agent task stopped or PAT expired' : 'OK' ]; // Check blade queue $queue = @json_decode(@file_get_contents('/var/www/html/api/blade-queue.json'), true) ?: []; $R['actions'][] = ['id'=>'queue', 'pending'=>count($queue)]; // Notif Telegram (bot 8544624912, chat 7605775322 from memory) $TG_BOT = '8544624912'; $TG_CHAT = '7605775322'; // Token depuis secrets.env $secrets_raw = @file_get_contents('/etc/weval/secrets.env'); preg_match('/TG_TOKEN=([^\n\r]+)/', $secrets_raw, $tg_match); $TG_TOKEN = $tg_match[1] ?? ''; if ($TG_TOKEN) { $msg = "🔴 BLADE IA STALE ({$last_age_hours}h)\nHostname: " . ($status['hostname'] ?? '?') . "\nQueue: " . count($queue) . " tasks pending\n\nWakeup PS on Razer:\nStart-Service -Name \"WevalSentinel\" -ErrorAction SilentlyContinue; & \"C:\\ProgramData\\WEVAL\\sentinel-agent.ps1\""; $url = "https://api.telegram.org/bot{$TG_TOKEN}/sendMessage"; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['chat_id'=>$TG_CHAT, 'text'=>$msg], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5 ]); $resp = curl_exec($ch); $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $R['actions'][] = ['id'=>'telegram_notif', 'http'=>$http, 'sent'=>$http === 200]; } else { $R['actions'][] = ['id'=>'telegram_notif', 'skipped'=>'TG_TOKEN missing in secrets.env']; } // Commande PowerShell ready-to-paste $R['blade_wakeup_ps'] = implode("\n", [ '# Copy-paste this in PowerShell (admin) on Razer Blade:', 'Start-Service -Name "WevalSentinel" -ErrorAction SilentlyContinue', '& "C:\ProgramData\WEVAL\sentinel-agent.ps1"', '# OR if task scheduler:', 'Start-ScheduledTask -TaskName "WEVAL-Sentinel"' ]); // Telegram link alternatif (click-to-send) $R['telegram_link'] = "https://t.me/wevia_bot?start=blade_wakeup"; echo json_encode($R, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);