Skip to content

Commit 4b1d28d

Browse files
authored
Improve output generated for Debug-SdnFabricInfrastructure (#534)
This pull request updates the health reporting logic in `src/modules/SdnDiag.Health.psm1` to standardize the severity terminology from `WARN` to `WARNING`, improves the health validation output formatting, and enhances the overall health report summary for SDN diagnostics. The changes also add color-coded output and a clear report header/footer for better readability. **Severity and terminology standardization:** * Changed all references and logic from `WARN` to `WARNING` for health test results, including allowed values and result aggregation in all relevant functions (`New-SdnHealthTest`, `New-SdnRoleHealthReport`, `New-SdnFabricHealthReport`, and all diagnostic functions). [[1]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L226-R226) [[2]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60R242-R245) [[3]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L261-R262) [[4]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L519-L531) [[5]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L656-R728) [[6]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L724-R796) [[7]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L770-R842) [[8]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L1083-R1150) [[9]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L1380-R1447) **Reporting and output improvements:** * Added a severity parameter to `Write-HealthValidationInfo`, which sets the output color based on severity and displays severity in the report. Output color is now dynamically set to yellow for `WARNING` and red for `FAIL`. [[1]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L292-R308) [[2]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60R317-R320) [[3]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L320-R335) [[4]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L557-R630) * Implemented a formatted report header and footer, and a summary section showing tested roles, nodes, timestamp, and overall health state with color coding. **Logic enhancements:** * Improved aggregation logic to ensure the worst-case health state is reflected (FAIL > WARNING > PASS) and summary is displayed accordingly. **Remediation and messaging:** * Updated remediation messages for clarity and consistency, especially in adapter performance settings and DNS resolution failures. [[1]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L995-R1062) [[2]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L1891-R1958) These changes make the health reporting more consistent, readable, and user-friendly for diagnosing SDN environments. <img width="1306" height="826" alt="image" src="https://github.com/user-attachments/assets/d8063554-1e29-4244-8bf3-d4cbce6ac6b8" /> # Change type - [x] Bug fix (non-breaking change) - [ ] Code style update (formatting, local variables) - [x] New Feature (non-breaking change that adds new functionality without impacting existing) - [x] Breaking change (fix or feature that may cause functionality impact) - [ ] Other # Checklist: - [x] My code follows the style and contribution guidelines of this project. - [x] I have tested and validated my code changes.
1 parent f1a76af commit 4b1d28d

File tree

1 file changed

+107
-30
lines changed

1 file changed

+107
-30
lines changed

src/modules/SdnDiag.Health.psm1

Lines changed: 107 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function New-SdnHealthTest {
223223

224224
$object = [PSCustomObject]@{
225225
Name = $Name
226-
Result = 'PASS' # default to PASS. Allowed values are PASS, WARN, FAIL
226+
Result = 'PASS' # default to PASS. Allowed values are PASS, WARNING, FAIL
227227
OccurrenceTime = [System.DateTime]::UtcNow
228228
Properties = @()
229229
Remediation = @()
@@ -239,9 +239,10 @@ function New-SdnRoleHealthReport {
239239
)
240240

241241
$object = [PSCustomObject]@{
242+
242243
Role = $Role
243244
ComputerName = $env:COMPUTERNAME
244-
Result = 'PASS' # default to PASS. Allowed values are PASS, WARN, FAIL
245+
Result = 'PASS' # default to PASS. Allowed values are PASS, WARNING, FAIL
245246
OccurrenceTime = [System.DateTime]::UtcNow
246247
HealthTest = @() # array of New-SdnHealthTest objects
247248
}
@@ -258,7 +259,7 @@ function New-SdnFabricHealthReport {
258259
$object = [PSCustomObject]@{
259260
OccurrenceTime = [System.DateTime]::UtcNow
260261
Role = $Role
261-
Result = 'PASS' # default to PASS. Allowed values are PASS, WARN, FAIL
262+
Result = 'PASS' # default to PASS. Allowed values are PASS, WARNING, FAIL
262263
RoleTest = @() # array of New-SdnRoleHealthReport objects
263264
}
264265

@@ -289,9 +290,22 @@ function Write-HealthValidationInfo {
289290
[String]$Name,
290291

291292
[Parameter(Mandatory = $false)]
292-
[String[]]$Remediation
293+
[String[]]$Remediation,
294+
295+
[Parameter(Mandatory = $false)]
296+
[ValidateSet('WARNING', 'FAIL')]
297+
[string]$Severity
293298
)
294299

300+
switch ($Severity) {
301+
'WARNING' {
302+
$foregroundColor = 'Yellow'
303+
}
304+
'FAIL' {
305+
$foregroundColor = 'Red'
306+
}
307+
}
308+
295309
$details = Get-HealthData -Property 'HealthValidations' -Id $Name
296310

297311
$outputString += "`r`n`r`n"
@@ -300,10 +314,11 @@ function Write-HealthValidationInfo {
300314
$outputString += "`r`n`r`n"
301315
$outputString += "Description:`t$($details.Description)`r`n"
302316
$outputString += "Impact:`t`t$($details.Impact)`r`n"
317+
$outputString += "Severity:`t$Severity`r`n"
303318

304319
if (-NOT [string]::IsNullOrEmpty($Remediation)) {
305-
if ($Remediation -ieq [array]) {
306-
$outputString += "Remediation:`r`n`t- $($Remediation -join "`r`n`t - ")`r`n"
320+
if ($Remediation -is [System.Collections.ICollection] -or $Remediation -is [System.Array]) {
321+
$outputString += "Remediation:`r`n`t- $($Remediation -join "`r`n`t- ")`r`n"
307322
}
308323
else {
309324
$outputString += "Remediation:`t$Remediation`r`n"
@@ -317,8 +332,7 @@ function Write-HealthValidationInfo {
317332
}
318333

319334
$outputString += "`r`n--------------------------`r`n"
320-
321-
$outputString | Write-Host -ForegroundColor Yellow
335+
$outputString | Write-Host -ForegroundColor $foregroundColor
322336
}
323337

324338
function Debug-SdnFabricInfrastructure {
@@ -376,6 +390,14 @@ function Debug-SdnFabricInfrastructure {
376390

377391
$script:SdnDiagnostics_Health.Cache = $null
378392
$aggregateHealthReport = @()
393+
$dateTimeNow = Get-Date -Format 'yyyyMMdd-HHmmss'
394+
$dateTimeNowFormatted = Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC'
395+
396+
$transcriptDirectory = Get-WorkingDirectory
397+
$transcriptPath = "{0}\SdnFabricHealthReport_{1}.txt" -f $transcriptDirectory, $dateTimeNow
398+
Start-Transcript -Path $transcriptPath -Force
399+
"Starting SDN Fabric Infrastructure health validation at {0}" -f $dateTimeNowFormatted | Trace-Output -Level:Information
400+
379401
if (Test-ComputerNameIsLocal -ComputerName $NetworkController) {
380402
Confirm-IsNetworkController
381403
}
@@ -413,7 +435,7 @@ function Debug-SdnFabricInfrastructure {
413435

414436
$Role = $Role | Sort-Object -Unique
415437
foreach ($object in $Role) {
416-
"Processing tests for {0} role" -f $object.ToString() | Trace-Output -Level:Verbose
438+
"Processing tests for {0} role" -f $object.ToString() | Trace-Output -Level:Information
417439
$config = Get-SdnModuleConfiguration -Role $object.ToString()
418440

419441
$roleHealthReport = New-SdnFabricHealthReport -Role $object.ToString()
@@ -516,19 +538,17 @@ function Debug-SdnFabricInfrastructure {
516538
}
517539
}
518540

519-
# evaluate the results of the tests and determine if any completed with Warning or FAIL
520-
# if so, we will want to set the Result of the report to reflect this
521-
foreach ($test in $healthReport) {
522-
if ($test.Result -ieq 'WARN') {
523-
$roleHealthReport.Result = 'WARN'
541+
$roleHealthReport.RoleTest += $healthReport
542+
foreach ($test in $roleHealthReport.RoleTest.HealthTest) {
543+
if ($test.Result -ieq 'WARNING') {
544+
$roleHealthReport.Result = 'WARNING'
524545
}
525-
if ($test.Result -ieq 'FAIL') {
546+
elseif ($test.Result -ieq 'FAIL') {
526547
$roleHealthReport.Result = 'FAIL'
527548
break
528549
}
529550
}
530551

531-
$roleHealthReport.RoleTest += $healthReport
532552
$aggregateHealthReport += $roleHealthReport
533553
}
534554
}
@@ -537,8 +557,55 @@ function Debug-SdnFabricInfrastructure {
537557
$_ | Write-Error
538558
}
539559
finally {
560+
Stop-Transcript
561+
"Transcript saved to {0}" -f $transcriptPath | Trace-Output -Level:Information
562+
540563
if ($aggregateHealthReport) {
541564

565+
# Display SDN Health Validation Report Header
566+
$reportHeader = @"
567+
568+
===============================================================================
569+
SDN HEALTH VALIDATION REPORT
570+
===============================================================================
571+
572+
"@
573+
Write-Host $reportHeader -ForegroundColor Cyan
574+
575+
# Calculate aggregate summary
576+
$allRoles = ($aggregateHealthReport | Select-Object -ExpandProperty Role) -join ', '
577+
$allSdnNodes = ($aggregateHealthReport | ForEach-Object { $_.RoleTest.ComputerName } | Sort-Object -Unique) -join ', '
578+
579+
# Determine overall health state (worst case wins: FAIL > WARNING > PASS)
580+
$overallState = 'PASS'
581+
foreach ($report in $aggregateHealthReport) {
582+
if ($report.Result -ieq 'FAIL') {
583+
$overallState = 'FAIL'
584+
break
585+
}
586+
elseif ($report.Result -ieq 'WARNING' -and $overallState -ne 'FAIL') {
587+
$overallState = 'WARNING'
588+
}
589+
}
590+
591+
# Set color based on overall state
592+
$stateColor = switch ($overallState) {
593+
'PASS' { 'Green' }
594+
'WARNING' { 'Yellow' }
595+
'FAIL' { 'Red' }
596+
}
597+
598+
# Display summary
599+
Write-Host "Report Generated: " -NoNewline -ForegroundColor Gray
600+
Write-Host $dateTimeNowFormatted -ForegroundColor White
601+
Write-Host "Roles Tested: " -NoNewline -ForegroundColor Gray
602+
Write-Host $allRoles -ForegroundColor White
603+
Write-Host "Nodes Tested: " -NoNewline -ForegroundColor Gray
604+
Write-Host $allSdnNodes -ForegroundColor White
605+
Write-Host "Overall State: " -NoNewline -ForegroundColor Gray
606+
Write-Host $overallState -ForegroundColor $stateColor
607+
Write-Host ""
608+
542609
# enumerate all the roles that were tested so we can determine if any completed with Warning or FAIL
543610
$aggregateHealthReport | ForEach-Object {
544611
if ($_.Result -ine 'PASS') {
@@ -554,13 +621,23 @@ function Debug-SdnFabricInfrastructure {
554621
$remediationList = [System.Collections.ArrayList]::new()
555622
$_.Remediation | ForEach-Object { [void]$remediationList.Add($_) }
556623

557-
Write-HealthValidationInfo -ComputerName $c -Name $_.Name -Remediation $remediationList
624+
Write-HealthValidationInfo -ComputerName $c -Name $_.Name -Remediation $remediationList -Severity $_.Result
558625
}
559626
}
560627
}
561628
}
562629
}
563630

631+
# Display SDN Health Validation Report Footer
632+
$reportFooter = @"
633+
634+
===============================================================================
635+
END OF SDN HEALTH VALIDATION REPORT
636+
===============================================================================
637+
638+
"@
639+
Write-Host $reportFooter -ForegroundColor Cyan
640+
564641
# save the aggregate health report to cache so we can use it for further analysis
565642
$script:SdnDiagnostics_Health.Cache = $aggregateHealthReport
566643
}
@@ -653,12 +730,12 @@ function Debug-SdnNetworkController {
653730
}
654731
}
655732

656-
# enumerate all the tests performed so we can determine if any completed with WARN or FAIL
657-
# if any of the tests completed with WARN, we will set the aggregate result to WARN
733+
# enumerate all the tests performed so we can determine if any completed with WARNING or FAIL
734+
# if any of the tests completed with WARNING, we will set the aggregate result to WARNING
658735
# if any of the tests completed with FAIL, we will set the aggregate result to FAIL and then break out of the foreach loop
659736
# we will skip tests with PASS, as that is the default value
660737
foreach ($test in $healthReport.HealthTest) {
661-
if ($test.Result -eq 'WARN') {
738+
if ($test.Result -eq 'WARNING') {
662739
$healthReport.Result = $test.Result
663740
}
664741
elseif ($test.Result -eq 'FAIL') {
@@ -721,12 +798,12 @@ function Debug-SdnServer {
721798
)
722799
}
723800

724-
# enumerate all the tests performed so we can determine if any completed with WARN or FAIL
725-
# if any of the tests completed with WARN, we will set the aggregate result to WARN
801+
# enumerate all the tests performed so we can determine if any completed with WARNING or FAIL
802+
# if any of the tests completed with WARNING, we will set the aggregate result to WARNING
726803
# if any of the tests completed with FAIL, we will set the aggregate result to FAIL and then break out of the foreach loop
727804
# we will skip tests with PASS, as that is the default value
728805
foreach ($test in $healthReport.HealthTest) {
729-
if ($test.Result -eq 'WARN') {
806+
if ($test.Result -eq 'WARNING') {
730807
$healthReport.Result = $test.Result
731808
}
732809
elseif ($test.Result -eq 'FAIL') {
@@ -767,12 +844,12 @@ function Debug-SdnLoadBalancerMux {
767844
)
768845
}
769846

770-
# enumerate all the tests performed so we can determine if any completed with WARN or FAIL
771-
# if any of the tests completed with WARN, we will set the aggregate result to WARN
847+
# enumerate all the tests performed so we can determine if any completed with WARNING or FAIL
848+
# if any of the tests completed with WARNING, we will set the aggregate result to WARNING
772849
# if any of the tests completed with FAIL, we will set the aggregate result to FAIL and then break out of the foreach loop
773850
# we will skip tests with PASS, as that is the default value
774851
foreach ($test in $healthReport.HealthTest) {
775-
if ($test.Result -eq 'WARN') {
852+
if ($test.Result -eq 'WARNING') {
776853
$healthReport.Result = $test.Result
777854
}
778855
elseif ($test.Result -eq 'FAIL') {
@@ -992,7 +1069,7 @@ function Test-SdnNetworkControllerApiNameResolution {
9921069
}
9931070
catch {
9941071
$_ | Trace-Exception
995-
"`t- Investigate DNS resolution failure against DNS server {0} for name {1}" -f $dnsServer, $Endpoint
1072+
"Investigate DNS resolution failure against DNS server {0} for name {1}" -f $dnsServer, $Endpoint
9961073
}
9971074
}
9981075

@@ -1080,7 +1157,7 @@ function Test-SdnCertificateMultiple {
10801157
"`t- Thumbprint: {0} Subject: {1} Issuer: {2} NotAfter: {3}" -f $_.Thumbprint, $_.Subject, $_.Issuer, $_.NotAfter
10811158
}
10821159

1083-
$sdnHealthTest.Result = 'WARN'
1160+
$sdnHealthTest.Result = 'WARNING'
10841161
$sdnHealthTest.Remediation = "Examine and cleanup the certificates if no longer needed:`r`n{0}" -f ($certDetails -join "`r`n")
10851162
}
10861163
}
@@ -1377,7 +1454,7 @@ function Test-SdnHostAgentConnectionStateToApiService {
13771454
if ($tcpConnection.State -ine 'Established') {
13781455
$serviceState = Get-Service -Name NCHostAgent -ErrorAction Stop
13791456
if ($serviceState.Status -ine 'Running') {
1380-
$sdnHealthTest.Result = 'WARN'
1457+
$sdnHealthTest.Result = 'WARNING'
13811458
$sdnHealthTest.Remediation += "Ensure the NCHostAgent service is running."
13821459
}
13831460
else {
@@ -1888,7 +1965,7 @@ function Test-SdnAdapterPerformanceSetting {
18881965
if ($adaptersToRepair.Count -gt 0) {
18891966
$sdnHealthTest.Result = 'WARNING'
18901967
foreach ($adapter in $adaptersToRepair) {
1891-
$sdnHealthTest.Remediation += "Use Invoke-SdnRemediationScript -ScriptName 'ConfigureForwardOptimization.ps1' -ArgumentList @{AdapterName='$adapter'; NoRestart=`$false}"
1968+
$sdnHealthTest.Remediation += "Run 'Invoke-SdnRemediationScript -ScriptName 'ConfigureForwardOptimization.ps1' -ArgumentList @{AdapterName='$adapter'; NoRestart=`$false}' on the impacted node to enable Forwarding Optimization."
18921969
}
18931970
}
18941971
}

0 commit comments

Comments
 (0)