diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b1a7fc9..2a8681b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Enhancement: - Added `Publish-HardwareCompatibilityHealth` to return the hardware compatibilty health from the SoS Health Summary JSON data. [GH-129](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/129) - Updated `Invoke-VcfHealthReport` to include the hardware compatibility health using the `Publish-HardwareCompatibilityHealth` cmdlet. [GH-129](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/129) - Added component size checks for vCenter Server instances and NSX Local Manager clusters to the overview report. [GH-130](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/130) +- Added `Publish-PingConnectivityHealth` to return the ping connectivity health from the SoS Health Summary JSON data. [GH-132](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/132) +- Updated `Publish-ComponentConnectivityHealth` to include the ping connectivity health using the `Publish-PingConnectivityHealth` cmdlet. [GH-132](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/132) ## [v2.0.0](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/releases/tag/v2.0.0) diff --git a/VMware.CloudFoundation.Reporting.psd1 b/VMware.CloudFoundation.Reporting.psd1 index c01192f9..197a0b7c 100644 --- a/VMware.CloudFoundation.Reporting.psd1 +++ b/VMware.CloudFoundation.Reporting.psd1 @@ -12,7 +12,7 @@ RootModule = '.\VMware.CloudFoundation.Reporting.psm1' # Version number of this module. - ModuleVersion = '2.1.0.1002' + ModuleVersion = '2.1.0.1004' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/VMware.CloudFoundation.Reporting.psm1 b/VMware.CloudFoundation.Reporting.psm1 index 18e1ecef..df9cf3ab 100644 --- a/VMware.CloudFoundation.Reporting.psm1 +++ b/VMware.CloudFoundation.Reporting.psm1 @@ -1145,6 +1145,91 @@ Function Publish-ConnectivityHealth { } Export-ModuleMember -Function Publish-ConnectivityHealth +Function Publish-PingConnectivityHealth { + <# + .SYNOPSIS + Formats the Ping Connectivity Health data from the SoS JSON output. + + .DESCRIPTION + The Publish-PingConnectivityHealth cmdlet formats the Ping Connectivity Health data from the SoS JSON output and + publishes it as either a standard PowerShell object or an HTML object. + + .EXAMPLE + Publish-PingConnectivityHealth -json + This example extracts and formats the Ping Connectivity Health data as a PowerShell object from the JSON file. + + .EXAMPLE + Publish-PingConnectivityHealth -json -html + This example extracts and formats the Ping Connectivity Health data as an HTML object from the JSON file. + + .EXAMPLE + Publish-PingConnectivityHealth -json -failureOnly + This example extracts and formats the Ping Connectivity Health data as a PowerShell object from the JSON file for only the failed items. + #> + + Param ( + [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$json, + [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [Switch]$html, + [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [Switch]$failureOnly + ) + + Try { + if (!(Test-Path -Path $json)) { + Write-Error "Unable to find JSON file at location ($json)" -ErrorAction Stop + } else { + $targetContent = Get-Content $json | ConvertFrom-Json + } + + $customObject = New-Object System.Collections.ArrayList + $jsonInputData = $targetContent.Connectivity.'Ping Status' + $pingStatusProperties = @('area', 'title', 'state', 'timestamp', 'message', 'status', 'alert') + + if (($jsonInputData | Measure-Object).Count -lt 1) { + Write-Warning 'Ping Status data not found in the JSON file: SKIPPED' + } else { + $esxiHosts = Get-VCFHost + foreach ($esxiHost in $esxiHosts) { + $fqdn = $esxiHost.fqdn + $propertiesName = $jsonInputData.$fqdn.PSObject.Properties.Name + if (($pingStatusProperties.contains($propertiesName))) { + # do nothing + } else { + $jsonInputData.$fqdn = $jsonInputData.$fqdn.$propertiesName + } + } + + if ($PsBoundParameters.ContainsKey('failureOnly')) { + $outputObject = Read-JsonElement -inputData $jsonInputData -failureOnly + } else { + $outputObject = Read-JsonElement -inputData $jsonInputData + } + $customObject += $outputObject + } + + # Return the structured data to the console or format using HTML CSS Styles + if ($PsBoundParameters.ContainsKey('html')) { + if (($jsonInputData | Measure-Object).Count -gt 0) { + if ($outputObject.Count -eq 0) { $addNoIssues = $true } + if ($addNoIssues) { + $customObject = $customObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '

Ping Connectivity Health Status

' -PostContent '

No issues found.

' + } else { + $customObject = $customObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '

Ping Connectivity Health Status

' -As Table + } + $customObject = Convert-CssClass -htmldata $customObject + } else { + $customObject = $customObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '

Ping Connectivity Health Status

' -PostContent '

WARNING: Ping Status data not found.

' -As Table + } + $customObject + } else { + $customObject | Sort-Object Component, Resource + } + } + Catch { + Debug-CatchWriter -object $_ + } +} +Export-ModuleMember -Function Publish-PingConnectivityHealth + Function Publish-DnsHealth { <# .SYNOPSIS @@ -4698,7 +4783,8 @@ Function Publish-ComponentConnectivityHealth { $vcenterConnectivity = Request-VcenterAuthentication -server $server -user $user -pass $pass -workloadDomain $workloadDomain -failureOnly; $allConnectivityObject += $vcenterConnectivity $NsxtConnectivity = Request-NsxtAuthentication -server $server -user $user -pass $pass -workloadDomain $workloadDomain -failureOnly; $allConnectivityObject += $NsxtConnectivity } - $connectivityRaw = Publish-ConnectivityHealth -json $json -failureOnly + $apiSshConnectivity = Publish-ConnectivityHealth -json $json -failureOnly + $pingConnectivity = Publish-PingConnectivityHealth -json $json -failureOnly } else { if ($PsBoundParameters.ContainsKey("allDomains")) { $vcenterConnectivity = Request-VcenterAuthentication -server $server -user $user -pass $pass -alldomains; $allConnectivityObject += $vcenterConnectivity @@ -4707,14 +4793,16 @@ Function Publish-ComponentConnectivityHealth { $vcenterConnectivity = Request-VcenterAuthentication -server $server -user $user -pass $pass -workloadDomain $workloadDomain; $allConnectivityObject += $vcenterConnectivity $NsxtConnectivity = Request-NsxtAuthentication -server $server -user $user -pass $pass -workloadDomain $workloadDomain; $allConnectivityObject += $NsxtConnectivity } - $connectivityRaw = Publish-ConnectivityHealth -json $json + $apiSshConnectivity = Publish-ConnectivityHealth -json $json + $pingConnectivity = Publish-PingConnectivityHealth -json $json } - $allConnectivityObject += $connectivityRaw + $allConnectivityObject += $apiSshConnectivity + $allConnectivityObject += $pingConnectivity if ($allConnectivityObject.Count -eq 0) { $addNoIssues = $true } if ($addNoIssues) { - $allConnectivityObject = $allConnectivityObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '

Connectivity Health Status

' -PostContent '

No issues found.

' + $allConnectivityObject = $allConnectivityObject | Sort-Object Component, Resource, Message | ConvertTo-Html -Fragment -PreContent '

Connectivity Health Status

' -PostContent '

No issues found.

' } else { - $allConnectivityObject = $allConnectivityObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '

Connectivity Health Status

' -As Table + $allConnectivityObject = $allConnectivityObject | Sort-Object Component, Resource, Message | ConvertTo-Html -Fragment -PreContent '

Connectivity Health Status

' -As Table } $allConnectivityObject = Convert-CssClass -htmldata $allConnectivityObject $allConnectivityObject