kind: ConfigMap
apiVersion: v1
metadata:
  name: alertmanager
data:
  config.yml: |-
    global:
      # ResolveTimeout is the time after which an alert is declared resolved
      # if it has not been updated.
      resolve_timeout: 5m

    # The directory from which notification templates are read.
    templates:
    - '/etc/alertmanager-templates/*.tmpl'

    # The root route on which each incoming alert enters.
    route:

      # The labels by which incoming alerts are grouped together. For example,
      # multiple alerts coming in for cluster=A and alertname=LatencyHigh would
      # be batched into a single group.
      group_by: ['alertname', 'cluster', 'service']

      # When a new group of alerts is created by an incoming alert, wait at
      # least 'group_wait' to send the initial notification.
      # This way ensures that you get multiple alerts for the same group that start
      # firing shortly after another are batched together on the first
      # notification.
      group_wait: 30s

      # When the first notification was sent, wait 'group_interval' to send a batch
      # of new alerts that started firing for that group.
      group_interval: 5m

      # If an alert has successfully been sent, wait 'repeat_interval' to
      # resend them.
      repeat_interval: 15m

      # A default receiver
      # If an alert isn't caught by a route, send it to default.
      receiver: email_receiver

      # All the above attributes are inherited by all child routes and can
      # overwritten on each.

      # The child route trees.
      routes:
      - match_re:
          severity: alert
        receiver: wechat_receiver
      - match_re:
          severity: warning|alert
        receiver: email_receiver
      - match_re:
          severity: notice|warning|alert
        receiver: webhook_receiver

    receivers:
    - name: 'wechat_receiver'
      wechat_configs:
      - corp_id: '$WECHAT_CORP_ID'
        agent_id: '$WECHAT_AGENT_ID'
        api_secret: '$WECHAT_API_SECRET'
        api_url: 'https://qyapi.weixin.qq.com/cgi-bin/'
        to_user: '$WECHAT_TO_USER'
        to_party: '$WECHAT_TO_PARTY'
        to_tag: '$WECHAT_TO_TAG'
        message: '{{ template "wechat.default.message" . }}'
        send_resolved: false

    - name: 'email_receiver'
      email_configs:
      - to: '$ALERT_TO'
        from: '$ALERT_FROM'
        smarthost: '$SMTP_HOST'
        auth_username: '$SMTP_USER'
        auth_password: '$SMTP_PASSWORD'
        auth_secret:
        auth_identity:
        html: '{{ template "email.default.html" . }}'
        require_tls: true
        hello: 'localhost'
        send_resolved: false

    #webhook post数据格式参考：https://prometheus.io/docs/alerting/configuration/#webhook_config
    - name: 'webhook_receiver'
      webhook_configs:
      - url: '$ALERT_WEBHOOK'
        send_resolved: true
        http_config:
          basic_auth:
            username:
            password:
          bearer_token:
          bearer_token_file:
          tls_config:
            ca_file:
            cert_file:
            key_file:
            server_name:
            insecure_skip_verify:
          proxy_url:
