apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: nais-prometheus-prometheus-alertmanager
  name: nais-prometheus-prometheus-alertmanager
  namespace: nais
data:
  alert.tmpl: "{{ define \"__single_message_title\" }}\n{{- range .Alerts.Firing }}{{
    .Labels.alertname }} in preprod-fss{{ end }}\n{{- range .Alerts.Resolved }}{{
    .Labels.alertname }} in preprod-fss{{ end }}\n{{ end }}\n \n{{ define \"nais-alert.sms\"
    -}}\n[ALERT {{ .Status | toUpper -}}] {{ template \"__single_message_title\" .
    -}}\n{{ end }}\n  \n{{ define \"nais-alert.title\" }}\n[{{ .Status | toUpper }}{{
    if eq .Status \"firing\" }}:{{ .Alerts.Firing | len }}{{ end }}]\n{{- if or (and
    (eq (len .Alerts.Firing) 1) (eq (len .Alerts.Resolved) 0)) (and (eq (len .Alerts.Firing)
    0) (eq (len .Alerts.Resolved) 1)) }}\n{{ template \"__single_message_title\" .
    }}\n{{ end }}\n{{ end }}\n  \n{{ define \"nais-alert.text\" }}\n{{ if or (and
    (eq (len .Alerts.Firing) 1) (eq (len .Alerts.Resolved) 0)) (and (eq (len .Alerts.Firing)
    0) (eq (len .Alerts.Resolved) 1)) }}\n{{- range .Alerts.Firing }}\n{{ .Annotations.description
    }}\naction: {{ .Annotations.action }}\n{{ end }}\n{{- range .Alerts.Resolved }}\n{{
    .Annotations.description }}\n{{ end }}\n{{ else }}\n{{ if gt (len .Alerts.Firing)
    0 }}\n*Alerts Firing in preprod-fss:*\n{{- range .Alerts.Firing }}\n{{ .Labels.alertname
    }}: {{ .Annotations.description }}\naction: {{ .Annotations.action }}\n{{ end
    }}\n{{ end }}\n{{ if gt (len .Alerts.Resolved) 0 }}\n*Alerts Resolved in preprod-fss:*\n{{-
    range .Alerts.Resolved }}\n{{ .Labels.alertname }}: {{ .Annotations.description
    }}\n{{ end }}\n{{ end }}\n{{ end }}\n{{ end }}\n"
  alertmanager.yml: |
    global:
      slack_api_url: web-site.com
      http_config:
        proxy_url: http://webproxy.nais:8088
      smtp_from: srvKubernetesAlarm@nav.no
      smtp_smarthost: smtp.preprod.local:26
      smtp_auth_username: blarg
      smtp_auth_password: blorg
      smtp_require_tls: false
    templates:
    - '/etc/config/alert.tmpl'
    receivers:
      - name: default-receiver
        slack_configs:
        - channel: '#nais-alerts-default'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
          username: 'Alertmanager in preprod-fss'
      - name: aura-slack
        slack_configs:
        - channel: '#nais-alerts-dev'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
      - name: integrasjon-slack
        slack_configs:
        - channel: '#int-alerts-dev'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
      - name: teameresept-slack
        slack_configs:
        - channel: '#eresept-alerts-dev'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
      - name: pus-slack
        slack_configs:
        - channel: '#pus-preprod'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
      - name: kartlegging-slack
        slack_configs:
        - channel: '#kartlegging-preprod'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
      - name: registrering-slack
        slack_configs:
        - channel: '#registrering-preprod'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
      - name: oppfolging-slack
        slack_configs:
        - channel: '#oppfolging-preprod'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
      - name: digisyfo-slack
        slack_configs:
        - channel: '#syfo-alerts-dev'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
      - name: ptsak-slack
        slack_configs:
        - channel: '#team_saksstatistikk'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
      - name: okonomi-slack
        slack_configs:
        - channel: '#okonomi-alerts-dev'
          username: 'Alertmanager in preprod-fss'
          send_resolved: true
          title: '{{ template "nais-alert.title" . }}'
          text: '{{ template "nais-alert.text" . }}'
    route:
      group_by: ['alertname','team', 'kubernetes_namespace']
      group_wait: 10s
      group_interval: 5m
      repeat_interval: 1h
      receiver: default-receiver
      routes:
        - receiver: aura-slack
          continue: true
          match:
            team: aura
        - receiver: integrasjon-slack
          continue: true
          match:
            team: integrasjon
        - receiver: teameresept-slack
          continue: true
          match:
            team: teameresept
        - receiver: pus-slack
          continue: true
          match:
            team: pus
        - receiver: kartlegging-slack
          continue: true
          match:
            team: kartlegging
        - receiver: registrering-slack
          continue: true
          match:
            team: registrering
        - receiver: oppfolging-slack
          continue: true
          match:
            team: oppfolging
        - receiver: digisyfo-slack
          continue: true
          match:
            team: digisyfo
        - receiver: ptsak-slack
          continue: true
          match:
            team: ptsak
        - receiver: okonomi-slack
          continue: true
          match:
            team: okonomi
