From 865dbcb794a1dd36af0542947f3a34534bc53284 Mon Sep 17 00:00:00 2001 From: lelik2be <119912987+lelik2be@users.noreply.github.com> Date: Thu, 21 Dec 2023 00:23:05 +0000 Subject: [PATCH] feat: add support for additional json outputs (#204) - Updated `Publish-VmConnectedCdrom` function to generate JSON output. - Updated `Publish-EsxiConnectionHealth` function to generate JSON output. - Updated `Publish-SddcManagerFreePool` function to generate JSON output. Signed-off-by: olga efremov --- CHANGELOG.md | 10 ++ VMware.CloudFoundation.Reporting.psd1 | 2 +- VMware.CloudFoundation.Reporting.psm1 | 92 +++++++++++++++---- .../functions/Publish-EsxiConnectionHealth.md | 28 +++++- .../functions/Publish-SddcManagerFreePool.md | 27 +++++- .../functions/Publish-VmConnectedCdrom.md | 29 +++++- 6 files changed, 165 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57502c66..985c9cd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Release History +## v2.6.0 + +> Release Date: Unreleased + +Enhancement: + +- Updated `Publish-VmConnectedCdrom` function to generate JSON output. [GH-204](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/204) +- Updated `Publish-EsxiConnectionHealth` function to generate JSON output. [GH-204](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/204) +- Updated `Publish-SddcManagerFreePool` function to generate JSON output. [GH-204](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-reporting/pull/204) + ## v2.5.0 > Release Date: 2023-12-15 diff --git a/VMware.CloudFoundation.Reporting.psd1 b/VMware.CloudFoundation.Reporting.psd1 index c2256778..bb5eb1be 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.5.0.1002' + ModuleVersion = '2.6.0.1000' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/VMware.CloudFoundation.Reporting.psm1 b/VMware.CloudFoundation.Reporting.psm1 index d015e2cb..906d1d4e 100644 --- a/VMware.CloudFoundation.Reporting.psm1 +++ b/VMware.CloudFoundation.Reporting.psm1 @@ -68,6 +68,9 @@ Set-Variable -Name "localuserexpiryJsonSuffix" -value "localuserexpiry-status.js Set-Variable -Name "storageCapacityHealthJsonSuffix" -value "storagecapacityhealth-status.json" -scope global Set-Variable -Name "componentConnectivityHealthNonSOSJsonSuffix" -value "componentconnectivityhealthnonsos-status.json" -scope global Set-Variable -Name "nsxtCombinedHealthNonSOSJsonSuffix" -value "nsxtcombinedhealthnonsos-status.json" -scope global +Set-Variable -Name "cdRomJsonSuffix" -value "cdrom-status.json" -scope global +Set-Variable -Name "esxiConnectionHealthJsonSuffix" -value "esxi-connection-status.json" -scope global +Set-Variable -Name "sddcFreePoolJsonSuffix" -value "sddc-manager-free-pool-status.json" -scope global ############################## E N D O F J S O N O U T P U T V A R I A B L E S ############################## ####################################################################################################################### @@ -6076,6 +6079,11 @@ Function Publish-VmConnectedCdrom { Publish-VmConnectedCdrom -server sfo-vcf01.sfo.rainpole.io -user admin@local -pass VMw@re1!VMw@re1! -workloadDomain sfo-w01 This example will returns the status of virtual machines with connected CD-ROMs in a workload domain. + .EXAMPLE + Publish-VmConnectedCdrom -server sfo-vcf01.sfo.rainpole.io -user admin@local -pass VMw@re1!VMw@re1! -allDomains -outputJson F:\Reporting + This example will generate a json with the status of virtual machines with connected CD-ROMs in all workload domains + and saves it under F:\Reporting with filename -cdrom-status.json + .PARAMETER server The fully qualified domain name of the SDDC Manager. @@ -6090,6 +6098,9 @@ Function Publish-VmConnectedCdrom { .PARAMETER workloadDomain The name of the workload domain to run against. + + .PARAMETER outputJson + The path to save the output as a JSON file. #> Param ( @@ -6097,7 +6108,8 @@ Function Publish-VmConnectedCdrom { [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$user, [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$pass, [Parameter (ParameterSetName = 'All-WorkloadDomains', Mandatory = $true)] [ValidateNotNullOrEmpty()] [Switch]$allDomains, - [Parameter (ParameterSetName = 'Specific-WorkloadDomain', Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$workloadDomain + [Parameter (ParameterSetName = 'Specific-WorkloadDomain', Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$workloadDomain, + [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$outputJson ) $pass = Get-Password -User $user -Password $pass @@ -6115,14 +6127,21 @@ Function Publish-VmConnectedCdrom { $vmConnectedCdrom = Request-VmConnectedCdrom -server $server -user $user -pass $pass -domain $workloadDomain; $allHealthObject += $vmConnectedCdrom } - if ($allHealthObject.Count -eq 0) { $addNoIssues = $true } - if ($addNoIssues) { - $allHealthObject = $allHealthObject | ConvertTo-Html -Fragment -PreContent '

Virtual Machines with Connected CD-ROMs

' -PostContent '

No virtual machines with connected CD-ROMs found.

' + + if ($PsBoundParameters.ContainsKey('outputJson')) { + $json = Start-CreateOutputJsonDirectory -jsonFolder $outputJson -jsonFileSuffix $cdRomJsonSuffix + $allHealthObject | ConvertTo-JSON -Depth 10 | Out-File $json -Encoding ASCII + Write-Output "JSON Created at $json" } else { - $allHealthObject = $allHealthObject | Sort-Object Cluster, 'VM Name' | ConvertTo-Html -Fragment -PreContent '

Virtual Machines with Connected CD-ROMs

' -As Table + if ($allHealthObject.Count -eq 0) { $addNoIssues = $true } + if ($addNoIssues) { + $allHealthObject = $allHealthObject | ConvertTo-Html -Fragment -PreContent '

Virtual Machines with Connected CD-ROMs

' -PostContent '

No virtual machines with connected CD-ROMs found.

' + } else { + $allHealthObject = $allHealthObject | Sort-Object Cluster, 'VM Name' | ConvertTo-Html -Fragment -PreContent '

Virtual Machines with Connected CD-ROMs

' -As Table + } + $allHealthObject = Convert-CssClass -htmlData $allHealthObject + $allHealthObject } - $allHealthObject = Convert-CssClass -htmlData $allHealthObject - $allHealthObject } } } Catch { @@ -6231,6 +6250,11 @@ Function Publish-EsxiConnectionHealth { Publish-EsxiConnectionHealth -server sfo-vcf01.sfo.rainpole.io -user admin@local -pass VMw@re1!VMw@re1! -allDomains -failureOnly This example will publish the connection status of ESXi hosts in all workload domains but only for failures. + .EXAMPLE + Publish-EsxiConnectionHealth -server sfo-vcf01.sfo.rainpole.io -user admin@local -pass VMw@re1!VMw@re1! -allDomains -outputJson F:\Reporting + This example will generate a json for the connection status of ESXi hosts in all workload domains and + saves it under F:\Reporting with filename -esxi-connection-status.json + .PARAMETER server The fully qualified domain name of the SDDC Manager. @@ -6248,6 +6272,9 @@ Function Publish-EsxiConnectionHealth { .PARAMETER failureOnly Switch to only output issues to the report. + + .PARAMETER outputJson + The path to save the output as JSON file. #> Param ( @@ -6256,7 +6283,8 @@ Function Publish-EsxiConnectionHealth { [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$pass, [Parameter (ParameterSetName = 'All-WorkloadDomains', Mandatory = $true)] [ValidateNotNullOrEmpty()] [Switch]$allDomains, [Parameter (ParameterSetName = 'Specific-WorkloadDomain', Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$workloadDomain, - [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [Switch]$failureOnly + [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [Switch]$failureOnly, + [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$outputJson ) $pass = Get-Password -User $user -Password $pass @@ -6282,6 +6310,12 @@ Function Publish-EsxiConnectionHealth { $esxiConnectionStatus = Request-EsxiConnectionHealth -server $server -user $user -pass $pass -domain $workloadDomain; $allHealthObject += $esxiConnectionStatus } + if ($PsBoundParameters.ContainsKey('outputJson')) { + $json = Start-CreateOutputJsonDirectory -jsonFolder $outputJson -jsonFileSuffix $esxiConnectionHealthJsonSuffix + $allHealthObject | ConvertTo-JSON -Depth 10 -EnumsAsStrings| Out-File $json -Encoding ASCII + Write-Output "JSON Created at $json" + + } else { if ($allHealthObject.Count -eq 0) { $addNoIssues = $true } if ($addNoIssues) { $allHealthObject = $allHealthObject | ConvertTo-Html -Fragment -PreContent '

ESXi Connection Health

' -PostContent '

No issues found.

' @@ -6290,6 +6324,7 @@ Function Publish-EsxiConnectionHealth { } $allHealthObject = Convert-CssClass -htmlData $allHealthObject $allHealthObject + } } } } Catch { @@ -6420,6 +6455,11 @@ Function Publish-SddcManagerFreePool { Publish-SddcManagerFreePool -server sfo-vcf01.sfo.rainpole.io -user admin@local -pass VMw@re1!VMw@re1! -failureOnly This example will return the free pool health from SDDC Manager and return the failures only. + .EXAMPLE + Publish-SddcManagerFreePool -server sfo-vcf01.sfo.rainpole.io -user admin@local -pass VMw@re1!VMw@re1! -outputJson F:\Reporting + This example will generate a json for the status the free pool health from SDDC Manager and saves it under + F:\Reporting with filename -sddc-manager-free-pool-status.json + .PARAMETER server The fully qualified domain name of the SDDC Manager. @@ -6431,13 +6471,17 @@ Function Publish-SddcManagerFreePool { .PARAMETER failureOnly Switch to only output issues to the report. + + .PARAMETER outputJson + The path to save the output as a JSON file. #> Param ( [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$server, [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$user, [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$pass, - [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [Switch]$failureOnly + [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [Switch]$failureOnly, + [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$outputJson ) $pass = Get-Password -User $user -Password $pass @@ -6454,18 +6498,32 @@ Function Publish-SddcManagerFreePool { $allConfigurationObject = Request-SddcManagerFreePool -server $server -user $user -pass $pass } - if ($allConfigurationObject.Count -eq 0) { $addNoIssues = $true } - if ($addNoIssues) { - $allConfigurationObject = $allConfigurationObject | ConvertTo-Html -Fragment -PreContent '

Free Pool Health

' -As Table -PostContent '

No issues found.

' + + if ($PsBoundParameters.ContainsKey('outputJson')) { + $json = Start-CreateOutputJsonDirectory -jsonFolder $outputJson -jsonFileSuffix $sddcFreePoolJsonSuffix + $allConfigurationObject | ConvertTo-JSON -Depth 10 -EnumsAsStrings| Out-File $json -Encoding ASCII + Write-Output "JSON Created at $json" + return } else { - $allConfigurationObject = $allConfigurationObject | ConvertTo-Html -Fragment -PreContent '

Free Pool Health

' -As Table + if ($allConfigurationObject.Count -eq 0) { $addNoIssues = $true } + if ($addNoIssues) { + $allConfigurationObject = $allConfigurationObject | ConvertTo-Html -Fragment -PreContent '

Free Pool Health

' -As Table -PostContent '

No issues found.

' + } else { + $allConfigurationObject = $allConfigurationObject | ConvertTo-Html -Fragment -PreContent '

Free Pool Health

' -As Table + } } } else { - $allConfigurationObject = $allConfigurationObject | ConvertTo-Html -Fragment -PreContent '

Free Pool Health

' -As Table -PostContent '

No ESXi hosts present in the free pool.

' - } - + if ($PsBoundParameters.ContainsKey('outputJson')) { + $json = Start-CreateOutputJsonDirectory -jsonFolder $outputJson -jsonFileSuffix $sddcFreePoolJsonSuffix + $allConfigurationObject | ConvertTo-JSON -Depth 10 -EnumsAsStrings| Out-File $json -Encoding ASCII + Write-Output "JSON Created at $json" + return + }else{ + $allConfigurationObject = $allConfigurationObject | ConvertTo-Html -Fragment -PreContent '

Free Pool Health

' -As Table -PostContent '

No ESXi hosts present in the free pool.

' + } + } $allConfigurationObject = Convert-CssClass -htmldata $allConfigurationObject - $allConfigurationObject + $allConfigurationObject } } } Catch { diff --git a/docs/documentation/functions/Publish-EsxiConnectionHealth.md b/docs/documentation/functions/Publish-EsxiConnectionHealth.md index eaa0ab36..2c1f33ab 100644 --- a/docs/documentation/functions/Publish-EsxiConnectionHealth.md +++ b/docs/documentation/functions/Publish-EsxiConnectionHealth.md @@ -9,13 +9,13 @@ Publish the connection status of ESXi hosts in a workload domain in HTML format. ### All-WorkloadDomains ```powershell -Publish-EsxiConnectionHealth -server -user -pass [-allDomains] [-failureOnly] [] +Publish-EsxiConnectionHealth -server -user -pass [-allDomains] [-failureOnly] [-outputJson ] [] ``` ### Specific-WorkloadDomain ```powershell -Publish-EsxiConnectionHealth -server -user -pass -workloadDomain [-failureOnly] [] +Publish-EsxiConnectionHealth -server -user -pass -workloadDomain [-failureOnly] [-outputJson ] [] ``` ## Description @@ -53,6 +53,14 @@ Publish-EsxiConnectionHealth -server sfo-vcf01.sfo.rainpole.io -user admin@local This example will publish the connection status of ESXi hosts in all workload domains but only for failures. +### Example 4 + +```powershell +Publish-EsxiConnectionHealth -server sfo-vcf01.sfo.rainpole.io -user admin@local -pass VMw@re1!VMw@re1! -allDomains -outputJson F:\Reporting +``` + +This example will generate a json for the connection status of ESXi hosts in all workload domains and saves it under F:\Reporting with filename -esxi-connection-status.json + ## Parameters ### -server @@ -151,6 +159,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -outputJson + +The path to save the output as a JSON file. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### Common Parameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/documentation/functions/Publish-SddcManagerFreePool.md b/docs/documentation/functions/Publish-SddcManagerFreePool.md index e1af2883..2e8b6a0a 100644 --- a/docs/documentation/functions/Publish-SddcManagerFreePool.md +++ b/docs/documentation/functions/Publish-SddcManagerFreePool.md @@ -7,7 +7,7 @@ Publish SDDC Manager free pool health information in HTML format. ## Syntax ```powershell -Publish-SddcManagerFreePool [-server] [-user] [-pass] [-failureOnly] [] +Publish-SddcManagerFreePool [-server] [-user] [-pass] [-failureOnly] [-outputJson ] [] ``` ## Description @@ -36,6 +36,15 @@ Publish-SddcManagerFreePool -server sfo-vcf01.sfo.rainpole.io -user admin@local This example will return the free pool health from SDDC Manager and return the failures only. +### Example 3 + +```powershell +Publish-SddcManagerFreePool -server sfo-vcf01.sfo.rainpole.io -user admin@local -pass VMw@re1!VMw@re1! -outputJson F:\Reporting +``` + +This example will generate a json for the status the free pool health from SDDC Manager and saves it under +F:\Reporting with filename -sddc-manager-free-pool-status.json + ## Parameters ### -server @@ -102,6 +111,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -outputJson + +The path to save the output as a JSON file. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### Common Parameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/documentation/functions/Publish-VmConnectedCdrom.md b/docs/documentation/functions/Publish-VmConnectedCdrom.md index bc73f30b..400bb205 100644 --- a/docs/documentation/functions/Publish-VmConnectedCdrom.md +++ b/docs/documentation/functions/Publish-VmConnectedCdrom.md @@ -9,13 +9,13 @@ Publish the status of virtual machines with connected CD-ROMs in a workload doma ### All-WorkloadDomains ```powershell -Publish-VmConnectedCdrom -server -user -pass [-allDomains] [] +Publish-VmConnectedCdrom -server -user -pass [-allDomains] [-outputJson ] [] ``` ### Specific-WorkloadDomain ```powershell -Publish-VmConnectedCdrom -server -user -pass -workloadDomain [] +Publish-VmConnectedCdrom -server -user -pass -workloadDomain [-outputJson ] [] ``` ## Description @@ -45,6 +45,15 @@ Publish-VmConnectedCdrom -server sfo-vcf01.sfo.rainpole.io -user admin@local -pa This example will returns the status of virtual machines with connected CD-ROMs in a workload domain. +### Example 3 + +```powershell +Publish-VmConnectedCdrom -server sfo-vcf01.sfo.rainpole.io -user admin@local -pass VMw@re1!VMw@re1! -allDomains -outputJson F:\Reporting +``` + +This example will generate a json with the status of virtual machines with connected CD-ROMs in all workload domains +and saves it under F:\Reporting with filename -cdrom-status.json + ## Parameters ### -server @@ -127,6 +136,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -outputJson + +The path to save the output as a JSON file. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### Common Parameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).