VMware Cloud Community
Panzerbjorn
Contributor
Contributor

How to get stats from VROPS via REST API

Hi all, we are trying to use REST API via PowerShell to get information from VROPS.
However, it isn't working, and the documentation isn't particularly helpful, so here I am.

I can authenticate fine and get a list of the resources I want to get stats for, in the particular case, 3par resources.
Looking at https://MyvROpsServer/suite-api/docs/rest/index.html, it looks like I need to make a request to https://MyvROpsServer//suite-api/api/resources/{$ResourceID}/stats/query,
but this gives me a "Invoke-RestMethod : The remote server returned an error: (400) Bad Request." error.

Here is my code:
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Headers.Add("Accept", "$Type")
$Headers.Add("X-vRealizeOps-API-use-unsupported", 'true')
$Type = "application/xml;charset=utf-8"
$ResourcesURL = $BaseURL + "resources/$ResourceID/stats/query"
$Stats = Invoke-RestMethod -Method POST -uri $ResourcesURL -Credential $cred -ContentType $Type -Headers $Headers

So in short, does anyone know which REST API command would give me the equivalent of PowerCLI's Get-OMStat?
Or perhaps know of a place that has good examples?
I have also been trying to format some XML to send in the body, but again, without some useful examples, I haven't been able to get that to work.

Reply
0 Kudos
6 Replies
Panzerbjorn
Contributor
Contributor

Disappointing, but I guess not surprising that no one has any suggestions.
I feel like this is something that surely someone somewhere must have done, but I have been unable to find *anything* on this.
And what is super annoying is that VMware has some of the worst technical documentation of any tech company (At least tech used in a corporate setting) that I have come across, so what little documentation there is, has mostly been useless -__- 
Reply
0 Kudos
Dpison
Contributor
Contributor

Hi Panzerbjorn!!

Iḿ also interested in your question, and I will try to help you:

You can download from vmware sample code a "postman vrops collection" and there is a web explaining how to configure it. (Do your google research).

Next you have to query to vrops for resourceid of your object, you will find something like this:

Screenshot from 2019-12-04 17-17-46.png

Once you got it, do your query with this identifier, setting the metric you need, and voila!:

Screenshot from 2019-12-04 17-22-07.pngScreenshot from 2019-12-04 17-23-34.png

Good luck!!

Reply
0 Kudos
abugeja
Hot Shot
Hot Shot

interested in this question as well. Let us know how you go

Reply
0 Kudos
Panzerbjorn
Contributor
Contributor

Hi, thanks for your reply. Unfortunately I'm not really interested in doing this via a GUI as we would like this to be automated.

I have seen several references to Postman in their documentation, and I guess VMware just really likes manual work rather than automation... -__-

Reply
0 Kudos
abugeja
Hot Shot
Hot Shot

imo vmware probably arent very interested for customers getting data out of vrops.

Reply
0 Kudos
dtaliafe
Hot Shot
Hot Shot

Are you sending a body with your request?  I don't see one in the Powershell sample you provided.  You need to send a body with your POST request that includes the details like begin/end time.  There's an example in the docs or this article: Extracting Data From vRealize Operations with the REST APIs - VMware Cloud Management

Postman is a useful tool for exploring and testing APIs.  Once you figure out which parameters you need in Postman you can transfer that into your language of choice.  Here are some different examples using Powershell.

https://virtualcloudit.net/2017/06/02/vrops-extract-temperature-metric-data-via-the-api/

Help using Suite-API - getStatsOfResourcesCSV with Powershell Invoke-RestMethod

Reply
0 Kudos