50 lines
2.1 KiB
PHP
50 lines
2.1 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
header("Access-Control-Allow-Origin: *");
|
|
|
|
$out = ['ts' => date('c'), 'doctrine' => '55-CRM-STALENESS + 57-NO-FAKE'];
|
|
|
|
// S95 via sentinel
|
|
function s95_query($sql) {
|
|
$url = "http://10.1.0.3:5890/api/sentinel-brain.php?action=exec&cmd=" . urlencode("PGPASSWORD=admin123 psql -h 127.0.0.1 -U admin -d adx_system -t -A -c \"$sql\" 2>&1");
|
|
$r = @file_get_contents($url);
|
|
$d = @json_decode($r, true);
|
|
return trim($d['output'] ?? '');
|
|
}
|
|
|
|
// Local S204
|
|
function local_query($sql) {
|
|
return intval(trim(@shell_exec("PGPASSWORD=admin123 psql -h 127.0.0.1 -U admin -d adx_system -t -A -c \"$sql\" 2>/dev/null")));
|
|
}
|
|
|
|
// Ethica HCPs (S95)
|
|
$out['ethica_hcps'] = intval(s95_query('SELECT COUNT(*) FROM ethica.medecins_real'));
|
|
|
|
// send_contacts (S95 ou local selon dispo)
|
|
$sc = intval(s95_query('SELECT COUNT(*) FROM send_contacts'));
|
|
$out['send_contacts'] = $sc > 0 ? $sc : intval(s95_query('SELECT COUNT(*) FROM public.send_contacts'));
|
|
|
|
// CRM twenty (deals)
|
|
$out['twenty_deals'] = intval(trim(@shell_exec("PGPASSWORD=admin123 psql -h 127.0.0.1 -U admin -d default -p 5433 -t -A -c \"SELECT COUNT(*) FROM workspace_c8qrnq9rmk5wya777sxdjsfb5.opportunity;\" 2>/dev/null")));
|
|
|
|
// Pipeline USD
|
|
$out['pipeline_usd'] = intval(trim(@shell_exec("PGPASSWORD=admin123 psql -h 127.0.0.1 -U admin -d default -p 5433 -t -A -c \"SELECT COALESCE(SUM(amount_amount_micros)/1000000, 0) FROM workspace_c8qrnq9rmk5wya777sxdjsfb5.opportunity;\" 2>/dev/null")));
|
|
|
|
// crm_contacts
|
|
$out['crm_contacts'] = intval(s95_query('SELECT COUNT(*) FROM crm_contacts'));
|
|
if ($out['crm_contacts'] === 0) {
|
|
// Try wevia_db or public.crm_contacts
|
|
$out['crm_contacts'] = intval(s95_query('SELECT COUNT(*) FROM public.crm_contacts'));
|
|
}
|
|
|
|
// Verdict: regression si send_contacts stopped >60j
|
|
$sc_last = s95_query("SELECT MAX(updated_at) FROM send_contacts_merge_log");
|
|
$out['send_contacts_last'] = $sc_last ?: null;
|
|
|
|
// Last imports
|
|
$out['verdict'] = 'OK';
|
|
if ($out['ethica_hcps'] < 100000) $out['verdict'] = 'WARN: ethica below 100K';
|
|
if ($out['send_contacts'] === 0) $out['verdict'] = 'WARN: send_contacts empty';
|
|
|
|
echo json_encode($out, JSON_PRETTY_PRINT);
|