简体   繁体   English

Azure:使用 ARM 模板部署日志警报失败

[英]Azure: Failed log alert deployment with ARM template

I'm trying to create log alert rule using ARM template.我正在尝试使用 ARM 模板创建日志警报规则。 The template is validated successfully, but deployment fails with quite unhelpful message:模板已成功验证,但部署失败并显示非常无用的消息:

{"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}"}]}}

I tried with Portal and CLI, both ways result in the same error.我尝试使用 Portal 和 CLI,两种方式都会导致相同的错误。 This is the template I'm using (stripped of parameters for brevity):这是我正在使用的模板(为简洁起见,去掉了参数):

{
    "$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"
                }
            }
        }
    ]
}

Do you know what could be the failure reason here?你知道这里的失败原因可能是什么吗?

We have tested this in our local environment it is working fine.我们已经在本地环境中对此进行了测试,它运行良好。 Below statements are based on our analysis.以下陈述基于我们的分析。

When We have loaded the above shared template in our local environment(VS code), the intellisense of VScode showed couple of syntactical error .当我们在本地环境(VS 代码)中加载上述共享模板时,VScode 的智能感知显示了几个语法错误

After fixing all those error's we have tried deploying the template it got deployed successfully without any errors.修复所有这些错误后,我们尝试部署模板,它已成功部署,没有任何错误。

Here is the ARM template post fixing those syntactical errors :这是修复这些语法错误后的 ARM 模板

{
   "$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>"
               }
            ]
         }
      }
   ]
}

Here is the sample output Screenshot for reference:这是示例 output 截图供参考:

在此处输入图像描述

Note: If you are using Visual Studio Code, to develop ARM templates we would suggest you to install the extension ARM Template Viewer which will help you in avoiding syntactical errors.注意:如果您使用 Visual Studio Code 开发 ARM 模板,我们建议您安装扩展ARM 模板查看器,这将帮助您避免语法错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM