From 7801bed41866d2b870c255a5500abdd035d2a669 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 13 Apr 2023 13:25:00 -0400 Subject: [PATCH] feat: add version health - Added `Publish-VersionHealth` to return the version health from the SoS Health Summary JSON data. - Updated `Invoke-VcfHealthReport` to include the version health using the `Publish-VersionHealth` cmdlet. - Fix typos. - Bumps the module version to v2.0.0.1008. - Updates `CHANGELOG.md`. Ref: #41 Signed-off-by: Ryan Johnson --- CHANGELOG.md | 2 + VMware.CloudFoundation.Reporting.psd1 | 2 +- VMware.CloudFoundation.Reporting.psm1 | 94 ++++++++++++++++++++++++++- 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c24132ab..c71867d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ Enhancement: - Updated `Publish-CertificateHealth` to include an "Expires In (Days)" column. [GH-107](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/107) - Updated `Publish-CertificateHealth` to include ESXi host certificates. [GH-107](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/107) - Updated `Publish-PasswordHealth` to include an "Expires In (Days)" column. [GH-111](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/111) +- Added `Publish-VersionHealth` to return the version health from the SoS Health Summary JSON data. +- Updated `Invoke-VcfHealthReport` to include the version health using the `Publish-VersionHealth` cmdlet. - Added `Show-ReportingOutput` cmdlet to format output to the console when `PowerVCF` is not installed. [GH-121](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/121) Refactor: diff --git a/VMware.CloudFoundation.Reporting.psd1 b/VMware.CloudFoundation.Reporting.psd1 index 34cb4833..a06c5c38 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.0.0.1007' + ModuleVersion = '2.0.0.1008' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/VMware.CloudFoundation.Reporting.psm1 b/VMware.CloudFoundation.Reporting.psm1 index 6d69df24..5e6bc9bd 100644 --- a/VMware.CloudFoundation.Reporting.psm1 +++ b/VMware.CloudFoundation.Reporting.psm1 @@ -125,11 +125,15 @@ Function Invoke-VcfHealthReport { Write-LogMessage -Type INFO -Message "Generating the Service Health Report using the SoS output for $workflowMessage." $serviceHtml = Invoke-Expression "Publish-ServiceHealth -json $jsonFilePath -html $($failureOnlySwitch)"; $reportData += $serviceHtml - # Generating the Connectivity Health Data Using SoS Data and Supplimental PowerShell Request Functions + # Generating the Version Health Data Using the SoS Data + Write-LogMessage -Type INFO -Message "Generating the Version Health Report using the SoS output for $workflowMessage." + $versionHtml = Invoke-Expression "Publish-VersionHealth -json $jsonFilePath -html $($failureOnlySwitch)"; $reportData += $versionHtml + + # Generating the Connectivity Health Data Using SoS Data and Supplemental PowerShell Request Functions Write-LogMessage -Type INFO -Message "Generating the Connectivity Health Report using the SoS output for $workflowMessage." $componentConnectivityHtml = Invoke-Expression "Publish-ComponentConnectivityHealth -server $sddcManagerFqdn -user $sddcManagerUser -pass $sddcManagerPass -json $jsonFilePath $($commandSwitch) $($failureOnlySwitch)"; $reportData += $componentConnectivityHtml - # Generating the Password Expiry Health Data Using PowerShell Request Functions + # Generating the Password Expiry Health Data Using the SoS Data Write-LogMessage -Type INFO -Message "Generating the Password Expiry Report for $workflowMessage." $passwordHtml = Invoke-Expression "Publish-PasswordHealth -json $jsonFilePath -html $($failureOnlySwitch)"; $reportData += $passwordHtml @@ -177,7 +181,7 @@ Function Invoke-VcfHealthReport { Write-LogMessage -Type INFO -Message "Generating the vSAN Storage Policy Health Report using the SoS output for $workflowMessage." $vsanPolicyHtml = Invoke-Expression "Publish-VsanStoragePolicy -json $jsonFilePath -html $($failureOnlySwitch)"; $reportData += $vsanPolicyHtml - # Generating the NSX Manager Health Data Using SoS output and Supplimental PowerShell Request Functions + # Generating the NSX Manager Health Data Using SoS output and Supplemental PowerShell Request Functions Write-LogMessage -Type INFO -Message "Generating the NSX-T Data Center Health Report using the SoS output for $workflowMessage." $nsxtHtml = Invoke-Expression "Publish-NsxtCombinedHealth -server $sddcManagerFqdn -user $sddcManagerUser -pass $sddcManagerPass -json $jsonFilePath $($commandSwitch) $($failureOnlySwitch)"; $reportData += $nsxtHtml @@ -1755,6 +1759,89 @@ Function Publish-PasswordHealth { } Export-ModuleMember -Function Publish-PasswordHealth +Function Publish-VersionHealth { + <# + .SYNOPSIS + Formats the Version Health data from the SoS JSON output. + + .DESCRIPTION + The Publish-VersionHealth cmdlet formats the Version Health data from the SoS JSON output and publishes it as + either a standard PowerShell object or an HTML object. + + .EXAMPLE + Publish-VersionHealth -json + This example extracts and formats the Version Health data as a PowerShell object from the JSON file. + + .EXAMPLE + Publish-VersionHealth -json -html + This example extracts and formats the Version Health data as an HTML object from the JSON file. + + .EXAMPLE + Publish-VersionHealth -json -failureOnly + This example extracts and formats the Version 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 + } + + # Version Health + $jsonInputData = $targetContent.'Version Check Status' # Extract Data from the provided SOS JSON + if (($jsonInputData | Measure-Object).Count -lt 1) { + Write-Warning 'Version Check Status not found in the JSON file: SKIPPED' + } else { + $outputObject = New-Object System.Collections.ArrayList + foreach ($element in $jsonInputData.PsObject.Properties.Value) { + $elementObject = New-Object -TypeName psobject + $elementObject | Add-Member -NotePropertyName 'Component' -NotePropertyValue ($element.area -Split (':'))[0].Trim() + $elementObject | Add-Member -NotePropertyName 'Resource' -NotePropertyValue ($element.area -Split (':'))[-1].Trim() + $elementObject | Add-Member -NotePropertyName 'Version' -NotePropertyValue $element.title[0] + $elementObject | Add-Member -NotePropertyName 'Alert' -NotePropertyValue $element.alert + $elementObject | Add-Member -NotePropertyName 'Message' -NotePropertyValue $element.message + if ($PsBoundParameters.ContainsKey('failureOnly')) { + if (($element.status -eq 'FAILED')) { + $outputObject += $elementObject + } + } + else { + $outputObject += $elementObject + } + } + } + + if ($PsBoundParameters.ContainsKey('html')) { + if (($jsonInputData | Measure-Object).Count -gt 0) { + if ($outputObject.Count -eq 0) { $addNoIssues = $true } + if ($addNoIssues) { + $outputObject = $outputObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '

Version Health Status

' -PostContent '

No issues found.

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

Version Health Status

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

Version Health Status

' -PostContent '

WARNING: Version data not found.

' -As Table + } + $outputObject + } + else { + $outputObject | Sort-Object Component, Resource + } + } + Catch { + Debug-CatchWriter -object $_ + } +} +Export-ModuleMember -Function Publish-VersionHealth + Function Publish-ServiceHealth { <# .SYNOPSIS @@ -8042,6 +8129,7 @@ Function Get-ClarityReportNavigation {