4
votes

I am using a logic app to create a webhook (used in a log search alert), which then pushes the alert payload to slack. I am trying to send along with the alert payload data (to slack) a url to the actual alert detail page and not use the built in field linkToSearchResults as that url is huge because my query is long. I essentially want a friendly url, something like the url that is provided in the email template that azure uses for View the alert in Azure Monitor. I have not been able to find a way of putting this link together, I know I can use a custom json payload on the alert for my webhook, but how would I generate this friendly url?

2
The provided solution works great, but the URL format could change and break. I've added a feature request to provide the URL in the common schema for alerts, so vote it up! feedback.azure.com/forums/913690-azure-monitor/suggestions/…Banjer

2 Answers

6
votes

I believe the question is more around how to get the link to actual alert, like which shows up in email like this.

enter image description here

Whereas the linkToSearchResults takes to the page where we can execute the search query.

Looking more into the link for the alert, it seems to be formatted as

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

Now if we look at the json we receive as part of the alert when common schema is enabled, it has these info.

{
  "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"
  }
}

Reference from msdoc.

Lets see, this schema has essentials.alertId which looks familiar to what is being used in the url above (but in url encoded form).

So the final code to generate the friendly url to alert becomes something like this

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

Hope this helps!

0
votes

If I understand correctly, you are looking for a URL Shortener. For Logic Apps, there is a Bitly connector that you could use to generate the smaller URLs.

If you'd like to use own URL Shortener, you could build simple function app that does this. There is great blog by Jeremy Likness (source) that covers how one could achieve this.

With your own shortener, you would have to use the HTTP Action to get the shortened URL.