resource "datadog_monitor" "amp_asset_service_http_sxx_response_codes_generated_by_registe" {
  name = "AMP Asset Service - HTTP 5XX response codes generated by registered instances on {{hostname.name}}"
  type = "query alert"
  query = <<EOT
sum(last_15m):avg:aws.applicationelb.httpcode_target_5xx{loadbalancer:app/k8s-ampproda-ampservi-0d2eb1156a/4f8cab3d532a46fd} by {hostname}.as_count() >= 1
EOT
  message = <<EOT
{{#is_alert}}
### Number of HTTP 5XX response codes generated by registered instances on {{hostname.name}} > 1 (threshold) {{value}}
PRIORITY=HIGH
{{/is_alert}}

{{#is_recovery}}
### Number of HTTP 5XX response codes generated by registered instances on {{hostname.name}} < 1 (threshold) {{value}}
PRIORITY=HIGH
{{/is_recovery}}

@pagerduty-AMP
@amp-microservices@sonymusic.com
EOT
  draft_status = "published"
  escalation_message = <<EOT
EOT
  tags = ["team:amp-team","managed_by:amp-terraform"]
  new_group_delay = 0
  on_missing_data = "default"
  require_full_window = false
  monitor_thresholds {
    critical = 1
  }
}
resource "datadog_monitor" "amp_asset_service_number_of_healthy_hosts_count_on_targetgroup" {
  name = "AMP Asset Service - Number of Healthy Hosts Count on {{targetgroup.name}}  is {{value}}"
  type = "query alert"
  query = <<EOT
min(last_15m):sum:aws.applicationelb.healthy_host_count{targetgroup:targetgroup/k8s-ampproda-ampservi-039f666917/9c01f63d3a360a61} by {targetgroup} < 2
EOT
  message = <<EOT
{{#is_alert}}
### Number of Healthy Host Count is {{value}} < {{threshold}} (value)
PRIORITY=HIGH
{{/is_alert}}

{{#is_recovery}}
### Number of Healthy Host Count is {{value}} > {{threshold}} (value)
PRIORITY=HIGH
{{/is_recovery}}

@pagerduty-AMP
@amp-microservices@sonymusic.com

EOT
  draft_status = "published"
  escalation_message = <<EOT
EOT
  tags = ["team:amp-team","managed_by:amp-terraform"]
  new_group_delay = 60
  on_missing_data = "show_and_notify_no_data"
  require_full_window = false
  monitor_thresholds {
    critical = 2
  }
}
resource "datadog_monitor" "amp_asset_service_number_of_un_healthy_hosts_count_on_hostname" {
  name = "AMP Asset Service - Number of Un-Healthy Hosts Count on {{host.name}} is {{valus}}"
  type = "query alert"
  query = <<EOT
max(last_15m):max:aws.applicationelb.un_healthy_host_count.maximum{targetgroup:targetgroup/k8s-ampproda-ampservi-301fd5dca8/5d9e6deef999807a} by {targetgroup} > 0
EOT
  message = <<EOT
{{#is_alert}}
### Number of Un-Healthy Host Count is {{value}} > {{threshold}} (value)
PRIORITY=HIGH
{{/is_alert}}

{{#is_recovery}}
### Number of Un-Healthy Host Count is {{value}} < {{threshold}} (value)
PRIORITY=HIGH
{{/is_recovery}}

@pagerduty-AMP
@amp-microservices@sonymusic.com

EOT
  draft_status = "published"
  escalation_message = <<EOT
EOT
  tags = ["team:amp-team","managed_by:amp-terraform"]
  new_group_delay = 0
  on_missing_data = "show_and_notify_no_data"
  require_full_window = false
  monitor_thresholds {
    critical = 0
  }
}
