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

Add support to show skipped or failed checks as warning / errors in the HTML report #146

Closed
4 tasks done
joisika opened this issue Jun 12, 2023 · 7 comments · Fixed by #209
Closed
4 tasks done

Add support to show skipped or failed checks as warning / errors in the HTML report #146

joisika opened this issue Jun 12, 2023 · 7 comments · Fixed by #209
Labels
enhancement Enhancement

Comments

@joisika
Copy link
Contributor

joisika commented Jun 12, 2023

Code of Conduct

  • I have read and agree to the project's Code of Conduct.
  • Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
  • Do not leave "+1" or other comments that do not add relevant information or questions.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

If there is some issue during running the report, script will show error in the console, but not in the HTML report.
Below are screenshots of console and report in case root account of one VC is locked or with wrong password in SDDC Manager DB

There is exception in the console:
image

The HTML report just skips this check:
image

In a complex environments or if "-failureOnly" is used, user will not see that some components are missing

Use Case(s)

If user is looking only into the report the information will not be there and some issues may be neglected. the HTML report should show an error that check "X" for component "Y" experienced an error "Error message".
Having this will catch user's attention and the issue will be resolved.

Potential Configuration

Those kind of issues, should be shown as an "ERROR" in the HTML report to catch user's attention.

References

No response

@joisika joisika added the enhancement Enhancement label Jun 12, 2023
@github-actions github-actions bot added the pending-review Pending Review label Jun 12, 2023
@tenthirtyam tenthirtyam added this to the Backlog milestone Jun 12, 2023
@tenthirtyam tenthirtyam removed the pending-review Pending Review label Jun 12, 2023
@tenthirtyam
Copy link
Collaborator

This is a good idea. I think it might be good to have a summary of the errors observed in the report which could come from the log.

@tenthirtyam tenthirtyam modified the milestones: Backlog, v2.2.0 Jun 13, 2023
@tenthirtyam tenthirtyam changed the title Show skipped/failed checks as errors in the HTML report Add support to how skipped or failed checks as warning / errors in the HTML report Aug 7, 2023
@tenthirtyam tenthirtyam changed the title Add support to how skipped or failed checks as warning / errors in the HTML report Add support to show skipped or failed checks as warning / errors in the HTML report Aug 10, 2023
@tenthirtyam
Copy link
Collaborator

tenthirtyam commented Aug 22, 2023

This might be accomplished by updating the Publish-* functions.

For example, display an error message in the output HTML if the Publish-ServiceHealth function or any of the functions it calls fails, we can modify the Catch block to add an error message to the $outputObject array.

For example:

Function Publish-ServiceHealth {
    <#
        .SYNOPSIS
        Formats the Service Health data from the SoS JSON output.

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

        .EXAMPLE
        Publish-ServiceHealth -json <file-name>
        This example extracts and formats the Service Health data as a PowerShell object from the JSON file.

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

        .EXAMPLE
        Publish-ServiceHealth -json <file-name> -failureOnly
        This example extracts and formats the Service Health data as a PowerShell object from the JSON file for only the failed items.

        .PARAMETER json
        The path to the JSON file containing the SoS Health Summary data.

        .PARAMETER html
        Specifies that the output should be formatted as an HTML object.

        .PARAMETER failureOnly
        Specifies that the output should only contain 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)) {
            $errorMessage = "Unable to find JSON file ($json): PRE_VALIDATION_FAILED"
            Write-Error $errorMessage
            Break
        } else {
            $targetContent = Get-Content $json | ConvertFrom-Json
        }

        $outputObject = New-Object System.Collections.ArrayList
        $inputData = $targetContent.'Services' # Extract Data from the provided SOS JSON
        if (($inputData | Measure-Object).Count -lt 1) {
            $warnMessage = "Services data not found in the JSON file ($json): SKIPPED"
            Write-Warning $warnMessage -WarningAction Stop
            Break
        } else {
            foreach ($component in $inputData) {
                foreach ($element in $component.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 'Service Name' -NotePropertyValue $element.title.ToUpper()
                    $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 (($inputData | 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-service"></a><h3>Service Health Status</h3>' -PostContent '<p>No issues found.</p>'
                } else {
                    $outputObject = $outputObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-service"></a><h3>Service Health Status</h3>' -As Table
                }
                $outputObject = Convert-CssClass -htmldata $outputObject
            } else {
                $outputObject = $outputObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-service"></a><h3>Service Health Status</h3>' -PostContent '<p><strong>WARNING</strong>: Services data not found.</p>' -As Table
            }
            $outputObject
        } else {
            $outputObject | Sort-Object Component, Resource
        }
    } Catch {
        if ($PsBoundParameters.ContainsKey('html')) {
            if ($errorMessage) {
                $outputObject = "<p><strong>ERROR</strong>: $errorMessage</p>"
            } elseif ($warnMessage) {
                $outputObject = "<p><strong>WARNING</strong>: $warnMessage</p>"
            } else {
                $outputObject = "<p><strong>EXCEPTION</strong>: $($_.Exception.Message)</p>"
            }
        } else {
            Debug-CatchWriter -object $_
        }
    }
}

@tenthirtyam tenthirtyam added the awaiting-response Awaiting Response label Aug 22, 2023
@tenthirtyam tenthirtyam modified the milestones: Backlog, .Next Aug 25, 2023
Copy link

'Marking this issue as stale due to inactivity. This helps us focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context.
Thank you!'

@github-actions github-actions bot added the stale Stale label Nov 11, 2023
@tenthirtyam tenthirtyam removed stale Stale awaiting-response Awaiting Response labels Nov 16, 2023
@tenthirtyam
Copy link
Collaborator

@burnsjared0415 - could you take a look at picking this one up?

@tenthirtyam tenthirtyam modified the milestones: v2.5.0, Backlog Nov 28, 2023
@tenthirtyam tenthirtyam added the backlog Backlog label Nov 28, 2023
@burnsjared0415
Copy link
Contributor

Running into some issues with the way the code has been writing capture the error messages on a account being locked out or json sending errors to the report. Will keep working through error handling but it will take some time to break about the function within the functions to get information out.

@bhumitra
Copy link
Contributor

@burnsjared0415 did you make any progress with this?

Copy link

github-actions bot commented Mar 8, 2024

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 8, 2024
@tenthirtyam tenthirtyam removed this from the Backlog milestone Mar 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants