{{- if .Values.prometheus.alertmanager.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: alertmanager
data:
  alertmanager.yml: |
    global: {}
    receivers:
    - name: 'slack'
      slack_configs:
      - channel: '#alerts'
        send_resolved: true
        title: {{ printf "'{{ if eq .Status \"resolved\" }}[RESOLVED]{{ else if eq .CommonLabels.severity \"critical\" }}[CRITICAL]{{ else if eq .CommonLabels.severity \"warning\" }}[WARNING]{{ else }}[FIRING]{{ end }} {{ .CommonLabels.alertname }} on %s'" (.Values.customer | upper) }}
        text: >
          *Alert:* {{ printf "{{ .CommonAnnotations.summary }}" }}

          *Description:* {{ printf "{{ .CommonAnnotations.description }}" }}
        api_url: 'https://hooks.slack.com/services/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'
        color: {{ printf "'{{ if eq .Status \"resolved\" }}good{{ else if eq .CommonLabels.severity \"critical\" }}danger{{ else if eq .CommonLabels.severity \"warning\" }}warning{{ else }}#439FE0{{ end }}'" }}

    - name: 'telegram'
      telegram_configs:
      - bot_token: '7335028149:AAHi7l7bGwfWAE--VDV71bZRmCzb319SZ08'
        chat_id: -1002345524139
        send_resolved: true
        message: >
          {{ printf "{{ .CommonAnnotations.summary }}" }}

          {{ printf "{{ .CommonAnnotations.description }}" }}

    - name: 'slack-telegram'
      slack_configs:
      - channel: '#alerts'
        send_resolved: true
        title: {{ printf "'{{ if eq .Status \"resolved\" }}[RESOLVED]{{ else if eq .CommonLabels.severity \"critical\" }}[CRITICAL]{{ else if eq .CommonLabels.severity \"warning\" }}[WARNING]{{ else }}[FIRING]{{ end }} {{ .CommonLabels.alertname }} on %s'" (.Values.customer | upper) }}
        text: >
          *Alert:* {{ printf "{{ .CommonAnnotations.summary }}" }}

          *Description:* {{ printf "{{ .CommonAnnotations.description }}" }}
        api_url: 'https://hooks.slack.com/services/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'
        color: {{ printf "'{{ if eq .Status \"resolved\" }}good{{ else if eq .CommonLabels.severity \"critical\" }}danger{{ else if eq .CommonLabels.severity \"warning\" }}warning{{ else }}#439FE0{{ end }}'" }}
  
      telegram_configs:
      - bot_token: '7335028149:AAHi7l7bGwfWAE--VDV71bZRmCzb319SZ08'
        chat_id: -1002345524139
        send_resolved: true
        message: >
          {{ printf "{{ .CommonAnnotations.summary }}" }}

          {{ printf "{{ .CommonAnnotations.description }}" }}

    route:
      group_by: ['alertname', 'instance']
      group_wait: 30s
      group_interval: 5m
      repeat_interval: 1h
      receiver: 'telegram'
      routes:
        - match:
            severity: 'warning'
          receiver: 'slack'
          continue: false

        - match:
            severity: 'critical'
          receiver: 'slack-telegram'
          continue: false
    templates:
    - /etc/alertmanager/*.tmpl
{{ end }}
