[ci skip] Add readme
This commit is contained in:
parent
4e0e6be104
commit
2c787860ef
86
README.md
Normal file
86
README.md
Normal file
@ -0,0 +1,86 @@
|
||||
# alertmanager-bark-webhook
|
||||
|
||||
将 alertmanager 告警转发到 [bark](https://github.com/Finb/bark-server) 的 webhook
|
||||
|
||||
## 配置
|
||||
|
||||
config.yaml
|
||||
|
||||
```yaml
|
||||
# 属于 flask 的一些配置
|
||||
DEBUG: true
|
||||
BIND_ADDRESS: 0.0.0.0
|
||||
BIND_PORT: 5000
|
||||
|
||||
APP_CONFIG:
|
||||
# bark-server 的地址,推荐使用内网地址,使用 api v2 版本的推送,参考
|
||||
# https://github.com/Finb/bark-server/blob/master/docs/API_V2.md
|
||||
bark_api: http://bark-server:8080/push
|
||||
# 推送时使用的标题,分为 告警时(firing) 解除时(resolved) 和 默认(default)
|
||||
title:
|
||||
firing: k8s02-prod 告警发生
|
||||
resolved: k8s02-prod 告警解除
|
||||
default: k8s02-prod
|
||||
# 推送给谁,这里写需要推送的 bark device_key
|
||||
to:
|
||||
- OMITTED
|
||||
# 这里暂不使用,可以不管
|
||||
severity:
|
||||
- 'warning'
|
||||
- 'critical'
|
||||
# 告警模板文件路径
|
||||
template_file: text_template.tpl
|
||||
```
|
||||
|
||||
告警模板文件使用 [jinja2 语法](https://jinja.palletsprojects.com/en/3.1.x/)
|
||||
|
||||
```jinja2
|
||||
{%- if status == 'firing' -%}
|
||||
告警发生:
|
||||
{%- for alert in alerts %}
|
||||
告警时间:{{alert.startsAt}}
|
||||
{% if alert.labels.instance -%}
|
||||
涉及实例:{{alert.labels.instance}}
|
||||
{% endif -%}
|
||||
{% if alert.labels.device -%}
|
||||
涉及设备:{{alert.labels.device}}
|
||||
{% endif -%}
|
||||
告警名称:{{alert.labels.alertname}}
|
||||
严重性:{{alert.labels.severity}}
|
||||
详情:{{alert.annotations.description}}
|
||||
{% if alert.annotations.value -%}
|
||||
告警数据:{{alert.annotations.value}}
|
||||
{% endif -%}
|
||||
{% if alert.annotations.runbook_url -%}
|
||||
参考文档:{{alert.annotations.runbook_url}}
|
||||
{%- endif %}
|
||||
---
|
||||
{%- endfor %}
|
||||
{%- else -%}
|
||||
告警恢复:
|
||||
{%- for alert in alerts %}
|
||||
告警时间:{{alert.startsAt}}
|
||||
恢复时间:{{alert.endsAt}}
|
||||
{% if alert.labels.instance -%}
|
||||
涉及实例:{{alert.labels.instance}}
|
||||
{%- endif %}
|
||||
{% if alert.labels.device -%}
|
||||
涉及设备:{{alert.labels.device}}
|
||||
{%- endif %}
|
||||
告警名称:{{alert.labels.alertname}}
|
||||
严重性:{{alert.labels.severity}}
|
||||
详情:{{alert.annotations.summary}}
|
||||
{% if alert.annotations.value -%}
|
||||
告警数据:{{alert.annotations.value}}
|
||||
{%- endif %}
|
||||
---
|
||||
{%- endfor %}
|
||||
{%- endif -%}
|
||||
```
|
||||
|
||||
## 注册设备
|
||||
|
||||
1. 安装 [bark 客户端](https://github.com/Finb/Bark)
|
||||
2. 在客户端增加服务器 `http://bark-test.hxjscloud.com/`
|
||||
3. 可以在客户端看到 device_key,加入上面的配置文件中
|
||||
4. webhook 重启即可收到推送
|
Loading…
Reference in New Issue
Block a user