【Azure Logic App】使用Logic App来定制Monitor Alert邮件内容遇见无法获取SearchResults的情况

简介: Log search alert rules from API version 2020-05-01 use this payload type, which only supports common schema. Search results aren't embedded in the log search alerts payload when you use this version.

问题描述

在使用Azure Monitor获取自定义告警指标并发出告警邮件时,默认的告警邮件内容不满足需要,需要把自定义查询语句的结果也直接显示在邮件中。

查阅官方文档(Customize alert notifications by using Logic Apps),可以通过Logic App来自定义Alert邮件内容。

但是,在实验中,遇见了内容为空的情况!在获取内容部分,使用的配置是 string(triggerBody()?['data']?['alertContext']?['SearchResults']), 如下:

{
  "type": "InitializeVariable",
  "inputs": {
    "variables": [
      {
        "name": "Get-Context",
        "type": "string",
        "value": "@string(triggerBody()?['data']?['alertContext']?['SearchResults'])"
      }
    ]
  },
  "runAfter": {
    "Initialize_variable": [
      "Succeeded"
    ]
  }
}

这是什么情况呢?如何来解决这个问题呢?

 

问题解答

同样,也需要对比Alert的官方文档,在文档中发现特别说明( the search results aren't embedded in the log search alerts payload. ):

所以 SearchResults 中不包含Alert 内容是设计使然。如果想获取结果,需要通过或HTTP请求去获取 LinkToSearchResultsAPI 的返回值。

在Logic App中需要进行的操作是,添加一个变量 ResultURL 和 HTTP 操作。

变量 ResultURL 的值设置为:string(triggerBody()?['data']?['alertContext']?['condition']?['allOf'][0]?['LinkToSearchResultsAPI'])

第一步添加变量 ResultURL 的配置代码如下:

{
  "type": "InitializeVariable",
  "inputs": {
    "variables": [
      {
        "name": "ResultURL",
        "type": "string",
        "value": "@string(triggerBody()?['data']?['alertContext']?['condition']?['allOf'][0]?['LinkToSearchResultsAPI'])"
      }
    ]
  },
  "runAfter": {
    "Initialize_variable_1": [
      "SUCCEEDED"
    ]
  }
}

如此调整之后,就可以实现从Alert中获取到告警的详细内容!

 

参考资料

Customize alert notifications by using Logic Apps : https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-logic-apps?tabs=send-email

Sample log search alert when the monitoringService = Log Alerts V2 : https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-common-schema#sample-log-search-alert-when-the-monitoringservice--log-alerts-v2

 

 


当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

相关文章
|
9月前
|
存储 安全 Linux
【Azure App Service】在App Service中查看CA证书
在 Azure App Service 中,使用自签名或私有 CA 证书的远程服务可能会导致 SSL 握手失败。解决方法包括使用受信任 CA 签发的证书,或通过 App Service Environment 加载自定义根证书,实现安全连接。
213 4
|
10月前
|
域名解析 网络协议 API
【Azure Container App】配置容器应用的缩放规则 Managed Identity 连接中国区 Azure Service Bus 问题
本文介绍了在 Azure Container Apps 中配置基于自定义 Azure Service Bus 的自动缩放规则时,因未指定云环境导致的域名解析错误问题。解决方案是在扩展规则中添加 `cloud=AzureChinaCloud` 参数,以适配中国区 Azure 环境。内容涵盖问题描述、原因分析、解决方法及配置示例,适用于使用 KEDA 实现事件驱动自动缩放的场景。
223 1
|
7月前
|
Java 应用服务中间件 API
【App Service】部署War包到Azure云上遇404错误
Java应用部署至Azure App Service for Windows后报404,本地运行正常。经排查,日志提示类文件版本不兼容:应用由Java 17(class file version 61.0)编译,但环境仅支持到Java 11(55.0)。错误根源为Java版本不匹配。调整App Service的Java版本至17后问题解决,成功访问接口。
696 3
|
存储 安全 数据安全/隐私保护
【Azure Function App】在Function App中使用System Managed Identity访问Storage Account
本文介绍了如何在Azure Function中使用托管身份(Managed Identity)替代AzureWebJobsStorage连接函数应用到存储账户,以提高安全性并减少Access Key的使用。具体步骤包括:1) 启用系统分配的身份;2) 为函数应用授予存储访问权限,添加必要角色(如Storage Blob Data Contributor);3) 配置`AzureWebJobsStorage__blobServiceUri`参数指定Blob Service Uri。完成后删除旧配置,即可通过Managed Identity访问Storage Account。
400 20
|
7月前
|
存储 Linux 网络安全
【Azure App Service】Root CA on App Service
Azure App Service for Windows应用连接外部SSL服务时,需确保其证书由受信任的根CA颁发。多租户环境下无法修改根证书,但ASE(单租户)可加载自定义CA证书。若遇证书信任问题,可更换为公共CA证书或将应用部署于ASE并导入私有CA证书。通过Kudu的PowerShell(Windows)或SSH(Linux)可查看当前受信任的根证书列表。
162 13
|
8月前
|
API 网络架构 容器
【Azure Container App】查看当前 Container App Environment 中的 CPU 使用情况的API
在扩展 Azure Container Apps 副本时,因 Container App Environment 的 CPU 核心数已达上限(500 cores),导致扩展失败。本文介绍如何使用 `az rest` 命令调用 Azure China Cloud 管理 API,查询当前环境的 CPU 使用情况,并提供具体操作步骤及示例。
296 17
|
8月前
|
网络协议 Java Linux
【App Service】在Azure环境中如何查看App Service实例当前的网络连接情况呢?
在 Azure App Service(Windows 和 Linux)中部署应用时,分析网络连接状态是排查异常、验证端口监听及确认后端连接的关键。本文介绍如何在 Linux 环境中使用 `netstat` 命令查看特定端口(如 443、3306、6380)的连接情况,并解析输出结果。同时说明在 Windows App Service 中 `netstat` 被禁用的情况下,如何通过门户抓包等替代方法进行网络诊断。内容涵盖命令示例、操作步骤及附录说明,帮助开发者快速掌握云环境中的网络分析技巧。
213 11
|
8月前
|
数据安全/隐私保护
【Azure Function App】PowerShell Function 执行 Get-AzAccessToken 的返回值类型问题:System.String 与 System.Security.SecureString
将PowerShell Function部署到Azure Function App后,Get-AzAccessToken返回值类型在不同环境中有差异。正常为SecureString类型,但部分情况下为System.String类型,导致后续处理出错。解决方法是在profile.ps1中设置环境变量$env:AZUREPS_OUTPUT_PLAINTEXT_AZACCESSTOKEN=false,以禁用明文输出。
217 1
|
11月前
|
Linux Shell 网络安全
【Azure App Service】使用 tcpping 来获取App Service的网络状态并把结果保存到文本文件中
本文针对云服务使用中网络状态抖动的问题,以Azure App Service为例,介绍如何利用其自带的`tcpping`工具检测网络连通性。通过在Windows或Linux版App Service中执行`tcpping`命令,将结果输出至文本文件,分析timeout行数以判断网络抖动的时间点。文章还提供了具体操作步骤、效果图及参考资料,帮助用户高效排查网络问题。
340 47
|
10月前
|
Java Shell Maven
【Azure Container App】构建Java应用镜像时候遇无法编译错误:ERROR [build 10/10] RUN ./mvnw.cmd dependency:go-offline -B -Dproduction package
在部署Java应用到Azure Container App时,构建镜像过程中出现错误:“./mvnw.cmd: No such file or directory”。尽管项目根目录包含mvnw和mvnw.cmd文件,但依然报错。问题出现在Dockerfile构建阶段执行`./mvnw dependency:go-offline`命令时,系统提示找不到可执行文件。经过排查,确认是mvnw文件内容异常所致。最终通过重新生成mvnw文件解决该问题,镜像成功构建。
562 1

热门文章

最新文章