Retrieving NSX Manager System Info Using Rest API

In this post we will explore how NSX manager system info can be retrieved via Rest API. NSX manager appliance home page is itself very descriptive and provides all system info. 

In this post we will learn how the same system info can be explored via API calls. Let’s get started.

Query NSX Manager Information

Below API query will provide you info like what is the major and minor version of NSX appliance you ae running along with patch number and build number

# curl -k -u “admin:Password” -X GET https://nsxmgr.alex.local/api/1.0/appliance-management/global/info xmllint –format –

<?xml version="1.0" encoding="UTF-8"?>
<globalInfo>
 <currentLoggedInUser>admin</currentLoggedInUser>
 <versionInfo>
 <majorVersion>6</majorVersion>
 <minorVersion>3</minorVersion>
 <patchVersion>2</patchVersion>
 <buildNumber>5672532</buildNumber>
 </versionInfo>
</globalInfo>

Query NSX Manager Summary Information

This API query will present you with all info which you used to see from the NSX manager homepage. This call can be used to obtain all system related info in one shot. 

# curl -k -u “admin:Password” -X GET https://nsxmgr.alex.local/api/1.0/appliance-management/summary/system | xmllint –format –

<?xml version="1.0" encoding="UTF-8"?>
<systemSummary>
 <ipv4Address>192.168.109.6</ipv4Address>
 <dnsName>nsxmgr.alex.local</dnsName>
 <hostName>nsxmgr</hostName>
 <domainName>alex.local</domainName>
 <applianceName>vShield Virtual Appliance Management</applianceName>
 <versionInfo>
 <majorVersion>6</majorVersion>
 <minorVersion>3</minorVersion>
 <patchVersion>2</patchVersion>
 <buildNumber>5672532</buildNumber>
 </versionInfo>
 <uptime>14 days, 23 hours, 56 minutes</uptime>
 <cpuInfoDto>
 <totalNoOfCPUs>4</totalNoOfCPUs>
 <capacity>2599 MHZ</capacity>
 <usedCapacity>187 MHZ</usedCapacity>
 <freeCapacity>2412 MHZ</freeCapacity>
 <usedPercentage>7</usedPercentage>
 </cpuInfoDto>
 <memInfoDto>
 <totalMemory>16025 MB</totalMemory>
 <usedMemory>5761 MB</usedMemory>
 <freeMemory>10264 MB</freeMemory>
 <usedPercentage>36</usedPercentage>
 </memInfoDto>
 <storageInfoDto>
 <totalStorage>81G</totalStorage>
 <usedStorage>20G</usedStorage>
 <freeStorage>61G</freeStorage>
 <usedPercentage>25</usedPercentage>
 </storageInfoDto>
 <currentSystemDate>Tuesday, 27 June 2017 04:29:52 PM IST</currentSystemDate>
</systemSummary>

You can also get details about individual components like CPU/Memory and Storage using below queries

Memory Info

# curl -k -u “admin:Password” -X GET https://nsxmgr.alex.local/api/1.0/appliance-management/system/meminfo | xmllint –format –

<?xml version="1.0" encoding="UTF-8"?>
<memInfo>
 <totalMemory>16025 MB</totalMemory>
 <usedMemory>5761 MB</usedMemory>
 <freeMemory>10264 MB</freeMemory>
 <usedPercentage>36</usedPercentage>
</memInfo>

CPU Info

# curl -k -u “admin:Password” -X GET https://nsxmgr.alex.local/api/1.0/appliance-management/system/cpuinfo | xmllint –format –

<?xml version="1.0" encoding="UTF-8"?>
<cpuInfo>
 <totalNoOfCPUs>4</totalNoOfCPUs>
 <capacity>2599 MHZ</capacity>
 <usedCapacity>56 MHZ</usedCapacity>
 <freeCapacity>2543 MHZ</freeCapacity>
 <usedPercentage>2</usedPercentage>
</cpuInfo>

Storage Info

# curl -k -u “admin:Password” -X GET https://nsxmgr.alex.local/api/1.0/appliance-management/system/storageinfo | xmllint –format –

<?xml version="1.0" encoding="UTF-8"?>
<storageInfo>
 <totalStorage>81G</totalStorage>
 <usedStorage>20G</usedStorage>
 <freeStorage>61G</freeStorage>
 <usedPercentage>25</usedPercentage>
</storageInfo>

Get vCenter Configuration Details

This API query will provide you details about vCenter to which this NSX manager is registered. 

# curl -k -u “admin:Password” -X GET https://nsxmgr.alex.local/api/2.0/services/vcconfig | xmllint –format –

<?xml version="1.0" encoding="UTF-8"?>
<vcInfo>
 <ipAddress>resourcevc01.alex.local</ipAddress>
 <userName>administrator@vsphere.local</userName>
 <certificateThumbprint>7A:6F:67:91:09:0E:3A:7C:10:D2:9A:FD:2C:FC:7B:FD:81:AD:8F:FE</certificateThumbprint>
 <assignRoleToUser>true</assignRoleToUser>
 <vcInventoryLastUpdateTime>1498367200677</vcInventoryLastUpdateTime>
</vcInfo>

Get vCenter Server connection status

# curl -k -u “admin:Password” -X GET https://nsxmgr.alex.local/api/2.0/services/vcconfig/status | xmllint –format –

<?xml version="1.0" encoding="UTF-8"?>
<vcConfigStatus>
 <connected>true</connected>
 <lastInventorySyncTime>1498367200677</lastInventorySyncTime>
</vcConfigStatus>

Synchronize NSX Manager with vCenter server

This API query can be used to synchronize NSX manager with vCenter Server. You need to provide info like VC IP Address, username/password and VC thumbprint. These data needs to be passed in xml format with your API call as shown below.

# curl -k -u “admin:Password” -H “Content-Type:application/xml” -d @syncvc.xml -X PUT https://nsxmgr.alex.local/api/2.0/services/vcconfig

Response Body

<vcInfo>
<ipAddress>resourcevc01.alex.local</ipAddress> 
<userName>administrator@vsphere.local</userName> 
<password>Password</password> 
<certificateThumbprint>7A:6F:67:91:09:0E:3A:7C:10:D2:9A:FD:2C:FC:7B:FD:81:AD:8F:FE</certificateThumbprint> 
</vcInfo>

Query NSX Manager Uptime

# curl -k -u “admin:Password” -X GET https://nsxmgr.alex.local/api/1.0/appliance-management/system/uptime | xmllint –format –

14 days, 23 hours, 47 minutes

Thats it. This is how you can generate system related info for your nsx manager. Above API calls can be used in scripting for doing a daily healt hcheck on your NSX manager. 

I hope you enjoyed reading this post. Feel free to share this on social media if it is worth sharing. Be sociable :)