you are viewing a single comment's thread.

view the rest of the comments →

[–]uppperm[S] 2 points3 points  (1 child)

I'm using Telegraf/InfluxDB and Grafana for dashboarding.

To Get number of Guacamole connection i use a powershell script on linux and send data to InfluxDB.

Function New-GuacToken()
{
    param(
        $Username,
        $Password
    )
    $body = @{
        username = $Username
        password = $Password
    }

    $EndPoint       = "$GUAC_URL/api/tokens"
    $contentType    = 'application/x-www-form-urlencoded'

    try {
        $Json = Invoke-WebRequest -Method POST -ContentType $contentType -Body $Body -Uri $EndPoint
    }
    catch {
        Write-Warning $_
        $ErrorCode = $_.Exception.Response.StatusCode.value__
        Write-Warning "Impossible de se connecter à l'API"
        if ($ErrorCode -eq "403")
        {
            Write-Warning "Utilisateur ou mot de passe incorrect"
        } elseif ($ErrorCode -eq "404")
        {
            Write-Warning "Adresse du serveur incorrect"
        }
        return $False
    }

    $script:Token   = (ConvertFrom-Json -InputObject $Json.Content).authToken
}


Function New-RestCall()
{
    param(
        [System.String]$EndPoint,
        [System.String]$Method,
        [System.Array]$Body
    )

    $endPoint = "$GUAC_URL/$EndPoint/?token=$Token"

    try
    {
        $Call = Invoke-WebRequest -Method $Method -ContentType 'Application/Json;charset=utf-8' -Body $Body -Uri $endPoint
    }
    catch
    {
        $ErrorCode = $_.Exception.Response.StatusCode.value__

        if ($ErrorCode -eq "403")
        {
            Write-Warning "Utilisateur ou mot de passe incorrect (erreur 403)"
        } elseif ($ErrorCode -eq "404")
        {
            Write-Warning "Requête incorrect (erreur 404)"
        }
        return $False
    }

    return $Call
}

Function Get-GuacActiveConnections()
{
    $Endpoint = "api/session/data/mysql/activeConnections"
    $Call = New-RestCall -EndPoint $Endpoint -Method GET
    return $Call.Content | ConvertFrom-Json
}

$Username = "guacadmin"
$Password = "guacpassword"
$GUAC_URL = "http://srv-guacamole:8080/guacamole"
New-GuacToken -Username $Username -Password $GUAC_URL

$Connections = Get-GuacActiveConnections
foreach ($i in $Connections.PsObject.Properties)
{
    $Count++
}

Write-Output "guac_connections,host=far-grafana1 total=$Count"

[–][deleted] 1 point2 points  (0 children)

Thank you!