【问题标题】:AlertManager is not forwarding alerts to webhook receiverAlertManager 未将警报转发到 webhook 接收器
【发布时间】:2021-08-10 16:04:05
【问题描述】:

我们使用 PrometheusOperator 在 Kubernetes 集群中设置了 Prometheus。我们正在尝试使用 AlertManagerConfig 自定义资源配置 AlertManager。我们尝试创建一个映射到 webhook 接收器的警报路由,然后触发测试警报。警报似乎被 AlertManager 捕获,但它没有被转发到 webhook 端点。 AlertManager pod 日志也不会打印任何有关发送到接收器以获取警报的通知的日志。分享下面的测试配置:

apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
  name: discord-config
spec:
  receivers:
  - name: discord
    webhookConfigs:
    - url: '<webhook-url>'
      sendResolved: true
  route:
    groupBy: ['job']
    groupWait: 15s
    groupInterval: 15s
    repeatInterval: 15s
    receiver: 'discord'
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: test-rules
spec:
  groups:
  - name: test-rule-group
    rules:
    - alert: TestAlert
      expr: vector(1)
      labels: 
        severity: medium  
      annotations:
        description: "This is a reciever test for webhook alert"
        summary: "This is a dummy summary"

为了让接收者开始接收警报,还有什么需要注意的吗?

【问题讨论】:

    标签: kubernetes webhooks prometheus-alertmanager prometheus-operator


    【解决方案1】:

    我能够找到问题的根本原因。其实根本原因。有两个问题:

    1. 我使用 webhook 与 Discord 频道集成,后来我了解到这并不简单。需要一个中间层来解析 Webhook 警报并将其转发到兼容模板中的 Discord。 Prometheus documentation 中已经提到了一个很好的解决方案,它指向了alertmanager-discord 应用程序。我使用了 docker 镜像来创建部署和服务,将 alertmanager 连接到不和谐。

    2. 操作员在最顶部的警报路线中添加了一个额外的namepsace 标签匹配器。所以我在我创建的警报中添加了相同的标签。我使用这个 Routing Tree editor 来可视化路线并确保给定的标签集与路线匹配。

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: alertmanager-discord
    spec:
      selector:
        matchLabels:
          app: alertmanager-discord
      replicas: 1
      template:
        metadata:
          labels:
            app: alertmanager-discord
        spec:
          containers:
          - name: alertmanager-discord
            image: benjojo/alertmanager-discord
            resources:
              limits:
                memory: "128Mi"
                cpu: "500m"
            ports:
            - containerPort: 9094
            env:
              - name: DISCORD_WEBHOOK
                value: {{ .Values.webhookURL }}
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: alertmanager-discord
    spec:
      selector:
        app: alertmanager-discord
      ports:
      - port: 9094
        targetPort: 9094
      type: ClusterIP
    ---
    apiVersion: monitoring.coreos.com/v1alpha1
    kind: AlertmanagerConfig
    metadata:
      name: alertmanager
    spec:
      receivers:
      - name: discord
        webhookConfigs:
        - url: 'http://alertmanager-discord:9094'
          sendResolved: true
    .
    .
    .
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 2022-07-13
      相关资源
      最近更新 更多