Genesys Cloud - Developer Community!

 View Only

Sign Up

CLI Check Call Queue Waiting

  • 1.  CLI Check Call Queue Waiting

    Posted 3 hours ago
    I am developing an automation in PowerShell using the Genesys Cloud CLI. In this automation, it should check if the call waiting for a specific queue is greater than 1, and if so, alert me with a message on the screen. Does anyone have any tips to improve this?

    $QueueName = "NOME-EXATO-DA-FILA"
    $Threshold = 1
    $IntervalSeconds = 30

     

    # Descobrir queueId uma vez
    $queueId = (
        (gc routing queues list --name "$QueueName" --pageSize 100 | ConvertFrom-Json).entities |
        Where-Object { $_.name -eq $QueueName }
    ).id

     

    if (-not $queueId) { Write-Error "Fila não encontrada."; exit 1 }

     

    while ($true) {
        $body = @{
            filter = @{
                type = "or"
                predicates = @(@{ dimension = "queueId"; value = $queueId })
            }
            metrics = @("oWaiting")
        } | ConvertTo-Json -Depth 5

     

        try {
            $obs = gc analytics queues observations query -b $body | ConvertFrom-Json
            $oWaiting = (
                $obs.results[0].data |
                Where-Object { $_.metric -eq "oWaiting" } |
                Select-Object -First 1
            ).stats.latest

     

            $oWaiting = [int]$oWaiting

     

            $timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
            if ($oWaiting -gt $Threshold) {
                Write-Host ("[$timestamp] ⚠️  ALERTA: '{0}' com {1} esperando (> {2})" -f $QueueName, $oWaiting, $Threshold) -ForegroundColor Yellow
                [console]::beep(1000, 400)
            } else {
                Write-Host ("[$timestamp] OK: '{0}' com {1} esperando (≤ {2})" -f $QueueName, $oWaiting, $Threshold) -ForegroundColor Green
            }
        } catch {
            Write-Warning "Erro na consulta: $($_.Exception.Message)"
        }

     

        Start-Sleep -Seconds $IntervalSeconds
    }

    #PlatformCLI

    ------------------------------
    Daniel Bernardi
    Network Designer Specialist-Cloud Applications
    ------------------------------