Last active
May 10, 2017 11:08
Star
You must be signed in to star a gist
Monitoring hardware status with Python and vSphere API calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyVim.connect import SmartConnect, Disconnect | |
import ssl | |
s = ssl.SSLContext(ssl.PROTOCOL_TLSv1) | |
s.verify_mode = ssl.CERT_NONE | |
try: | |
c = SmartConnect(host='vcenter.lab.local', user='root', pwd='Passw0rd') | |
print('Valid certificate\n') | |
except: | |
c = SmartConnect(host='vcenter.lab.local', user='root', pwd='Passw0rd', sslContext=s) | |
print('Invalid or untrusted certificate\n') | |
host = c.content.searchIndex.FindByDnsName(None,'esx1.lab.local',False) | |
health = host.runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo | |
print('Hostname: ' + host.name) | |
print('Type: ' + host.hardware.systemInfo.model) | |
print('Getting temperature sensor data...\n') | |
for i in health: | |
if i.sensorType == 'temperature': | |
temp=i.currentReading/100 | |
print(i.name + ' ' + str(temp) + ' ' + i.baseUnits) | |
Disconnect(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment