resource "datadog_monitor" "rds_delphi_main_db_cpu_load_monitor" {
  escalation_message = <<-EOT
CPU Load is still very high on {{dbinstanceidentifier.name}}

Please contact DevOps team ASAP
EOT

  evaluation_delay = 900

  include_tags = true

  message = <<-EOT
{{#is_alert}} {{dbinstanceidentifier.name}} average CPU load for the past 30 minutes is too high {{/is_alert}}
{{#is_recovery}} CPU load is back to normal {{/is_recovery}}

${var.slack_channels["etl"]}
EOT

  name            = "${var.environment}-${var.service_name} CPU load is very high on delphi main db instance"
  new_group_delay = 0

  no_data_timeframe    = 0
  notify_audit         = false
  notify_by            = []
  notify_no_data       = false
  priority             = 0
  query                = "avg(last_30m):avg:aws.rds.cpuutilization{platform_with_env:delphi_qa,plat_env_project_service:dlp_qa_data_aura} by {dbinstanceidentifier} > 90"
  renotify_interval    = 120
  renotify_occurrences = 0
  require_full_window  = true
  tags                 = local.common_tags
  timeout_h            = 0
  type                 = "metric alert"
  restricted_roles     = [data.datadog_role.datadog_admin_role.id]

  monitor_thresholds {
    critical = "90"
    warning  = "80"
  }
}

resource "datadog_monitor" "rds_delphi_slz_db_cpu_load_monitor" {
  escalation_message = <<-EOT
CPU Load is still very high on {{dbinstanceidentifier.name}}

Please contact DevOps team ASAP
EOT

  evaluation_delay = 900

  include_tags = true

  message = <<-EOT
{{#is_alert}} {{dbinstanceidentifier.name}} average CPU load for the past 30 minutes is too high {{/is_alert}}
{{#is_recovery}} CPU load is back to normal {{/is_recovery}}

${var.slack_channels["slz"]}
EOT

  name            = "${var.environment}-${var.service_name} CPU load is very high on delphi slz db instance"
  new_group_delay = 0

  no_data_timeframe    = 0
  notify_audit         = false
  notify_by            = []
  notify_no_data       = false
  priority             = 0
  query                = "avg(last_30m):avg:aws.rds.cpuutilization{platform_with_env:delphi_qa,plat_env_project_service:dlp_qa_data_aura} by {dbinstanceidentifier} > 50"
  renotify_interval    = 120
  renotify_occurrences = 0
  require_full_window  = true
  tags                 = local.common_tags
  timeout_h            = 0
  type                 = "metric alert"
  restricted_roles     = [data.datadog_role.datadog_admin_role.id]

  monitor_thresholds {
    critical = "50"
    warning  = "40"
  }
}
