---

- type: replace
  path: /instance_groups/name=alertmanager/jobs/name=alertmanager/properties/alertmanager/route?
  value:
    receiver: critical-receiver
    group_by:
      - alertname
    group_wait: 30s
    group_interval: 1m
    repeat_interval: 1h
    routes:
      - receiver: warning-receiver
        match:
          severity: "warning"
      - receiver: critical-receiver
        match:
          severity: "critical"

- type: replace
  path: /instance_groups/name=alertmanager/jobs/name=alertmanager/properties/alertmanager/receivers?/-
  value:
    name: warning-receiver
    email_configs:
      - from: govpaas-alerting-((aws_account))@digital.cabinet-office.gov.uk
        to: govpaas-alerting-((aws_account))+warning@digital.cabinet-office.gov.uk

- type: replace
  path: /instance_groups/name=alertmanager/jobs/name=alertmanager/properties/alertmanager/receivers?/-
  value:
    name: critical-receiver
    email_configs:
      - from: govpaas-alerting-((aws_account))@digital.cabinet-office.gov.uk
        to: govpaas-alerting-((aws_account))+critical@digital.cabinet-office.gov.uk

---

- type: replace
  path: /instance_groups/name=alertmanager/jobs/name=alertmanager/properties/alertmanager/route?
  value:
    receiver: critical-receiver
    group_by:
      - alertname
    group_wait: 30s
    group_interval: 1m
    repeat_interval: 1h
    routes:
      - receiver: warning-receiver
        match:
          severity: "warning"
      - receiver: critical-receiver
        match:
          severity: "critical"

- type: replace
  path: /instance_groups/name=alertmanager/jobs/name=alertmanager/properties/alertmanager/receivers?/-
  value:
    name: warning-receiver
    email_configs:
      - from: govpaas-alerting-((aws_account))@digital.cabinet-office.gov.uk
        to: govpaas-alerting-((aws_account))+warning@digital.cabinet-office.gov.uk
        headers:
          Subject: "[((metrics_environment))] [warning] {{ .GroupLabels.SortedPairs.Values | join \" \" }}"

- type: replace
  path: /instance_groups/name=alertmanager/jobs/name=alertmanager/properties/alertmanager/receivers?/-
  value:
    name: critical-receiver
    email_configs:
      - from: govpaas-alerting-((aws_account))@digital.cabinet-office.gov.uk
        to: govpaas-alerting-((aws_account))+critical@digital.cabinet-office.gov.uk
        headers:
          Subject: "[((metrics_environment))] [critical] {{ .GroupLabels.SortedPairs.Values | join \" \" }}"

Set email subject for Alertmanager alerts
Set email subject for Alertmanager alerts

The original email subject looks the following:
[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}

As we group by alertname currently we simplify the email template to the following:
[<env>] [<severity>] <alert name>

Instead of using the alert name we'll still use `{{.GroupLabels.SortedPairs.Values | join \" \" }}`
so we don't break the email subject if we ever change the grouping.
