-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvmware_tools_check.py
More file actions
59 lines (46 loc) · 1.52 KB
/
vmware_tools_check.py
File metadata and controls
59 lines (46 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import requests
VCENTER = "192.168.1.69"
USER = "administrator@vsphere.local"
PASSWORD = "VMware123!"
requests.packages.urllib3.disable_warnings()
def get_token():
resp = requests.post(
f"https://{VCENTER}/rest/com/vmware/cis/session",
auth=(USER, PASSWORD),
verify=False
)
return resp.json()["value"]
def get_all_vms(token):
headers = {"vmware-api-session-id":token}
result = requests.get(
f"https://{VCENTER}/rest/vcenter/vm",
headers=headers,
verify= False
)
return result.json()
def get_vm_details(vm_id,token):
headers = {"vmware-api-session-id":token}
resp = requests.get(
f"https://{VCENTER}/rest/vcenter/vm/{vm_id}",
headers=headers,
verify = False
)
return resp.json()["value"]
def check_tools(vm_list,token):
print("\n----- VMS Missing Tools -----")
for vm in vm_list:
if vm["power_state"] == "POWERED_ON":
continue
details = get_vm_details(vm["vm"], token)
tools = details.get("tools",{})
run_state = tools.get("run_state")
version_status = tools.get("version_status")
if run_state != "RUNNING" or version_status != "CURRENT":
print(f"{vm['name']} (ID: {vm['vm']}) -- Tools: {run_state}, Version: {version_status}")
def main():
token = get_token()
print("\nSession token: " + token + "\n\n")
vms = get_all_vms(token)["value"]
print("Total VMs found: ", len(vms))
check_tools(vms,token)
main()