Skip to content

Commit 9963189

Browse files
committed
Add an alert on Exceptions for App Insights
We want to trigger an alert whenever there is an exception for manage-breast-screening - specifically for the Invite team's container app jobs in the notifications app. This should trigger whenever the Exception count is above 0 - may want to tweak that but in theory there should never be an Exception unless something has completely failed.
1 parent b7a1915 commit 9963189

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
resource "azurerm_monitor_metric_alert" "res-0" {
2+
count = var.enable_alerting ? 1 : 0
3+
4+
auto_mitigate = true
5+
description = "Triggered by any Exception"
6+
enabled = true
7+
frequency = var.alert_frequency
8+
name = "Exceptions"
9+
resource_group_name = var.resource_group_name
10+
scopes = [azurerm_application_insights.appins.id]
11+
severity = 1
12+
window_size = local.alert_window_size
13+
14+
action {
15+
action_group_id = var.action_group_id
16+
}
17+
18+
criteria {
19+
aggregation = "Count"
20+
metric_name = "exceptions/count"
21+
metric_namespace = "microsoft.insights/components"
22+
operator = "GreaterThan"
23+
skip_metric_validation = false
24+
threshold = 0
25+
}
26+
}

infrastructure/modules/app-insights/variables.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,36 @@ variable "resource_group_name" {
3333
type = string
3434
description = "The name of the resource group in which the App Insights is created. Changing this forces a new resource to be created."
3535
}
36+
37+
variable "enable_alerting" {
38+
description = "Whether monitoring and alerting is enabled for this module."
39+
type = bool
40+
default = false
41+
}
42+
43+
variable "alert_frequency" {
44+
type = string
45+
nullable = true
46+
default = "PT5M"
47+
validation {
48+
condition = contains(["PT1M", "PT5M", "PT15M", "PT30M", "PT1H"], var.alert_frequency)
49+
error_message = "The alert_frequency must be one of: PT1M, PT5M, PT15M, PT30M, PT1H"
50+
}
51+
description = "The frequency an alert is checked e.g. PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H."
52+
}
53+
54+
variable "action_group_id" {
55+
type = string
56+
description = "The ID of the Action Group to use for alerts."
57+
default = null
58+
}
59+
60+
locals {
61+
alert_window_size_map = {
62+
PT5M = "PT6M"
63+
PT15M = "PT16M"
64+
PT30M = "PT31M"
65+
PT1H = "PT61M"
66+
}
67+
alert_window_size = local.alert_window_size_map[var.alert_frequency]
68+
}

0 commit comments

Comments
 (0)