Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get URL to an Azure Alert Detail Page

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?

like image 718
newbie_86 Avatar asked Mar 03 '23 18:03

newbie_86


1 Answers

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!

like image 164
akashperfect Avatar answered Mar 06 '23 15:03

akashperfect