-
Notifications
You must be signed in to change notification settings - Fork 0
/
vMotion_Connection_Check.ps1
255 lines (249 loc) · 11.5 KB
/
vMotion_Connection_Check.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# $DebugPreference = "Continue"
$DebugPreference = "SilentlyContinue"
$ScriptVersion = "2022.03.1.4"
$StartDate = Get-Date
#Select Number of Pings to perform per VMK test
[int]$NumOfPings = 2
Clear-Host
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
$reportPath = Join-Path $ScriptPath -ChildPath "Reports"
if(!(Test-Path $reportPath)){New-Item -Path $reportPath -ItemType Directory|Out-Null}
$dateSerial = Get-Date -Format yyyyMMddHHmmss
$reportName = "$dateSerial-vMotionReport.csv"
$ReportFile = Join-Path $reportPath -ChildPath $reportName
write-host ""
Write-Host ("="*80) -ForegroundColor DarkGreen
write-host "This Script will generate a list of all vMotion kernel IPs and cross check connectivity between them all"
write-host "A report will be generated and placed in the same location as this script"
write-host ""
write-host "Connect to all relavent vCenter instances before running this script" -ForegroundColor Yellow
Write-Host ("="*80) -ForegroundColor DarkGreen
write-host ""
$selectDC = New-Object System.Management.Automation.Host.ChoiceDescription "&Datacenter","CSV Listing of vCenter Datacenter(s)"
$selectCluster = New-Object System.Management.Automation.Host.ChoiceDescription "&Cluster","CSV list of vCenter Cluster(s)"
$selectHosts = New-Object System.Management.Automation.Host.ChoiceDescription "&Hosts","CSV list of multiple host names"
$selectAll = New-Object System.Management.Automation.Host.ChoiceDescription "&All","All Hosts in current connection"
$defaultPings = New-Object System.Management.Automation.Host.ChoiceDescription "&Default","Leave Ping count at $NumOfPings"
$changePings = New-Object System.Management.Automation.Host.ChoiceDescription "&Change","Increase or decrease the number of test pings"
$cancel = New-Object System.Management.Automation.Host.ChoiceDescription "&Exit","Eject! Eject! Eject!"
$title = "DC or All Hosts?";$message = "Run against a single Datacenter or All Hosts?"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($selectDC,$selectCluster,$selectHosts,$selectAll,$cancel)
$result = $host.UI.PromptForChoice($title, $message, $options, 1)
Write-Host ""
switch($result){
0{
$dcName = Read-Host -Prompt "Which vCenter Datacenter to check? (Comma seperated for multiple datacenters)"
if($dcName){
$dcList = $dcName -split ","
write-host "You have selected to check all vMotion adapters in:" -NoNewline
write-host $($dcList) -ForegroundColor Cyan
$vmhostList = Get-Datacenter $dcList|Get-VMHost|Where-Object{$_.ConnectionState -match "connected|maintenance"}|Sort-Object Parent,Name
}
else{
write-host "missing Datacenter name, please try again"
Exit-Script
}
}
1{
$clusterName = Read-Host -Prompt "Which vCenter Cluster to check? (Comma seperated for multiple clusters)"
if($clusterName){
$clusterList = $clusterName -split ","
write-host "You have selected to check all vMotion adapters in " -NoNewline
write-host $($clusterList) -ForegroundColor Cyan
$vmhostList = Get-Cluster $clusterList|Get-VMHost|Where-Object{$_.ConnectionState -match "connected|maintenance"}|Sort-Object Parent,Name
}
else{
write-host "missing Cluster name, please try again"
Exit-Script
}
}
2{
$hostNames = Read-Host -Prompt "Which vCenter ESXi Hosts to check? (Comma seperated for multiple host names)"
if($hostNames){
$hostnameList = $hostNames -split ","
if($hostnameList.count -ge 2){
write-host "You have selected to check all vMotion adapters for " -NoNewline
write-host $($hostnameList) -ForegroundColor Cyan
$vmhostList = Get-VMHost $hostnameList|Where-Object{$_.ConnectionState -match "connected|maintenance"}|Sort-Object Parent,Name
}
else{
write-host "Minumum of 2 ESXi hosts required to test vMotion" -ForegroundColor Yellow
Exit-Script
}
}
else{
write-host "missing host names, please try again"
Exit-Script
}
}
3{
write-host "You have opted to check every vMotion adapter in the currently connected vCenter instance(s)"
write-host "NOTE:" -ForegroundColor Red
Write-Host "This will generate a lot of failures trying to connect between CBO and Datacenter vMotion VLANs"
write-host "You will need to manually reconcile these failures afterwards to determine validity of communication failures."
$vmhostList = Get-VMHost|Where-Object{$_.ConnectionState -match "connected|maintenance"}|Sort-Object Parent,Name
}
4{
write-host "Cancelling"
Exit-Script
}
}
write-host ""
Write-Host ("="*80) -ForegroundColor DarkGreen
$title = "Change Ping Count?";$message = "Keep Default PING count of $NumOfPings or change number of pings to send?"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($defaultPings,$changePings)
$result = $host.UI.PromptForChoice($title, $message, $options, 0)
switch ($result){
0{
write-host "Testing with default PING count"
}
1{
write-host "You selected to change the test PING count. Provide an integer from 1-100"
write-host "*NOTE:" -ForegroundColor Yellow -NoNewline;write-host "Increasing the number of PINGs can greatly increase the time to test."
write-host "Modify this setting with caution."
[int]$NumOfPings = Read-Host -Prompt "Provide new number of Pings to test per VMK connection:"
}
}
write-host ""
write-host "Testing with " -NoNewline
write-host $NumOfPings -ForegroundColor Cyan -NoNewline
write-host " pings per VMK test"
Write-Host ("="*80) -ForegroundColor DarkGreen
write-host ""
$testCounter = $mtuCounter = $passCounter = $failCounter = 0
if($vmhostList.count -gt 0){
$hostCount = $vmhostList.count
write-host "Found " -NoNewline
write-host $vmhostList.count -ForegroundColor Cyan -NoNewline
write-host " hosts to check"
write-host ""
write-host "Collecting vMotion adapters"
$vMOadapters = $vmhostList|Get-VMHostNetworkAdapter -VMKernel|Where-Object{$_.VMotionEnabled}
$vmkCount = $vMOadapters.Count
write-host "Found " -NoNewline
write-host $vMOadapters.count -ForegroundColor Cyan -NoNewline
write-host " adapters to test communications on"
write-host ""
write-host "Beginning Host Testing, this can take a while depending on the number of hosts and vMotion Kernel ports..."
write-host $(Get-Date) -ForegroundColor Yellow
$vMotionReport = @()
$h = 1
$vmhostList|ForEach-Object{
$localVMHost = $_.Name
Write-Progress -Id 1 -Activity "Testing Host vMotion Connections | v$ScriptVersion | Started:$StartDate" -Status "$localVMHost [ $h of $hostCount ]" -PercentComplete (($h/$hostCount)*100);$h++
write-host "$(Get-Date -UFormat "%R")" -ForegroundColor Cyan -NoNewline
write-host `t" Testing " -NoNewline;write-host $localVMHost -ForegroundColor Cyan
$esxcli = Get-EsxCli -VMHost $_ -V2
$params = $esxcli.network.diag.ping.CreateArgs()
$localKernels = $_|Get-VMHostNetworkAdapter -VMKernel|Where-Object{$_.VMotionEnabled}
write-host "$(Get-Date -UFormat "%R")" -ForegroundColor Cyan -NoNewline
write-host `t`t"Found $($localKernels.count) local VMK to test"
$k = 1
$localKernels|foreach-Object{
Write-Progress -Id 2 -ParentId 1 -Activity "Testing Local VMK Ports" -Status "$($_.Name) [ $k of $($localKernels.count) ]" -PercentComplete (($k/$($localKernels.count))*100);$k++
$localVMK = $_.Name
$localVMKip = $_.IP
$localStack = $_.ExtensionData.Spec.NetstackInstanceKey
$localMTU = $_.Mtu
$v = 1
$vMOadapters|ForEach-Object{
if(!($_.IP -eq $localVMKip)){
$testCounter++
Write-Progress -Id 3 -ParentId 2 -Activity "Testing Remote VMK Ports" -Status "$($_.Name) on $($_.VMhost.Name) [ $v of $vmkCount ]" -PercentComplete (($v/$vmkCount)*100);$v++
if($localMTU -ne $_.Mtu){
write-host `t`t">> MTU MISMATCH <<" -ForegroundColor Yellow
$mtuMismatch = $true
$mtuCounter++
}
else{
$mtuMismatch = $false
}
$arrMTU = @($localMTU,$_.Mtu)
$maxMTU = ($arrMTU|Measure-Object -Minimum).Minimum
Write-Debug -Message "MTU: $maxMTU, from Local:$localMTU Remote:$($_.Mtu)"
if ($maxMTU -eq 1500) {
$thisPacket = '1472'
write-host `t`t">> NO JUMBOS <<" -ForegroundColor Yellow
}
else{
$thisPacket = '8972'
}
$params.host = $_.IP
$params.size = $thisPacket
$params.interface = $localVMK
$params.netstack = $localStack
$params.count = $NumOfPings
Write-Debug -Message "HOST: $($params.host)"
Write-Debug -Message "Size: $($params.size)"
Write-Debug -Message "VMK: $($params.interface)"
Write-Debug -Message "STCK: $($params.netstack)"
Write-Debug -Message "PINGs: $($params.count)"
$thisResult = $null;$error.Clear();$testErrorValue=""
try {
$thisResult = $esxcli.network.diag.ping.Invoke($params)
if($thisResult.Summary.PacketLost -eq 0){
$testPassed = $true
$passCounter++
}
else{
$testPassed = $false
write-host "$(Get-Date -UFormat "%R")" -ForegroundColor Cyan -NoNewline
write-host `t`t"FAIL: $localVMK $localVMKip >> $($params.interface) $($params.host) $($params.size)bytes" -ForegroundColor Red
$failCounter++
}
$packetStats = "$($thisResult.Summary.Transmitted);$($thisResult.Summary.Received);$($thisResult.Summary.PacketLost)"
}
catch {
if ($error.Exception.Message|ForEach-Object{$_ -like "*Network is unreachable*"}){
write-host "$(Get-Date -UFormat "%R")" -ForegroundColor Cyan -NoNewline
write-host `t`t"Network is unreachable: $localVMK $localVMKip >> $($params.interface) $($params.host)" -ForegroundColor Red
$testErrorValue = "Destination Newtork Unreachable"
}
else{
write-host "$(Get-Date -UFormat "%R")" -ForegroundColor Cyan -NoNewline
write-host `t`t"ESXCLI Error: $localVMK $localVMKip >> $($params.interface) $($params.host)" -ForegroundColor Red
$testErrorValue = "Unknown"
}
}
$columnList = @('SourceHost','SourceVMK','SourceIP','SourceMTU','DestinationHost','DestinationVMK','DestinationIP','DestinationMTU','PacketSize','testPassed','Stats T/R/L','mtuMismatch','Error')
$row = ""|Select-Object $columnList
$row.SourceHost = $localVMHost
$row.SourceVMK = $localVMK
$row.SourceIP = $localVMKip
$row.SourceMTU = $localMTU
$row.DestinationHost = $_.VMhost
$row.DestinationVMK = $_.Name
$row.DestinationIP = $_.IP
$row.DestinationMTU = $_.Mtu
$row.PacketSize = $thisPacket
$row.mtuMismatch = $mtuMismatch
$row.Error = $testErrorValue
if($thisResult){
$row.testPassed = $testPassed
$row."Stats T/R/L" = $packetStats
}
else{
$row.testPassed = $false
$row."Stats T/R/L" = ""
}
$vMotionReport += $row
}
else{write-debug -Message "Self-Test, skipping"}
}
}
}
write-host ""
Write-Host ("="*80) -ForegroundColor DarkGreen
write-host "Passed: " -NoNewline;write-host $passCounter -ForegroundColor Green
write-host "Failed: " -NoNewline;write-host $failCounter -ForegroundColor Red
write-host "FailurePercent: " -NoNewline;write-host "$([math]::Round((($failCounter/$testCounter)*100),1))" -ForegroundColor Cyan
write-host "Number of MTU Mismatch connections: " -NoNewline;write-host $mtuCounter -ForegroundColor Cyan
Write-Host ("="*80) -ForegroundColor DarkGreen
write-host "Saving Report to Disk:"
write-host $ReportFile -foregroundColor Cyan
$vMotionReport|Export-Csv -NoTypeInformation $ReportFile
}
else{
write-host "No Hosts found, check connection to vCenter and try again."
Exit-Script
}