AlertManager 没有将警报转发给 webhook 接收器
AlertManager is not forwarding alerts to webhook receiver
我们使用 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"
接收者开始接收警报还有什么需要注意的吗?
我找到了问题的根本原因。实际上是根本原因。有两个问题:
我是用webhook与一个Discord频道集成的,后来才知道这并不简单。需要一个中间层来解析 Webhook 警报并将其转发到兼容模板中的 Discord。 Prometheus documentation, which points to alertmanager-discord 应用中已经提到了一个很好的解决方案。我使用 docker 图像为它创建了一个部署和一个将 alertmanager 桥接到 discord 的服务。
操作员正在最上面的警报路由中添加一个额外的 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
.
.
.
我们使用 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"
接收者开始接收警报还有什么需要注意的吗?
我找到了问题的根本原因。实际上是根本原因。有两个问题:
我是用webhook与一个Discord频道集成的,后来才知道这并不简单。需要一个中间层来解析 Webhook 警报并将其转发到兼容模板中的 Discord。 Prometheus documentation, which points to alertmanager-discord 应用中已经提到了一个很好的解决方案。我使用 docker 图像为它创建了一个部署和一个将 alertmanager 桥接到 discord 的服务。
操作员正在最上面的警报路由中添加一个额外的
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
.
.
.