Skip to content

Commit 904dfd8

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 e678810 commit 904dfd8

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-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 = local.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 = var.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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,38 @@ 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_window_size" {
44+
type = string
45+
nullable = false
46+
default = "PT15M"
47+
validation {
48+
condition = contains(["PT1M", "PT5M", "PT15M", "PT30M", "PT1H", "PT6H", "PT12H"], var.alert_window_size)
49+
error_message = "The alert_window_size must be one of: PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H"
50+
}
51+
description = "The period of time that is used to monitor alert activity e.g. PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H. The interval between checks is adjusted accordingly."
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_frequency_map = {
62+
PT5M = "PT5M"
63+
PT15M = "PT15M"
64+
PT30M = "PT30M"
65+
PT1H = "PT1H"
66+
PT6H = "PT6H"
67+
PT12H = "PT12H"
68+
}
69+
alert_frequency = local.alert_frequency_map[var.alert_window_size]
70+
}

0 commit comments

Comments
 (0)