你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Budgets - Create Or Update
用于创建或更新预算的作。 如果需要,可以选择提供 eTag 作为并发控制的形式。 若要获取给定预算的最新 eTag,请在放置作之前执行 get作。
PUT https://management.azure.com/{scope}/providers/Microsoft.Consumption/budgets/{budgetName}?api-version=2024-08-01
URI 参数
名称 | 在 | 必需 | 类型 | 说明 |
---|---|---|---|---|
budget
|
path | True |
string |
预算名称。 |
scope
|
path | True |
string |
与预算作关联的范围。 这包括订阅范围的“/subscriptions/{subscriptionId}/”、resourceGroup 范围的“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}”、 计费帐户范围的'/providers/Microsoft.Billing/billingAccounts/{billingAccountId}','/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{EnrollmentAccount 作用域的 enrollmentAccountId},“/providers/Microsoft.Management/managementGroups/{managementGroupId}”,用于管理组范围, billingProfile 范围的'/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}','/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for invoiceSection scope. |
api-version
|
query | True |
string |
要用于客户端请求的 API 的版本。 当前版本为 2023-03-01。 |
请求正文
名称 | 必需 | 类型 | 说明 |
---|---|---|---|
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> |
与预算关联的通知字典。 预算最多可以有五个通知。 |
响应
名称 | 类型 | 说明 |
---|---|---|
200 OK |
还行。 请求已成功。 |
|
201 Created |
创建。 |
|
Other Status Codes |
描述作失败的原因的错误响应。 |
安全性
azure_auth
Azure Active Directory OAuth2 Flow。
类型:
oauth2
流向:
implicit
授权 URL:
https://login.microsoftonline.com/common/oauth2/authorize
作用域
名称 | 说明 |
---|---|
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"
}
}
}
}
定义
名称 | 说明 |
---|---|
Budget |
预算资源。 |
Budget |
要用于预算的比较表达式。 |
Budget |
可用于按资源组、资源或计量筛选预算。 |
Budget |
要按其筛选预算的维度或标记。 |
Budget |
要用于比较的运算符。 |
Budget |
预算的开始日期和结束日期。 |
Category |
预算类别,无论是预算跟踪成本还是使用情况。 |
Culture |
收件人接收通知的语言 |
Current |
正在跟踪预算的当前成本量。 |
Error |
错误的详细信息。 |
Error |
错误响应指示服务无法处理传入请求。 错误消息中提供了原因。 一些错误响应:
|
Forecast |
正在跟踪预算的预测成本。 |
Notification |
与预算关联的通知。 |
Operator |
比较运算符。 |
Threshold |
阈值的类型 |
Time |
预算涵盖的时间。 将根据时间粒度重置对金额的跟踪。 仅 WD 客户支持 BillingMonth、BillingQuarter 和 BillingAnnual |
Budget
预算资源。
名称 | 类型 | 说明 |
---|---|---|
eTag |
string |
资源的 eTag。 若要处理并发更新方案,此字段将用于确定用户是否正在更新最新版本。 |
id |
string |
资源 ID。 |
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
要用于预算的比较表达式。
名称 | 类型 | 说明 |
---|---|---|
name |
string |
要进行比较的列的名称。 |
operator |
要用于比较的运算符。 |
|
values |
string[] |
要用于比较的值数组 |
BudgetFilter
可用于按资源组、资源或计量筛选预算。
名称 | 类型 | 说明 |
---|---|---|
and |
逻辑“AND”表达式。 必须至少有 2 个项目。 |
|
dimensions |
具有维度的比较表达式 |
|
tags |
具有标记的比较表达式 |
BudgetFilterProperties
要按其筛选预算的维度或标记。
名称 | 类型 | 说明 |
---|---|---|
dimensions |
具有维度的比较表达式 |
|
tags |
具有标记的比较表达式 |
BudgetOperatorType
要用于比较的运算符。
值 | 说明 |
---|---|
In |
BudgetTimePeriod
预算的开始日期和结束日期。
名称 | 类型 | 说明 |
---|---|---|
endDate |
string (date-time) |
预算的结束日期。 如果未提供,则从开始日期默认为 10 年。 |
startDate |
string (date-time) |
预算的开始日期。 |
CategoryType
预算类别,无论是预算跟踪成本还是使用情况。
值 | 说明 |
---|---|
Cost |
CultureCode
收件人接收通知的语言
值 | 说明 |
---|---|
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
正在跟踪预算的当前成本量。
名称 | 类型 | 说明 |
---|---|---|
amount |
number (decimal) |
预算跟踪的总成本量。 |
unit |
string |
预算金额的度量单位。 |
ErrorDetails
错误的详细信息。
名称 | 类型 | 说明 |
---|---|---|
code |
string |
错误代码。 |
message |
string |
指示作失败的原因的错误消息。 |
ErrorResponse
错误响应指示服务无法处理传入请求。 错误消息中提供了原因。
一些错误响应:
429 TooManyRequests - 请求受到限制。 等待“x-ms-ratelimit-microsoft.consumption-retry-after”标头中指定的时间后重试。
503 ServiceUnavailable - 服务暂时不可用。 在等待“Retry-After”标头中指定的时间后重试。
504 网关超时 - 处理请求时服务超时。 尽可能减少请求中的日期范围。
名称 | 类型 | 说明 |
---|---|---|
error |
错误的详细信息。 |
ForecastSpend
正在跟踪预算的预测成本。
名称 | 类型 | 说明 |
---|---|---|
amount |
number (decimal) |
预算跟踪的总时间段的预测成本。 仅当预算包含预测警报类型时,才提供此值。 |
unit |
string |
预算金额的度量单位。 |
Notification
与预算关联的通知。
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
contactEmails |
string[] |
用于在超出阈值时将预算通知发送到的电子邮件地址。 必须在订阅或资源组范围内至少指定一个联系人电子邮件或联系人组。 所有其他范围必须至少指定一个联系人电子邮件。 |
|
contactGroups |
string[] |
要向超出阈值时发送预算通知的操作组。 必须以完全限定的 Azure 资源 ID 的形式提供。仅在订阅或资源组范围内受支持。 |
|
contactRoles |
string[] |
联系角色,将预算通知发送到超出阈值时。 |
|
enabled |
boolean |
通知已启用或不启用。 |
|
locale |
收件人接收通知的语言 |
||
operator |
比较运算符。 |
||
threshold |
number (decimal) |
与通知关联的阈值。 当成本超出阈值时发送通知。 它始终是百分比,必须介于 0 到 1000 之间。 |
|
thresholdType | Actual |
阈值的类型 |
OperatorType
比较运算符。
值 | 说明 |
---|---|
EqualTo |
如果评估的成本与阈值相同,将触发警报。 注意:不建议使用此 OperatorType,因为成本与阈值完全相同,从而导致警报缺失。 将来将弃用此 OperatorType。 |
GreaterThan |
如果评估的成本大于阈值,将触发警报。 注意:这是配置预算警报时建议的 OperatorType。 |
GreaterThanOrEqualTo |
如果评估的成本大于或等于阈值,将触发警报。 |
ThresholdType
阈值的类型
值 | 说明 |
---|---|
Actual |
实际成本预算警报通知实际应计成本超过已分配预算的时间。 |
Forecasted |
预测成本预算警报提供高级通知,指出支出趋势可能超过分配的预算,因为它依赖于预测的成本预测。 |
TimeGrainType
预算涵盖的时间。 将根据时间粒度重置对金额的跟踪。 仅 WD 客户支持 BillingMonth、BillingQuarter 和 BillingAnnual
值 | 说明 |
---|---|
Annually | |
BillingAnnual | |
BillingMonth | |
BillingQuarter | |
Monthly | |
Quarterly |