top of page

Generate SDDC overall Health report and get via email every day to monitor VMware Cloud Foundation Environment.

  • Writer: Milton Sarkar
    Milton Sarkar
  • 2 days ago
  • 2 min read

1.Initially, if your SDDC lacks a direct Internet connection, a Proxy server needs to be added to download required modules.


#export https_proxy="http://proxy:port"




2. Set up the following directories:




3.Download the below modules:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

Install-Module -Name VMware.PowerCLI -MinimumVersion 13.2.1 -Repository PSGallery -Scope AllUsers

Install-Module -Name VMware.vSphere.SsoAdmin -MinimumVersion 1.3.9 -Repository PSGallery -Scope AllUsers

Install-Module -Name PowerVCF -MinimumVersion 2.4.1 -Repository PSGallery -Scope AllUsers

Install-Module -Name PowerValidatedSolutions -MinimumVersion 2.11.0 -Repository PSGallery -Scope AllUsers

Install-Module -Name VMware.CloudFoundation.Reporting -Repository PSGallery -Scope AllUsers




4. Ensure the modules are imported before continuing:

Import-Module -Name VMware.PowerCLI

Import-Module -Name VMware.vSphere.SsoAdmin

Import-Module -Name PowerVCF

Import-Module -Name PowerValidatedSolutions

Import-Module -Name VMware.CloudFoundation.Reporting




5. Remove proxy settings from bash,

unset http_proxy

unset https_proxy

unset HTTP_PROXY

unset HTTPS_PROXY


6.Create the directories listed below and assign permissions,

mkdir /tmp/reporting

Chmod 664 /tmp/reporting


7. Use the following commands to update the time zone and synchronize with NTP servers,


timedatectl set-timezone Australia/Brisbane

timedatectl


If ntp not sync, then run

systemctl disable --now ntpd

systemctl enable --now systemd-timesyncd

timedatectl status




8.Make the directories mentioned below, configure permissions, and set up the Script,


# mkdir -p /opt/scripts

#vim /opt/scripts/SendHealthReport.ps1


Script:



*********************************************************************************************************

# Define SDDC Manager details

$sddcManagerFqdn = "Your SDDC Manager"

$sddcManagerUser = "administrator@vsphere.local"

$sddcManagerPass = "Password"

$sddcManagerLocalUser = "vcf"

$sddcManagerLocalPass = "Password"



# Define the path for the report directory

$reportDirectory = "/tmp/reporting/"


# Create the directory if it doesn't exist

if (-not (Test-Path $reportDirectory)) {

New-Item -Path $reportDirectory -ItemType Directory

}


# Generate the health report

Invoke-VcfHealthReport -sddcManagerFqdn $sddcManagerFqdn `

-sddcManagerUser $sddcManagerUser `

-sddcManagerPass $sddcManagerPass `

-sddcManagerLocalUser $sddcManagerLocalUser `

-sddcManagerLocalPass $sddcManagerLocalPass `

-reportPath $reportDirectory `

-allDomains


# Find the latest HTML report file

$latestReportFile = Get-ChildItem -Path $reportDirectory/HealthReports -Filter "*.htm" | Sort-Object LastWriteTime -Descending | Select-Object -First 1


if (-not $latestReportFile) {

Write-Host "No HTML report found in $reportDirectory."

exit

}


# Full path to the latest report

$reportPath = $latestReportFile.FullName

Write-Host "Attaching report: $reportPath"




# Email configuration

$EmailFrom = "Source Email address"

$EmailTo = "Destination Email address"

$SMTPServer = "SMTP Server"

$SMTPPort = port number (default 25)

$Subject = "SDDC Health Report"

$Body = "PLEASE FIND THE ATTACHED SDDC Health Report."


# Send the email with the attachment

try {

Send-MailMessage -From $EmailFrom `

-To $EmailTo `

-Subject $Subject `

-Body $Body `

-SmtpServer $SMTPServer `

-Port $SMTPPort `

-Attachments $reportPath



# Delete the report if the email is successfully sent

if ($?) {

Remove-Item /tmp/reporting/* -Force -Recurse

} else {

Write-Host "Failed to send health report."

}

} catch {

Write-Host "Error while sending email: $_"

}

***************************************End Script***************************************************


#chmod 755 /opt/scripts/SendHealthReport.ps1


9. Next, create the designated folder within /etc/cron.d, set the necessary permissions, and change the ownership from the root user,


chmod 644 /etc/cron.d/send_health_report

chown root:root /etc/cron.d/send_health_report


10. Set the schedule according to your needs. I have it running every day at 7:30 AM.

#vim /etc/cron.d/send_health_report

********************************************

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin


30 7 * * * root /usr/bin/pwsh -File /opt/scripts/SendHealthReport.ps1 >> /var/log/health_report.log 2>&1

*******************************************************************************



11.Restart crond if not running or stop,

#systemctl restart crond


You can now receive the SDDC Overall Health report daily or based on your schedule via Email to monitor the VCF Environment.













Comments


bottom of page