问题描述
我开发了一个包含多个组件的托管应用程序。现在,当我从服务目录部署应用程序时,所有组件都已成功部署除了 Azure Monitor 部署。它在 403 上很糟糕,并以错误的网关代码结束。
当我将它部署为非托管应用程序时,所有组件都已成功部署,没有任何错误。所以我知道模板是正确的。
当我删除失败的 azure 警报并使用提供程序“Microsoft.Insights/metricAlert”向托管应用程序添加新的指标警报时,部署成功。
所以我怀疑提供程序“Microsoft.Insights/scheduledQueryRules”没有启用托管应用程序。 (?)
有人有想法吗?
这是我使用的模板:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {
"alertName": {
"type": "string","defaultValue": "","Metadata": {
"description": "Name of the alert"
}
},"query": {
"type": "string","Metadata": {
"description": "The log query to execute"
}
},"threshold": {
"type": "int","Metadata": {
"description": "The log query threshold"
}
},"alertDescription": {
"type": "string","Metadata": {
"description": "The Alert description"
}
},"alertSeverity": {
"type": "string","defaultValue": "4","Metadata": {
"description": "The Alert Severity 4 is the highest"
}
},"alertThresholdOperator": {
"type": "string","Metadata": {
"description": ""
}
},"sourceId": {
"type": "string","Metadata": {
"description": "Resource ID of the Log Analytics workspace."
}
},"location": {
"type": "string","Metadata": {
"description": "Location for the alert. Must be the same location as the workspace."
}
},"actionGroupId": {
"type": "string","Metadata": {
"description": "The ID of the action group that is triggered when the alert is activated."
}
}
},"resources": [
{
"type": "Microsoft.Insights/scheduledQueryRules","name": "[parameters('alertName')]","apiVersion": "2018-04-16","location": "[parameters('location')]","properties": {
"description": "","enabled": "true","source": {
"query": "[parameters('query')]","dataSourceId": "[parameters('sourceId')]","queryType": "ResultCount"
},"schedule": {
"frequencyInMinutes": 5,"timeWindowInMinutes": 5
},"action": {
"odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction","severity": "[parameters('alertSeverity')]","aznsAction": {
"actionGroup": "[array(parameters('actionGroupId'))]","emailSubject": "Alert mail"
},"trigger": {
"thresholdOperator": "[parameters('alertThresholdOperator')]","threshold": "[parameters('threshold')]","metricTrigger": {
"thresholdOperator": "GreaterThan","threshold": 0,"metricTriggerType": "Consecutive","metricColumn": "Computer,CounterName,InstanceName"
}
}
}
}
}
]
}
....
"properties": {
"statusCode": "BadGateway","serviceRequestId": null,"statusMessage": "{\"error\":{\"code\":\"The Remote Server returned an error: (403) Forbidden.\",\"message\":{\"lang\":\"en-US\",\"value\":\"The Remote Server returned an error: (403) Forbidden.\"}}}","eventCategory": "Administrative","entity": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/mngapp-webapp-01032021094311/providers/Microsoft.Insights/scheduledQueryRules/morethan2requestpersecdetected","message": "Microsoft.Insights/scheduledQueryRules/write","hierarchy": "a06c42dd-f12b-4f1e-a454-0e7236d84790"
},....
谢谢, 米歇尔
解决方法
"sourceId": { “类型”:“字符串”, “默认值”: ””, “元数据”:{ "description": "Log Analytics 工作区的资源 ID。" } }
日志分析工作区是否在与托管资源组不同的资源组中?