达到预测时发出预算警报
Make a budget alert when forcasted is reached
我在 ARM 模板中做了预算,其中有两个通知下的警报。默认情况下,“ThresholdType”是“实际”,如果我尝试将其更改为预测,它会给我错误“值必须是以下值之一:”实际“”
这个想法是在达到预测预算时触发警报。您可以在门户中执行此操作,但是否可以通过编程方式执行此操作?
{
"type": "Microsoft.Consumption/budgets",
"apiVersion": "2019-10-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')]",
"contactEmails": "[parameters('ErrorEmailReceivers')]",
"contactRoles": "[parameters('contactRoles')]",
"contactGroups": "[resourceId('Microsoft.Insights/actionGroups',variables('WarnAGName'))]"
},
"NotificationForExceededBudget2": {
"enabled": true,
"operator": "GreaterThan",
"threshold": "[parameters('secondThreshold')]",
"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')]"
}
}
]
}
}
}
您可以使用以下 ARM 模板创建预测警报。我们已经在本地环境中测试了以下模板,它工作正常。
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"budgetName": {
"defaultValue": "MyBudget",
"type": "String",
"metadata": {
"description": "Name of the Budget. It should be unique within a resource group."
}
},
"amount": {
"defaultValue": "1000",
"type": "String",
"metadata": {
"description": "The total amount of cost or usage to track with the budget"
}
},
"timeGrain": {
"defaultValue": "Monthly",
"allowedValues": [
"Monthly",
"Quarterly",
"Annually"
],
"type": "String",
"metadata": {
"description": "The time covered by a budget. Tracking of the amount will be reset based on the time grain."
}
},
"startDate": {
"type": "String",
"metadata": {
"description": "The start date must be first of the month in YYYY-MM-DD format. Future start date should not be more than three months. Past start date should be selected within the timegrain preiod."
}
},
"endDate": {
"type": "String",
"metadata": {
"description": "The end date for the budget in YYYY-MM-DD format. If not provided, we default this to 10 years from the start date."
}
},
"firstThreshold": {
"defaultValue": "90",
"type": "String",
"metadata": {
"description": "Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000."
}
},
"secondThreshold": {
"defaultValue": "110",
"type": "String",
"metadata": {
"description": "Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000."
}
},
"contactRoles": {
"defaultValue": [
"Owner",
"Contributor",
"Reader"
],
"type": "Array",
"metadata": {
"description": "The list of contact roles to send the budget notification to when the threshold is exceeded."
}
},
"contactEmails": {
"type": "Array",
"metadata": {
"description": "The list of email addresses to send the budget notification to when the threshold is exceeded."
}
},
"contactGroups": {
"type": "Array",
"metadata": {
"description": "The list of action groups to send the budget notification to when the threshold is exceeded. It accepts array of strings."
}
},
"resourceGroupFilterValues": {
"type": "Array",
"metadata": {
"description": "The set of values for the first filter"
}
},
"meterCategoryFilterValues": {
"type": "Array",
"metadata": {
"description": "The set of values for the second filter"
}
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Consumption/budgets",
"apiVersion": "2019-10-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": "Actual",
"contactEmails": "[parameters('contactEmails')]",
"contactRoles": "[parameters('contactRoles')]",
"contactGroups": "[parameters('contactGroups')]"
},
"NotificationForExceededBudget2": {
"enabled": true,
"operator": "GreaterThan",
"threshold": "[parameters('secondThreshold')]",
"thresholdType": "Forecasted",
"contactEmails": "[parameters('contactEmails')]",
"contactRoles": "[parameters('contactRoles')]",
"contactGroups": "[parameters('contactGroups')]"
}
},
"filter": {
"and": [
{
"dimensions": {
"name": "ResourceGroupName",
"operator": "In",
"values": "[parameters('resourceGroupFilterValues')]"
}
},
{
"dimensions": {
"name": "MeterCategory",
"operator": "In",
"values": "[parameters('meterCategoryFilterValues')]"
}
}
]
}
}
}
]
}
这里是示例输出以供参考:
我在 ARM 模板中做了预算,其中有两个通知下的警报。默认情况下,“ThresholdType”是“实际”,如果我尝试将其更改为预测,它会给我错误“值必须是以下值之一:”实际“”
这个想法是在达到预测预算时触发警报。您可以在门户中执行此操作,但是否可以通过编程方式执行此操作?
{
"type": "Microsoft.Consumption/budgets",
"apiVersion": "2019-10-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')]",
"contactEmails": "[parameters('ErrorEmailReceivers')]",
"contactRoles": "[parameters('contactRoles')]",
"contactGroups": "[resourceId('Microsoft.Insights/actionGroups',variables('WarnAGName'))]"
},
"NotificationForExceededBudget2": {
"enabled": true,
"operator": "GreaterThan",
"threshold": "[parameters('secondThreshold')]",
"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')]"
}
}
]
}
}
}
您可以使用以下 ARM 模板创建预测警报。我们已经在本地环境中测试了以下模板,它工作正常。
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"budgetName": {
"defaultValue": "MyBudget",
"type": "String",
"metadata": {
"description": "Name of the Budget. It should be unique within a resource group."
}
},
"amount": {
"defaultValue": "1000",
"type": "String",
"metadata": {
"description": "The total amount of cost or usage to track with the budget"
}
},
"timeGrain": {
"defaultValue": "Monthly",
"allowedValues": [
"Monthly",
"Quarterly",
"Annually"
],
"type": "String",
"metadata": {
"description": "The time covered by a budget. Tracking of the amount will be reset based on the time grain."
}
},
"startDate": {
"type": "String",
"metadata": {
"description": "The start date must be first of the month in YYYY-MM-DD format. Future start date should not be more than three months. Past start date should be selected within the timegrain preiod."
}
},
"endDate": {
"type": "String",
"metadata": {
"description": "The end date for the budget in YYYY-MM-DD format. If not provided, we default this to 10 years from the start date."
}
},
"firstThreshold": {
"defaultValue": "90",
"type": "String",
"metadata": {
"description": "Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000."
}
},
"secondThreshold": {
"defaultValue": "110",
"type": "String",
"metadata": {
"description": "Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000."
}
},
"contactRoles": {
"defaultValue": [
"Owner",
"Contributor",
"Reader"
],
"type": "Array",
"metadata": {
"description": "The list of contact roles to send the budget notification to when the threshold is exceeded."
}
},
"contactEmails": {
"type": "Array",
"metadata": {
"description": "The list of email addresses to send the budget notification to when the threshold is exceeded."
}
},
"contactGroups": {
"type": "Array",
"metadata": {
"description": "The list of action groups to send the budget notification to when the threshold is exceeded. It accepts array of strings."
}
},
"resourceGroupFilterValues": {
"type": "Array",
"metadata": {
"description": "The set of values for the first filter"
}
},
"meterCategoryFilterValues": {
"type": "Array",
"metadata": {
"description": "The set of values for the second filter"
}
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Consumption/budgets",
"apiVersion": "2019-10-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": "Actual",
"contactEmails": "[parameters('contactEmails')]",
"contactRoles": "[parameters('contactRoles')]",
"contactGroups": "[parameters('contactGroups')]"
},
"NotificationForExceededBudget2": {
"enabled": true,
"operator": "GreaterThan",
"threshold": "[parameters('secondThreshold')]",
"thresholdType": "Forecasted",
"contactEmails": "[parameters('contactEmails')]",
"contactRoles": "[parameters('contactRoles')]",
"contactGroups": "[parameters('contactGroups')]"
}
},
"filter": {
"and": [
{
"dimensions": {
"name": "ResourceGroupName",
"operator": "In",
"values": "[parameters('resourceGroupFilterValues')]"
}
},
{
"dimensions": {
"name": "MeterCategory",
"operator": "In",
"values": "[parameters('meterCategoryFilterValues')]"
}
}
]
}
}
}
]
}
这里是示例输出以供参考: