-
Notifications
You must be signed in to change notification settings - Fork 2
/
modules.alertRulesLogicAppExecutions.bicep
104 lines (96 loc) · 3.64 KB
/
modules.alertRulesLogicAppExecutions.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
@description('The prefix will be used for every parameter that represents a resource name')
param resourceNamePrefix string
@description('The suffix will be appended to every parameter that represents a resource name')
param resourceNameSuffix string
param logicAppResId string
param actionGroupResId string
param alertOnEveryFailure bool = false
param enableAlertRules bool = true
var alertRuleRunFailurePercentageName = '${resourceNamePrefix}-lafailpct-ar-${resourceNameSuffix}'
var alertRuleRunFailedExecutionsName = '${resourceNamePrefix}-lafails-ar-${resourceNameSuffix}'
// General note 1: Currently metrics can only gathered for a specific resource, not for all Logic Apps in a Resource Group or Subscription. If you
// need to create a general monitoring (i.e. not resource specific), you need to enable logging to Log Analytics Workspace
// (via Diagnostic Settings) and create a query-based alert.
// General note 2: There are metrics for Triggers, Actions and Runs. Important: If a Trigger fails, no Run will be created (so you need to monitor both)
// More: https://learn.microsoft.com/en-us/azure/logic-apps/monitor-logic-apps-log-analytics
resource alertRuleRunFailurePercentageRes 'Microsoft.Insights/metricAlerts@2018-03-01' = if (!empty(actionGroupResId) && !empty(logicAppResId) && !alertOnEveryFailure) {
name: alertRuleRunFailurePercentageName
location: 'global'
properties: {
severity: 3
enabled: enableAlertRules
scopes: [
logicAppResId
]
targetResourceType: 'Microsoft.Logic/workflows'
evaluationFrequency: 'PT30M'
windowSize: 'PT1H'
criteria: {
allOf: [
{
name: 'FailureRate' // Required name to identify criteria - can have any value
metricNamespace: 'Microsoft.Logic/workflows'
metricName: 'RunFailurePercentage'
operator: 'GreaterThan'
threshold: 50
timeAggregation: 'Total'
criterionType: 'StaticThresholdCriterion'
}
]
'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
}
autoMitigate: true // Auto-resolve (default = true)
actions: [
{
actionGroupId: actionGroupResId
webHookProperties: {
}
}
]
}
}
resource alertRuleRunFailedExecutionsRes 'Microsoft.Insights/metricAlerts@2018-03-01' = if (!empty(actionGroupResId) && !empty(logicAppResId) && alertOnEveryFailure) {
name: alertRuleRunFailedExecutionsName
location: 'global'
properties: {
severity: 1
enabled: enableAlertRules
scopes: [
logicAppResId
]
targetResourceType: 'Microsoft.Logic/workflows'
evaluationFrequency: 'PT1H'
windowSize: 'PT1H'
criteria: {
allOf: [
{
name: 'Triggers' // Required name to identify criteria - can have any value
metricNamespace: 'Microsoft.Logic/workflows'
metricName: 'TriggersFailed'
operator: 'GreaterThan'
threshold: 0
timeAggregation: 'Total'
criterionType: 'StaticThresholdCriterion'
}
{
name: 'Runs' // Required name to identify criteria - can have any value
metricNamespace: 'Microsoft.Logic/workflows'
metricName: 'RunsFailed'
operator: 'GreaterThan'
threshold: 0
timeAggregation: 'Total'
criterionType: 'StaticThresholdCriterion'
}
]
'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
}
autoMitigate: false // Auto-resolve (default = true)
actions: [
{
actionGroupId: actionGroupResId
webHookProperties: {
}
}
]
}
}