Created
May 8, 2025 22:23
-
-
Save TiloGit/d20610a36e0ecbe43aa6b1570561535b to your computer and use it in GitHub Desktop.
Revisions
-
TiloGit created this gist
May 8, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ subs=( 52zzzzzzzzzzzzzzzzzzzzzzzzzzzzz9b6dd a2zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz480d 1azzzzzzzzzzzzzzzzzzzzzzzzzzzzzz9a1e ) ##now run for sub in ${subs[@]} do echo "$(date -Is) Now work on $sub" ##create budget via CLI #sub='a2czzzzzzzzzzzzzzzzzzzzzzzz80d' emailToNotify='[email protected]' amount=210 budgetName_suffix='_BudgetAlert' azapiversion='2024-08-01' enddatePlusYears=15 ##calc some of the values enddate=$(date -d "`date +%Y%m01` +$enddatePlusYears years" +%Y-%m-%d) startdate=$(date -d "`date +%Y%m01` " +%Y-%m-%d) SubName=$(az account subscription show --id $sub --query "[displayName"] -o tsv) budgetName=$SubName$budgetName_suffix ### Invoke request az rest --method PUT --url "https://management.azure.com/subscriptions/$sub/providers/Microsoft.Consumption/budgets/$budgetName?api-version=$azapiversion" \ --body @<(cat <<EOF { "properties": { "amount": $amount, "category": "cost", "notifications": { "actual_GreaterThan_85_Percent": { "contactEmails": [ "$emailToNotify" ], "enabled": true, "operator": "GreaterThan", "threshold": "85.0" }, "actual_GreaterThan_95_Percent": { "contactEmails": [ "$emailToNotify" ], "enabled": true, "operator": "GreaterThan", "threshold": "95.0" } }, "timeGrain": "BillingMonth", "timePeriod": { "endDate": "$enddate", "startDate": "$startdate" } } } EOF ) done