Automation

 View Only
Expand all | Collapse all

Scripts to obtain Health Status information

  • 1.  Scripts to obtain Health Status information

    Posted May 02, 2010 09:55 AM

    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.



  • 2.  RE: Scripts to obtain Health Status information

    Posted May 02, 2010 10:19 AM

    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



  • 3.  RE: Scripts to obtain Health Status information

    Posted May 02, 2010 10:24 AM

    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



  • 4.  RE: Scripts to obtain Health Status information

    Broadcom Employee
    Posted May 02, 2010 06:53 PM

    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%20Software%20Status-1 (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".



  • 5.  RE: Scripts to obtain Health Status information

    Posted May 02, 2010 07:20 PM

    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.



  • 6.  RE: Scripts to obtain Health Status information

    Posted May 02, 2010 08:18 PM

    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



  • 7.  RE: Scripts to obtain Health Status information
    Best Answer

    Posted May 02, 2010 08:24 PM

    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
    }
    



  • 8.  RE: Scripts to obtain Health Status information

    Posted May 02, 2010 09:51 PM

    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.



  • 9.  RE: Scripts to obtain Health Status information

    Posted May 03, 2010 06:17 AM

    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."



  • 10.  RE: Scripts to obtain Health Status information

    Posted May 03, 2010 08:51 AM

    Thank you.



  • 11.  RE: Scripts to obtain Health Status information

    Posted Apr 03, 2020 04:07 PM

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