Skip to content

Commit

Permalink
Merge pull request #250 from ReneRebsdorf/TimeSpanCalc
Browse files Browse the repository at this point in the history
Calculate time span for AzureConsumptionPeriod when using `-DoAzureConsumptionPreviousMonth`
  • Loading branch information
JulianHayward authored Aug 28, 2024
2 parents 687ab6a + 9ec14d5 commit df21245
Show file tree
Hide file tree
Showing 9 changed files with 2,676 additions and 2,678 deletions.
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,9 @@ The [Azure Governance Visualizer accelerator](https://github.com/Azure/Azure-Gov

## Release history

**Changes** (2024-August-15 / 6.5.0 Minor/Patch)

- ALZ policy refresh H2 FY24 (initiatives.json)
- [DevSkim](https://github.com/microsoft/DevSkim-Action), [PSScriptAnalyzer](https://github.com/microsoft/psscriptanalyzer-action) and [OpenSSF Scorecard](https://github.com/ossf/scorecard?tab=readme-ov-file#scorecard-github-action) integration
- fixes and optimization based on DevSkim, PSScriptAnalyzer and OpenSSF Scorecard findings
- api version mapping in param block for cloud environment api version availability drift
- update GitHub workflows to use azure/login@v2 (previous: azure/login@v1):
- [AzGovViz_OIDC.yml](/.github/workflows/AzGovViz_OIDC.yml)
- [AzGovViz.yml](/.github/workflows/AzGovViz.yml)
- update getConsumption (getConsumptionv2): instead of full Management Group scope costmanagement data retrieval, batch by Subscription quotaId in batches of 100. Failing batches and batches of Subscriptions of quotaId `CSP_2015-05-01` (see param block variable `SubscriptionQuotaIdsThatDoNotSupportCostManagementManagementGroupScopeQuery`) will fallback to get costmanagement data per Subscription.
- html; update jquery; source tablefilter js
- update `.devcontainer/devcontainer.json`
- use [AzAPICall](https://aka.ms/AzAPICall) PowerShell module version 1.2.3 (Handle costManagement error `SubscriptionCostDisabled`)
**Changes** (2024-August-21 / 6.5.1 Patch)

- Calculate time span for AzureConsumptionPeriod when using `-DoAzureConsumptionPreviousMonth`

[Full release history](history.md)

Expand Down
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Azure Governance Visualizer version 6

**Changes** (2024-August-21 / 6.5.1 Patch)

- Calculate time span for AzureConsumptionPeriod when using `-DoAzureConsumptionPreviousMonth`

**Changes** (2024-August-15 / 6.5.0 Minor/Patch)

- ALZ policy refresh H2 FY24 (initiatives.json)
Expand Down
5,312 changes: 2,657 additions & 2,655 deletions pwsh/AzGovVizParallel.ps1

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pwsh/dev/devAzGovVizParallel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ Param
$Product = 'AzGovViz',

[string]
$ProductVersion = '6.5.0',
$ProductVersion = '6.5.1',

[string]
$GithubRepository = 'aka.ms/AzGovViz',
Expand Down Expand Up @@ -967,6 +967,8 @@ if (-not $HierarchyMapOnly) {
if ($azAPICallConf['htParameters'].DoAzureConsumptionPreviousMonth -eq $true) {
$azureConsumptionStartDate = ((Get-Date).AddMonths(-1).AddDays( - $((Get-Date).Day) + 1)).ToString('yyyy-MM-dd')
$azureConsumptionEndDate = ((Get-Date).AddDays( - $((Get-Date).Day))).ToString('yyyy-MM-dd')
# Since the start and end date is calculated to start of day, we need to add one to get the full month
$AzureConsumptionPeriod = (New-TimeSpan -Start $azureConsumptionStartDate -End $azureConsumptionEndDate).Days + 1
}
}
$customDataCollectionDuration = [System.Collections.ArrayList]::Synchronized((New-Object System.Collections.ArrayList))
Expand Down
6 changes: 3 additions & 3 deletions pwsh/dev/functions/getConsumption.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
if ($subsToProcessInCustomDataCollectionCount -gt 0) {
#region mgScopeWhitelisted
#$subscriptionIdsOptimizedForBody = '"{0}"' -f ($subsToProcessInCustomDataCollection.subscriptionId -join '","')
$currenttask = "Getting Consumption data (scope MG '$($ManagementGroupId)') for $($subsToProcessInCustomDataCollectionCount) Subscriptions (QuotaId Whitelist: '$($SubscriptionQuotaIdWhitelist -join ', ')') for period $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
$currenttask = "Getting Consumption data (scope MG '$($ManagementGroupId)') for $($subsToProcessInCustomDataCollectionCount) Subscriptions (QuotaId Whitelist: '$($SubscriptionQuotaIdWhitelist -join ', ')') for $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
Write-Host "$currentTask"
#https://learn.microsoft.com/rest/api/cost-management/query/usage
$uri = "$($azAPICallConf['azAPIEndpointUrls'].ARM)/providers/Microsoft.Management/managementGroups/$($ManagementGroupId)/providers/Microsoft.CostManagement/query?api-version=$($costManagementQueryAPIVersion)&`$top=5000"
Expand All @@ -47,7 +47,7 @@
foreach ($batch in $subscriptionsBatch) {
$batchCnt++
$subscriptionIdsOptimizedForBody = '"{0}"' -f (($batch.Group).subscriptionId -join '","')
$currenttask = "Getting Consumption data #batch$($batchCnt)/$(($subscriptionsBatch | Measure-Object).Count) (scope MG '$($ManagementGroupId)') for $(($batch.Group).Count) Subscriptions (QuotaId Whitelist: '$($SubscriptionQuotaIdWhitelist -join ', ')') for period $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
$currenttask = "Getting Consumption data #batch$($batchCnt)/$(($subscriptionsBatch | Measure-Object).Count) (scope MG '$($ManagementGroupId)') for $(($batch.Group).Count) Subscriptions (QuotaId Whitelist: '$($SubscriptionQuotaIdWhitelist -join ', ')') for $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
Write-Host "$currentTask" -ForegroundColor Cyan

$body = @"
Expand Down Expand Up @@ -250,7 +250,7 @@

if ($subsToProcessInCustomDataCollectionCount -gt 0) {
#region mgScope
$currenttask = "Getting Consumption data (scope MG '$($ManagementGroupId)') for period $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
$currenttask = "Getting Consumption data (scope MG '$($ManagementGroupId)') for $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
Write-Host "$currentTask"
#https://learn.microsoft.com/rest/api/cost-management/query/usage
$uri = "$($azAPICallConf['azAPIEndpointUrls'].ARM)/providers/Microsoft.Management/managementGroups/$($ManagementGroupId)/providers/Microsoft.CostManagement/query?api-version=$($costManagementQueryAPIVersion)&`$top=5000"
Expand Down
4 changes: 2 additions & 2 deletions pwsh/dev/functions/getConsumptionv2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$startConsumptionData = Get-Date

if ($subsToProcessInCustomDataCollectionCount -gt 0) {
$currenttask = "Getting Consumption data scope MG (ManagementGroupId '$($ManagementGroupId)') for $($subsToProcessInCustomDataCollectionCount) Subscriptions for period $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
$currenttask = "Getting Consumption data scope MG (ManagementGroupId '$($ManagementGroupId)') for $($subsToProcessInCustomDataCollectionCount) Subscriptions for $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
Write-Host "$currentTask"
#https://learn.microsoft.com/rest/api/cost-management/query/usage
$uri = "$($azAPICallConf['azAPIEndpointUrls'].ARM)/providers/Microsoft.Management/managementGroups/$($ManagementGroupId)/providers/Microsoft.CostManagement/query?api-version=$($costManagementQueryAPIVersion)&`$top=5000"
Expand All @@ -58,7 +58,7 @@
}
else {
$subscriptionIdsOptimizedForBody = '"{0}"' -f (($batch.Group).subscriptionId -join '","')
$currenttask = " Getting Consumption data QuotaId '$($quotaIdGroup.Name)' #batch$($batchCnt)/$(($subscriptionsBatch | Measure-Object).Count) (scope MG '$($ManagementGroupId)') for $(($batch.Group).Count) Subscriptions for period $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
$currenttask = " Getting Consumption data QuotaId '$($quotaIdGroup.Name)' #batch$($batchCnt)/$(($subscriptionsBatch | Measure-Object).Count) (scope MG '$($ManagementGroupId)') for $(($batch.Group).Count) Subscriptions for $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)"
Write-Host "$currentTask" -ForegroundColor Cyan


Expand Down
4 changes: 2 additions & 2 deletions pwsh/dev/functions/processScopeInsightsMgOrSub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ extensions: [{ name: 'sort' }]
$htmlTableId = "ScopeInsights_Consumption_$($subscriptionId -replace '-','_')"
$randomFunctionName = "func_$htmlTableId"
[void]$htmlScopeInsights.AppendLine(@"
<button onclick="loadtf$("func_$htmlTableId")()" type="button" class="collapsible"><i class="fa fa-credit-card blue" aria-hidden="true"></i> <span class="valignMiddle">Total cost $($arrayTotalCostSummarySub -join ', ') last $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)</span></button>
<button onclick="loadtf$("func_$htmlTableId")()" type="button" class="collapsible"><i class="fa fa-credit-card blue" aria-hidden="true"></i> <span class="valignMiddle">Total cost $($arrayTotalCostSummarySub -join ', ') $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)</span></button>
<div class="content contentSISub">
&nbsp;&nbsp;<i class="fa fa-table" aria-hidden="true"></i> Download CSV <a class="externallink" href="#" onclick="download_table_as_csv_semicolon('$htmlTableId');">semicolon</a> | <a class="externallink" href="#" onclick="download_table_as_csv_comma('$htmlTableId');">comma</a>
<table id="$htmlTableId" class="$cssClass">
Expand Down Expand Up @@ -1296,7 +1296,7 @@ extensions: [{ name: 'sort' }]
$htmlTableId = "ScopeInsights_Consumption_$($mgChild -replace '\(','_' -replace '\)','_' -replace '-','_' -replace '\.','_')"
$randomFunctionName = "func_$htmlTableId"
[void]$htmlScopeInsights.AppendLine(@"
<button onclick="loadtf$("func_$htmlTableId")()" type="button" class="collapsible"><i class="fa fa-credit-card blue" aria-hidden="true"></i> <span class="valignMiddle">Total cost $($arrayTotalCostSummaryMg -join "$CsvDelimiterOpposite ") last $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)</span></button>
<button onclick="loadtf$("func_$htmlTableId")()" type="button" class="collapsible"><i class="fa fa-credit-card blue" aria-hidden="true"></i> <span class="valignMiddle">Total cost $($arrayTotalCostSummaryMg -join "$CsvDelimiterOpposite ") $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)</span></button>
<div class="content contentSIMG">
&nbsp;&nbsp;<i class="fa fa-table" aria-hidden="true"></i> Download CSV
<a class="externallink" href="#" onclick="download_table_as_csv_semicolon('$htmlTableId');">semicolon</a> |
Expand Down
2 changes: 1 addition & 1 deletion pwsh/dev/functions/processTenantSummary.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13161,7 +13161,7 @@ tf.init();}}
$tfCount = ($arrayConsumptionData | Measure-Object).Count
$htmlTableId = 'TenantSummary_Consumption'
[void]$htmlTenantSummary.AppendLine(@"
<button onclick="loadtf$("func_$htmlTableId")()" type="button" class="collapsible" id="buttonTenantSummary_Consumption"><i class="padlx fa fa-credit-card blue" aria-hidden="true"></i> <span class="valignMiddle">Total cost $($arrayTotalCostSummary -join "$CsvDelimiterOpposite ") last $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)</span></button>
<button onclick="loadtf$("func_$htmlTableId")()" type="button" class="collapsible" id="buttonTenantSummary_Consumption"><i class="padlx fa fa-credit-card blue" aria-hidden="true"></i> <span class="valignMiddle">Total cost $($arrayTotalCostSummary -join "$CsvDelimiterOpposite ") $AzureConsumptionPeriod days ($azureConsumptionStartDate - $azureConsumptionEndDate)</span></button>
<div class="content TenantSummary">
<i class="padlxx fa fa-table" aria-hidden="true"></i> Download CSV <a class="externallink" href="#" onclick="download_table_as_csv_semicolon('$htmlTableId');">semicolon</a> | <a class="externallink" href="#" onclick="download_table_as_csv_comma('$htmlTableId');">comma</a>
<table id="$htmlTableId" class="summaryTable">
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ProductVersion": "6.5.0"
"ProductVersion": "6.5.1"
}

0 comments on commit df21245

Please sign in to comment.