Skip to content

Commit

Permalink
Migrate chart code to separate function. AsBuiltReport#132
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelinux committed Jan 16, 2024
1 parent 907498f commit 2af3dc7
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 489 deletions.
45 changes: 5 additions & 40 deletions Src/Private/Get-AbrVbrBackupRepository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,53 +80,18 @@ function Get-AbrVbrBackupRepository {
try {
$sampleData = $OutObj | Select-Object -Property 'Name','Used Space %'

$exampleChart = New-Chart -Name BackupRepository -Width 600 -Height 400

$addChartAreaParams = @{
Chart = $exampleChart
Name = 'exampleChartArea'
}
$exampleChartArea = Add-ChartArea @addChartAreaParams -PassThru

$addChartSeriesParams = @{
Chart = $exampleChart
ChartArea = $exampleChartArea
Name = 'exampleChartSeries'
XField = 'Name'
YField = 'Used Space %'
Palette = 'Green'
ColorPerDataPoint = $true
}
$exampleChartSeries = $sampleData | Add-PieChartSeries @addChartSeriesParams -PassThru

$addChartLegendParams = @{
Chart = $exampleChart
Name = 'Backup Repository'
TitleAlignment = 'Center'
}
Add-ChartLegend @addChartLegendParams

$addChartTitleParams = @{
Chart = $exampleChart
ChartArea = $exampleChartArea
Name = 'UsedSpace'
Text = 'Percentage of Used Space'
Font = New-Object -TypeName 'System.Drawing.Font' -ArgumentList @('Arial', '12', [System.Drawing.FontStyle]::Bold)
}
Add-ChartTitle @addChartTitleParams

$chartFileItem = Export-Chart -Chart $exampleChart -Path (Get-Location).Path -Format "PNG" -PassThru
}
catch {
Write-PscriboMessage -IsWarning "Backup Repository graph Section: $($_.Exception.Message)"
$chartFileItem = Get-PieChart -SampleData $sampleData -ChartName 'BackupRepository' -XField 'Name' -YField 'Used Space %' -ChartLegendName 'Backup Repository' -ChartTitleName 'UsedSpace' -ChartTitleText 'Percentage of Used Space'
} catch {
Write-PscriboMessage -IsWarning "Backup Repository chart section: $($_.Exception.Message)"
}
}

if ($OutObj) {
Section -Style Heading3 'Backup Repository' {
Paragraph "The following section provides Backup Repository summary information."
BlankLine
if ($Options.EnableCharts -and $chartFileItem) {
Image -Text 'Backup Repository - Diagram' -Align 'Center' -Percent 100 -Path $chartFileItem
Image -Text 'Backup Repository - Diagram' -Align 'Center' -Percent 100 -Base64 $chartFileItem
}
BlankLine
$OutObj | Sort-Object -Property 'Name' | Table @TableParams
Expand Down
44 changes: 4 additions & 40 deletions Src/Private/Get-AbrVbrBackupjob.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,51 +79,15 @@ function Get-AbrVbrBackupjob {
$Alljobs += (Get-VBRSureBackupJob -ErrorAction SilentlyContinue).LastResult
}
$sampleData = $Alljobs | Group-Object
$exampleChart = New-Chart -Name BackupJobs -Width 600 -Height 400

$addChartAreaParams = @{
Chart = $exampleChart
Name = 'BackupJobs'
AxisXTitle = 'Status'
AxisYTitle = 'Count'
NoAxisXMajorGridLines = $true
NoAxisYMajorGridLines = $true
}
$exampleChartArea = Add-ChartArea @addChartAreaParams -PassThru

$addChartSeriesParams = @{
Chart = $exampleChart
ChartArea = $exampleChartArea
Name = 'exampleChartSeries'
XField = 'Name'
YField = 'Count'
Palette = 'Green'
ColorPerDataPoint = $true
}
$sampleData | Add-ColumnChartSeries @addChartSeriesParams

$addChartTitleParams = @{
Chart = $exampleChart
ChartArea = $exampleChartArea
Name = 'BackupJob'
Text = 'Jobs Latest Result'
Font = New-Object -TypeName 'System.Drawing.Font' -ArgumentList @('Arial', '12', [System.Drawing.FontStyle]::Bold)
}
Add-ChartTitle @addChartTitleParams

$chartFileItem = Export-Chart -Chart $exampleChart -Path (Get-Location).Path -Format "PNG" -PassThru
$chartFileItem = Get-ColumnChart -SampleData $sampleData -ChartName 'BackupJobs' -XField 'Name' -YField 'Count' -ChartAreaName 'Infrastructure' -AxisXTitle 'Status' -AxisYTitle 'Count' -ChartTitleName 'BackupJobs' -ChartTitleText 'Jobs Latest Result'

if ($PassThru)
{
Write-Output -InputObject $chartFileItem
}
}
catch {
Write-PscriboMessage -IsWarning "$($_.Exception.Message) (Account Security Assessment Table)"
} catch {
Write-PscriboMessage -IsWarning "Backup Jobs chart section: $($_.Exception.Message)"
}
if ($OutObj) {
if ($chartFileItem) {
Image -Text 'Backup Repository - Diagram' -Align 'Center' -Percent 100 -Path $chartFileItem
Image -Text 'Backup Repository - Diagram' -Align 'Center' -Percent 100 -Base64 $chartFileItem
}
Section -Style Heading3 'Backup Jobs' {
Paragraph "The following section list backup jobs created in Veeam Backup & Replication."
Expand Down
47 changes: 6 additions & 41 deletions Src/Private/Get-AbrVbrCloudConnectSummary.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function Get-AbrVbrCloudConnectSummary {
.DESCRIPTION
Documents the configuration of Veeam VBR in Word/HTML/Text formats using PScribo.
.NOTES
Version: 0.7.1
Version: 0.8.4
Author: Jonathan Colon
Twitter: @jcolonfzenpr
Github: rebelinux
Expand Down Expand Up @@ -60,51 +60,16 @@ function Get-AbrVbrCloudConnectSummary {
try {
$sampleData = $inObj.GetEnumerator() | Select-Object @{ Name = 'Category'; Expression = {$_.key}},@{ Name = 'Value'; Expression = {$_.value}} | Sort-Object -Property 'Category'

$exampleChart = New-Chart -Name TapeInfrastructure -Width 600 -Height 400

$addChartAreaParams = @{
Chart = $exampleChart
Name = 'exampleChartArea'
}
$exampleChartArea = Add-ChartArea @addChartAreaParams -PassThru

$addChartSeriesParams = @{
Chart = $exampleChart
ChartArea = $exampleChartArea
Name = 'exampleChartSeries'
XField = 'Category'
YField = 'Value'
Palette = 'Green'
ColorPerDataPoint = $true
}
$exampleChartSeries = $sampleData | Add-PieChartSeries @addChartSeriesParams -PassThru

$addChartLegendParams = @{
Chart = $exampleChart
Name = 'Infrastructure'
TitleAlignment = 'Center'
}
Add-ChartLegend @addChartLegendParams

$addChartTitleParams = @{
Chart = $exampleChart
ChartArea = $exampleChartArea
Name = ' '
Text = ' '
Font = New-Object -TypeName 'System.Drawing.Font' -ArgumentList @('Arial', '12', [System.Drawing.FontStyle]::Bold)
}
Add-ChartTitle @addChartTitleParams

$chartFileItem = Export-Chart -Chart $exampleChart -Path (Get-Location).Path -Format "PNG" -PassThru
}
catch {
Write-PscriboMessage -IsWarning $($_.Exception.Message)
$chartFileItem = Get-PieChart -SampleData $sampleData -ChartName 'CloudConnectInventory' -XField 'Category' -YField 'Value' -ChartLegendName 'Infrastructure'
} catch {
Write-PscriboMessage -IsWarning "Cloud Connect Inventory chart section: $($_.Exception.Message)"
}
}

if ($OutObj) {
Section -Style NOTOCHeading3 -ExcludeFromTOC 'Cloud Connect Infrastructure' {
if ($Options.EnableCharts -and $chartFileItem -and ($inObj.Values | Measure-Object -Sum).Sum -ne 0) {
Image -Text 'Cloud Connect Infrastructure - Diagram' -Align 'Center' -Percent 100 -Path $chartFileItem
Image -Text 'Cloud Connect Infrastructure - Diagram' -Align 'Center' -Percent 100 -Base64 $chartFileItem
}
BlankLine
$OutObj | Table @TableParams
Expand Down
45 changes: 5 additions & 40 deletions Src/Private/Get-AbrVbrInfrastructureSummary.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,51 +89,16 @@ function Get-AbrVbrInfrastructureSummary {
$inObj.Remove('Capacity Licenses (Total/Used)')
$sampleData = $inObj.GetEnumerator() | Select-Object @{ Name = 'Category'; Expression = {$_.key}},@{ Name = 'Value'; Expression = {$_.value}} | Sort-Object -Property 'Category'

$exampleChart = New-Chart -Name BackupInfrastructure -Width 600 -Height 400

$addChartAreaParams = @{
Chart = $exampleChart
Name = 'exampleChartArea'
}
$exampleChartArea = Add-ChartArea @addChartAreaParams -PassThru

$addChartSeriesParams = @{
Chart = $exampleChart
ChartArea = $exampleChartArea
Name = 'exampleChartSeries'
XField = 'Category'
YField = 'Value'
Palette = 'Green'
ColorPerDataPoint = $true
}
$exampleChartSeries = $sampleData | Add-PieChartSeries @addChartSeriesParams -PassThru

$addChartLegendParams = @{
Chart = $exampleChart
Name = 'Infrastructure'
TitleAlignment = 'Center'
}
Add-ChartLegend @addChartLegendParams

$addChartTitleParams = @{
Chart = $exampleChart
ChartArea = $exampleChartArea
Name = ' '
Text = ' '
Font = New-Object -TypeName 'System.Drawing.Font' -ArgumentList @('Arial', '12', [System.Drawing.FontStyle]::Bold)
}
Add-ChartTitle @addChartTitleParams

$chartFileItem = Export-Chart -Chart $exampleChart -Path (Get-Location).Path -Format "PNG" -PassThru
}
catch {
Write-PscriboMessage -IsWarning $($_.Exception.Message)
$chartFileItem = Get-PieChart -SampleData $sampleData -ChartName 'BackupInfrastructure' -XField 'Category' -YField 'Value' -ChartLegendName 'Infrastructure'
} catch {
Write-PscriboMessage -IsWarning "Backup Infrastructure chart section: $($_.Exception.Message)"
}
}

if ($OutObj) {
Section -Style NOTOCHeading3 -ExcludeFromTOC 'Backup Infrastructure Inventory' {
if ($Options.EnableCharts -and $chartFileItem -and ($inObj.Values | Measure-Object -Sum).Sum -ne 0) {
Image -Text 'Backup Infrastructure - Diagram' -Align 'Center' -Percent 100 -Path $chartFileItem
Image -Text 'Backup Infrastructure - Diagram' -Align 'Center' -Percent 100 -Base64 $chartFileItem
}
BlankLine
$OutObj | Table @TableParams
Expand Down
Loading

0 comments on commit 2af3dc7

Please sign in to comment.