Skip to content

Commit

Permalink
feat: add support for additional json outputs
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
lelik2be authored and tenthirtyam committed Dec 21, 2023
1 parent f61e673 commit d28cb1f
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 23 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion VMware.CloudFoundation.Reporting.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @()
Expand Down
92 changes: 75 additions & 17 deletions VMware.CloudFoundation.Reporting.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##############################
#######################################################################################################################
Expand Down Expand Up @@ -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 <timestamp>-cdrom-status.json

.PARAMETER server
The fully qualified domain name of the SDDC Manager.

Expand All @@ -6090,14 +6098,18 @@ 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 (
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$server,
[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
Expand All @@ -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 '<a id="storage-vm-cdrom"></a><h3>Virtual Machines with Connected CD-ROMs</h3>' -PostContent '<p>No virtual machines with connected CD-ROMs found.</p>'

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 '<a id="storage-vm-cdrom"></a><h3>Virtual Machines with Connected CD-ROMs</h3>' -As Table
if ($allHealthObject.Count -eq 0) { $addNoIssues = $true }
if ($addNoIssues) {
$allHealthObject = $allHealthObject | ConvertTo-Html -Fragment -PreContent '<a id="storage-vm-cdrom"></a><h3>Virtual Machines with Connected CD-ROMs</h3>' -PostContent '<p>No virtual machines with connected CD-ROMs found.</p>'
} else {
$allHealthObject = $allHealthObject | Sort-Object Cluster, 'VM Name' | ConvertTo-Html -Fragment -PreContent '<a id="storage-vm-cdrom"></a><h3>Virtual Machines with Connected CD-ROMs</h3>' -As Table
}
$allHealthObject = Convert-CssClass -htmlData $allHealthObject
$allHealthObject
}
$allHealthObject = Convert-CssClass -htmlData $allHealthObject
$allHealthObject
}
}
} Catch {
Expand Down Expand Up @@ -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 <timestamp>-esxi-connection-status.json

.PARAMETER server
The fully qualified domain name of the SDDC Manager.

Expand All @@ -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 (
Expand All @@ -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
Expand All @@ -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 '<a id="esxi-connection"></a><h3>ESXi Connection Health</h3>' -PostContent '<p>No issues found.</p>'
Expand All @@ -6290,6 +6324,7 @@ Function Publish-EsxiConnectionHealth {
}
$allHealthObject = Convert-CssClass -htmlData $allHealthObject
$allHealthObject
}
}
}
} Catch {
Expand Down Expand Up @@ -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 <timestamp>-sddc-manager-free-pool-status.json

.PARAMETER server
The fully qualified domain name of the SDDC Manager.

Expand All @@ -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
Expand All @@ -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 '<a id="esxi-free-pool"></a><h3>Free Pool Health</h3>' -As Table -PostContent '<p>No issues found.</p>'

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 '<a id="esxi-free-pool"></a><h3>Free Pool Health</h3>' -As Table
if ($allConfigurationObject.Count -eq 0) { $addNoIssues = $true }
if ($addNoIssues) {
$allConfigurationObject = $allConfigurationObject | ConvertTo-Html -Fragment -PreContent '<a id="esxi-free-pool"></a><h3>Free Pool Health</h3>' -As Table -PostContent '<p>No issues found.</p>'
} else {
$allConfigurationObject = $allConfigurationObject | ConvertTo-Html -Fragment -PreContent '<a id="esxi-free-pool"></a><h3>Free Pool Health</h3>' -As Table
}
}
} else {
$allConfigurationObject = $allConfigurationObject | ConvertTo-Html -Fragment -PreContent '<a id="esxi-free-pool"></a><h3>Free Pool Health</h3>' -As Table -PostContent '<p>No ESXi hosts present in the free pool.</p>'
}

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 '<a id="esxi-free-pool"></a><h3>Free Pool Health</h3>' -As Table -PostContent '<p>No ESXi hosts present in the free pool.</p>'
}
}
$allConfigurationObject = Convert-CssClass -htmldata $allConfigurationObject
$allConfigurationObject
$allConfigurationObject
}
}
} Catch {
Expand Down
28 changes: 26 additions & 2 deletions docs/documentation/functions/Publish-EsxiConnectionHealth.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Publish the connection status of ESXi hosts in a workload domain in HTML format.
### All-WorkloadDomains

```powershell
Publish-EsxiConnectionHealth -server <String> -user <String> -pass <String> [-allDomains] [-failureOnly] [<CommonParameters>]
Publish-EsxiConnectionHealth -server <String> -user <String> -pass <String> [-allDomains] [-failureOnly] [-outputJson <String>] [<CommonParameters>]
```

### Specific-WorkloadDomain

```powershell
Publish-EsxiConnectionHealth -server <String> -user <String> -pass <String> -workloadDomain <String> [-failureOnly] [<CommonParameters>]
Publish-EsxiConnectionHealth -server <String> -user <String> -pass <String> -workloadDomain <String> [-failureOnly] [-outputJson <String>] [<CommonParameters>]
```

## Description
Expand Down Expand Up @@ -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 <timestamp>-esxi-connection-status.json

## Parameters

### -server
Expand Down Expand Up @@ -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).
27 changes: 26 additions & 1 deletion docs/documentation/functions/Publish-SddcManagerFreePool.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Publish SDDC Manager free pool health information in HTML format.
## Syntax

```powershell
Publish-SddcManagerFreePool [-server] <String> [-user] <String> [-pass] <String> [-failureOnly] [<CommonParameters>]
Publish-SddcManagerFreePool [-server] <String> [-user] <String> [-pass] <String> [-failureOnly] [-outputJson <String>] [<CommonParameters>]
```

## Description
Expand Down Expand Up @@ -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 <timestamp>-sddc-manager-free-pool-status.json

## Parameters

### -server
Expand Down Expand Up @@ -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).
29 changes: 27 additions & 2 deletions docs/documentation/functions/Publish-VmConnectedCdrom.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Publish the status of virtual machines with connected CD-ROMs in a workload doma
### All-WorkloadDomains

```powershell
Publish-VmConnectedCdrom -server <String> -user <String> -pass <String> [-allDomains] [<CommonParameters>]
Publish-VmConnectedCdrom -server <String> -user <String> -pass <String> [-allDomains] [-outputJson <String>] [<CommonParameters>]
```

### Specific-WorkloadDomain

```powershell
Publish-VmConnectedCdrom -server <String> -user <String> -pass <String> -workloadDomain <String> [<CommonParameters>]
Publish-VmConnectedCdrom -server <String> -user <String> -pass <String> -workloadDomain <String> [-outputJson <String>] [<CommonParameters>]
```

## Description
Expand Down Expand Up @@ -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 <timestamp>-cdrom-status.json

## Parameters

### -server
Expand Down Expand Up @@ -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).

0 comments on commit d28cb1f

Please sign in to comment.