lElOUCHE_79
Enthusiast
Enthusiast

Test vmkping within a cluster

due to a random issue we need to check the vmkping for the entire cluster.

I found the below script on the internet, and I would like to know if it's possible to reconfigure it to test ping on all interfaces and collect report

 

$esxcli = Get-EsxCli -VMHost (Get-VMHost "testesxihost") -V2

$params = $esxcli.network.diag.ping.CreateArgs()

$params.host = '10.1.1.2'

$params.interface = 'vmk0'

$params.size = '1472' #use 1472 for 1500 MTU or 8972 for 9000 MTU (VMware uses these values on MTU pings on ESXi)

$res = $esxcli.network.diag.ping.Invoke($params) $res.summary

Labels (3)
0 Kudos
7 Replies
LucD
Leadership
Leadership

You could do something like this.
I use the IP address of the my station, but you can change that to any IP address you want.

 

$myIP = (Get-NetIPConfiguration).IPv4Address.IPAddress

$sPing = @{
    host      = $myIP
    interface = ''
    size      = '1472'
}
$clusterName = 'cluster'

Get-Cluster -Name $clusterName |
    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        $esxcli = Get-EsxCli -VMHost $esx -V2
        $esxcli.network.ip.interface.list.Invoke() |
            ForEach-Object -Process {
                $sPing.interface = $_.Name
                $esxcli.network.diag.ping.Invoke($sPing) |
                    select @{N = 'Cluster'; E = { $clusterName } },
                    @{N = 'VMHost'; E = { $esx.Name } },
                    @{N = 'VMKernel'; E = { $sPing.interface } },
                    @{N = 'Target'; E = { $_.Summary.HostAddr } },
                    @{N = 'Transmitted'; E = { $_.Summary.Transmitted } },
                    @{N = 'Received'; E = { $_.Summary.Received } },
                    @{N = 'Lost'; E = { $_.Summary.PacketLost } },
                    @{N = 'RoundtripAvg'; E = { $_.Summary.RoundtripAvg } }
                }
            }

 


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

0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast

Thank you LucD 🙂

it's working fine except that it's pinging only vmk2 and not able to get a report.

it's possible to ping all vmkernel or no?

0 Kudos
LucD
Leadership
Leadership

My bad, I misplaced the closing curly brace for the inner loop.
The code above is corrected.


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

0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast

No issue LucD, now it's much better 🙂 

it's pinging all interfaces which is perfect, unfortunately I tried in multiple way to have the output in csv without success 😞

also I would like to know

the received argement is empty, is that OK?

the number that I fing in lost it's in percentage?

The RoundtripAvg it's the MTU Size?

0 Kudos
LucD
Leadership
Leadership

You can just pipe the result to Export-Csv.
No, my Received value shows the number of packets that were received back.
If there is an issue with the interface than you could see values different from 0.
The RoundTripAvg is time in 10-6 x seconds, or 10-3 x milliseconds.

$myIP = (Get-NetIPConfiguration).IPv4Address.IPAddress

$sPing = @{
    host      = $myIP
    interface = ''
    size      = '1472'
}
$clusterName = 'cluster'

Get-Cluster -Name $clusterName |
    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        $esxcli = Get-EsxCli -VMHost $esx -V2
        $esxcli.network.ip.interface.list.Invoke() |
            ForEach-Object -Process {
                $sPing.interface = $_.Name
                $esxcli.network.diag.ping.Invoke($sPing) |
                    select @{N = 'Cluster'; E = { $clusterName } },
                    @{N = 'VMHost'; E = { $esx.Name } },
                    @{N = 'VMKernel'; E = { $sPing.interface } },
                    @{N = 'Target'; E = { $_.Summary.HostAddr } },
                    @{N = 'Transmitted'; E = { $_.Summary.Transmitted } },
                    @{N = 'Received'; E = { $_.Summary.Received } },
                    @{N = 'Lost'; E = { $_.Summary.PacketLost } },
                    @{N = 'RoundtripAvg'; E = { $_.Summary.RoundtripAvg } }
                }
            } |
Export-Csv -path .\report.csv -NotypeInformation -UseCulture


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

0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast

then for sure there's something wrong in our network as the received packet is empty 🙂 

0 Kudos
LucD
Leadership
Leadership

Then you probably forgot the pipeline symbol (|) on the the second to last line


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

0 Kudos