Browse by type
首先你需要对飞书机器人有点了解 。我们使用 自定义机器人 转发来自 AlertManager 的告警。
自定义机器人相比应用机器人的好处是免应用创建,不需要维护 app_id/secret。
其他区别 @20210729:
基于参考配置文件 config.example.yml 调整。运行:
$ alertmanager-webhook-feishu server --config=/path/to/config.yml
数据链路:Prometheus -> AlertManager -> alertmanager-webhook-feishu -> Feishu。AlertManager 配置文件中添加:
receivers:
- name: 'you_name_it'
webhook_configs:
- url: 'http://alertmanager-webhook-feishu.monitoring/hook/your_group_name'
send_resolved: true
完整配置参数:
$ alertmanager-webhook-feishu server -h
start webhook server
Usage:
alertmanager-webhook-feishu server [flags]
Flags:
-c, --config string config file for bot webhook
-e, --email if email supported, need feishu appid/secret for enabling
-h, --help help for server
-p, --port int server port (default 8000)
Global Flags:
-v, --verbose show verbose log
见 helm/charts/alertmanager-webhook-feishu
open_id 理论上用于标识一个 User ID 在具体某一应用中的身份。但是经过实践发现,随便某个应用下的 open_id 可以用于自定义机器人 @某人。很奇怪的设计。
目前,为了能通过 email 得到 open_id,需要创建飞书「企业自建应用」。需要注意如下两点:
项目本质上是将数据结构 model.WebhookMessage 生成为 飞书消息格式 发送到飞书服务器。
当前的默认消息模板为「消息卡片」,见 tmpl/templates/default.tmpl。其中,为每个 Alert 对象模板化输出了 markdown 文本,飞书 markdown 只支持部分标签。(为 Alert 对象输出 markdown 文本使用了独立的模板,发现一个模板搞不定 - -!)
默认模板适配 kube-prometheus 项目。比如,在模板中会使用如下 Alert 的 labels 和 annotations。
spec:
groups:
- name: kubernetes-apps
rules:
- alert: KubePodCrashLooping
annotations:
description: Pod {{ $labels.namespace }}/{{ $labels.pod }} ({{ $labels.container }}) is restarting {{ printf "%.2f" $value }} times / 10 minutes.
runbook_url: https://runbooks.prometheus-operator.dev/runbooks/kubernetes/kubepodcrashlooping
summary: Pod is crash looping.
expr: |
increase(kube_pod_container_status_restarts_total{job="kube-state-metrics"}[10m]) > 0
and
kube_pod_container_status_waiting{job="kube-state-metrics"} == 1
for: 15m
labels:
severity: warning
主要是如下字段:
为了满足个性化需求,可以自定义模板。模板基于 go text/template。参考这个链接,配置编辑器的语法提示,提高配置速度。
使用自定义模板:
bots:
webhook:
url: https://open.feishu.cn/open-apis/bot/v2/hook/xxx
template:
custom_path: /path/to/custom/path
$ claude mcp add alertmanager-webhook-feishu \
-- python -m otcore.mcp_server <graph>