89 lines
4.7 KiB
PHP
89 lines
4.7 KiB
PHP
<?php
|
|
// Ops intents RE-FIX — proper structure
|
|
|
|
if (!function_exists('wevia_ops_automation_status')) {
|
|
function wevia_ops_automation_status($msg) {
|
|
if (!$msg) return false;
|
|
if (!preg_match('/\b(automation|status.*automation|automations|crons?\s+auto|état\s+automations?)\b/i', $msg)) return false;
|
|
|
|
$out = ['intent' => 'automation_status', 'tool' => 'automation_live'];
|
|
$automations = [];
|
|
$s95_cron = @file_get_contents("http://10.1.0.3:5890/api/sentinel-brain.php?action=exec&cmd=" . urlencode("ls /etc/cron.d/deliverads-automation 2>/dev/null"));
|
|
$automations['crm_pipeline_sync_S95'] = (strpos($s95_cron ?: '', 'deliverads') !== false) ? 'active' : 'missing';
|
|
$automations['crm_observation_daily'] = file_exists('/etc/cron.d/crm-observation') ? 'active' : 'missing';
|
|
$automations['blade_selfheal_5min'] = file_exists('/etc/cron.d/automation-blade-selfheal') ? 'active' : 'missing';
|
|
$automations['ovh_cancel_daily'] = file_exists('/etc/cron.d/automation-ovh-daily') ? 'active' : 'missing';
|
|
$automations['azure_rotation'] = file_exists('/var/www/html/api/azure-reregister-api.php') ? 'ready' : 'missing';
|
|
$automations['send_kaouther_intent'] = file_exists('/var/www/html/api/wevia-send-kaouther-intent.php') ? 'ready' : 'missing';
|
|
$automations['observe_crm_intent'] = file_exists('/var/www/html/api/wevia-observe-crm-intent.php') ? 'ready' : 'missing';
|
|
$automations['nonreg_guard_15min'] = file_exists('/etc/cron.d/nonreg-daily') ? 'active' : 'missing';
|
|
$automations['ethica_enrich_boost'] = @shell_exec("crontab -u www-data -l 2>/dev/null | grep -c ethica-ma-boost") > 0 ? 'active' : 'missing';
|
|
|
|
$out['automations'] = $automations;
|
|
$out['count_active'] = count(array_filter($automations, fn($v) => in_array($v, ['active', 'ready'])));
|
|
$out['count_total'] = count($automations);
|
|
$out['pct'] = intval(100 * $out['count_active'] / $out['count_total']);
|
|
|
|
$pending_file = '/var/www/html/api/automation-pending.json';
|
|
if (is_readable($pending_file)) {
|
|
$pending = json_decode(@file_get_contents($pending_file), true) ?: [];
|
|
$out['pending_count'] = count($pending);
|
|
$out['pending'] = $pending;
|
|
}
|
|
$out['dashboard'] = 'https://weval-consulting.com/automation-hub.html';
|
|
|
|
header("Content-Type: application/json");
|
|
echo json_encode($out, JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('wevia_ops_blade_health')) {
|
|
function wevia_ops_blade_health($msg) {
|
|
if (!$msg) return false;
|
|
if (!preg_match('/\b(blade\s+(health|status|état|etat|check|ok)|razer\s+status)\b/i', $msg)) return false;
|
|
|
|
$out = ['intent' => 'blade_health', 'tool' => 'blade_real_check'];
|
|
$status_raw = @file_get_contents('http://127.0.0.1/api/blade-status.php?k=BLADE2026');
|
|
$status = json_decode($status_raw, true);
|
|
if ($status && !empty($status['blade'])) {
|
|
$b = $status['blade'];
|
|
$out['online'] = $b['online'] ?? false;
|
|
$out['agent_version'] = $b['heartbeat']['agent_version'] ?? '?';
|
|
$out['ip'] = $b['heartbeat']['ip'] ?? '?';
|
|
$out['heartbeat_ts'] = $b['heartbeat']['ts'] ?? '?';
|
|
$out['stats'] = $b['stats'] ?? [];
|
|
|
|
if (($out['stats']['pending'] ?? 0) > 0 && ($out['stats']['done'] ?? 0) === 0) {
|
|
$out['diagnostic'] = 'Agent v2 online mais ne poll pas les taches. Cause racine: agent v2 ignore exec_cmd response. Fix: upgrade vers v3.';
|
|
$out['fix_url'] = 'https://weval-consulting.com/api/blade-tasks/wevia-agent-v3.ps1';
|
|
$out['fix_status'] = file_exists('/var/www/html/api/blade-tasks/wevia-agent-v3.ps1') ? 'v3 available, waiting agent upgrade' : 'v3 not yet uploaded';
|
|
$out['recommended_action'] = 'Créer pending_exec.json dans /var/www/html/api/blade-tasks/ avec exec_cmd=iex v3 URL';
|
|
} else {
|
|
$out['diagnostic'] = 'Blade OK';
|
|
}
|
|
} else {
|
|
$out['error'] = 'blade-status.php unavailable';
|
|
}
|
|
$out['dashboard'] = 'https://weval-consulting.com/blade-control.html';
|
|
|
|
header("Content-Type: application/json");
|
|
echo json_encode($out, JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Auto-dispatch
|
|
$_ops_msg = '';
|
|
$_body = @file_get_contents('php://input');
|
|
if ($_body) {
|
|
$_j = @json_decode($_body, true);
|
|
if (is_array($_j) && !empty($_j['message'])) $_ops_msg = $_j['message'];
|
|
}
|
|
if (!$_ops_msg) $_ops_msg = $_POST['message'] ?? $_GET['message'] ?? '';
|
|
|
|
if ($_ops_msg) {
|
|
wevia_ops_automation_status($_ops_msg);
|
|
wevia_ops_blade_health($_ops_msg);
|
|
}
|