The simple way to add alerts to Logic App Workflows
It’s essential to monitor your deployed Logic App workflows to capture unexpected failures. The easiest way to do this is with an Azure Alert[1]
Alerts help you detect and address issues before users notice them by proactively notifying you when Azure Monitor data indicates there might be a problem with your infrastructure or application.
A subscription may require many alerts, so it doesn’t make sense to template their creation everywhere. This article describes a simple way to add an alert to a list of workflows. This technique also demonstrates how to use arrays in bicep.
Bicep module
First up, you will need a bicep module that creates a single alert. The module will be called multiple times from another bicep template with appropriate parameters for each workflow.
The module incorporates some standard practices I use, including baked-in naming conventions e.g., the Logic App name always starts with intg-la- and ends with the location and environment codes e.g., “aue” and “prod”.
The template first retrieves a reference to an existing App Insights instance. An App Insights instance is required for an alert.
Next, an existing Action Group reference is retrieved. The alert will send notifications to any destination configured on the Action Group.
Finally, the alert is created to monitor the Runs Failed metric using a default evaluation frequency and window size. In the example, failures occurring over a 5-minute window (PT5M) will be checked every minute (PT1M). This basically generates one alert for all failures within that 5-minute window.
param environmentAbbr string
param locationAbbr string
param locationName string
param logicAppNameBase string
param workflowNames array
param appInsightsName string
param managementSubscriptionId string
param managementResourceGroup string
param actionGroupName string
var logicAppName = 'intg-la-${logicAppNameBase}-${locationAbbr}-${environmentAbbr}'
resource appInsights 'Microsoft.Insights/components@2020-02-02' existing = {
name: '${appInsightsName}-${locationAbbr}-${environmentAbbr}'
[1] https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-overview
scope: resourceGroup(managementSubscriptionId,
&'${managementResourceGroup}-${locationAbbr}-${environmentAbbr}&')
}
resource actionGroup Microsoft.Insights/actionGroups@2022-06-01&' existing = {
name: actionGroupName
}
resource metricAlertsLogicApp &'Microsoft.Insights/metricAlerts@2018-03-01&' =
[for (workflowName, index) in workflowNames: {
name: &'[${toUpper(environmentAbbr)}] Runs Failed - ${logicAppName}-${workflowName}&'
location: locationName
properties: {
severity: 1
enabled: true
scopes: [
appInsights.id
]
evaluationFrequency: &'PT1M&'
windowSize: &'PT5M&'
criteria: {
allOf: [
{
threshold: 0
name: &'Metric1&'
metricNamespace: &'${logicAppName}.${workflowName}&'
metricName: &'Runs Failed&'
operator: &'greaterthan&'
timeAggregation: &'count&'
criterionType: &'StaticThresholdCriterion&'
skipMetricValidation: true
}
}
]
&'odata.type&': &'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria&'
}
autoMitigate: false
targetResourceType: &'Microsoft.Insights/components&'
targetResourceRegion: &'australiaeast&'
actions: [
{
actionGroupId: actionGroup.id
webHookProperties: {
}
}
]
}
}]
Bicep template
Now what is needed is a bicep template to call the module. This is where using an array makes it easy to add as many workflow names as you need.
The array logicapps contains a list of Logic Apps and each of the workflows that require an alert. The bicep template loops over the array, calling the module each time to create each alert.
And hey presto, you’re in business.
Note that logicAppNameBase is the name of the Logic App without the standard prefix and suffixes.
param locationAbbr string = &'aue&'
param locationName string = &'Global&'
param actionGroupName string = &'MyAlertGroup&'
param appInsightsName string = &'ai-shared&'
param managementSubscriptionId string = &'XXXXXX-XXXXX-XXXXXX-XXX&'
param managementResourceGroup string = &'rg-management&'
param logicapps array = [
{
logicAppNameBase: &'hr&'
workflows: [
&'wf-intg-la-createwidget&'
&'wf-intg-la-response-duplicate&'
&'wf-intg-la-response-eligible&'
]
}
{
logicAppNameBase: &'infomgmt&'
workflows: [
&'wf-intg-la-newaccount&'
&'wf-intg-la-webhook-deliveryreport&'
]
}
]
module logicApp &'alerts.logicapp.module.bicep&' = [for logicapp in logicapps: {
name: &'logicAppAlerts${toUpper(logicapp.logicAppNameBase)}&'
params: {
environmentAbbr: environmentAbbr
locationAbbr: locationAbbr
locationName: locationName
logicAppNameBase: logicapp.logicAppNameBase
workflowNames: logicapp.workflows
appInsightsName: appInsightsName
managementSubscriptionId: managementSubscriptionId
managementResourceGroup: managementResourceGroup
actionGroupName: actionGroupName
}
}]
Using Bicep with an array to add alerts for Logic App workflows is an efficient and straightforward approach to monitor your deployed Logic App workflows, alerting to unexpected failures and enabling proactive support. By leveraging the capabilities of Bicep and Azure Alerts, you can create a more resilient and proactive infrastructure that keeps you ahead of potential issues before they impact your users.
Adaptiv, with its extensive experience in integration, consulting, execution, and data and analytics services, is well-positioned to help you implement such a solution. Our team of experts is committed to delivering world-class services that cater to your specific needs. By working with us, you can expect fast, friendly, agile, and no-nonsense professional service and outcomes that provide value to your bottom line.
Don’t wait for your application to fail before taking action. Get ahead of potential issues and provide your users with the best possible experience. Reach out to Adaptiv today and let us help you implement a robust and proactive monitoring solution using Bicep and Azure Alerts. Together, we can ensure the smooth running and success of your application.
Contact Adaptiv now for a consultation and learn how our expertise can benefit your business by implementing Bicep and Azure Alerts for your Logic App workflows. Call us at (+64 09 2806675) to get started.