netgescon-day0/scripts/ops/windows/start-netgescon-panasonic-live.ps1

69 lines
2.1 KiB
PowerShell

param(
[string]$BaseUrl = 'https://staging.netgescon.it',
[string]$Extensions = '201-208,601,603,0001,0003',
[string]$LogFile = '.\netgescon-tapi-dotnet-events-live.log',
[string]$InteropOutputDir = '',
[string]$Token = '',
[int]$RestartDelaySeconds = 5,
[switch]$IncludeDiagnosticEvents
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$scriptPath = Join-Path $PSScriptRoot 'watch-netgescon-panasonic-tapi-dotnet-events.ps1'
if (-not (Test-Path $scriptPath)) {
throw "Watcher non trovato: $scriptPath"
}
if ([string]::IsNullOrWhiteSpace($Token)) {
$Token = [string]([Environment]::GetEnvironmentVariable('NETGESCON_CTI_SHARED_TOKEN', 'Machine'))
}
if ([string]::IsNullOrWhiteSpace($Token)) {
$Token = [string]([Environment]::GetEnvironmentVariable('NETGESCON_CTI_SHARED_TOKEN', 'User'))
}
if ([string]::IsNullOrWhiteSpace($Token)) {
throw 'Token mancante. Imposta NETGESCON_CTI_SHARED_TOKEN a livello User o Machine, oppure passa -Token.'
}
if ([string]::IsNullOrWhiteSpace($InteropOutputDir)) {
if (-not [string]::IsNullOrWhiteSpace($env:LOCALAPPDATA)) {
$InteropOutputDir = Join-Path $env:LOCALAPPDATA 'NetGescon\tapi-interop'
}
else {
$InteropOutputDir = Join-Path $PSScriptRoot 'tapi-interop'
}
}
elseif (-not [System.IO.Path]::IsPathRooted($InteropOutputDir)) {
$InteropOutputDir = Join-Path $PSScriptRoot $InteropOutputDir
}
while ($true) {
$timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
Write-Host "$timestamp | AVVIO bridge live Panasonic -> NetGescon"
try {
$params = @{
Extensions = $Extensions
LogFile = $LogFile
InteropOutputDir = $InteropOutputDir
BridgeMode = 'live'
BaseUrl = $BaseUrl
Token = $Token
}
if ($IncludeDiagnosticEvents.IsPresent) {
$params.IncludeDiagnosticEvents = $true
}
& $scriptPath @params
}
catch {
$timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
Write-Host "$timestamp | ERRORE bridge live: $($_.Exception.Message)"
}
Start-Sleep -Seconds ([Math]::Max(1, $RestartDelaySeconds))
}