如何在ARM模板中配置预测阈值触发的Azure预算告警
Azure ARM模板配置预测类预算告警解决方案
问题根因
你当前使用的Microsoft.Consumption/budgets资源API版本为2019-10-01,该版本的架构规范中仅支持Actual(实际消耗)这一种阈值类型,不支持预测类阈值配置,因此修改为forecasted时会触发参数校验报错。
实现方案
可以通过编程方式实现预测预算金额触发告警的需求,仅需要做两处调整:
- 升级
Microsoft.Consumption/budgets资源的API版本至2021-10-01及以上稳定版本 - 在每一条通知规则中新增
thresholdType字段,赋值为Forecasted(注意首字母大写)
修改后的完整ARM模板示例如下:
{ "type": "Microsoft.Consumption/budgets", "apiVersion": "2023-05-01", "name": "[parameters('budgetName')]", "properties": { "timePeriod": { "startDate": "[parameters('startDate')]", "endDate": "[parameters('endDate')]" }, "timeGrain": "[parameters('timeGrain')]", "amount": "[parameters('amount')]", "category": "Cost", "notifications": { "NotificationForExceededBudget1": { "enabled": true, "operator": "GreaterThan", "threshold": "[parameters('firstThreshold')]", "thresholdType": "Forecasted", "contactEmails": "[parameters('ErrorEmailReceivers')]", "contactRoles": "[parameters('contactRoles')]", "contactGroups": "[resourceId('Microsoft.Insights/actionGroups',variables('WarnAGName'))]" }, "NotificationForExceededBudget2": { "enabled": true, "operator": "GreaterThan", "threshold": "[parameters('secondThreshold')]", "thresholdType": "Forecasted", "contactEmails": "[parameters('WarningEmailReceivers')]", "contactRoles": "[parameters('contactRoles')]", "contactGroups": "[resourceId('Microsoft.Insights/actionGroups',variables('WarnAGName'))]" } }, "filter": { "and": [ { "dimensions": { "name": "ResourceGroupName", "operator": "In", "values": "[parameters('resourceGroupFilterValues')]" } }, { "dimensions": { "name": "MeterCategory", "operator": "In", "values": "[parameters('meterCategoryFilterValues')]" } } ] } } }
注意事项
thresholdType字段的有效值仅为Actual和Forecasted,大小写敏感,小写格式会触发校验失败- 预测类预算的时间粒度
timeGrain仅支持Monthly、Quarterly、Annual三个选项,和Azure门户的配置限制一致 - 升级API版本后原有配置项无需调整,过滤规则、联系人、动作组等配置均可直接沿用
内容的提问来源于stack exchange,提问作者Nadia Hansen
相关产品推荐
相关产品推荐

