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 hardware compatibility checks #129

Merged
merged 4 commits into from
Apr 25, 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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## [v2.1.0](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/releases/tag/v2.1.0)

> Release Date: Unreleased

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)

## [v2.0.0](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/releases/tag/v2.0.0)

> Release Date: 2023-04-25
Expand Down
6 changes: 3 additions & 3 deletions VMware.CloudFoundation.Reporting.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Gary Blake, Cloud Infrastructure Business Group (CIBG)
#
# Generated on: 04/25/2023
# Generated on: 05/30/2023
#

@{
Expand All @@ -12,13 +12,13 @@
RootModule = '.\VMware.CloudFoundation.Reporting.psm1'

# Version number of this module.
ModuleVersion = '2.0.0.1013'
ModuleVersion = '2.1.0.1001'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = '603813a8-4f36-424a-be6a-f2914f987961'
GUID = '046bcd4d-209a-4520-87f5-080650399a43'

# Author of this module
Author = 'Gary Blake, Ryan Johnson, Ivaylo Ivanov, Antony Stefanov - Cloud Infrastructure Business Group (CIBG)'
Expand Down
103 changes: 103 additions & 0 deletions VMware.CloudFoundation.Reporting.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ Function Invoke-VcfHealthReport {
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 Hardware Compatibility Health Data Using the SoS Data
Write-LogMessage -type INFO -Message "Generating the Hardware Compatibility Health Report using the SoS output for $workflowMessage."
$hardwareCompatibilityHtml = Invoke-Expression "Publish-HardwareCompatibilityHealth -json $jsonFilePath -html $($failureOnlySwitch)"; $reportData += $hardwareCompatibilityHtml

# 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
Expand Down Expand Up @@ -1842,6 +1846,102 @@ Function Publish-VersionHealth {
}
Export-ModuleMember -Function Publish-VersionHealth

Function Publish-HardwareCompatibilityHealth {
<#
.SYNOPSIS
Formats the Hardware Compatibility data from the SoS JSON output.

.DESCRIPTION
The Publish-HardwareCompatibilityHealth cmdlet formats the Hardware Compatibility data from the SoS JSON output and publishes
it as either a standard PowerShell object or an HTML object.

.EXAMPLE
Publish-HardwareCompatibilityHealth -json <file-name>
This example extracts and formats the Hardware Compatibility data as a PowerShell object from the JSON file.

.EXAMPLE
Publish-HardwareCompatibilityHealth -json <file-name> -html
This example extracts and formats the Hardware Compatibility data as an HTML object from the JSON file.

.EXAMPLE
Publish-HardwareCompatibilityHealth -json <file-name> -failureOnly
This example extracts and formats the Hardware Compatibility 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
}

# Hardware Compatibility
$jsonInputData = $targetContent.'Hardware Compatibility' # Extract Data from the provided SOS JSON
if (($jsonInputData | Measure-Object).Count -lt 1) {
Write-Warning 'Hardware Compatibility not found in the JSON file: SKIPPED'
}
else {
$outputObject = New-Object System.Collections.ArrayList
foreach ($component in $jsonInputData.PsObject.Properties.Value) {
foreach ($element in $component.PsObject.Properties.Value) {
if ($element.title -ne '-' -and $element.alert -ne '-') {
$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 'Alert' -NotePropertyValue $element.alert

$message = $element.message
$fixupMessage = $message.Replace('is Successul', 'is successful')

$elementObject | Add-Member -NotePropertyName 'Message' -NotePropertyValue $fixupMessage
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-hardware"></a><h3>Hardware Compatibility Health Status</h3>' -PostContent '<p>No issues found.</p>'
}
else {
$outputObject = $outputObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-hardware"></a><h3>Hardware Compatibility Health Status</h3>' -As Table
}
$outputObject = Convert-CssClass -htmlData $outputObject
}
else {
$outputObject = $outputObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-hardware"></a><h3>Hardware Compatibility Health Status</h3>' -PostContent '<p><strong>WARNING</strong>: Hardware compatibility data not found.</p>' -As Table
}
$outputObject
}
else {
$outputObject | Sort-Object Component, Resource
}
}
Catch {
Debug-CatchWriter -object $_
}
}
Export-ModuleMember -Function Publish-HardwareCompatibilityHealth

Function Publish-ServiceHealth {
<#
.SYNOPSIS
Expand Down Expand Up @@ -8102,6 +8202,7 @@ Function Get-ClarityReportHeader {
.alertOK { color: #61B715; font-weight: bold }
.alertWarning { color: #FDD008; font-weight: bold }
.alertCritical { color: #F55047; font-weight: bold }
.alertSkipped { font-weight: bold }
.table th, .table td { text-align: left; }

:root { --cds-global-base: 20; }
Expand Down Expand Up @@ -8454,6 +8555,8 @@ Function Convert-CssClass {
$newAlertCritical = '<td class="alertCritical">RED</td>'
$oldAlertWarning = '<td>YELLOW</td>'
$newAlertWarning = '<td class="alertWarning">YELLOW</td>'
$oldAlertSkipped = '<td>SKIPPED/td>'
$newAlertSkipped = '<td class="alertSkipped">SKIPPED</td>'
$oldTable = '<table>'
$newTable = '<table class="table">'
$oldAddLine = ':-: '
Expand Down