获取 Azure 警报详细信息页面的 URL

new*_*_86 4 azure webhooks azure-logic-apps

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

小智 6

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

在此处输入图片说明

而 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
Run Code Online (Sandbox Code Playgroud)

现在,如果我们查看在启用公共模式时作为警报一部分收到的 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"
  }
}
Run Code Online (Sandbox Code Playgroud)

来自msdoc 的参考。

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

所以生成友好的 url 到 alert 的最终代码变成了这样

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

希望这可以帮助!


Pra*_*SFT 0

如果我理解正确的话,您正在寻找 URL 缩短器。对于逻辑应用程序,有一个Bitly 连接器,您可以使用它来生成较小的 URL。

如果您想使用自己的 URL 缩短器,您可以构建简单的函数应用程序来执行此操作。Jeremy Likness有一篇很棒的博客(来源),其中介绍了如何实现这一目标。

使用您自己的缩短器,您必须使用HTTP 操作来获取缩短的 URL。