Inventory with API

  • 9 May 2019
  • 4 replies

Is there a way to see/export the Hostname and IP of the VMs with the API via cURL?
Anybody have an example o extract this information?


This topic has been closed for comments

4 replies

Userlevel 2
Badge +4
cURL isn't really meant to be used as a filter mechanism but you can achieve this by setting the cURL output to a variable then using egrep to pull out the strings that you want.

The below should get you the information filtered down from the whole JSON that is returned. I tested this with V2 of the API:

output=$(curl -k -X GET   'https://{{IP_ADDRESS}}:9440/PrismGateway/services/rest/v2.0/vms/?length=1&include_vm_nic_config=true' -H 'Authorization: Basic {{AuthGuid}}=')

echo $output | egrep -o '"name": *"[^"]*"|"ip_address": *"[^"]*"'

I would really suggest using Python or the JQ Module to parse the Key Value pairs for JSON output rather than trying to egrep it. It would be much cleaner:
thanks for the answer @rhunt
Is it possible to extract with sed the content of 'ipAddresses' ? for example:

"hypervisorType": "kKvm",
"ipAddresses": [
"memoryCapacityInBytes": 4294967296,
Userlevel 2
Badge +4
sed is going to be a little more difficult. You will have to use substitution to print ONLY the data you want and not the entire line. I have only ever used sed for file line replacements.

I THINK the regex for sed would look something like this to get exactly what you have listed above. Untested:

\"hypervisorType\": \"[a-zA-Z0-9]+\",\"ipAddresses\": \[\"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\"\],\"memoryCapacityInBytes\": \d+
Userlevel 4
Badge +19

Please find the script