You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Bicep结合KQL批量创建Azure告警时遇到反序列化错误的问题排查求助

通过Bicep结合KQL批量创建Azure告警时遇到反序列化错误的问题排查求助

大家好,我现在尝试用Bicep编写模板,结合KQL查询并通过for循环批量创建Azure日志告警,但部署时一直遇到反序列化错误。KQL查询在Log Analytics工作区里能正常返回结果,但放到Bicep里就报错了,想请各位帮忙看看问题出在哪。

我的Bicep模板(alerts.bicep)

// Parameters

@description('Log alerts parameter from json')
param logAlertParam object

@description('Location of Resource group ')
param location string

@description('Id of the action group')
param actiongroups_rcp_externalid string

@description('Id of the log analytics workspace')
param workspaceResourceId string

resource logAlertQuerySymbolicname 'Microsoft.Insights/scheduledQueryRules@2022-06-15' = [ for component in logAlertParam.infraComponents: {
  name: component.alertRuleName
  location: location
  kind: 'LogAlert'
  properties: {
    actions: {
      actionGroups: [
        actiongroups_rcp_externalid
      ]
      customProperties: {}
    }
    autoMitigate: false
    checkWorkspaceAlertsStorageConfigured: false
    criteria: {
      allOf: [
        {
          query: component.queryParam
          timeAggregation: component.timeaggregation
          dimensions: []
          operator: component.operator
          threshold: 1
          failingPeriods: {
            numberOfEvaluationPeriods: 1
            minFailingPeriodsToAlert: 1
          }
        }
      ]
    }
    displayName: component.alertRuleName
    enabled: true
    evaluationFrequency: component.evaluationFrequency
    scopes: [
      workspaceResourceId
    ]
    severity: component.severity
    skipQueryValidation: false
    targetResourceTypes: component.targetResourceType
    windowSize: component.windowsize
  }
}]

参数文件(parameters.json)

{
  "logAlertParam": {
    "infraComponents": [
      {
        "alertRuleName": "AKS-Cluster-Deletion",
        "queryParam": "AzureActivity\n| where ResourceProviderValue contains \"MICROSOFT.CONTAINERSERVICE\" and OperationNameValue contains \"MICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/DELETE\"\n| where ActivityStatusValue contains \"Success\"\n| project TimeGenerated, _ResourceId, Caller, ActivityStatusValue, CallerIpAddress\n",
        "timeaggregation": "Count",
        "operator": "GreaterThanOrEqual",
        "evaluationFrequency": "P1D",
        "severity": 0,
        "ResourceType": "Microsoft.ContainerService/managedClusters",
        "windowSize": "P1D",
        "threshold": 1
      }
    ]
  }
}

部署时遇到的错误信息

2023-02-20T14:59:20.6470013Z ERROR: {"status":"Failed","error":
{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":
[{"code":"Conflict","message":"{\r\n "status": "Failed",\r\n "error":
{\r\n "code": "ResourceDeploymentFailure",\r\n "message": "The 'AzureAsyncOperationWaiting' resource operation completed with terminal provisioning state 'Failed'.",\r\n "details": [\r\n {\r\n
"code": "DeploymentFailed",\r\n "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",\r\n
"details": [\r\n {\r\n "code": "BadRequest",\r\n
"message": "{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n \"message\": \"{\\r\\n \\\"error\\\": {\\r\\n \\\"code\\\": \\\"InvalidRequestContent\\\",\\r\\n \\\"message\\\": \\\"The request content was invalid and could not be deserialized: 'Error converting value \\\\\\\"Microsoft.ContainerService/managedClusters\\\\\\\" to type 'System.Collections.Generic.List`1[System.String]'. Path 'properties.targetResourceTypes', line 1, position 1185.'\\\"\\r\\n }\\r\\n}\"\r\n }\r\n}"\r\n }\r\n ]\r\n }\r\n
]\r\n }\r\n}"}]}}

错误里的关键提示是:
Error converting value "Microsoft.ContainerService/managedClusters" to type 'System.Collections.Generic.List1[System.String]'. Path 'properties.targetResourceTypes', line 1, position 1185.`

我已经确认KQL查询在Log Analytics里能正常输出结果,但部署Bicep时就触发这个错误,实在找不到问题所在,麻烦大家帮忙分析一下!

备注:内容来源于stack exchange,提问作者ramesh reddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 11:29:12