Skip to content

Instantly share code, notes, and snippets.

@PatrickTerlisten
Last active May 10, 2017 11:08
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save PatrickTerlisten/bfb3f9edc39d31fc3859e3f0d28ba82f to your computer and use it in GitHub Desktop.
Monitoring hardware status with Python and vSphere API calls
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