Management Pack Builder

 View Only

 How to use paging functionality in the API-response from the NSX-API?

Jump to Best Answer
koit12's profile image
koit12 posted May 24, 2024 02:29 AM

Hi all!

I have an issue with creating an integration with the NSX-API.
I can't find a way to configure paging to handle the API-response from the NSX-API.
It seems like the paging functionality in the NSX-API is unsupported by the paging-handling in the Management Pack Builder.

The API-call I'm using is: https://{{URL}}/policy/api/v1/infra/realized-state/virtual-machines/
At the bottom of the result from the above API-call are the following two lines:
"result_count": 6694,
"cursor": "1000"

The NSX-API seems to return pages with 1000 objects on each page. When using the "Offset"-method, you need to provide an Offset parameter, but the NSX-API doesn't seem to support this and the MPB-GUI doesn't allow to skip this parameter.

See picture below:

This is the API-result when using "offset" as a test value in the Offset parameter field:

The Offset-parameter is mandatory in the GUI and I can't figure out which value the NSX-API supports.

How can I use the paging-functionality with the API-response from the NSX-API?
Is it supported?

Mark Arbogast's profile image
Broadcom Employee Mark Arbogast Best Answer

Hi koit12,

Based on the docs here, please try these settings:

Paging Method: Offset
Offset Parameter: cursor
Limit Parameter: page_size
Limit Value: 1000

Please let me know if you run into any further issues.

Best regards,

Mark

koit12's profile image
koit12

Hi Mark and thank you for your answer.

You are correct - after some tinkering I came to the same conclusion.

These paging settings seems to work:

After solving the paging functionality I encountered a new issue.
My API-call fram NSX returns a list of VMs with some properties.
I want to use the properties in the "tags"-array from the NSX API-response and place them as properties on existing "virtual_machine"-objects in vROps.
How can I accomplish this task in the Management Pack Builder?

This is an excerpt from the API-response:

{
    "results": [
        {
            "host_id": "4c530c0e-a6fa-4050-abb1-2806ca8c1e2c",
            "source": {
                "target_id": "4c530c0e-a6fa-4050-abb1-2806ca8c1e2c",
                "target_display_name": "<ESX Host Name>",
                "target_type": "HostNode",
                "is_valid": true
            },
            "external_id": "5004d0df-1d4f-4de8-7911-1b8730e16f70",
            "power_state": "VM_RUNNING",
            "local_id_on_host": "13",
            "compute_ids": [
                "moIdOnHost:13",
                "hostLocalId:13",
                "locationId:564dced6-7210-15cd-29c3-eafc80fb9a7e",
                "instanceUuid:5004d0df-1d4f-4de8-7911-1b8730e16f70",
                "externalId:5004d0df-1d4f-4de8-7911-1b8730e16f70",
                "biosUuid:42042354-753f-2f98-2d45-c08dde9bd8d2"
            ],
            "type": "REGULAR",
            "guest_info": {
                "os_name": "Red Hat Enterprise Linux 8 (64-bit)",
                "computer_name": "<VM Name>"
            },
            "resource_type": "VirtualMachine",
            "display_name": "<VM Name>",
            "tags": [
                {
                    "scope": "ProductionLevel",
                    "tag": "Test"
                },
                {
                    "scope": "SecurityLevel",
                    "tag": "Intern"
                },
                {
                    "scope": "Application",
                    "tag": "aordn-magnet"
                },
                {
                    "scope": "BusinessGroup",
                    "tag": "GLD"
                },
                {
                    "scope": "NetworkClass",
                    "tag": "Server"
                }
            ],
            "_last_sync_time": 1717869845489
        },

How can I extract the individual tag properties from the tags-array and create eg. a string in a custom format and place the string as a new property on existing "virtual-machine"-objects in vROps?
Is array-handling supported in the Management Pack Builder?

Mark Arbogast's profile image
Broadcom Employee Mark Arbogast

Hi koit12,

Unfortunately there's no way to parse those tags as properties today. Is the idea that you would have a property with the key "ProductionLevel" and the value "Test", then another property with key "SecurityLevel" and value "Intern", and so on?

Best regards,

Mark

koit12's profile image
koit12

Hi Mark and thank you for your response :-)

I'm not sure about how to best implement this.
vSphere Tags in vROps are implemented as a long string containing all the tag-categories and tags. 
One approach is to copy the vSphere-Tags way. Another approach is the way you suggests, by creating one property for each Tag-category.

I think I would have startet with the vSphere approach first, with one property containing all the tag-categories and tags. This approach may make it easier to create symptoms & alerts in vROps based on the same property, avoiding taking several individual object properties into consideration.

Do you have array handling and the functionality required to accomplish the above task on your roadmap for the Management Pack Builder?

Regards
Bernt