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 ping connectivity #132

Merged
merged 2 commits into from
May 2, 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 @@ -9,6 +9,8 @@ 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)
- Added component size checks for vCenter Server instances and NSX Local Manager clusters to the overview report. [GH-130](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/130)
- Added `Publish-PingConnectivityHealth` to return the ping connectivity health from the SoS Health Summary JSON data. [GH-132](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/132)
- Updated `Publish-ComponentConnectivityHealth` to include the ping connectivity health using the `Publish-PingConnectivityHealth` cmdlet. [GH-132](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/132)

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.1.0.1003'
ModuleVersion = '2.1.0.1004'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
98 changes: 93 additions & 5 deletions VMware.CloudFoundation.Reporting.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,91 @@ Function Publish-ConnectivityHealth {
}
Export-ModuleMember -Function Publish-ConnectivityHealth

Function Publish-PingConnectivityHealth {
<#
.SYNOPSIS
Formats the Ping Connectivity Health data from the SoS JSON output.

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

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

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

.EXAMPLE
Publish-PingConnectivityHealth -json <file-name> -failureOnly
This example extracts and formats the Ping Connectivity 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
}

$customObject = New-Object System.Collections.ArrayList
$jsonInputData = $targetContent.Connectivity.'Ping Status'
$pingStatusProperties = @('area', 'title', 'state', 'timestamp', 'message', 'status', 'alert')

if (($jsonInputData | Measure-Object).Count -lt 1) {
Write-Warning 'Ping Status data not found in the JSON file: SKIPPED'
} else {
$esxiHosts = Get-VCFHost
foreach ($esxiHost in $esxiHosts) {
$fqdn = $esxiHost.fqdn
$propertiesName = $jsonInputData.$fqdn.PSObject.Properties.Name
if (($pingStatusProperties.contains($propertiesName))) {
# do nothing
} else {
$jsonInputData.$fqdn = $jsonInputData.$fqdn.$propertiesName
}
}

if ($PsBoundParameters.ContainsKey('failureOnly')) {
$outputObject = Read-JsonElement -inputData $jsonInputData -failureOnly
} else {
$outputObject = Read-JsonElement -inputData $jsonInputData
}
$customObject += $outputObject
}

# Return the structured data to the console or format using HTML CSS Styles
if ($PsBoundParameters.ContainsKey('html')) {
if (($jsonInputData | Measure-Object).Count -gt 0) {
if ($outputObject.Count -eq 0) { $addNoIssues = $true }
if ($addNoIssues) {
$customObject = $customObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-ping-connectivity"></a><h3>Ping Connectivity Health Status</h3>' -PostContent '<p>No issues found.</p>'
} else {
$customObject = $customObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-ping-connectivity"></a><h3>Ping Connectivity Health Status</h3>' -As Table
}
$customObject = Convert-CssClass -htmldata $customObject
} else {
$customObject = $customObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-ping-connectivity"></a><h3>Ping Connectivity Health Status</h3>' -PostContent '<p><strong>WARNING</strong>: Ping Status data not found.</p>' -As Table
}
$customObject
} else {
$customObject | Sort-Object Component, Resource
}
}
Catch {
Debug-CatchWriter -object $_
}
}
Export-ModuleMember -Function Publish-PingConnectivityHealth

Function Publish-DnsHealth {
<#
.SYNOPSIS
Expand Down Expand Up @@ -4698,7 +4783,8 @@ Function Publish-ComponentConnectivityHealth {
$vcenterConnectivity = Request-VcenterAuthentication -server $server -user $user -pass $pass -workloadDomain $workloadDomain -failureOnly; $allConnectivityObject += $vcenterConnectivity
$NsxtConnectivity = Request-NsxtAuthentication -server $server -user $user -pass $pass -workloadDomain $workloadDomain -failureOnly; $allConnectivityObject += $NsxtConnectivity
}
$connectivityRaw = Publish-ConnectivityHealth -json $json -failureOnly
$apiSshConnectivity = Publish-ConnectivityHealth -json $json -failureOnly
$pingConnectivity = Publish-PingConnectivityHealth -json $json -failureOnly
} else {
if ($PsBoundParameters.ContainsKey("allDomains")) {
$vcenterConnectivity = Request-VcenterAuthentication -server $server -user $user -pass $pass -alldomains; $allConnectivityObject += $vcenterConnectivity
Expand All @@ -4707,14 +4793,16 @@ Function Publish-ComponentConnectivityHealth {
$vcenterConnectivity = Request-VcenterAuthentication -server $server -user $user -pass $pass -workloadDomain $workloadDomain; $allConnectivityObject += $vcenterConnectivity
$NsxtConnectivity = Request-NsxtAuthentication -server $server -user $user -pass $pass -workloadDomain $workloadDomain; $allConnectivityObject += $NsxtConnectivity
}
$connectivityRaw = Publish-ConnectivityHealth -json $json
$apiSshConnectivity = Publish-ConnectivityHealth -json $json
$pingConnectivity = Publish-PingConnectivityHealth -json $json
}
$allConnectivityObject += $connectivityRaw
$allConnectivityObject += $apiSshConnectivity
$allConnectivityObject += $pingConnectivity
if ($allConnectivityObject.Count -eq 0) { $addNoIssues = $true }
if ($addNoIssues) {
$allConnectivityObject = $allConnectivityObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-connectivity"></a><h3>Connectivity Health Status</h3>' -PostContent '<p>No issues found.</p>'
$allConnectivityObject = $allConnectivityObject | Sort-Object Component, Resource, Message | ConvertTo-Html -Fragment -PreContent '<a id="general-connectivity"></a><h3>Connectivity Health Status</h3>' -PostContent '<p>No issues found.</p>'
} else {
$allConnectivityObject = $allConnectivityObject | Sort-Object Component, Resource | ConvertTo-Html -Fragment -PreContent '<a id="general-connectivity"></a><h3>Connectivity Health Status</h3>' -As Table
$allConnectivityObject = $allConnectivityObject | Sort-Object Component, Resource, Message | ConvertTo-Html -Fragment -PreContent '<a id="general-connectivity"></a><h3>Connectivity Health Status</h3>' -As Table
}
$allConnectivityObject = Convert-CssClass -htmldata $allConnectivityObject
$allConnectivityObject
Expand Down