组件下载地址:
https://github.com/prometheus/
vim /etc/systemd/system/alertmanager.service
[Unit]
Description=alertmanager
After=network.target
[Service]
ExecStart=/usr/local/prometheus/alertmanager-0.21.0.linux-amd64/alertmanager \
--config.file=/usr/local/prometheus/alertmanager-0.21.0.linux-amd64/alertmanager.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
cat alertmanager.yml
---
global:
resolve_timeout: 5m
wechat_api_url: "https://qyapi.weixin.qq.com/cgi-bin/"
wechat_api_secret: "xxxxxx"
wechat_api_corp_id: "yyyy"
templates:
- '/usr/local/prometheus/alertmanager-0.21.0.linux-amd64/*.tmpl'
route:
receiver: 'weixin'
group_wait: 10s
group_interval: 5m
repeat_interval: 5h
group_by: ['alertname_wechat']
receivers:
- name: 'weixin'
wechat_configs:
- corp_id: 'yyyy'
to_user: '@all'
agent_id: '1000026'
api_secret: 'yyyyyyyyyyyy'
send_resolved: true
---
cat weixin.tmpl
{{ define "wechat.default.message" }}
{{ range .Alerts }}
告警主题: {{ .Annotations.summary }}
告警详情: {{ .Annotations.description }}
监控类型: {{ .Labels.job }}
故障主机: {{ .Labels.instance }}
触发时间: {{ (.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
{{- end }}
{{- end }}