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

标签 azure webhooks azure-logic-apps

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

最佳答案

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

enter image description here

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

希望这有帮助!

关于azure - 获取 Azure 警报详细信息页面的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56841361/

相关文章:

sql - 我们可以为逻辑应用 - SQL 数据库连接器定义超时吗

azure - 如何从http触发的逻辑应用程序解析xml?

azure - 将 Json 转换为 Poco Collection/如何编写 For Each?

rest - 如何使 Application Insights Rest Api 返回所有数据,即使它不存在?

azure - 在Azure函数(Blob触发器)中动态计算 "Path"的文件名模式

从 native 应用程序进行 Azure Active Directory 身份验证,无需用户登录

javascript - 添加操作 woocommerce_add_to_cart 破坏网站原始添加到购物车功能

azure - 在 Azure API 管理中重命名出站请求中的查询参数

php - Shopify Webhooks 到 Laravel 路线

webhooks - Slack webhook html 表