Monitoring hardware status with Python and vSphere API calls

This posting is ~4 years years old. You should keep this in mind. IT is a short living business. This information might be outdated.

Apparently it’s “how to monitor hardware status” week on vcloudnine.de. Some days ago, I wrote an article about using SNMP for hardware monitoring. You can also use the vSphere Web Client to get the status of the host hardware. A third way is through the vSphere API. I just want to share a short example how to use vSphere API calls and pyVmomi. pyVmomi is the Python SDK for the VMware vSphere API.

Get hardware status with vSphere API calls

I just want to share a small example, that shows the basic principle. The script gathers the temperature sensor data of a ProLiant DL360 G7 running ESXi 6.0 U2 using vSphere API calls.

The output of the script looks like this:

Valid certificate

Hostname: esx1.lab.local
Type: ProLiant DL360 G7
Getting temperature sensor data...

Other 1 Temp 28 --- Normal 65.0 Degrees C
Drive Backplane 1 Temp 27 --- Normal 35.0 Degrees C
Peripheral Bay 8 Temp 26 --- Normal 42.0 Degrees C
Peripheral Bay 7 Temp 25 --- Normal 38.0 Degrees C
Peripheral Bay 6 Temp 24 --- Normal 45.0 Degrees C
Peripheral Bay 5 Temp 23 --- Normal 39.0 Degrees C
Peripheral Bay 4 Temp 22 --- Normal 46.0 Degrees C
Peripheral Bay 3 Temp 21 --- Normal 44.0 Degrees C
Peripheral Bay 2 Temp 20 --- Normal 39.0 Degrees C
Peripheral Bay 1 Temp 19 --- Normal 37.0 Degrees C
Other 5 Temp 18 --- Normal 39.0 Degrees C
Memory Module 10 Temp 17 --- Normal 36.0 Degrees C
Other 4 Temp 16 --- Normal 34.0 Degrees C
Other 3 Temp 15 --- Normal 35.0 Degrees C
Memory Module 9 Temp 14 --- Normal 34.0 Degrees C
Power Supply 5 Temp 13 --- Normal 45.0 Degrees C
Power Supply 4 Temp 12 --- Normal 36.0 Degrees C
Memory Module 8 Temp 11 --- Normal 36.0 Degrees C
Memory Module 7 Temp 10 --- Normal 38.0 Degrees C
Memory Module 6 Temp 9 --- Normal 36.0 Degrees C
Memory Module 5 Temp 8 --- Normal 39.0 Degrees C
Memory Module 4 Temp 7 --- Normal 35.0 Degrees C
Memory Module 3 Temp 6 --- Normal 37.0 Degrees C
Memory Module 2 Temp 5 --- Normal 36.0 Degrees C
Memory Module 1 Temp 4 --- Normal 38.0 Degrees C
Other 2 Temp 3 --- Normal 40.0 Degrees C
Other 1 Temp 2 --- Normal 40.0 Degrees C
Other 1 Temp 1 --- Normal 27.0 Degrees C
>>>

Nothing fancy. You can easily loop through numericSensorInfo to gather data from other sensors. Use the Managed Object Browser (MOB) to navigate through the API. This is handy if you search for specific sensors. If you need accurate data, the vSphere API is the way to go. If you focus on something lightweight, try SNMP.

Patrick Terlisten
Follow me

4 thoughts on “Monitoring hardware status with Python and vSphere API calls

  1. Jon Forrest

    I need to find a way to get all the ESXi hosts in a vCenter, and then, for each hosts, check to see if they have a Fibre Channel HBA, and then, if they do, see some information about the Fibre Channel connections.

    Your example gets information about a specific host (e.g. esx1.lab.local). Can you give me some idea of how to get the list of hosts from the Python API?

    Thanks.

    Reply
  2. ale

    I got the error ‘NoneType’ object has no attribute ‘runtime’ running this code;
    Thats becouse host is none type, i don’t know why, can you please help me?

    Reply

Leave a Reply to Jon Forrest Cancel reply

Your email address will not be published. Required fields are marked *