Azure:使用 ARM 模板的日志警报部署失败
Azure: Failed log alert deployment with ARM template
我正在尝试使用 ARM 模板创建日志警报规则。模板已成功验证,但部署失败并显示非常无用的消息:
{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"InternalServerError","message":"{\r\n \"error\": {\r\n \"code\": \"ResourceDeploymentFailure\",\r\n \"message\": \"The response for resource had empty or invalid content.\"\r\n }\r\n}"}]}}
我尝试使用 Portal 和 CLI,两种方式都导致相同的错误。
这是我正在使用的模板(为简洁起见去掉了参数):
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": { },
"resources": [
{
"name": "My new rule",
"type": "Microsoft.Insights/scheduledQueryRules",
"location": "germanywestcentral",
"apiVersion": "2021-08-01",
"tags": {},
"properties": {
"description": "Description",
"severity": "3",
"enabled": "true",
"scopes": ["/subscriptions/###/resourceGroups/###/providers/microsoft.insights/components/###"],
"evaluationFrequency":"PT5M",
"windowSize": "PT5M",
"criteria": {
"allOf": [
{
"query": "union \r\n traces,\r\n exceptions\r\n| where severityLevel > 2",
"metricMeasureColumn": "",
"resourceIdColumn": "",
"dimensions":[],
"operator": "GreaterThan",
"threshold" : "5000",
"timeAggregation": "Count",
"failingPeriods": {
"numberOfEvaluationPeriods": "1",
"minFailingPeriodsToAlert": "1"
}
}
]
},
"actions": {
"actionGroups": "/subscriptions/###/resourcegroups/persevere/providers/microsoft.insights/actiongroups/my-action-group"
}
}
}
]
}
你知道这里失败的原因是什么吗?
我们已经在本地环境中对此进行了测试,它运行良好。以下陈述基于我们的分析。
当我们在本地环境(VS 代码)中加载上述共享模板时,VScode 的智能感知显示了几个语法错误。
修复所有这些错误后,我们尝试部署模板,它已成功部署,没有任何错误。
这是 ARM 模板 post 修复了那些语法错误:
{
"$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion":"1.0.0.0",
"parameters":{
},
"variables":{
},
"resources":[
{
"name":"My new rule",
"type":"Microsoft.Insights/scheduledQueryRules",
"location":"germanywestcentral",
"apiVersion":"2020-05-01-preview",
"tags":{
},
"properties":{
"description":"Description",
"severity":3,
"enabled":true,
"scopes":[
"/subscriptions/xxxxxxxxx-xxx-xxx/resourceGroups/<RGName>/providers/microsoft.insights/components/<AppInsightsName>"
],
"evaluationFrequency":"PT5M",
"windowSize":"PT5M",
"criteria":{
"allOf":[
{
"query":"union \r\n traces,\r\n exceptions\r\n| where severityLevel > 2",
"metricMeasureColumn":"",
"resourceIdColumn":"",
"dimensions":[
],
"operator":"GreaterThan",
"threshold":5000,
"timeAggregation":"Count",
"failingPeriods":{
"numberOfEvaluationPeriods":1,
"minFailingPeriodsToAlert":1
}
}
]
},
"actions":[
{
"actionGroupId":"/subscriptions/xxxxxxx-xxxx-xxx/resourceGroups/<RGName>/providers/microsoft.insights/actionGroups/<actiongroupName>"
}
]
}
}
]
}
这里是示例输出截图供参考:
注:
如果您使用 Visual Studio 代码来开发 ARM 模板,我们建议您安装扩展 ARM Template Viewer,这将帮助您避免语法错误。
我正在尝试使用 ARM 模板创建日志警报规则。模板已成功验证,但部署失败并显示非常无用的消息:
{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"InternalServerError","message":"{\r\n \"error\": {\r\n \"code\": \"ResourceDeploymentFailure\",\r\n \"message\": \"The response for resource had empty or invalid content.\"\r\n }\r\n}"}]}}
我尝试使用 Portal 和 CLI,两种方式都导致相同的错误。 这是我正在使用的模板(为简洁起见去掉了参数):
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": { },
"resources": [
{
"name": "My new rule",
"type": "Microsoft.Insights/scheduledQueryRules",
"location": "germanywestcentral",
"apiVersion": "2021-08-01",
"tags": {},
"properties": {
"description": "Description",
"severity": "3",
"enabled": "true",
"scopes": ["/subscriptions/###/resourceGroups/###/providers/microsoft.insights/components/###"],
"evaluationFrequency":"PT5M",
"windowSize": "PT5M",
"criteria": {
"allOf": [
{
"query": "union \r\n traces,\r\n exceptions\r\n| where severityLevel > 2",
"metricMeasureColumn": "",
"resourceIdColumn": "",
"dimensions":[],
"operator": "GreaterThan",
"threshold" : "5000",
"timeAggregation": "Count",
"failingPeriods": {
"numberOfEvaluationPeriods": "1",
"minFailingPeriodsToAlert": "1"
}
}
]
},
"actions": {
"actionGroups": "/subscriptions/###/resourcegroups/persevere/providers/microsoft.insights/actiongroups/my-action-group"
}
}
}
]
}
你知道这里失败的原因是什么吗?
我们已经在本地环境中对此进行了测试,它运行良好。以下陈述基于我们的分析。
当我们在本地环境(VS 代码)中加载上述共享模板时,VScode 的智能感知显示了几个语法错误。
修复所有这些错误后,我们尝试部署模板,它已成功部署,没有任何错误。
这是 ARM 模板 post 修复了那些语法错误:
{
"$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion":"1.0.0.0",
"parameters":{
},
"variables":{
},
"resources":[
{
"name":"My new rule",
"type":"Microsoft.Insights/scheduledQueryRules",
"location":"germanywestcentral",
"apiVersion":"2020-05-01-preview",
"tags":{
},
"properties":{
"description":"Description",
"severity":3,
"enabled":true,
"scopes":[
"/subscriptions/xxxxxxxxx-xxx-xxx/resourceGroups/<RGName>/providers/microsoft.insights/components/<AppInsightsName>"
],
"evaluationFrequency":"PT5M",
"windowSize":"PT5M",
"criteria":{
"allOf":[
{
"query":"union \r\n traces,\r\n exceptions\r\n| where severityLevel > 2",
"metricMeasureColumn":"",
"resourceIdColumn":"",
"dimensions":[
],
"operator":"GreaterThan",
"threshold":5000,
"timeAggregation":"Count",
"failingPeriods":{
"numberOfEvaluationPeriods":1,
"minFailingPeriodsToAlert":1
}
}
]
},
"actions":[
{
"actionGroupId":"/subscriptions/xxxxxxx-xxxx-xxx/resourceGroups/<RGName>/providers/microsoft.insights/actionGroups/<actiongroupName>"
}
]
}
}
]
}
这里是示例输出截图供参考:
注: 如果您使用 Visual Studio 代码来开发 ARM 模板,我们建议您安装扩展 ARM Template Viewer,这将帮助您避免语法错误。