首页 > 解决方案 > 获取 Azure 警报详细信息页面的 URL

问题描述

我正在使用逻辑应用程序创建一个 webhook(用于日志搜索警报),然后将警报有效负载推送到 slack。我正在尝试将 url 与警报有效负载数据(松弛)一起发送到实际警报详细信息页面,而不使用内置字段linkToSearchResults,因为该 url 很大,因为我的查询很长。我本质上想要一个友好的 url,类似于 azure 用于在 Azure Monitor 中查看警报的电子邮件模板中提供的 url 。我无法找到将这个链接放在一起的方法,我知道我可以在我的 webhook 的警报上使用自定义 json 有效负载,但是我将如何生成这个友好的 url?

标签: azurewebhooksazure-logic-apps

解决方案


我相信问题更多是关于如何获得实际警报的链接,就像在这样的电子邮件中显示的那样。

在此处输入图像描述

而 linkToSearchResults 进入我们可以执行搜索查询的页面。

更多地查看警报的链接,它似乎被格式化为

https://ms.portal.azure.com/#blade/Microsoft_Azure_Monitoring/AlertDetailsTemplateBlade/alertId/%2fsubscriptions%2f<subscription_id>%2fproviders%2fMicrosoft.AlertsManagement%2falerts%2f<alert_id>/invokedFrom/emailcommonschema

现在,如果我们查看启用公共模式时作为警报的一部分收到的 json,它具有这些信息。

{
  "essentials": {
    "alertId": "/subscriptions/<subscription ID>/providers/Microsoft.AlertsManagement/alerts/b9569717-bc32-442f-add5-83a997729330",
    "alertRule": "Contoso IT Metric Alert",
    "severity": "Sev3",
    "signalType": "Metric",
    "monitorCondition": "Fired",
    "monitoringService": "Platform",
    "alertTargetIDs": [
      "/subscriptions/<subscription ID>/resourceGroups/aimon-rg/providers/Microsoft.Insights/components/ai-orion-int-fe"
    ],
    "originAlertId": "74ff8faa0c79db6084969cf7c72b0710e51aec70b4f332c719ab5307227a984f",
    "firedDateTime": "2019-03-26T05:25:50.4994863Z",
    "description": "Test Metric alert",
    "essentialsVersion": "1.0",
    "alertContextVersion": "1.0"
  }
}

来自msdoc的参考。

让我们看看,这个模式有essentials.alertId,它看起来很熟悉上面 url 中使用的内容(但以 url 编码形式)。

所以最终生成友好 url 来提醒的代码变成了这样

string.Format("https://ms.portal.azure.com/#blade/Microsoft_Azure_Monitoring/AlertDetailsTemplateBlade/alertId/{0}",
                                HttpUtility.UrlEncode(alertEssentials.AlertId)),

希望这可以帮助!


推荐阅读