Private/Checks/Vsan/Test-VcfVsanWitnessnodeVersion.ps1
|
# Copyright (c) 2026 Broadcom. All Rights Reserved. # Broadcom Confidential. The term "Broadcom" refers to Broadcom Inc. # and/or its subsidiaries. # # ============================================================================= # # SOFTWARE LICENSE AGREEMENT # # Copyright (c) CA, Inc. All rights reserved. # # You are hereby granted a non-exclusive, worldwide, royalty-free license # under CA, Inc.'s copyrights to use, copy, modify, and distribute this # software in source code or binary form for use in connection with CA, Inc. # products. # # This copyright notice shall be included in all copies or substantial # portions of the software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # # ============================================================================= function Test-VcfVsanWitnessnodeVersion { <# .SYNOPSIS Checks that the vSAN witness host ESX build matches data hosts on stretched vSAN clusters across all vCenter domains. .DESCRIPTION Queries stretched vSAN cluster configurations and ESX host inventories across all vCenter appliances connected to SDDC Manager using Get-VcfCheckVsanClusterConfig and Get-VcfCheckVMHostInventory. Compares ESX build versions between the witness host and data hosts in each stretched cluster: - Pass: All stretched vSAN clusters have a reported witness host whose ESX build matches the data hosts. - Warning: One or more stretched clusters have no reported witness host reference. - Fail: ESX build mismatches are detected between witness hosts and data hosts. - Skipped: No stretched vSAN clusters are configured on the target vCenter. Populates a structured Rows table detailing ClusterName, WitnessHostName/HostName, Build/WitnessHostBuild, HostType, and Matches. Delegates per-vCenter execution and per-domain outcome packaging to Invoke-VcfCheckPerVCenterCheck. .PARAMETER Context The VcfCheck.Context object. Must already be connected to SDDC Manager. .PARAMETER DisplayName Optional friendly display name for the check result. .OUTPUTS [PSObject[]] Per-vCenter check results generated by Invoke-VcfCheckPerVCenterCheck. #> [CmdletBinding()] [OutputType([PSObject])] Param ( [Parameter(Mandatory = $true)] [PSObject]$Context, [Parameter(Mandatory = $false)] [String]$DisplayName = '' ) return Invoke-VcfCheckPerVCenterCheck -Context $Context -CheckId 'vsan_witnessnode_version' -Area vSAN -DisplayName $DisplayName -Body { param($Context, $VCenterFqdn) $configs = @(Get-VcfCheckVsanClusterConfig -Server $VCenterFqdn | Where-Object { $_.StretchedClusterEnabled }) $allHosts = @(Get-VcfCheckVMHostInventory -Server $VCenterFqdn) if ($configs.Count -eq 0) { return [PSCustomObject]@{ Status = 'Skipped'; Detail = 'No vSAN Witness detected.'; SkipReasonTag = 'No vSAN Witness detected'; Rows = @() } } $mismatches = [System.Collections.Generic.List[String]]::new() $missingWitnesses = [System.Collections.Generic.List[String]]::new() $rows = [System.Collections.Generic.List[Object]]::new() foreach ($config in $configs) { if (-not $config.WitnessHost) { $missingWitnesses.Add($config.Cluster.Name) continue } $dataHosts = @($allHosts | Where-Object { $_.Parent.Name -eq $config.Cluster.Name -and $_.Name -ne $config.WitnessHost.Name }) $mismatchedHosts = @($dataHosts | Where-Object { $_.Build -ne $config.WitnessHost.Build }) $rows.Add([PSCustomObject]@{ ClusterName = $config.Cluster.Name WitnessHostName = $config.WitnessHost.Name WitnessHostBuild = $config.WitnessHost.Build }) foreach ($dataHost in $dataHosts) { $rows.Add([PSCustomObject]@{ ClusterName = $config.Cluster.Name HostType = 'Data' HostName = $dataHost.Name Build = $dataHost.Build Matches = $dataHost.Build -eq $config.WitnessHost.Build }) } if ($mismatchedHosts.Count -gt 0) { $mismatches.Add("$($config.Cluster.Name): witness build $($config.WitnessHost.Build) vs. data host build(s) $(($mismatchedHosts | ForEach-Object { $_.Build } | Select-Object -Unique) -join ', ')") } } $rows = $rows.ToArray() if ($mismatches.Count -gt 0) { $filteredRows = @($rows | Where-Object { $_.Matches -eq $false }) $detail = $mismatches -join '; ' if ($missingWitnesses.Count -gt 0) { $detail += "; stretched cluster(s) with no witness host reported: $($missingWitnesses -join ', ')." } return [PSCustomObject]@{ Status = 'Fail'; Detail = $detail; Rows = $filteredRows } } if ($missingWitnesses.Count -gt 0) { $detail = "Stretched cluster(s) with no witness host reported: $($missingWitnesses -join ', ')." return [PSCustomObject]@{ Status = 'Warning'; Detail = $detail; Rows = $rows } } return [PSCustomObject]@{ Status = 'Pass'; Detail = "Checked $($configs.Count) stretched cluster(s); witness host build matches data hosts."; Rows = $rows } } } |