feat(cluster): add configurable BLF expiry interval in HA menu with 120s default and automatic check-sync notify on failover
This commit is contained in:
1 parent
c1c6eab03c
commit
f14185d597
6 files changed
+145
-17
No files matched your search
+53
-5
@@ -15,8 +15,9 @@ class ConfigGenerator
|
||||
public const MOH_CONF_PATH = '/etc/asterisk/musiconhold.custom.conf';
|
||||
public const RTP_CONF_PATH = '/etc/asterisk/rtp.conf';
|
||||
public const FEATURES_CONF_PATH = '/etc/asterisk/features.conf';
|
||||
public const VOICEMAIL_CONF_PATH = '/etc/asterisk/voicemail.custom.conf';
|
||||
public const BACKUP_DIR = __DIR__ . '/../storage/backups';
|
||||
public const VOICEMAIL_CONF_PATH = '/etc/asterisk/voicemail.custom.conf';
|
||||
public const PJSIP_NOTIFY_CONF_PATH = '/etc/asterisk/pjsip_notify.conf';
|
||||
public const BACKUP_DIR = __DIR__ . '/../storage/backups';
|
||||
|
||||
public function __construct(private PDO $db) {}
|
||||
|
||||
@@ -187,6 +188,18 @@ class ConfigGenerator
|
||||
$lines[] = "; ===========================================================================";
|
||||
$lines[] = "; POSTES TÉLÉPHONIQUES (EXTENSIONS)";
|
||||
$lines[] = "; ===========================================================================";
|
||||
|
||||
// Détection de l'état du Cluster Haute Disponibilité (HA)
|
||||
$clusterSt = [];
|
||||
try {
|
||||
$clusterSt = $this->db->query('SELECT enabled, blf_expiry FROM cluster_settings WHERE id = 1')->fetch(PDO::FETCH_ASSOC) ?: [];
|
||||
} catch (\Throwable $e) {}
|
||||
$isHaActive = !empty($clusterSt['enabled']);
|
||||
// En mode Haute Disponibilité, on plafonne l'expiration des AOR/souscriptions sur la valeur configurée (par défaut 120s)
|
||||
// afin que les téléphones se réabonnent très vite en cas de bascule. Sans HA, on conserve le standard 1800s (30 min).
|
||||
$regExpiration = $isHaActive ? max(30, min(3600, (int)($clusterSt['blf_expiry'] ?? 120))) : 1800;
|
||||
$subMinExpiry = $isHaActive ? 30 : 0;
|
||||
|
||||
foreach ($extensions as $ext) {
|
||||
$num = trim((string)$ext['extension']);
|
||||
$name = str_replace('"', '', trim((string)$ext['name']));
|
||||
@@ -274,9 +287,9 @@ class ConfigGenerator
|
||||
$lines[] = "type = aor";
|
||||
$lines[] = "max_contacts = {$maxContacts}";
|
||||
$lines[] = "remove_existing = yes";
|
||||
$lines[] = "default_expiration = 120";
|
||||
$lines[] = "maximum_expiration = 300";
|
||||
$lines[] = "minimum_expiration = 60";
|
||||
$lines[] = "default_expiration = {$regExpiration}";
|
||||
$lines[] = "maximum_expiration = {$regExpiration}";
|
||||
$lines[] = "minimum_expiration = " . ($isHaActive ? 30 : 60);
|
||||
$lines[] = "qualify_frequency = 30";
|
||||
if ($hasVm) {
|
||||
$lines[] = "mailboxes = {$num}@default";
|
||||
@@ -1874,6 +1887,39 @@ class ConfigGenerator
|
||||
return implode("\n", $lines) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Génère la configuration des événements SIP Notify (/etc/asterisk/pjsip_notify.conf)
|
||||
* Profils check-sync pour Yealink, Fanvil, Snom, Polycom, etc.
|
||||
*/
|
||||
public function generatePjsipNotifyConf(): string
|
||||
{
|
||||
return <<<EOF
|
||||
; ===========================================================================
|
||||
; CONFIGURATION DES NOTIFICATIONS SIP PJSIP - NexusPBX
|
||||
; Profils de resynchronisation immédiate (check-sync) Yealink, Fanvil, Snom, etc.
|
||||
; ===========================================================================
|
||||
|
||||
[check-sync]
|
||||
Event=>check-sync\;reboot=false
|
||||
|
||||
[yealink-check-cfg]
|
||||
Event=>check-sync\;reboot=false
|
||||
|
||||
[snom-check-cfg]
|
||||
Event=>check-sync\;reboot=false
|
||||
|
||||
[polycom-check-cfg]
|
||||
Event=>check-sync
|
||||
|
||||
[cisco-check-cfg]
|
||||
Event=>check-sync
|
||||
|
||||
[aastra-check-cfg]
|
||||
Event=>check-sync
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
public function writeAllConfigs(): array
|
||||
{
|
||||
if (!is_dir(self::BACKUP_DIR)) {
|
||||
@@ -1886,6 +1932,7 @@ class ConfigGenerator
|
||||
$rtpContent = $this->generateRtpConf();
|
||||
$featuresContent = $this->generateFeaturesConf();
|
||||
$voicemailContent = $this->generateVoicemailConf();
|
||||
$notifyContent = $this->generatePjsipNotifyConf();
|
||||
|
||||
$this->writeAtomicWithPermissions(self::PJSIP_CONF_PATH, $pjsipContent);
|
||||
$this->writeAtomicWithPermissions(self::EXTENSIONS_CONF_PATH, $extensionsContent);
|
||||
@@ -1893,6 +1940,7 @@ class ConfigGenerator
|
||||
$this->writeAtomicWithPermissions(self::RTP_CONF_PATH, $rtpContent);
|
||||
$this->writeAtomicWithPermissions(self::FEATURES_CONF_PATH, $featuresContent);
|
||||
$this->writeAtomicWithPermissions(self::VOICEMAIL_CONF_PATH, $voicemailContent);
|
||||
$this->writeAtomicWithPermissions(self::PJSIP_NOTIFY_CONF_PATH, $notifyContent);
|
||||
|
||||
// S'assurer que pjsip.conf et extensions.conf incluent bien les fichiers .custom.conf
|
||||
SystemChecker::ensureAsteriskIncludes();
|
||||
|
||||
Reference in new issue
Block a user