VMware Cloud Community
Dave_Mishchenko
Immortal
Immortal
Jump to solution

Scripts to obtain Health Status information

Would anyone have any sample scripts that would query an ESXi 4 host for the info found on the Health Status or Hardware Status tabs? I'm looking for something simple (ideally fewer lines of code) so even if it returns just info about the host's CPU that would be fine.

Thanks.

1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The next script displays the status of the sensors of an ESX server:

$VMHostName = "YourEsxServerName"
$HostView = Get-VMHost -Name $VMHostName | Get-View
$HealthStatusSystem = Get-View $HostView.ConfigManager.HealthStatusSystem
$SystemHealthInfo = $HealthStatusSystem.Runtime.SystemHealthInfo
ForEach ($Sensor in $SystemHealthInfo.NumericSensorInfo) {
  $Report = "" | Select-Object VMHost,Sensor,Status
  $Report.VMHost = $VMHostName
  $Report.Sensor = $Sensor.Name
  $Report.Status = $Sensor.HealthState.Key
  $Report
}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
10 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Dave,

the most simple script to get information about an ESXi server is:

Get-VMHost YourESXiServerName | Format-List *

If you want specific other information included in the output, let me know, and I can make a script for that.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Dave, the information HW Status tab is obtained through CIM interfaces which are specific to the HW.

Afaik these APIs are not public.

I suspect you will have to use CIM APIs, if available, provided by the HW vendor.

I, for example, use IBM Director to get sensor info from my IBM HW.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Luc,

I thought the information that displays under the hardware tab is data via CIM interface and hardware would basically send this information up to CIM client running on ESX(i) host, that's how this information is being displayed?

At least from my testing, all this information displayed under the hardware tab/status can be obtained using HostHealthStatusSystem

I even wrote a vSphere SDK for Perl script that queries from each of the major components: and the detail information is also included in my vSphere Health Check Script output - http://engineering.ucsb.edu/~duonglt/vmware/sample_vmware_health_report.html#ESX/ESXi%20Health%20Sof... (click on the Click here for more detail info for the break down)

I'm assuming this can also be retrieved via PowerCLI?

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

Dave_Mishchenko
Immortal
Immortal
Jump to solution

I had found this previously which uses a function to query the CIM broker - http://blogs.vmware.com/vipowershell/2009/03/monitoring-esx-hardware-with-powershell.html. I was hoping that this had made it into a cmd-let.

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Dave,

the next script uses the HostHealthStatusSystem William mentioned, to display the status of the ESX server's processor:

$VMHostName = "YourEsxServerName"
$HostView = Get-VMHost -Name $VMHostName | Get-View
$HealthStatusSystem = Get-View $HostView.ConfigManager.HealthStatusSystem
$SystemHealthInfo = $HealthStatusSystem.Runtime.SystemHealthInfo
$HardwareStatusInfo = $HealthStatusSystem.Runtime.HardwareStatusInfo
ForEach ($Cpu in $HardwareStatusInfo.CpuStatusInfo) {
  $Report = "" | Select-Object VMHost,Cpu,Status
  $Report.VMHost = $VMHostName
  $Report.Cpu = $Cpu.Name
  $Report.Status = $Cpu.Status.Key
  $Report
}

Regards, Robert

Message was edited by: RvdNieuwendijk

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The next script displays the status of the sensors of an ESX server:

$VMHostName = "YourEsxServerName"
$HostView = Get-VMHost -Name $VMHostName | Get-View
$HealthStatusSystem = Get-View $HostView.ConfigManager.HealthStatusSystem
$SystemHealthInfo = $HealthStatusSystem.Runtime.SystemHealthInfo
ForEach ($Sensor in $SystemHealthInfo.NumericSensorInfo) {
  $Report = "" | Select-Object VMHost,Sensor,Status
  $Report.VMHost = $VMHostName
  $Report.Sensor = $Sensor.Name
  $Report.Status = $Sensor.HealthState.Key
  $Report
}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
Dave_Mishchenko
Immortal
Immortal
Jump to solution

Thank you Robert. I update the script to include the Reading column (divided by 100 to make the value match the real value).

$VMHostName = "esx01"
$HostView = Get-VMHost -Name $VMHostName | Get-View
$HealthStatusSystem = Get-View $HostView.ConfigManager.HealthStatusSystem
$SystemHealthInfo = $HealthStatusSystem.Runtime.SystemHealthInfo
ForEach ($Sensor in $SystemHealthInfo.NumericSensorInfo) {
 $Report = "" | Select-Object VMHost,Sensor,Status,Reading
 $Report.VMHost = $VMHostName
 $Report.Sensor = $Sensor.Name
 $Report.Status = $Sensor.HealthState.Key
 $Report.Reading = $Sensor.CurrentReading/100
 $Report
}

What's the best way to format the column widths? The Sensor column ends up truncated.

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The best way to format the column width is to pipe the output to:

Format-Table -AutoSize

The AutoSize parameter "Adjusts the column size and number of columns based on the width of the data. By default, the column size and number are determined by the view."

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
Dave_Mishchenko
Immortal
Immortal
Jump to solution

Thank you.

Reply
0 Kudos
AndersonSimplic
Contributor
Contributor
Jump to solution

Dave.Mishchenko Sorry, I didn't understand the Reading column