如何在警报规则或操作规则的目标资源移动到其他 Azure 区域时对这些规则进行更新How to update alert rules or action rules when their target resource moves to a different Azure region

本文介绍了当你在区域之间移动其他 Azure 资源时,为何现有的警报规则操作规则会受影响,以及如何识别和解决这些问题。This article describes why existing alert rules and action rules may be impacted when you move other Azure resources between regions, and how to identify and resolve those issues. 请查看主要的资源移动文档,详细了解何时需要在区域之间移动资源,以及用于设计移动过程的清单。Check the main resource move documentation for additional information on when is resource move between regions useful and a checklist of designing a move process.

存在此问题的原因Why the problem exists

警报规则和操作规则引用其他 Azure 资源。Alert rules and action rules reference other Azure resources. 示例包括 Azure VMAzure SQLAzure 存储Examples include Azure VMs, Azure SQL, and Azure Storage. 当你移动这些规则所引用的资源时,这些规则可能会因为找不到其引用的资源而停止正常工作。When you move the resources those rules refer to, the rules are likely to stop working correctly because they can't find the resources they reference.

规则可能会在移动目标资源后停止工作的两个主要原因如下所述:There are two main reasons why your rules might stop working after moving the target resources:

  • 你的规则的范围显式引用了旧资源。The scope of your rule is explicitly referring the old resource.
  • 你的警报规则基于指标。Your alert rule is based on metrics.

规则范围显式引用了旧资源Rule scope explicitly refers to the old resource

大多数情况下,当你移动资源时,其资源 ID 会发生更改。When you move a resource, its resource ID changes in most cases. 在后台,系统会将该资源复制到新区域中,然后将其从旧区域中删除。Behind the scenes, the system replicates the resource into the new region before deleting it from the old region. 此过程要求两个资源以及两个不同的资源 ID 在一小段时间内同时存在。This process requires that two resources and thus two different resource IDs exist simultaneously for a small period of time. 由于资源 ID 必须是唯一的,因此在此过程中必须创建一个新 ID。Since resource IDs must be unique, a new ID must be created during the process.

移动资源对现有规则有何影响?How does moving the resource affect existing rules?

警报规则和操作规则在应用到资源时有一个资源范围。Alert rules and action rules have a scope of resources they apply to. 该范围可以是整个订阅、某个资源组或者一个或多个特定资源。The scope could be an entire subscription, a resource group, or one or more specific resources. 例如,下面是范围为两个资源(两个虚拟机)的一个规则:For example, here is a rule with a scope with two resources (two virtual machines):

多资源警报规则

如果规则范围显式提到了某个资源,而该资源已移动并更改了其资源 ID,则该规则会查找一个错误的或不存在的资源,因此会失败。If the rule scope explicitly mentions a resource, and that resource has moved and changed its resource ID, then that rule will look for a wrong or non-existent resource and thus fail.

如何解决此问题?How to fix the problem?

更新或重新创建受影响的规则,使之指向新资源。Update or recreate the affected rule to point to the new resource. 可以在本文的后面部分找到更新此范围的过程。The process to update the scope is found later in this article.

此问题影响这些规则类型:The problem applies to these rule types:

  • 活动日志警报规则Activity log alert rules
  • 操作规则Action rules
  • 经典警报Classic alerts
  • 指标警报 - 有关详细信息,请参阅下一部分:基于指标的警报规则Metric alerts - For more information, see the next section Alert rules based on metrics.

备注

日志搜索警报规则和智能检测器警报规则不受影响,因为它们的范围是工作区或 Application Insights。Log search alert rules and smart detector alert rules are not affected because their scope is either a workspace or Application Insights. 这两种范围当前都不支持区域移动。Neither of these scopes currently support region moves.

基于指标的警报规则Alert rules based on metrics

Azure 资源发出的指标是区域性的。The metrics that Azure resources emit are regional. 每次将资源移到新区域时,它就会开始在该新区域中发出指标。Whenever a resource moves to a new region, it starts emitting its metrics in that new region. 因此,需要更新或重新创建基于指标的任何警报规则,使其指向正确区域中的当前指标流。As a result, any alert rules based on metrics need to be updated or recreated so they point to the current metric stream in the correct region.

此说明同时适用于指标警报规则可用性测试警报规则This explanation applies to both metric alert rules and availability test alert rules.

如果移动了范围中的所有资源,则无需重新创建规则。If all the resources in the scope have moved, you don't need to recreate the rule. 可以直接更新警报规则的任何字段(例如警报规则说明),然后将其保存。You can just update any field of the alert rule, such as the alert rule description, and save it. 如果仅移动了范围中的某些资源,则需要从现有规则中删除已移动的资源,并创建一个仅涵盖已移动资源的新规则。If only some of the resources in the scope have moved, you need to remove the moved resources from the existing rule and create a new rule that covers only the moved resources.

解决问题的过程Procedures to fix problems

从 Azure 门户中查明与已移动资源关联的规则Identifying rules associated with a moved resource from the Azure portal

  • 对于警报规则 - 导航到“警报”>“管理警报规则”> 按包含项目的订阅和移动的资源进行筛选。For alert rules - Navigate to Alerts > Manage alert rules > filter by the containing subscription and the moved resource.

备注

活动日志警报规则不支持此过程。Activity Log alert rules do not support this process. 无法更新活动日志警报规则的范围,也无法将其指向另一个订阅中的资源。It’s not possible to update the scope of an activity log alert rule and have it point to a resource in another subscription. 你可以改为创建新规则来替换旧规则。Instead you can create a new rule that will replace the old one.

  • 对于操作规则 - 导航到“警报”>“管理操作”>“操作规则(预览版)”> 按包含项目的订阅和移动的资源进行筛选。For action rules - Navigate to Alerts > Manage actions > Action rules (preview) > filter by the containing subscription and the moved resource.

从 Azure 门户中更改规则的范围Change scope of a rule from the Azure portal

  1. 以单击方式打开你在上一步中查明的规则。Open the rule that you have identified in the previous step by clicking on it.
  2. 在“资源”下,单击“编辑”并根据需要调整范围。Under Resource, click Edit and adjust the scope, as needed.
  3. 根据需要调整规则的其他属性。Adjust other properties of the rule as needed.
  4. 单击“保存” 。Click Save.

更改警报规则范围

使用 Azure 资源管理器模板更改规则的范围Change the scope of a rule using Azure Resource Manager templates

  1. 获取规则的 Azure 资源管理器模板。Obtain the Azure Resource Manager template of the rule. 若要从 Azure 门户导出规则的模板,请执行以下操作:To export the template of a rule from the Azure portal:
    1. 在门户中导航到“资源组”部分,打开包含该规则的资源组。Navigate to the Resource Groups section in the portal and open the resource group containing the rule.
    2. 在“概览”部分中,选中“显示隐藏的类型”复选框,并按规则的相关类型进行筛选。In the Overview section, check the Show hidden type checkbox, and filter by the relevant type of the rule.
    3. 选择相关规则以查看其详细信息。Select the relevant rule to view its details.
    4. 在“设置”下,选择“导出模板”。 Under Settings, select Export template.
  2. 修改模板。Modify the template. 如果需要,请将其拆分为两个规则(这适用于指标警报的某些案例,如上文所述)。If needed, split into two rules (relevant for some cases of metric alerts, as noted above).
  3. 重新部署模板。Redeploy the template.

使用 REST API 更改规则的范围Change scope of a rule using REST API

  1. 获取现有规则(指标警报活动日志警报Get the existing rule (metric alerts, activity log alerts)
  2. 修改范围(活动日志警报Modify the scope (activity log alerts)
  3. 重新部署规则(指标警报活动日志警报Redeploy the rule (metric alerts, activity log alerts)

使用 PowerShell 更改规则的范围Change scope of a rule using PowerShell

  1. 获取现有规则(指标警报活动日志警报操作规则)。Get the existing rule (metric alerts, activity log alerts, action rules).
  2. 修改范围。Modify the scope. 如果需要,请将其拆分为两个规则(这适用于指标警报的某些案例,如上文所述)。If needed, split into two rules (relevant for some cases of metric alerts, as noted above).
  3. 重新部署规则(指标警报活动日志警报操作规则)。Redeploy the rule (metric alerts, activity log alerts, action rules).

使用 Azure CLI 更改规则的范围Change the scope of a rule using Azure CLI

  1. 获取现有规则(指标警报活动日志警报)。Get the existing rule (metric alerts, activity log alerts).
  2. 直接更新规则范围(指标警报活动日志警报Update the rule scope directly (metric alerts, activity log alerts)
  3. 如果需要,请将其拆分为两个规则(这适用于指标警报的某些案例,如上文所述)。If needed, split into two rules (relevant for some cases of metric alerts, as noted above).

后续步骤Next steps

了解如何解决警报通知指标警报日志警报的其他问题。Learn about fixing other problems with alert notifications, metric alerts, and log alerts.