PowerCLI – configure host dump-collector

There are a number of post showing how to setup VMware’s Dump Collector, once that is done the hosts need to be configured to point to the dump collector.

First check that you can connect to the dump collector

nc -z -u <your dump collector ip><port>

see the following kb for troubleshooting

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2003042

 

Jonathan Medd created a couple of really useful functions that can save a whole bunch of time;

http://www.jonathanmedd.net/2013/06/using-powercli-to-set-esxi-dump-collector-settings.html

If you are not sure how to add functions he even explains that;

http://www.jonathanmedd.net/2015/01/how-to-make-use-of-functions-in-powershell.html

Then all you need to do is run the following commands from powerCLI connected to the vcenter;

get-cluster <your cluster> | Get-VMHost| Get-VMHostDumpCollector | Format-Table VMHost,HostVNic,NetworkServerIP,NetworkServerPort,Enabled

get-cluster <your cluster> | Get-VMHost | Set-VMHostDumpCollector -HostVNic “vmk0” -NetworkServerIP “<your dump collector ip>” -NetworkServerPort 6500

 

 

[code language=”powershell”]
function Get-VMHostDumpCollector {
<#
 .SYNOPSIS
 Function to get the Dump Collector config of a VMHost.

 .DESCRIPTION
 Function to get the Dump Collector config of a VMHost.

 .PARAMETER VMHost
 VMHost to configure Dump Collector settings for.

.INPUTS
 String.
 System.Management.Automation.PSObject.

.OUTPUTS
 System.Management.Automation.PSObject.

.EXAMPLE
 PS> Get-VMHostDumpCollector -VMHost ESXi01

 .EXAMPLE
 PS> Get-VMHost ESXi01,ESXi02 | Get-VMHostDumpCollector
#>
[CmdletBinding()][OutputType(‘System.Management.Automation.PSObject’)]

Param
 (

[parameter(Mandatory=$true,ValueFromPipeline=$true)]
 [ValidateNotNullOrEmpty()]
 [PSObject[]]$VMHost
 )

begin {

 $DumpCollectorObject = @()
 }

 process {

 foreach ($ESXiHost in $VMHost){

try {

if ($ESXiHost.GetType().Name -eq "string"){

 try {
 $ESXiHost = Get-VMHost $ESXiHost -ErrorAction Stop
 }
 catch [Exception]{
 Write-Warning "VMHost $ESXiHost does not exist"
 }
 }

 elseif ($ESXiHost -isnot [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]){
 Write-Warning "You did not pass a string or a VMHost object"
 Return
 }

# — Get Dump Collector Config via ESXCli

$ESXCli = Get-EsxCli -VMHost $ESXiHost

$DumpCollector = $ESXCli.System.Coredump.Network.Get()

$hash = @{

 VMHost = $ESXiHost
 HostVNic = $DumpCollector.HostVNic
 NetworkServerIP = $DumpCollector.NetworkServerIP
 NetworkServerPort = $DumpCollector.NetworkServerPort
 Enabled = $DumpCollector.Enabled
 }
 $Object = New-Object PSObject -Property $hash
 $DumpCollectorObject += $Object

}
 catch [Exception]{

 throw "Unable to get Dump Collector config"
 }
 }
 }
 end {

 Write-Output $DumpCollectorObject
 }
}
[/code]

———————————–

[code language=”powershell”]
function Set-VMHostDumpCollector {
<#
 .SYNOPSIS
 Function to set the Dump Collector config of a VMHost.

 .DESCRIPTION
 Function to set the Dump Collector config of a VMHost.

 .PARAMETER VMHost
 VMHost to configure Dump Collector settings for.

.PARAMETER HostVNic
 VNic to use

.PARAMETER NetworkServerIP
 IP of the Dump Collector

.PARAMETER NetworkServerPort
 Port of the Dump Collector

.INPUTS
 String.
 System.Management.Automation.PSObject.

.OUTPUTS
 None.

.EXAMPLE
 PS> Set-VMHostDumpCollector -HostVNic "vmk0" -NetworkServerIP "192.168.0.100" -NetworkServerPort 6500 -VMHost ESXi01

 .EXAMPLE
 PS> Get-VMHost ESXi01,ESXi02 | Set-VMHostDumpCollector -HostVNic "vmk0" -NetworkServerIP "192.168.0.100" -NetworkServerPort 6500
#>
[CmdletBinding()]

Param
 (

[parameter(Mandatory=$true,ValueFromPipeline=$true)]
 [ValidateNotNullOrEmpty()]
 [PSObject[]]$VMHost,

[parameter(Mandatory=$true,ValueFromPipeline=$false)]
 [ValidateNotNullOrEmpty()]
 [String]$HostVNic,

[parameter(Mandatory=$true,ValueFromPipeline=$false)]
 [ValidateNotNullOrEmpty()]
 [String]$NetworkServerIP,

[parameter(Mandatory=$true,ValueFromPipeline=$false)]
 [ValidateNotNullOrEmpty()]
 [int]$NetworkServerPort
 )

begin {

 }

 process {

 foreach ($ESXiHost in $VMHost){

try {

if ($ESXiHost.GetType().Name -eq "string"){

 try {
 $ESXiHost = Get-VMHost $ESXiHost -ErrorAction Stop
 }
 catch [Exception]{
 Write-Warning "VMHost $ESXiHost does not exist"
 }
 }

 elseif ($ESXiHost -isnot [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]){
 Write-Warning "You did not pass a string or a VMHost object"
 Return
 }

# — Set the Dump Collector config via ESXCli
 Write-Verbose "Setting Dump Collector config for $ESXiHost"
 $ESXCli = Get-EsxCli -VMHost $ESXiHost

$ESXCli.System.Coredump.Network.Set($null, $HostVNic, $NetworkServerIP, $NetworkServerPort) | Out-Null
 $ESXCli.System.Coredump.Network.Set($true) | Out-Null

Write-Verbose "Successfully Set Dump Collector config for $ESXiHost"
 }
 catch [Exception]{

 throw "Unable to set Dump Collector config"
 }
 }
 }
 end {

 }
}

[/code]

 

If you want to see this in action, there is a command which when run from esxi console will force a PSOD.

DO NOT RUN THIS ON PRODUCTION SERVERS HOSTING VMS!

vsish -e set /reliability/crashMe/Panic 1


 

 

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.