apiVersion: v1
kind: Secret
type: Opaque
metadata:
  name: altermanager-email-credentials
  namespace: freeleaps-prod
data:
  password: cHducGNya3d0aXp5Z2RoZQ==
---
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
  name: alertmanager-config
  namespace: freeleaps-prod
spec:
  receivers:
    # - msteamsConfigs:
    #     - sendResolved: true
    #       text: '{{ template "msteams.default.text" . }}'
    #       title: >-
    #         {{ if eq .Status "firing" }}🚨 [FIRING] 🔥{{- else -}}🙌 [RESOLVED]
    #         🍻{{- end -}}
    #       webhookUrl:
    #         key: webhook-url
    #         name: freeleaps-teams-webhook
    #   name: ms-teams
    - emailConfigs:
        - to: "1535145760@qq.com,icecheng@mathmast.com"
          from: "1535145760@qq.com"
          smarthost: "smtp.qq.com:465"
          authUsername: "1535145760@qq.com"
          authPassword:
            name: "altermanager-email-credentials"
            key: "password"
          authIdentity: "1535145760@qq.com"
          requireTLS: false
          sendResolved: true
          headers:
            - key: Subject
              value: '{{ if eq .Status "firing" }}🚨 Freeleaps Alert: {{ .CommonAnnotations.summary }}{{ else }}✅ Freeleaps Resolved: {{ .CommonAnnotations.summary }}{{ end }}'
          html: |-
            <h3><strong>{{ if eq .Status "firing" }}🚨 Alert: {{ .CommonAnnotations.summary }}{{ else }}✅ Resolved: {{ .CommonAnnotations.summary }}{{ end }}</strong></h3>
            <p><strong>📝 AlertName:</strong> {{ .CommonLabels.alertname }}</p>
            <p><strong>🔧 Service:</strong> {{ .CommonLabels.service }}</p>
            <p><strong>🔧 Pod:</strong> {{ .CommonLabels.pod }}({{ .CommonLabels.instance }})</p>
            <p><strong>🏷️ Severity:</strong> {{ .CommonLabels.severity }}</p>
            <p><strong>{{ if eq .Status "firing" }}🔴 Status:{{ else }}🟢 Status:{{ end }}</strong> {{ .Status | toUpper }}</p>
            <p>📝 Description: {{ .CommonAnnotations.description }}</p>
            <p>📖 Runbook: <a href="{{ .CommonAnnotations.runbook_url }}">{{ .CommonAnnotations.runbook_url }}</a></p>
      name: email
  route:
    groupBy:
      - severity
    groupInterval: 5m
    receiver: email
    groupWait: 5m
    repeatInterval: 6h
