Create vRealize Operations Manager custom groups with REST API

There are lots of possibilities for customization within vRealize Operations manager, but one of the most simple and interesting of those are custom groups. You can create completely individual monitoring points, by defining exactly what objects are monitored together. You can even, thanks to the dynamic nature of membership criteria’s, define what kinds of objects are monitored, current or even future ones are possible. Because of the shear number of objects in a larger environment, this can be a lot of work and it could be helpful to automate using the REST API of vROps.

With the REST API of the vRealize Operations Manager we can create custom groups. However, with the official API you can only create a type of static group or groups, this is because the interface doesn’t allow you to define the criteria required for dynamic groups. There is a second API called „internal“, but this is not officially supported. VMware doesn’t guarantee that this API will continue to work in the future. That being said, using this second API enables you to create every kind of custom group.

To create a custom group you always need a group type, regardless of the route you choose. This group type is internally defined as a so called resourceKind. This is essentially a type defined in the default „container“. With the official API you cannot create this directly, but it will be created automatically when creating a custom group with a non-existent resourceKind. However, this lacks important metadata and also you will not see the group or the group type in the GUI. Therefore it’s not really that helpful.
Again there is a non-supported solution, by way of the internal API. However I guess the documentation of this API is not correct, as I got always internal errors when using it.
Unfortunately, for now at least, group types seem not to be creatable with the API.

The documentation can be found on your vrops server: https://vropsserver/suite-api/docs/rest/index.html

2016-03-09_vrealizeopsapi

Some examples:

I have to start by manually creating a group type in the GUI, in this case „testGroupType“.

2016-03-09_vrealize_ops_api2

 

For this group type, I create a custom group by calling a POST to:

https://vropsserver/suite-api/api/resources/adapters/{ID}

The ID at the end has to be the ID of the default container. You get it by calling GET:

https://vropsserver/suite-api/api/resources?name=Container

 

The body of the POST request is:

<?xml version=“1.0″ encoding=“UTF-8″ standalone=“yes“?>

<ops:resource xmlns:xs=“http://www.w3.org/2001/XMLSchema“ xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance“ xmlns:ops=“http://webservice.vmware.com/vRealizeOpsMgr/1.0/„>
<ops:description>Description of this group</ops:description>
<ops:resourceKey>
<ops:name>mynewgroup</ops:name>
<ops:adapterKindKey>Container</ops:adapterKindKey>
<ops:resourceKindKey>testGroupType</ops:resourceKindKey>
<ops:resourceIdentifiers/>
</ops:resourceKey>
<ops:credentialInstanceId/>
<ops:resourceStatusStates/>
<ops:dtEnabled>true</ops:dtEnabled>
<ops:badges/>
</ops:resource>

In the API documentation you can also find several examples with json.
In the response I must save the created group ID, because it is needed to add objects to this group. To do this, I send a POST to:

https://vropsserver/suite-api/api/resources/{CustomGroupID}/relationships/children

With the body:

<?xml version=“1.0″ encoding=“UTF-8″ standalone=“yes“?>
<ops:uuid-values xmlns:xs=“http://www.w3.org/2001/XMLSchema“ xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance“ xmlns:ops=“http://webservice.vmware.com/vRealizeOpsMgr/1.0/„>
<ops:uuids>{ID} {ID} {ID} {ID}</ops:uuids>
</ops:uuid-values>

The IDs, of course, are the IDs of the objects I want to have within that group. I can get them inmuch the same way as the example given for the container above.

At the end, I start the monitoring for this new group with a simple PUT to:

https://vropsserver/suite-api/api/resources/{id}/monitoringstate/start

The outcome is a static custom group, which is not manually changeable and also does not dynamically accept any new objects.

If we want to use the internal API, we have to add to every call an additional HEADER:

X-vRealizeOps-API-use-unsupported=true

Now we can call a POST to:

https://vropsserver/suite-api/internal/resources/groups

With the body:

<?xml version=“1.0″ encoding=“UTF-8″ standalone=“yes“ ?>
<ops:group >
<ops:resourceKey>
<ops:name>mynewgroup</ops:name>
<ops:adapterKindKey>Container</ops:adapterKindKey>
<ops:resourceKindKey>testGroupType</ops:resourceKindKey>
<ops:resourceIdentifiers />
</ops:resourceKey>
<ops:description />
<ops:membershipDefinition>
<ops:includedResources>{ID}</ops:includedResources>
<ops:excludedResources />
</ops:membershipDefinition>
</ops:group>

Within the membershipDefinition we can directly add group elements or could even define a more complex dynamic definition of the custom group. The outcome is also changeable within the GUI.

You can also add elements with the API later, with a POST to:

https://vropsserver/suite-api/internal/resources/groups/{GroupID}/includedResources?resourceId={ID}

Without any ‘body’, we have to add the additional ID to the query string. Yes, the internal API is somewhat dirty…

As I said, there is an interface for creating these resourceKinds, but I didn’t get it to work. If you want to try, you can call a POST to:

https://vropsserver/suite-api/internal/adapterkinds/{id}/resourcekinds

Again, with the ID of the container, the body is:

<?xml version=“1.0″ encoding=“UTF-8″ standalone=“yes“?>
<ops:resource-kind key=“newGroupType“ xmlns:xs=“http://www.w3.org/2001/XMLSchema“ xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance“ xmlns:ops=“http://webservice.vmware.com/vRealizeOpsMgr/1.0/„>
<ops:name>newGroupType</ops:name>
<ops:resourceKindType>GROUP</ops:resourceKindType>
<ops:resourceKindSubType>GROUP_RULES_MANAGED</ops:resourceKindSubType>
<ops:resourceIdentifierTypes/>
</ops:resource-kind>

The important types here are resourceKindType and subType, as they are necessary for us to see the outcome in the GUI.

Have fun!

1 Kommentar

Kommentar absenden

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert