使用 ARM 模板成功创建 Azure 日志警报规则但未出现在门户中

Azure log alert rule created successfully with ARM template but not appearing in portal

我已经创建了一些用于部署 Azure 指标警报规则的 ARM 模板,但我现在需要部署日志警报规则(即基于 Application Insights 查询而不是平台指标的规则)。

我已经按照 example here (which suggests I need to create a resource of type Microsoft.Insights/scheduledQueryRules) and deployed using Azure portal's Template Deployment service as described here.

编写了模板脚本

Azure 报告部署成功,activity 日志为我提供了部署结果,包括我的新资源的 ID,例如/subscriptions/[subscription-id]/resourcegroups/[alerts-resource-group]/providers/Microsoft.Insights/scheduledQueryRules/Custom errors spike alert.

但是,当我导航到订阅 [subscription-id] 中的监视器 blade 并按资源组 [alerts-resource-group] 过滤时,我没有看到我的新警报。

作为健全性检查,我使用相同的进程针对相同的 App Insights 资源创建了一个指标警报,并且该警报确实显示在监视器中 blade。

我想我的问题是,我对 log-based 警报规则有什么误解吗?例如,Microsoft.Insights/scheduledQueryRules 类型的 Azure 'resource' 是否等同于 Monitor / Alerts / Manage alert rules 中信号类型 Log Search 的警报规则?我确信我的模板是正确的,因为它通过了验证并成功完成。但我对警报规则的结束位置感到困惑!

我应该提到的一件事是,我在与 App Insights 实例本身不同的资源组中创建警报规则,但指标警报也是如此,因此假设这并不重要。

事实证明,日志警报需要 隐藏 link 到他们正在监视的资源。否则它们会被创建但不会在门户中的任何地方列出。

在我的例子中,我将以下变量添加到模板中:

"linkToAiResource" : "[concat('hidden-link:', resourceId('microsoft.insights/components', parameters('appInsightsResourceName')))]"

然后将其作为标签包含在资源定义中,如下所示:

"tags": {
    "[variables('linkToAiResource')]": "Resource"
}

重新部署后,警报规则会出现在门户的监视器边栏选项卡中。