fix(metrics): robust contact detection with AstDB fallback and reset f2b counters on clear log (v1.4.7)
This commit is contained in:
1 parent
bda4cb18a6
commit
1e288af617
5 files changed
+65
-13
No files matched your search
+36
-4
@@ -298,17 +298,19 @@ class SystemMetrics
|
||||
}
|
||||
}
|
||||
|
||||
$seenExts = [];
|
||||
foreach (preg_split('/\r?\n/', $rawContacts) ?: [] as $line) {
|
||||
// Contact: 101/sip:101@10.10.167.162:5060 5dd9a21be8 Avail 9.234
|
||||
// or with -nan: Contact: 102/sip:102@10.10.168.228:5060;x-ast-txp=trans bb0686ce80 Unavail -nan
|
||||
if (preg_match('/Contact:\s+([^\s\/]+)\/sip:([^\s]+)\s+([a-f0-9]+)\s+(\S+)\s+(-?[0-9.]+|nan|-nan)/i', $line, $m)) {
|
||||
// Supporte sip:, sips:, sans préfixe, tous types de hash et RTT (numérique, nan, N/A ou absent)
|
||||
if (preg_match('/Contact:\s+([^\s\/]+)\/(?:sips?:)?([^\s]+)\s+([a-zA-Z0-9]+)\s+(\S+)(?:\s+(\S+))?/i', $line, $m)) {
|
||||
$extNum = $m[1];
|
||||
$uri = $m[2];
|
||||
$status = $m[4];
|
||||
$rttRaw = $m[5] ?? null;
|
||||
$isAvail = (stripos($status, 'Avail') !== false && stripos($status, 'Unavail') === false) || stripos($status, 'NonQual') !== false;
|
||||
if ($isAvail) {
|
||||
$onlineCount++;
|
||||
}
|
||||
$seenExts[$extNum] = true;
|
||||
|
||||
$meta = $contactMeta[$extNum] ?? [];
|
||||
$fullUri = $meta['uri'] ?? ("sip:" . $uri);
|
||||
@@ -330,7 +332,37 @@ class SystemMetrics
|
||||
'user_agent' => $userAgent,
|
||||
'active_transport' => $activeTransport,
|
||||
'status' => $status,
|
||||
'rtt_ms' => is_numeric($m[5]) ? round((float)$m[5], 1) : null,
|
||||
'rtt_ms' => ($rttRaw !== null && is_numeric($rttRaw)) ? round((float)$rttRaw, 1) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Filet de sécurité 100% infaillible : Tous les contacts enregistrés dans AstDB (/registrar/contact)
|
||||
// non encore répertoriés (par exemple si qualify est désactivé ou RTT non disponible)
|
||||
$nowTime = time();
|
||||
foreach ($contactMeta as $extNum => $meta) {
|
||||
if (isset($seenExts[$extNum])) {
|
||||
continue;
|
||||
}
|
||||
$exp = (int)($meta['expiration_time'] ?? 0);
|
||||
if ($exp === 0 || $exp > $nowTime) {
|
||||
$onlineCount++;
|
||||
$fullUri = $meta['uri'] ?? '';
|
||||
$activeTransport = 'udp';
|
||||
if (preg_match('/transport=(tls|wss|ws|tcp|udp)/i', $fullUri, $tm)) {
|
||||
$activeTransport = strtolower($tm[1]);
|
||||
} elseif (preg_match('/x-ast-txp=transport-(tls|wss|ws|tcp|udp)/i', $fullUri, $tm)) {
|
||||
$activeTransport = strtolower($tm[1]);
|
||||
} elseif (str_starts_with($fullUri, 'sips:')) {
|
||||
$activeTransport = 'tls';
|
||||
}
|
||||
$contacts[] = [
|
||||
'extension' => (string)$extNum,
|
||||
'uri' => $fullUri,
|
||||
'user_agent' => $meta['user_agent'] ?? '',
|
||||
'active_transport' => $activeTransport,
|
||||
'status' => 'Avail',
|
||||
'rtt_ms' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user