Using Power Automate for telemetry alerts
Note: This flow is created from this template: App Insights Monitoring Alert Email | Microsoft Power Automate; however, I made a few changes to the structure/flow to support our requirements better.
Telemetry (Application Insights) is a great tool to see what is happening. However, both KQL queries and Telemetry PowerBI apps require users to go to the app and check if something has happened. This may be great for some unexpected things, but if you want to really proactive, the best way is to be notified whenever something happens.
You can use different options for notifying – Insights Alerts, PowerBI Alerts or Power Automate. In this article, I will describe the last option – Power Automate.
Power Automate for telemetry
The Power Automate is really simple – we just need to run the KQL script, transform and process the response and send the results to other applications (Teams, Email etc…).
The first three steps are simple
- Use the recurrence as a trigger. For these notifications, I run the power automate every hour.
- The second step specifies the recipient emails. You can specify the email directly in the emailing step, but I always prefer to have the configuration option before everything else.
- The third step is the most important – it’s the connector for Application Insights that will query our telemetry and return the results. In my example, I’m looking for signals with the EventId AL0000JRG (failed and stopped job queues), except objects 260, 1441 and 1509 (failed emails and notifications).
- DO NOT FORGET to set the same period as you have for the trigger!
The next step is a condition that checks whether the previous query returned any content. I use the returned dataset (together with the length() expression) and verify that the length of the returned dataset is greater than 0.
And finally, the last two steps
- If the previous condition is false (length(returnedResults) is equal to 0) the flow ends.
- If it’s non-empty, it creates a CSV table from the returned resultsset and attaches it as an email attachment to the email sent to my address.
It’s simple, isn’t it?