VMware Aria Automation Orchestrator

 View Only
  • 1.  Trying to monitor workflows through the API

    Posted Dec 18, 2023 01:18 PM

    I'm trying to monitor failed workflows through PRTG, using a PowerShell sensor. When querying 'all workflows' from /vro/runs, it only shows me those workflows that were triggered by users. The ones that are run on schedules, by the system account, do not appear in this list. Is there any way to get to these through the API? 

    Thanks. 

     

    $vra = "##########.lab.local"
    $Credential = get-credential
    $Username = $credential.UserName.Split('@')[0]
    $Domain= $credential.UserName.Split('@')[1]
    $JSONPassword = $Credential.GetNetworkCredential().Password

    #Get Refresh token
    $URI = "https://$($vra)/csp/gateway/am/api/login?access_token"
    $AuthBody = @{
    username = $Username
    password = $JSONPassword
    # domain = $Domain
    } | ConvertTo-Json

    $Headers = @{
    "Accept"="application/json";
    "Content-Type"="application/json";
    }
    $Response = Invoke-RestMethod -Method POST -URI $URI -Headers $Headers -Body $AuthBody
    $Refreshtoken = $Response.refresh_token
    $refreshTokenBody = @{
    "refreshToken" = $refreshToken
    } | ConvertTo-Json

    #Get Access Token
    $URI = "https://" + $vra + "/iaas/api/login"
    $Headers = @{
    "Accept"="application/json";
    "Content-Type"="application/json";
    }

    $accessToken = Invoke-RestMethod -Uri $URI -Method POST -Headers $Headers -body $refreshTokenBody
    $accessToken = "Bearer " + $accessToken.token

    #Get Workflow Runs
    $Headers.Add("Authorization",$accessToken)
    $URI = "https://$($vra)/vro/runs?size=200"
    $WorkflowRuns = Invoke-RestMethod -Method GET -URI $URI -Headers $Headers

    $WorkflowRuns

    foreach ($run in $workflowruns.content) {
    $startedOnDateTime = [System.DateTimeOffset]::FromUnixTimeMilliseconds($run.startedOn)

    $formattedRun = [PSCustomObject]@{
    Name = $run.name
    RunStatus = $run.runStatus
    Error = $run.errorMessage
    StartedOn = $startedOnDateTime.DateTime
    StartedBy = $run.startedBy
    }

    # Display or further process the formatted run
    Write-Output $formattedRun | Where-Object {$_.RunStatus -ne 'COMPLETED'}
    }



  • 2.  RE: Trying to monitor workflows through the API

    Posted Dec 18, 2023 01:57 PM

    I believe that to check the scheduled workflows, you need to verify the Tasks:

    https://developer.vmware.com/docs/13975/GUID-81729AB0-C625-4CC1-8B8D-1CCB0BD14AB2.html

    Hope this help!



  • 3.  RE: Trying to monitor workflows through the API

    Posted Dec 18, 2023 03:05 PM

    It does get me information on the scheduled workflows, and the workflows attached to them, but not the individual runs, as far as I can tell.

    It seems unintended that I'm not seeing the workflows on the URL I'm checking, or it might be a permission issue? 



  • 4.  RE: Trying to monitor workflows through the API

    Posted Dec 18, 2023 03:52 PM

    I haven't had a chance to try it out, but the documentation is clear about the execution of tasks:

    To check the status of all runs of a certain task, make a GET request at the URL where the task runs reside:

    GET https://{orchestrator_fqdn}/vco/api/tasks/{taskID}/executions/

    Not knowing the permissions you have, but I definitely suggest you check them!