vROps
vRealize Operations

vRealize Operations REST API: Find Resource by Identifiers

This past week, I was working with my technical marketing peer, Chris McClanahan on an exciting new demo with vRealize Operations and Cloud Automation Services. Basically, I needed to get the deployment for a virtual machine so I could take some action on an alert. To do this, I was trying to find a way to fetch a virtual machine resource from vRealize Operations using the MOID or UUID of the virtual machine. After searching for an answer in the REST API documentation, I reached out to Suren Balikyan, a Staff Engineer for vRealize Operations and my inside line to quick answers to hard questions.

Suren didn’t disappoint and gave me the API I needed, and I thought I would share in a blog post since it is very useful and not very clear from the documentation.

Resource Identifiers

Every resource in vRealize Operations has a unique identifier. However, the vRealize Operations identifier is not the same as the identifier in other solutions, such as vCenter and vRealize Automation. But, since vCenter is the primary management tool for vSphere both vRealize Operations and vRealize Automation will store the vCenter resource identifiers as a reference.

For example, in vRealize Operations here is the partial response, in JSON, for a virtual machine. You can see a list of resourceIdentifiers in this snippet:

 
   "creationTime":1551764411708,
   "resourceKey": 
      "name":"web-c-901",
      "adapterKindKey":"VMWARE",
      "resourceKindKey":"VirtualMachine",
      "resourceIdentifiers": 
          
            "identifierType": 
               "name":"VMEntityInstanceUUID",
               "dataType":"STRING",
               "isPartOfUniqueness":false
            },
            "value":"50177cd7-8eac-ee93-dff3-c4ce6c3d9841"
         },
          
            "identifierType": 
               "name":"VMEntityName",
               "dataType":"STRING",
               "isPartOfUniqueness":false
            },
            "value":"web-c-901"
         },
          
            "identifierType": 
               "name":"VMEntityObjectID",
               "dataType":"STRING",
               "isPartOfUniqueness":true
            },
            "value":"vm-1537"
         },
          
            "identifierType": 
               "name":"VMEntityVCID",
               "dataType":"STRING",
               "isPartOfUniqueness":true
            },
            "value":"d8c1ec65-f72b-47d6-af1f-7a089bf31293"
         }
      ]
   },

There are several identifiers. Each has a name and a value (for this post I’m going to ignore the datatype and isPartOfUniqueness keys). The two I’m interested in are the identifierTypes named “VMEntityObjectID” with is the MOID and the VMEntityInstanceID which is the UUID for the VM in vCenter.

Finally, the vRealize Operations resource ID can be found in the JSON response under the “identifier” key.

"identifier": "10ad320b-c9ca-47bd-8c4c-17e7c48eca3f"

In Cloud Automation Services, the JSON payload for a virtual machine in a deployment would include:

"__moref": "VirtualMachine:vm-1537",

Which is the MOID and what I can use as the key to match the virtual machine resource in vRealize Operations with the virtual machine in the CAS deployment.

The Mystery API

After focusing on the documentation section on /resources APIs for a couple of hours, I gave up and asked for help. This is the API that Suren suggested:

GET /api/adapterkinds/{adapterKind}/resourcekinds/{resourceKind}/resources

This was a surprise, to say the least. I never thought to use the adapterKind APIs. So, I checked the documentation and sure enough, this API accepts a query for identifiers! What I ended up with was this:

GET /api/adapterkinds/VMWARE/resourcekinds/virtualmachine/resources?identifiers[VMEntityObjectID]=vm-1537

Boom! The response came back with the specific virtual machine resource, no need to grab all resources and then parse that to find the one I needed. It’s really fast, too!