Budgets - Create Or Update
建立或更新預算的作業。 視需要做為並行控制形式,您可以選擇提供 eTag。 若要取得指定預算的最新 eTag,請在放置作業之前執行取得作業。
PUT https://management.azure.com/{scope}/providers/Microsoft.Consumption/budgets/{budgetName}?api-version=2024-08-01
URI 參數
名稱 | 位於 | 必要 | 類型 | Description |
---|---|---|---|---|
budget
|
path | True |
string |
預算名稱。 |
scope
|
path | True |
string |
與預算作業相關聯的範圍。 這包括訂用帳戶範圍的 '/subscriptions/{subscriptionId}/' 、'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' 資源群組範圍、 '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{EnrollmentAccount 範圍的 enrollmentAccount 範圍, '/providers/Microsoft.Management/managementGroups/{managementGroupId}' for Management Group scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for billingProfile scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for invoiceSection scope. |
api-version
|
query | True |
string |
要與用戶端要求搭配使用的 API 版本。 目前的版本是 2023-03-01。 |
要求本文
名稱 | 必要 | 類型 | Description |
---|---|---|---|
properties.amount | True |
number (decimal) |
使用預算追蹤的總成本量 |
properties.category | True |
預算的類別,無論是預算追蹤成本還是使用量。 |
|
properties.timeGrain | True |
預算涵蓋的時間。 追蹤數量將會根據時間粒紋重設。 僅 WD 客戶支援 BillingMonth、BillingQuarter 和 BillingAnnual |
|
properties.timePeriod | True |
具有預算的開始和結束日期。 開始日期必須是月份的第一個,而且應該小於結束日期。 預算開始日期必須是 2017 年 6 月 1 日或之後。 未來的開始日期不應超過12個月。 應該在時間根期間內選取過去的開始日期。 結束日期沒有任何限制。 |
|
eTag |
string |
資源的 eTag。 若要處理並行更新案例,此字段將用來判斷使用者是否要更新最新版本。 |
|
properties.filter |
可用來依使用者指定的維度和/或標籤來篩選預算。 |
||
properties.notifications |
<string, Notification> |
與預算相關聯的通知字典。 預算最多可以有五個通知。 |
回應
名稱 | 類型 | Description |
---|---|---|
200 OK |
還行。 要求已成功。 |
|
201 Created |
創建。 |
|
Other Status Codes |
描述作業失敗原因的錯誤回應。 |
安全性
azure_auth
Azure Active Directory OAuth2 Flow。
類型:
oauth2
Flow:
implicit
授權 URL:
https://login.microsoftonline.com/common/oauth2/authorize
範圍
名稱 | Description |
---|---|
user_impersonation | 模擬您的用戶帳戶 |
範例
CreateOrUpdateBudget
範例要求
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Consumption/budgets/TestBudget?api-version=2024-08-01
{
"eTag": "\"1d34d016a593709\"",
"properties": {
"category": "Cost",
"amount": 100.65,
"timeGrain": "Monthly",
"timePeriod": {
"startDate": "2017-10-01T00:00:00Z",
"endDate": "2018-10-31T00:00:00Z"
},
"filter": {
"and": [
{
"dimensions": {
"name": "ResourceId",
"operator": "In",
"values": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/Microsoft.Compute/virtualMachines/MSVM2",
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/Microsoft.Compute/virtualMachines/platformcloudplatformGeneric1"
]
}
},
{
"tags": {
"name": "category",
"operator": "In",
"values": [
"Dev",
"Prod"
]
}
},
{
"tags": {
"name": "department",
"operator": "In",
"values": [
"engineering",
"sales"
]
}
}
]
},
"notifications": {
"Actual_GreaterThan_80_Percent": {
"enabled": true,
"operator": "GreaterThan",
"threshold": 80,
"locale": "en-us",
"contactEmails": [
"johndoe@contoso.com",
"janesmith@contoso.com"
],
"contactRoles": [
"Contributor",
"Reader"
],
"contactGroups": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/microsoft.insights/actionGroups/SampleActionGroup"
],
"thresholdType": "Actual"
}
}
}
}
範例回覆
{
"id": "subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/Microsoft.Consumption/budgets/TestBudget",
"name": "TestBudget",
"type": "Microsoft.Consumption/budgets",
"eTag": "\"1d34d012214157f\"",
"properties": {
"category": "Cost",
"amount": 100.65,
"timeGrain": "Monthly",
"timePeriod": {
"startDate": "2017-10-01T00:00:00Z",
"endDate": "2018-10-31T00:00:00Z"
},
"filter": {
"and": [
{
"dimensions": {
"name": "ResourceId",
"operator": "In",
"values": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/Microsoft.Compute/virtualMachines/MSVM2",
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/Microsoft.Compute/virtualMachines/platformcloudplatformGeneric1"
]
}
},
{
"tags": {
"name": "category",
"operator": "In",
"values": [
"Dev",
"Prod"
]
}
},
{
"tags": {
"name": "department",
"operator": "In",
"values": [
"engineering",
"sales"
]
}
}
]
},
"currentSpend": {
"amount": 80.89,
"unit": "USD"
},
"notifications": {
"Actual_GreaterThan_80_Percent": {
"enabled": true,
"operator": "GreaterThan",
"threshold": 80,
"locale": "en-us",
"contactEmails": [
"johndoe@contoso.com",
"janesmith@contoso.com"
],
"contactRoles": [
"Contributor",
"Reader"
],
"contactGroups": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/microsoft.insights/actionGroups/SampleActionGroup"
],
"thresholdType": "Actual"
}
}
}
}
{
"id": "subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Consumption/budgets/TestBudget",
"name": "TestBudget",
"type": "Microsoft.Consumption/budgets",
"eTag": "\"1d34d012214157f\"",
"properties": {
"category": "Cost",
"amount": 100.65,
"timeGrain": "Monthly",
"timePeriod": {
"startDate": "2017-10-01T00:00:00Z",
"endDate": "2018-10-31T00:00:00Z"
},
"filter": {
"and": [
{
"dimensions": {
"name": "ResourceId",
"operator": "In",
"values": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/Microsoft.Compute/virtualMachines/MSVM2",
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/Microsoft.Compute/virtualMachines/platformcloudplatformGeneric1"
]
}
},
{
"tags": {
"name": "category",
"operator": "In",
"values": [
"Dev",
"Prod"
]
}
},
{
"tags": {
"name": "department",
"operator": "In",
"values": [
"engineering",
"sales"
]
}
}
]
},
"currentSpend": {
"amount": 80.89,
"unit": "USD"
},
"notifications": {
"Actual_GreaterThan_80_Percent": {
"enabled": true,
"operator": "GreaterThan",
"threshold": 80,
"locale": "en-us",
"contactEmails": [
"johndoe@contoso.com",
"janesmith@contoso.com"
],
"contactRoles": [
"Contributor",
"Reader"
],
"contactGroups": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MYDEVTESTRG/providers/microsoft.insights/actionGroups/SampleActionGroup"
],
"thresholdType": "Actual"
}
}
}
}
定義
名稱 | Description |
---|---|
Budget |
預算資源。 |
Budget |
要在預算中使用的比較表達式。 |
Budget |
可用來依資源群組、資源或計量來篩選預算。 |
Budget |
要篩選預算依據的維度或標籤。 |
Budget |
要用於比較的運算符。 |
Budget |
預算的開始日期和結束日期。 |
Category |
預算的類別,無論是預算追蹤成本還是使用量。 |
Culture |
收件者將接收通知的語言 |
Current |
正在追蹤預算的目前成本量。 |
Error |
錯誤的詳細數據。 |
Error |
錯誤回應表示服務無法處理傳入要求。 錯誤訊息中會提供原因。 某些錯誤回應:
|
Forecast |
正在追蹤預算的預測成本。 |
Notification |
與預算相關聯的通知。 |
Operator |
比較運算子。 |
Threshold |
臨界值的類型 |
Time |
預算涵蓋的時間。 追蹤數量將會根據時間粒紋重設。 僅 WD 客戶支援 BillingMonth、BillingQuarter 和 BillingAnnual |
Budget
預算資源。
名稱 | 類型 | Description |
---|---|---|
eTag |
string |
資源的 eTag。 若要處理並行更新案例,此字段將用來判斷使用者是否要更新最新版本。 |
id |
string |
資源標識碼。 |
name |
string |
資源名稱。 |
properties.amount |
number (decimal) |
使用預算追蹤的總成本量 |
properties.category |
預算的類別,無論是預算追蹤成本還是使用量。 |
|
properties.currentSpend |
正在追蹤預算的目前成本量。 |
|
properties.filter |
可用來依使用者指定的維度和/或標籤來篩選預算。 |
|
properties.forecastSpend |
正在追蹤預算的預測成本。 |
|
properties.notifications |
<string, Notification> |
與預算相關聯的通知字典。 預算最多可以有五個通知。 |
properties.timeGrain |
預算涵蓋的時間。 追蹤數量將會根據時間粒紋重設。 僅 WD 客戶支援 BillingMonth、BillingQuarter 和 BillingAnnual |
|
properties.timePeriod |
具有預算的開始和結束日期。 開始日期必須是月份的第一個,而且應該小於結束日期。 預算開始日期必須是 2017 年 6 月 1 日或之後。 未來的開始日期不應超過12個月。 應該在時間根期間內選取過去的開始日期。 結束日期沒有任何限制。 |
|
type |
string |
資源類型。 |
BudgetComparisonExpression
要在預算中使用的比較表達式。
名稱 | 類型 | Description |
---|---|---|
name |
string |
要用於比較的數據行名稱。 |
operator |
要用於比較的運算符。 |
|
values |
string[] |
要用於比較的值陣列 |
BudgetFilter
可用來依資源群組、資源或計量來篩選預算。
名稱 | 類型 | Description |
---|---|---|
and |
邏輯 「AND」 表達式。 必須至少有2個專案。 |
|
dimensions |
具有維度的比較表達式 |
|
tags |
具有標記的比較表達式 |
BudgetFilterProperties
要篩選預算依據的維度或標籤。
名稱 | 類型 | Description |
---|---|---|
dimensions |
具有維度的比較表達式 |
|
tags |
具有標記的比較表達式 |
BudgetOperatorType
要用於比較的運算符。
值 | Description |
---|---|
In |
BudgetTimePeriod
預算的開始日期和結束日期。
名稱 | 類型 | Description |
---|---|---|
endDate |
string (date-time) |
預算的結束日期。 如果未提供,我們預設為開始日期的10年。 |
startDate |
string (date-time) |
預算的開始日期。 |
CategoryType
預算的類別,無論是預算追蹤成本還是使用量。
值 | Description |
---|---|
Cost |
CultureCode
收件者將接收通知的語言
值 | Description |
---|---|
cs-cz | |
da-dk | |
de-de | |
en-gb | |
en-us | |
es-es | |
fr-fr | |
hu-hu | |
it-it | |
ja-jp | |
ko-kr | |
nb-no | |
nl-nl | |
pl-pl | |
pt-br | |
pt-pt | |
ru-ru | |
sv-se | |
tr-tr | |
zh-cn | |
zh-tw |
CurrentSpend
正在追蹤預算的目前成本量。
名稱 | 類型 | Description |
---|---|---|
amount |
number (decimal) |
預算所追蹤的成本總計。 |
unit |
string |
預算金額的度量單位。 |
ErrorDetails
錯誤的詳細數據。
名稱 | 類型 | Description |
---|---|---|
code |
string |
錯誤碼。 |
message |
string |
錯誤訊息,指出作業失敗的原因。 |
ErrorResponse
錯誤回應表示服務無法處理傳入要求。 錯誤訊息中會提供原因。
某些錯誤回應:
429 TooManyRequests - 要求已節流。 等候 「x-ms-ratelimit-microsoft.consumption-retry-after」 標頭中指定的時間後重試。
503 ServiceUnavailable - 服務暫時無法使用。 等候 「Retry-After」 標頭中指定的時間後重試。
504 閘道逾時 - 處理要求時服務逾時。 儘可能減少要求中的日期範圍。
名稱 | 類型 | Description |
---|---|---|
error |
錯誤的詳細數據。 |
ForecastSpend
正在追蹤預算的預測成本。
名稱 | 類型 | Description |
---|---|---|
amount |
number (decimal) |
預算所追蹤的總時間週期預測成本。 只有當預算包含預測警示類型時,才會提供此值。 |
unit |
string |
預算金額的度量單位。 |
Notification
與預算相關聯的通知。
名稱 | 類型 | 預設值 | Description |
---|---|---|---|
contactEmails |
string[] |
超過臨界值時,要傳送預算通知的電子郵件位址。 在訂用帳戶或資源群組範圍中至少必須指定一個聯繫人電子郵件或聯繫人群組。 所有其他範圍必須至少指定一個聯繫人電子郵件。 |
|
contactGroups |
string[] |
當超過臨界值時,要傳送預算通知的動作群組。 必須以完整 Azure 資源標識碼的形式提供。只有訂用帳戶或資源群組範圍才支援。 |
|
contactRoles |
string[] |
連絡角色,以在超過臨界值時將預算通知傳送至 。 |
|
enabled |
boolean |
通知已啟用或未啟用。 |
|
locale |
收件者將接收通知的語言 |
||
operator |
比較運算子。 |
||
threshold |
number (decimal) |
與通知相關聯的臨界值。 當成本超過閾值時,就會傳送通知。 一律為百分比,且必須介於 0 到 1000 之間。 |
|
thresholdType | Actual |
臨界值的類型 |
OperatorType
比較運算子。
值 | Description |
---|---|
EqualTo |
如果評估的成本與閾值相同,就會觸發警示。 注意:不建議使用此 OperatorType,因為成本與臨界值完全相同,導致警示遺失。 此 OperatorType 未來將會淘汰。 |
GreaterThan |
如果評估的成本大於臨界值,將會觸發警示。 注意:這是設定預算警示時建議的 OperatorType。 |
GreaterThanOrEqualTo |
如果評估的成本大於或等於臨界值,就會觸發警示。 |
ThresholdType
臨界值的類型
值 | Description |
---|---|
Actual |
實際成本預算警示會在實際累算成本超過配置預算時通知。 |
Forecasted |
預測的成本預算警示會提供進階通知,指出您的支出趨勢可能會超過您配置的預算,因為它依賴預測的成本預測。 |
TimeGrainType
預算涵蓋的時間。 追蹤數量將會根據時間粒紋重設。 僅 WD 客戶支援 BillingMonth、BillingQuarter 和 BillingAnnual
值 | Description |
---|---|
Annually | |
BillingAnnual | |
BillingMonth | |
BillingQuarter | |
Monthly | |
Quarterly |