VMware vRealize Operations Adapter for Nutanix


Badge +4
This script creates a custom adapter for a Nutanix Cluster in VMware vRealize Operations. It delivers simple values like freeBytes, capacityBytes and usageBytes and enables vROps to monitor and display the values.
By using the Nutanix REST API you can use nearly every value that is available.




config.py

global vmw global ntnxvmw = dict( server = "your-vrops-server", username = "admin", password = "VMware1!")ntnx = dict( server = "your-ntnx-server", username = "admin", password = "nutanix/4u", )
NTNX_vROPS.py

#!/usr/bin/python### Nutanix to VMmware vRealize Operations #### Use-Case: Push your Nutanix environment data to vROps/vCOps###import json import requestsimport timeimport unicodedataimport configglobal resourceNamegetNutanixDataUrl = "https://"+config.ntnx["server"]+":9440/PrismGateway/services/rest/v1/clusters"getResourcesUrl = "https://"+config.vmw["server"]+"/suite-api/api/resources"createResourceUrl = "https://"+config.vmw["server"]+"/suite-api/api/resources/adapterkinds/http%20post"addResourceDataUrl = "https://"+config.vmw["server"]+"/suite-api/api/resources/identifier/stats/adapterkinds/http%20post"resourceName = "Nutanix Cluster"def getMs(): return int(round(time.time()*1000))def getRest(base_url): requests.packages.urllib3.disable_warnings() s = requests.Session() s.headers.update({'Content-Type': 'application/json; charset=utf-8', 'Accept':'application/json'}) request = s.get(base_url, verify=False, auth=(config.vmw["username"],config.vmw["password"])) return request.json()def postRest(base_url, data): requests.packages.urllib3.disable_warnings() s = requests.Session() s.headers.update({'Content-Type': 'application/json; charset=utf-8', 'Accept':'application/json'}) request = s.post(base_url, data=json.dumps(data), verify=False, auth=(config.vmw["username"],config.vmw["password"])) return requestdef getNutanixData(): values = {} base_url = getNutanixDataUrl requests.packages.urllib3.disable_warnings() s = requests.Session() s.headers.update({'Content-Type': 'application/json; charset=utf-8', 'Accept':'application/json'}) request = s.get(base_url, verify=False, auth=(config.ntnx["username"],config.ntnx["password"])) data = request.json() for i in data["entities"]: values["freeBytes"] = i["usageStats"]["storage.free_bytes"] values["capacityBytes"] = i["usageStats"]["storage.capacity_bytes"] values["usageBytes"] = i["usageStats"]["storage.usage_bytes"] return valuesdef getResources(): base_url = getResourcesUrl result = getRest(base_url) return resultdef getResourceId(resource): resources = getResources() for i in resources["resourceList"]: name = i["resourceKey"]["name"] identifier = i["identifier"] if resource == name: return identifier def createResourceByAdapterKind(resourceName): base_url = createResourceUrl data = { "description" : None, "resourceKey" : { "name" : resourceName, "adapterKindKey" : "OPENAPI", "resourceKindKey" : "Storage", "resourceIdentifiers" : [ { "identifierType" : { "name" : "freeBytes", "dataType" : "STRING", "isPartOfUniqueness" : True }, "value" : "0" },{ "identifierType" : { "name" : "usageBytes", "dataType" : "STRING", "isPartOfUniqueness" : True }, "value" : "0" },{ "identifierType" : { "name" : "capacityBytes", "dataType" : "STRING", "isPartOfUniqueness" : True }, "value" : "0" } ] }, "resourceStatusStates" : [ ], "dtEnabled" : True, } result = postRest(base_url, data) return resultdef addResourceData(identifier): values = getNutanixData() identifier = str(identifier) base_url = addResourceDataUrl.replace("identifier", identifier) stats = { "stat-content" : [ { "statKey" : "freeBytes", "timestamps" : [ getMs() ], "data" : [ values["freeBytes"] ] },{ "statKey" : "capacityBytes", "timestamps" : [ getMs() ], "data" : [ values["capacityBytes"] ] },{ "statKey" : "usageBytes", "timestamps" : [ getMs() ], "data" : [ values["usageBytes"] ] }] } request = postRest(base_url, stats) return requestif __name__ == "__main__": identifier = getResourceId(resourceName) if identifier == None: print "resource is not available. creating..." createResourceByAdapterKind(resourceName) identifier = getResourceId(resourceName) while identifier != None: print "resource is available. adding data..." addResourceData(identifier) time.sleep(5)

2 replies

Userlevel 7
Badge +34
Great job  - good luck in the competition!
Badge
How can we create an adapter for nagios inside VROps using python for calling the API's??

Reply