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

如何将触发Azure AppInsights警报的跟踪消息纳入Teams邮件负载?

实现Azure App Insights严重级别3日志触发Teams警报(含实际日志)的Logic App方案

核心步骤拆解

1. 配置App Insights警报规则(触发Logic App)

  • 在Azure门户创建日志警报规则,用Kusto查询筛选traces表中严重级别3的日志:
    traces
    | where severityLevel == 3
    | project timestamp, message, severityLevel, operation_Name, cloud_RoleName
    
  • 触发条件设为「结果数大于0」,将警报的动作组关联到你的Logic App(选择「Logic App」作为动作类型,指定目标Logic App)。

2. Logic App中提取实际日志消息

Logic App被警报触发后,可从触发器输出中获取查询结果的原始数据,关键操作如下:

  • 触发器选择「当收到Azure Monitor警报时」
  • 添加**「解析JSON」**动作,使用以下Schema匹配App Insights traces查询的输出结构:
    {
      "properties": {
        "data": {
          "properties": {
            "searchResults": {
              "properties": {
                "tables": {
                  "items": {
                    "properties": {
                      "rows": {
                        "items": {
                          "items": {},
                          "type": "array"
                        },
                        "type": "array"
                      },
                      "columns": {
                        "items": {
                          "properties": {
                            "name": {
                              "type": "string"
                            }
                          },
                          "type": "object"
                        },
                        "type": "array"
                      }
                    },
                    "type": "object"
                  },
                  "type": "array"
                }
              },
              "type": "object"
            }
          },
          "type": "object"
        }
      },
      "type": "object"
    }
    
  • 解析完成后,添加**「应用到每个」**循环,遍历searchResults.tables[0].rows,根据columns中字段的顺序提取日志消息(比如items()[1]对应message列,具体索引可从columns的name字段确认)。

3. 构造Teams消息并发送

  • 添加**「发布消息到Teams频道」**连接器(或用「发送HTTP请求」调用Teams Webhook),消息内容插入提取到的日志字段,示例格式:

    触发严重级别3警报:
    时间:@{items()[0]}
    日志内容:@{items()[1]}
    服务名称:@{items()[4]}

常见问题排查

  • 查询结果为空:检查警报规则的Kusto查询是否能返回有效数据,在Logic App运行历史中查看触发器的原始输入,确认data.searchResults是否有值。
  • 字段索引错误:通过searchResults.tables[0].columns确认每个字段的位置,比如columns中name为message的索引,对应rows数组中的位置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 07:54:56