diff --git a/operations/template/alert.tf b/operations/template/alert.tf index d93305c0..20431026 100644 --- a/operations/template/alert.tf +++ b/operations/template/alert.tf @@ -134,4 +134,45 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "rs_sftp_log_errors_alert tags["zone"] ] } +} + +resource "azurerm_monitor_metric_alert" "low_instance_count_alert" { + count = local.non_pr_environment ? 1 : 0 + name = "cdc-rs-sftp-${var.environment}-azure-low-instance-count-alert" + resource_group_name = data.azurerm_resource_group.group.name + scopes = [azurerm_monitor_autoscale_setting.sftp_autoscale.id] + description = "The instance count in ${var.environment} is too low" + severity = 2 // warning + frequency = "PT1M" // Checks every 1 minute + window_size = "PT15M" // Every Check, looks back 15 minutes in history + + criteria { + metric_namespace = "Microsoft.Insights/autoscalesettings" + metric_name = "ObservedCapacity" + aggregation = "Average" + operator = "LessThanOrEqual" + threshold = azurerm_monitor_autoscale_setting.sftp_autoscale.profile[0].capacity[0].default - 0.5 + } + + action { + action_group_id = data.azurerm_monitor_action_group.notify_slack_email[count.index].id + } + + lifecycle { + # Ignore changes to tags because the CDC sets these automagically + ignore_changes = [ + tags["business_steward"], + tags["center"], + tags["environment"], + tags["escid"], + tags["funding_source"], + tags["pii_data"], + tags["security_compliance"], + tags["security_steward"], + tags["support_group"], + tags["system"], + tags["technical_steward"], + tags["zone"] + ] + } } \ No newline at end of file