From 4079cdea7175555018f48a8ab321393eaf05bd26 Mon Sep 17 00:00:00 2001 From: Jared Burns Date: Tue, 6 Feb 2024 12:49:15 -0500 Subject: [PATCH] fix: add connection check (#209) Added information in the HTML report if a vCenter Server authentication fails to be caught. Signed-off-by: Jared Burns --- CHANGELOG.md | 8 ++++++++ VMware.CloudFoundation.Reporting.psd1 | 2 +- VMware.CloudFoundation.Reporting.psm1 | 25 ++++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1061835d..67410aa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Release History +## v2.6.1 + +> Release Date: Not Released + +Bugfix: + +- Updated `Request-VcenterStorageHealth` cmdlet to output an error message if authentication to vCenter Server fails. [GH-209] https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/209 + ## v2.6.0 > Release Date: 2024-01-30 diff --git a/VMware.CloudFoundation.Reporting.psd1 b/VMware.CloudFoundation.Reporting.psd1 index 5c40432d..e87c71dd 100644 --- a/VMware.CloudFoundation.Reporting.psd1 +++ b/VMware.CloudFoundation.Reporting.psd1 @@ -11,7 +11,7 @@ RootModule = '.\VMware.CloudFoundation.Reporting.psm1' # Version number of this module. - ModuleVersion = '2.6.0.1001' + ModuleVersion = '2.6.1.1000' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/VMware.CloudFoundation.Reporting.psm1 b/VMware.CloudFoundation.Reporting.psm1 index 31080904..643306cd 100644 --- a/VMware.CloudFoundation.Reporting.psm1 +++ b/VMware.CloudFoundation.Reporting.psm1 @@ -5116,13 +5116,28 @@ Function Request-VcenterStorageHealth { # Reference: https://kb.vmware.com/s/article/76563. $command = 'df -h | grep -e "^/" | grep -v "/dev/loop" | grep -v "/dev/mapper/archive_vg-archive"' $vcenter = (Get-VCFWorkloadDomain | Where-Object { $_.name -eq $domain }).vcenters + $vcenterfqdn = $vcenter.fqdn $rootPass = (Get-VCFCredential | Where-Object { $_.credentialType -eq "SSH" -and $_.resource.resourceName -eq $vcenter.fqdn }).password $dfOutput = Invoke-VMScript -VM ($vcenter.fqdn.Split(".")[0]) -ScriptText $command -GuestUser root -GuestPassword $rootPass -Server $vcfVcenterDetails.fqdn - if ($PsBoundParameters.ContainsKey("failureOnly")) { - Format-DfStorageHealth -dfOutput $dfOutput -systemFqdn $vcenter.fqdn -failureOnly - } else { - Format-DfStorageHealth -dfOutput $dfOutput -systemFqdn $vcenter.fqdn - } + if ($dfOutput.ExitCode -eq 0) { + if ($PsBoundParameters.ContainsKey("failureOnly")) { + Format-DfStorageHealth -dfOutput $dfOutput -systemFqdn $vcenter.fqdn -failureOnly + } else { + Format-DfStorageHealth -dfOutput $dfOutput -systemFqdn $vcenter.fqdn + } + } else { + $alert = "RED" + $message = "vCenter Connection check failed!" + $elementObject = New-Object System.Collections.ArrayList + $elementObject = New-Object -TypeName psobject + $elementObject | Add-Member -NotePropertyName 'Component' -NotePropertyValue "vCenter" + $elementObject | Add-Member -NotePropertyName 'Resource' -NotePropertyValue $vcenterfqdn + $elementObject | Add-Member -NotePropertyName 'Alert' -NotePropertyValue $alert + $elementObject | Add-Member -NotePropertyName 'Message' -NotePropertyValue $message + $customObject += $elementObject + } + $customObject | Sort-Object Component, Resource + } Disconnect-VIServer * -Force -Confirm:$false -WarningAction SilentlyContinue | Out-Null }