Recently, I devoted all the time to exploring the latest release of vReazlize, namely version 8. In my opinion, an interesting project related to this product is being created, but not for long. However, this article will still be about version 7.x.
Every day, each of us must check whether vRA is working, whether we have the option of deployment or in a moment we can expect P1 in our queue.
To make checking easier, a very simple script based on Python and REST API has been created which checks all our services.
The Scrips is checking if VM is powered on on vCenter and also services on Windows, rest are functionality of vRA
For script I’m still usign my Data Collection which you can also download but I’m working for rewrite this to not use external library
#!/usr/bin/env python
import xlrd
import json
import requests
import urllib3
import wmi
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
null = None
__author__ = "Lukasz Tworek"
__copyright__ = "Copyright 2019"
__license__ = "GPL"
__version__ = "1.0"
__maintainer__ = "Lukasz Tworek"
__email__ = "lukasz.tworek@gmail.com"
__status__ = "DEV"
hostname = ""
username = ""
password = ""
tenant = ""
iaashostname = ""
iaasusername = ""
iaaspassword = ""
vcenterhostname = ""
vcusername = ''
vcpassword = ''
fname = "c:\\pliki\\RGD.xlsx"
vamiusername = ''
vamipassword = ''
def vCenterID(vcenterhostname,vcusername,vcpassword):
URL = vcenterhostname+"/rest/com/vmware/cis/session"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
response = requests.request("POST", URL, auth=(vcusername, vcpassword), headers=headers,
verify=False)
vCenterID = response.json()['value']
return vCenterID
sessionID = vCenterID(vcenterhostname,vcusername,vcpassword)
vheaders = {
'accept': "application/json",
"vmware-api-session-id": sessionID
}
def PowerStatus(vheaders,fname):
URL = vcenterhostname+"/rest/vcenter/vm"
response = requests.request("GET", URL, headers=vheaders, verify=False)
# print(response.content)
book = xlrd.open_workbook(fname)
sh1 = book.sheet_by_name("Workload Summary")
for rownum in range(0, sh1.nrows):
for num in range(len(response.json()['value'])):
# print(sh1.cell_value(rownum, 0))
if sh1.cell_value(rownum, 0) == response.json()['value'][num]['name']:
name = response.json()['value'][num]['name']
status = response.json()['value'][num]['power_state']
print(name + " " + status)
def CheckvRAServices(hostname,vamiusername,vamipassword):
headers = {"Accept": "application/json", "Content-Type": "application/json"}
url = hostname+":5480/config/nodes/list?json=true&components=true"
response = requests.request("GET", url, auth=(vamiusername, vamipassword), headers=headers, verify=False)
# print(response.json()[1])
for num in range(len(response.json()[1]['components'])):
nodeName = response.json()[1]['components'][num]['nodeType']
nodeStatus = response.json()[1]['components'][num]['state']
print(nodeName + " " + nodeStatus)
def CheckvRACluster(hostname):
headers = {"Accept": "application/json", "Content-Type": "application/json"}
url = hostname+"/SAAS/API/1.0/REST/system/clusterInstances"
response = requests.request("GET", url, headers=headers, verify=False)
status = response.json()[0]['status']
print("Cluster Status: "+status)
def CheckSystemHealth(hostname):
headers = {"Accept": "application/json", "Content-Type": "application/json"}
url = hostname+"/SAAS/API/1.0/REST/system/health"
response = requests.request("GET", url, headers=headers, verify=False)
DatabaseStatus = response.json()['DatabaseStatus']
MessagingConnectionOk = response.json()['MessagingConnectionOk']
print("DatabaseStatus: "+DatabaseStatus)
print("MessagingConnectionOk: "+MessagingConnectionOk)
def CheckIaaSStaus(iaashostname,iaasusername,iaaspassword):
headers = {"Accept": "application/json", "Content-Type": "application/json"}
url = iaashostname+"/WAPI/api/status"
try:
response = requests.request("GET", url,auth=(iaasusername, iaaspassword), headers=headers, verify=False, timeout=10)
#print(response.json())
#print(response.json())
print(response.json()['serviceName']+" "+response.json()['serviceInitializationStatus'])
if (response.json()['errorMessage']) != None:
print(response.json()['errorMessage'])
except (requests.exceptions.ReadTimeout):
print("WebPage is not accessible")
def CheckVMPS(iaashostname,iaasusername,iaaspassword):
headers = {"Accept": "application/json", "Content-Type": "application/json"}
url = iaashostname+"/VMPSProvision"
response = requests.request("GET", url, auth=(iaasusername, iaaspassword), headers=headers, verify=False)
if response.status_code == 200:
print("VMPSProvision Work correctly")
else:
print("Issue with VMPS")
def CheckServices(hostname):
headers = {"Accept": "application/json", "Content-Type": "application/json"}
url = hostname+"/component-registry/services/status/current?page=1&limit=200"
response = requests.request("GET", url, headers=headers, verify=False)
#print(response.json())
for num in range(len(response.json()['content'])):
#print(response.json()['content'][num]['serviceName'])
#print(response.json()['content'][num]['serviceStatus']['serviceInitializationStatus'])
if response.status_code == 200:
if response.json()['content'][num]['notAvailable'] == False:
print(response.json()['content'][num]['serviceName']+" "+response.json()['content'][num]['serviceStatus']['serviceInitializationStatus'])
else:
print(response.json()['content'][num]['serviceName']+" Issue with Service ErrorMessage: "+response.json()['content'][num]['serviceStatus']['errorMessage'])
else:
print("Issue")
def ServiceStatus(fname):
book = xlrd.open_workbook(fname)
sh1 = book.sheet_by_name("Workload Summary")
for rownum in range(0, sh1.nrows):
if "IaaS" in sh1.cell_value(rownum, 1):
hostname = sh1.cell_value(rownum, 0)
if hostname != "":
print("Service Status on "+hostname)
conn = wmi.WMI(hostname, user=r"Administrator@vworld.domain.local", password="VMware1!")
for service in conn.Win32_Service(state="Running"):
if "VMware" in service.Name:
print(service.Name+": Running")
for service in conn.Win32_Service(state="Stopped"):
if "VMware" in service.Name:
print(service.Name+": Stopped")
def Main():
print("**********************************************")
print("************* vRA Health Check ***************")
print("**********************************************")
print("************* VM Status on vCenter ***********")
PowerStatus(vheaders,fname)
print("************* Services on vRA ****************")
CheckvRAServices(hostname,vamiusername,vamipassword)
print("************* Cluster Status *****************")
CheckvRACluster(hostname)
print("************* System Health ******************")
CheckSystemHealth(hostname)
print("************* IaaS Status ********************")
CheckIaaSStaus(iaashostname,iaasusername,iaaspassword)
print("************* VMPS Status ********************")
CheckVMPS(iaashostname,iaasusername,iaaspassword)
print("************* Services for vRA ***************")
CheckServices(hostname)
print("************* IaaS Service Status ************")
ServiceStatus(fname)
print("**********************************************")
print("************* End of Health Check ************")
print("**********************************************")
Main()