Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions infrastructure/modules/app-insights/alerts.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "azurerm_monitor_metric_alert" "exceptions" {
count = var.enable_alerting ? 1 : 0

auto_mitigate = true
description = "Triggered by any Exception"
enabled = true
frequency = var.alert_frequency
name = "Exceptions"
resource_group_name = var.resource_group_name
scopes = [azurerm_application_insights.appins.id]
severity = 1
window_size = local.alert_window_size

action {
action_group_id = var.action_group_id
}

criteria {
aggregation = "Count"
metric_name = "exceptions/count"
metric_namespace = "microsoft.insights/components"
operator = "GreaterThan"
skip_metric_validation = false
threshold = 0
}
}
25 changes: 25 additions & 0 deletions infrastructure/modules/app-insights/tfdocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ Type: `string`

The following input variables are optional (have default values):

### <a name="input_action_group_id"></a> [action\_group\_id](#input\_action\_group\_id)

Description: The ID of the Action Group to use for alerts.

Type: `string`

Default: `null`

### <a name="input_alert_frequency"></a> [alert\_frequency](#input\_alert\_frequency)

Description: The frequency an alert is checked e.g. PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H.

Type: `string`

Default: `"PT5M"`

### <a name="input_enable_alerting"></a> [enable\_alerting](#input\_enable\_alerting)

Description: Whether monitoring and alerting is enabled for this module.

Type: `bool`

Default: `false`

### <a name="input_tags"></a> [tags](#input\_tags)

Description: A mapping of tags to assign to the resource.
Expand Down Expand Up @@ -70,3 +94,4 @@ Description: n/a
The following resources are used by this module:

- [azurerm_application_insights.appins](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_insights) (resource)
- [azurerm_monitor_metric_alert.exceptions](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_metric_alert) (resource)
27 changes: 27 additions & 0 deletions infrastructure/modules/app-insights/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,30 @@ variable "resource_group_name" {
type = string
description = "The name of the resource group in which the App Insights is created. Changing this forces a new resource to be created."
}

variable "enable_alerting" {
description = "Whether monitoring and alerting is enabled for this module."
type = bool
default = false
}

variable "alert_frequency" {
type = string
nullable = true
default = "PT5M"
validation {
condition = contains(["PT1M", "PT5M", "PT15M", "PT30M", "PT1H"], var.alert_frequency)
error_message = "The alert_frequency must be one of: PT1M, PT5M, PT15M, PT30M, PT1H"
}
description = "The frequency an alert is checked e.g. PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H."
}

variable "action_group_id" {
type = string
description = "The ID of the Action Group to use for alerts."
default = null
}

locals {
alert_window_size = var.alert_frequency
}
Loading