Skip to content

Commit e4ff323

Browse files
authored
Improve output generated for Debug-SdnFabricInfrastructure - 2 (#535)
This pull request introduces several improvements and refinements to the SDN health diagnostics PowerShell module, focusing on severity handling, summary display flexibility, and transcript management. The most significant changes are the addition of a new severity level, improved parameterization for summary output, and adjustments to transcript handling for clarity and correctness. **Severity and Health State Handling:** * Added 'FAILURE' as a valid severity value alongside 'FAIL', standardized severity mapping to use 'Failure' internally, and updated all related logic to treat 'FAILURE' as the primary failure state throughout the health validation and summary reporting. [[1]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L296-R310) [[2]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L583-R595) [[3]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L595-R604) **Summary Display Control:** * Introduced a new `SkipSummaryDisplay` switch parameter to the `Debug-SdnFabricInfrastructure` function, allowing users to optionally suppress the summary output in the console. Logic was updated to respect this flag when displaying results. [[1]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60R361-R362) [[2]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L388-R400) [[3]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L560-R572) **Transcript Management:** * Improved transcript handling by capturing the result of `Start-Transcript` and `Stop-Transcript` to `$null` to avoid unnecessary output, and moved the transcript stop and summary message to execute after all processing, ensuring the transcript captures the entire session. [[1]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L398-R410) [[2]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60R655-R657) These changes enhance the flexibility, clarity, and reliability of the SDN diagnostics script, making it easier to interpret results and control output during automated or manual runs. # Change type - [x] Bug fix (non-breaking change) - [ ] Code style update (formatting, local variables) - [ ] New Feature (non-breaking change that adds new functionality without impacting existing) - [ ] 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 4b1d28d commit e4ff323

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/modules/SdnDiag.Health.psm1

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,21 @@ function Write-HealthValidationInfo {
293293
[String[]]$Remediation,
294294

295295
[Parameter(Mandatory = $false)]
296-
[ValidateSet('WARNING', 'FAIL')]
296+
[ValidateSet('WARNING', 'FAIL', 'FAILURE', IgnoreCase = $true)]
297297
[string]$Severity
298298
)
299299

300300
switch ($Severity) {
301301
'WARNING' {
302+
$Severity = 'Warning'
302303
$foregroundColor = 'Yellow'
303304
}
304305
'FAIL' {
306+
$Severity = 'Failure'
307+
$foregroundColor = 'Red'
308+
}
309+
'FAILURE' {
310+
$Severity = 'Failure'
305311
$foregroundColor = 'Red'
306312
}
307313
}
@@ -352,6 +358,8 @@ function Debug-SdnFabricInfrastructure {
352358
Enter a variable that contains a certificate or a command or expression that gets the certificate.
353359
.PARAMETER NcRestCredential
354360
Specifies a user account that has permission to perform this action against the Network Controller REST API. The default is the current user.
361+
.PARAMETER SkipSummaryDisplay
362+
Switch parameter to skip displaying the summary of results to the console.
355363
.EXAMPLE
356364
PS> Debug-SdnFabricInfrastructure
357365
.EXAMPLE
@@ -385,7 +393,11 @@ function Debug-SdnFabricInfrastructure {
385393

386394
[Parameter(Mandatory = $false, ParameterSetName = 'Role')]
387395
[Parameter(Mandatory = $false, ParameterSetName = 'ComputerName')]
388-
[X509Certificate]$NcRestCertificate
396+
[X509Certificate]$NcRestCertificate,
397+
398+
[Parameter(Mandatory = $false, ParameterSetName = 'Role')]
399+
[Parameter(Mandatory = $false, ParameterSetName = 'ComputerName')]
400+
[switch]$SkipSummaryDisplay
389401
)
390402

391403
$script:SdnDiagnostics_Health.Cache = $null
@@ -395,7 +407,7 @@ function Debug-SdnFabricInfrastructure {
395407

396408
$transcriptDirectory = Get-WorkingDirectory
397409
$transcriptPath = "{0}\SdnFabricHealthReport_{1}.txt" -f $transcriptDirectory, $dateTimeNow
398-
Start-Transcript -Path $transcriptPath -Force
410+
$null = Start-Transcript -Path $transcriptPath -Force
399411
"Starting SDN Fabric Infrastructure health validation at {0}" -f $dateTimeNowFormatted | Trace-Output -Level:Information
400412

401413
if (Test-ComputerNameIsLocal -ComputerName $NetworkController) {
@@ -557,10 +569,7 @@ function Debug-SdnFabricInfrastructure {
557569
$_ | Write-Error
558570
}
559571
finally {
560-
Stop-Transcript
561-
"Transcript saved to {0}" -f $transcriptPath | Trace-Output -Level:Information
562-
563-
if ($aggregateHealthReport) {
572+
if ($aggregateHealthReport -and (-not $SkipSummaryDisplay)) {
564573

565574
# Display SDN Health Validation Report Header
566575
$reportHeader = @"
@@ -580,10 +589,10 @@ function Debug-SdnFabricInfrastructure {
580589
$overallState = 'PASS'
581590
foreach ($report in $aggregateHealthReport) {
582591
if ($report.Result -ieq 'FAIL') {
583-
$overallState = 'FAIL'
592+
$overallState = 'FAILURE'
584593
break
585594
}
586-
elseif ($report.Result -ieq 'WARNING' -and $overallState -ne 'FAIL') {
595+
elseif ($report.Result -ieq 'WARNING' -and $overallState -ne 'FAILURE') {
587596
$overallState = 'WARNING'
588597
}
589598
}
@@ -592,7 +601,7 @@ function Debug-SdnFabricInfrastructure {
592601
$stateColor = switch ($overallState) {
593602
'PASS' { 'Green' }
594603
'WARNING' { 'Yellow' }
595-
'FAIL' { 'Red' }
604+
'FAILURE' { 'Red' }
596605
}
597606

598607
# Display summary
@@ -643,6 +652,9 @@ function Debug-SdnFabricInfrastructure {
643652
}
644653
}
645654

655+
$null = Stop-Transcript
656+
"Transcript saved to {0}" -f $transcriptPath | Trace-Output -Level:Information
657+
646658
if ($script:SdnDiagnostics_Health.Cache) {
647659
"Results for fabric health have been saved to cache for further analysis. Use 'Get-SdnFabricInfrastructureResult' to examine the results." | Trace-Output
648660
return $script:SdnDiagnostics_Health.Cache

0 commit comments

Comments
 (0)