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

Azure Logic App 非JSON格式内容提取AlertID问题求助

提取Azure Logic App Compose操作中的AlertID值

问题场景

配置Azure Logic App的某一Compose操作时,输出为非结构化文本(非JSON格式),需要从中提取AlertID值,但调用函数时因格式问题触发无效格式错误。Compose操作输出内容如下:

:azure: :alert:
非生产环境警报:RuleCpupercetange
严重级别: Sev4
时间戳: 2024-10-10T17:55:18.5144302Z
警报ID: /subscriptions/32476574-bf58-4703-96d9-4378327845/providers/Microsoft.AlertsManagement/alerts/629bd98a-f9b5-c79a-75b1-b807b48d0002
点击此处查看代码


受影响资源: W008ssaltmost
资源修改人:unknown@gmail.com


选择响应:(含交互元素)

解决方案

可通过Azure Logic App内置字符串函数直接提取AlertID,无需转换为JSON:

方法1:Split函数分步提取

按分隔符拆分文本,逐步定位AlertID:

  1. 获取包含AlertID的文本片段:
    split(outputs('Compose'), '*警报ID*: ')[1]
    
  2. 拆分出AlertID所在行:
    split(split(outputs('Compose'), '*警报ID*: ')[1], decodeUriComponent('%0A'))[0]
    
  3. 去除前后反引号,得到纯ID值:
    replace(replace(split(split(outputs('Compose'), '*警报ID*: ')[1], decodeUriComponent('%0A'))[0], '```', ''), '`', '')
    

方法2:正则表达式匹配提取

用matches函数精准匹配Azure警报ID格式,直接提取目标值:

first(matches(outputs('Compose'), '/subscriptions/[a-f0-9-]+/providers/Microsoft.AlertsManagement/alerts/[a-f0-9-]+'))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 05:42:08