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

如何使用Azure CLI列出资源组下所有类型的警报规则?

解决思路

智能检测器类型警报的专属查询方式

Application Insights智能检测器属于智能检测规则,和常规的指标警报、日志搜索警报不属于同一类别,因此需要用专门的CLI命令查询:

  • 针对单个Application Insights实例查询智能检测规则:

    az monitor app-insights smart-detection-rule list --resource-group 'myresourcegroup' --app '你的AppInsights实例名称' --output table
    

    也可以直接传入App Insights的资源ID替代实例名称:

    az monitor app-insights smart-detection-rule list --app '/subscriptions/你的订阅ID/resourceGroups/myresourcegroup/providers/Microsoft.Insights/components/你的AppInsights实例名称' --output table
    
  • 批量获取资源组下所有App Insights实例的智能检测规则:
    可以结合az resource list先枚举资源组内的所有App Insights资源,再循环查询每个实例的规则(以bash脚本为例):

    # 提取资源组内所有App Insights的资源ID
    app_ids=$(az resource list --resource-group 'myresourcegroup' --resource-type "Microsoft.Insights/components" --query "[].id" -o tsv)
    
    # 逐个查询智能检测规则
    for id in $app_ids; do
        echo "--- 实例 $id 的智能检测规则 ---"
        az monitor app-insights smart-detection-rule list --app $id --output table
    done
    

按特定应用筛选所有类型警报

  • 对于指标/日志搜索警报,可以通过--query参数筛选关联目标应用的规则:
    # 筛选关联到指定AppInsights的指标警报
    az monitor metrics alert list --resource-group 'myresourcegroup' --query "[?contains(targetResourceIds, '你的AppInsights资源ID')]" --output table
    
    # 筛选关联到指定AppInsights的日志搜索警报
    az monitor scheduled-query list --resource-group 'myresourcegroup' --query "[?contains(targetResourceIds, '你的AppInsights资源ID')]" --output table
    
  • 智能检测规则本身就是绑定到单个App Insights实例的,直接针对该实例查询即可得到对应应用的所有智能检测器警报。

内容的提问来源于stack exchange,提问作者evolmonster

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 18:52:07