VMware Cloud Community
Catbou
Enthusiast
Enthusiast

report of all requests

Where, how can I get a report or list of all requests in which I can fe search for the field "item"? In which DB or tabel are they stored?

Reply
0 Kudos
2 Replies
BenNeise
Contributor
Contributor

Hi Catbou,

You can get this information via the Catalog Service of the REST API (although it's not very quick). Some sample PowerShell below.

Cheers,

Ben

function Get-VraAuthorisationToken {

    <#

        .SYNOPSIS

        Get a vRA Authentication token

        .DESCRIPTION

        Get a vRA bearer token for use in subsequent requests.

        Tokens are valid for 24 hours by default. They can be removed.

        .PARAMETER Server

        The name of the vRA server to be used

        .PARAMETER UserName

        vRA username

        .PARAMETER Password

        vRA Password

        .PARAMETER Tenant

        Name of the vRA tenant. Default is "vsphere.local"

        .EXAMPLE

        $token = Get-vRAAuthorisationToken -Server "myVraServer" -UserName "User01" -Password "Hunter2"

    #>

    param (

        [parameter(Position = 0,

            Mandatory = $true

        )]

        [string]

        $Server,

        [parameter(Position = 1,

            Mandatory = $true

        )]

        [string]

        $UserName,

        [parameter(Position = 2,

            Mandatory = $true

        )]

        [string]

        $Password,

         

        [parameter(Position = 3,

            Mandatory = $false

        )]

        [string]

        $Tenant = "vsphere.local"

    )

    begin {

        #

    }

    process {

        $body = New-Object -TypeName "PSObject" -Property @{

            'username' = $UserName

            'password' = $Password

            'tenant' = $Tenant

        } | ConvertTo-Json -Depth 1 -Compress

        $webRequestParameters = @{

            Uri  = "https://$($Server)/identity/api/tokens"

            ContentType = "application/json"

            Body = $body

            Method = "POST"

            UseBasicParsing = $true

        }

        $objtoken = try {

            Invoke-WebRequest @webRequestParameters

        } catch {

            Write-Warning -Message $_.Exception.Message

            return

        }

    }

    end {

        (ConvertFrom-Json -InputObject $objToken.content).id

    }

}

function Get-VraRequests {

    <#

        .SYNOPSIS

        Gets vRealize Automation requests

        .DESCRIPTION

        Gets a collection of vRealize Automation requests

        .PARAMETER Server

        The name of the vRA server

        .PARAMETER Token

        Authentication token, you can use Get-vRAAuthorisationToken to get this.

        .PARAMETER MaxSamples

        Number of requests to be returned.

       

        .PARAMETER StartDate

        Will get requests after this date

        .PARAMETER EndDate

        Will get requests prior to this date

        .EXAMPLE

        Return the last 500 requests

        $token = Get-vRAAuthorisationToken -Server "e2portal" -UserName "bne06" -Password "Hunter2"

        $requests = Get-vraRequests -Server "e2portal" -Token $token -MaxSamples 500

       

        .EXAMPLE

        Get all requests from the last 7 days

        $token = Get-vRAAuthorisationToken -Server "myVraServer" -UserName "User01" -Password "Hunter2"

        Get-vraRequests -Server "myVraServer" -Token $token -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date)

    #>

    param (

        [parameter(

            Mandatory = $true,

            Position = 1

        )]

        [string]

        $Server,

        [Parameter(

            Mandatory = $true,

            Position = 2

        )]

        [string]

        $Token,

        [Parameter(

            Mandatory = $false,

            Position = 3

        )]

        [Datetime]

        $StartDate,

        [Parameter(

            Mandatory = $false,

            Position = 4

        )]

        [Datetime]

        $EndDate,

        [Parameter(

            Mandatory = $false,

            Position = 5

        )]

        [int]

        [alias("Requests")]

        $MaxSamples = 1000

    )

    begin {

        $arrRequests = @()

        $boolEmptyPage = $false

        $i = 0

        $arrDatesToBeSubstituted = @(

            "dateCreated",

            "lastUpdated",

            "dateSubmitted",

            "dateApproved",

            "dateCompleted"

        )

    }

    process {

        do {

            $i++

            $activity = "Getting vRA Requests"

            $status = "Got " + $arrRequests.count + " requests so far"

            $currentOperation = "Getting page: " + $i

            $percentageComplete = $arrRequests.count / $MaxSamples * 100

            Write-Progress -Activity $activity -Status $status -CurrentOperation $currentOperation -PercentComplete $percentageComplete

            $uri = "https://$($Server)/catalog-service/api/consumer/requests/?page=$($i)&limit=100&`$orderby=requestNumb... desc"

            if ($StartDate){$uri += '&$filter=dateSubmitted+gt+%27' + $startDate + '%27'}

            if ($EndDate){$uri += '+and+dateSubmitted+lt+%27' + $endDate + '%27'}

            $webRequestParameters = @{

                ContentType = "application/json"

                Headers = @{"Authorization"=("Bearer " + $token)}

                Method  = "GET"

                Uri = $uri

                UseBasicParsing = $true

            }

            $webRequest = try {

                Invoke-WebRequest @webRequestParameters

            } catch {

                Write-Warning -Message $_.Exception.Message

                return

            }

            if (($webRequest.content | ConvertFrom-JSON).content.count -eq 0){

                Write-Warning -Message "Last page was empty, this normally means that you've requested more requests than are available."

                Write-Progress -Activity $activity -Completed

                $boolEmptyPage = $true

            }

            $arrRequests += ($webRequest.content | ConvertFrom-JSON).content

        }

        until (

            $boolEmptyPage -or $arrRequests.count -ge $MaxSamples

        )

        # Date objects will be returned as strings; let's convert them to PowerShell dateTime objects

        $arrRequests | ForEach-Object {

            forEach ($strDateToBeSubstituted in $arrDatesToBeSubstituted){

                if ($_.$strDateToBeSubstituted){

                    $_ | Add-Member -Name $strDateToBeSubstituted -MemberType "NoteProperty" -Value (Get-Date -Date $_.$strDateToBeSubstituted) -Force

                }

            }

        }

    }

    end {

        $arrRequests | Select-Object -First $MaxSamples

    }

}

$token = Get-vRAAuthorisationToken -Server "myVraServer" -UserName "user01" -Password "Hunter2"

$requests = Get-vraRequests -Server "myVraServer" -Token $token -StartDate (Get-Date).AddDays(-30) -EndDate (Get-Date)

$requests | Select-Object "@type",requestNumber,requestedItemName | Format-Table -Auto

Reply
0 Kudos
pizzle85
Expert
Expert

vRO you can do:

var requests = vCACCAFEEntitiesFinder.getRequests(cafeHost);

for each (request in requests) {

     if (request.requestedItemName == "ABC123") {

          System.log(request.propertyIWantToSee);

     }

}

where host is a vCACCAFE:vCACHost type.

Reply
0 Kudos