是否有一种简单的方法可以使用 Application Insights 将相同的警报添加到所有资源?
我想创建服务器异常计数/阈值警报,但不想手动更新 20 多个 AI 资源。
此外,随着规则和需求的变化,如果能够做点什么那就太好了。我认为 ARM 可能会提供一种方法来提取资源,然后迭代每个资源以创建警报。还有其他想法吗?或者提示?
最佳答案
您可以使用 Azure Power Shell 或模板来执行此操作。
对于模板:你可以检查这个template .
{
"name": "[variables('responseAlertName')]",
"type": "Microsoft.Insights/alertrules",
"apiVersion": "2014-04-01",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Insights/components', variables('appInsName'))]"
],
"tags": {
"[concat('hidden-link:', resourceId('Microsoft.Insights/components', variables('appInsName')))]": "Resource"
},
"properties": {
"name": "[variables('responseAlertName')]",
"description": "response time alert",
"isEnabled": true,
"condition": {
"$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client",
"odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
"dataSource": {
"$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client",
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
"resourceUri": "[resourceId('microsoft.insights/components', variables('appInsName'))]",
"metricName": "request.duration"
},
"threshold": "[parameters('responseTime')]",
"windowSize": "PT5M"
},
"actions": [
{
"$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client",
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": true,
"customEmails": []
}
]
}
}
您还可以查看此 link .
对于 PowerShell,您可以使用命令 Add-AzureRmLogAlertRule
。例如:
Add-AzureRmLogAlertRule -Name "logRule" -Location "East US" -ResourceGroup "Default-Web-EastUS" -OperationName "Create" -TargetResourceId "/subscriptions/abbfb07c-6c93-40be-bc9b-4f0deba32f4c/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo" -Description "My log rule"
关于azure - 为所有资源创建 Application Insights 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48980157/