Microsoft.Insights/scheduledQueryRules 无法更新范围

问题描述 投票:0回答:1

问题基本上是我试图更新 Azure 中现有的“Microsoft.Insights/scheduledQueryRules”资源,但我收到了:“范围无法更新(错误请求)”错误。

我所做的是上传一个 ARM 来更新已经存在的资源,希望我可以更改范围,因为我创建了一个新的 AppInisghts,但它引发了上面的错误。

我非常确定答案是此类资源无法更新其范围。但为什么? “Microsoft.Insights/metricAlerts”可以做到这一点:(

经过一番研究后,我在一些迁移警报的相关文档中发现了这个问题https://github.com/MicrosoftDocs/azure-docs/issues/108608

只是想确保我无法更新范围,如果这是真的,请通过这篇文章警告每个人,这样他们就不会浪费时间寻找解决方案(因为我在官方文档中没有找到任何澄清的内容)

谢谢大家。

PD:我确信删除资源并再次创建它可以解决问题,但这不是我现在可以做的事情。

您可以用来测试我的问题的 ARM 代码:

  • 先决条件:拥有已设置范围的现有资源

      {
    "type": "Microsoft.Insights/scheduledQueryRules",
    "apiVersion": "2022-08-01-preview",
    "name": "string",
    "location": "string",
    "tags": {
      "tagName1": "tagValue1",
      "tagName2": "tagValue2"
    },
    "kind": "string",
    "identity": {
      "type": "string",
      "userAssignedIdentities": {}
    },
    "properties": {
      "actions": {
        "actionGroups": [ "string" ],
        "customProperties": {}
      },
      "scopes": [ PUT NEW SCOPE HERE ],
    }
    

    }

azure azure-resource-manager
1个回答
0
投票

如果您想更新ARM中已有的代码,您需要按照以下步骤操作,因为部署完成后无法直接更新

scope
属性。

请参阅MSDoc了解相关功能。

如果资源组中已存在该资源且设置未更改,则不对该资源进行任何操作。如果您更改资源的属性值,资源将使用这些新值进行更新。

如果您尝试更新现有资源的位置、类型或范围,部署将失败并出现错误。相反,请部署具有您需要的位置或类型的新资源。

但是上述功能不适合您所提到的这种说法的环境。

我确信删除资源并再次创建它可以解决问题,但这不是我现在可以做的事情。

替代方法是使用资源下的

export template
选项。

为了实现这一目标,首先我部署了一个 Insight 计划查询规则,其范围为虚拟机资源 ID,部署成功,如下所示。

enter image description here

现在转到 Portal 中已部署的资源并访问

Automation >> Export Template
,如下所示。

参考导出模板 MS Doc。

enter image description here

生成相关 Json 模板后,单击

Deploy
选项,它会将您重定向到
custom deployment
页面。现在选择页面顶部的
Edit template
选项并添加以下具有修改范围的代码 (
workspace ID
),如下所示。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "metricAlerts_mylatalertj_name": {
            "defaultValue": "mylatalertj",
            "type": "String"
        },
        "workspace_externalid": {
            "defaultValue": "/subscriptions/xxxxx/resourcegroups/xxxxx/providers/microsoft.operationalinsights/workspaces/newwsj",
            "type": "String"
        },
        "actiongroups_newact_externalid": {
            "defaultValue": "/subscriptions/xxxxx/resourceGroups/xxxxx/providers/microsoft.insights/actiongroups/newact",
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Insights/metricAlerts",
            "apiVersion": "2018-03-01",
            "name": "[parameters('metricAlerts_mylatalertj_name')]",
            "location": "global",
            "tags": {
                "Reason": "Repro",
                "CreatedDate": "2/26/2024 8:08:20 AM",
                "CreatedBy": "NA",
                "OwningTeam": "NA"
            },
            "properties": {
                "description": "This is a metric alert",
                "severity": 3,
                "enabled": true,
                "scopes": [
                    "[parameters('workspace_externalid')]"
                ],
                "evaluationFrequency": "PT1M",
                "windowSize": "PT5M",
                "criteria": {
                    "allOf": [
                        {
                            "threshold": 0,
                            "name": "1st criterion",
                            "metricName": "<Metric Name>", //As per your requirement
                            "operator": "GreaterThan",
                            "timeAggregation": "Average",
                            "criterionType": "StaticThresholdCriterion"
                        }
                    ],
                    "odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria"
                },
                "actions": [
                    {
                        "actionGroupId": "[parameters('actiongroups_newact_externalid')]"
                    }
                ]
            }
        }
    ]
}

应用修改后,单击

Save
并进入
Review + create,
,然后选择
Create
。这将通过更改新的
scope
属性和值来启动使用现有配置部署更新的资源。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.