【问题标题】:Get URL to an Azure Alert Detail Page获取 Azure 警报详细信息页面的 URL
【发布时间】:2019-07-01 19:26:00
【问题描述】:

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

【问题讨论】:

标签: azure webhooks azure-logic-apps


【解决方案1】:

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

而 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)),

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    如果我理解正确,您正在寻找 URL Shortener。对于逻辑应用,您可以使用 Bitly connector 来生成较小的 URL。

    如果您想使用自己的 URL Shortener,您可以构建一个简单的函数应用程序来执行此操作。有很棒的 blog by Jeremy Likness (source) 介绍了如何实现这一目标。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      • 2022-12-20
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多