Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add version health #123

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion VMware.CloudFoundation.Reporting.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @()
Expand Down
94 changes: 91 additions & 3 deletions VMware.CloudFoundation.Reporting.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 <file-name>
This example extracts and formats the Version Health data as a PowerShell object from the JSON file.

.EXAMPLE
Publish-VersionHealth -json <file-name> -html
This example extracts and formats the Version Health data as an HTML object from the JSON file.

.EXAMPLE
Publish-VersionHealth -json <file-name> -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 '<a id="general-version"></a><h3>Version Health Status</h3>' -PostContent '<p>No issues found.</p>'
} else {
$outputObject = $outputObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-version"></a><h3>Version Health Status</h3>' -As Table
}
$outputObject = Convert-CssClass -htmldata $outputObject
} else {
$outputObject = $outputObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-version"></a><h3>Version Health Status</h3>' -PostContent '<p><strong>WARNING</strong>: Version data not found.</p>' -As Table
}
$outputObject
}
else {
$outputObject | Sort-Object Component, Resource
}
}
Catch {
Debug-CatchWriter -object $_
}
}
Export-ModuleMember -Function Publish-VersionHealth

Function Publish-ServiceHealth {
<#
.SYNOPSIS
Expand Down Expand Up @@ -8042,6 +8129,7 @@ Function Get-ClarityReportNavigation {
<label for="general">General</label>
<ul class="nav-list">
<li><a class="nav-link" href="#general-service">Service Health</a></li>
<li><a class="nav-link" href="#general-version">Version Health</a></li>
<li><a class="nav-link" href="#general-connectivity">Connectivity</a></li>
</ul>
</section>
Expand Down