Apprise 简介

Apprise 是一款开源的多通道通知库,支持 100+ 通知服务,包括邮件、Telegram、Slack、微信企业号、钉钉、Pushover 等。它提供命令行工具和 Python API,适合集成到自动化脚本和运维工具链中。

安装与配置

pip install apprise

使用 apprise 命令行工具发送通知:

apprise -t "告警标题" -b "告警内容" \
  "mailto://user:pass@gmail.com" \
  "slack://token_a/token_b/token_c"

常用通知通道配置

邮件通知:使用 mailto:// 协议,支持 SMTP 服务器自定义配置。

Telegram:使用 tgram:// 协议,需要 Bot Token 和 Chat ID。

Webhook:支持自定义 JSON 格式,可以对接任意 HTTP API。

NTFY:使用 ntfys:// 或 ntfy:// 协议,与自建 NTFY 服务无缝对接。

与监控系统集成

Apprise 可与 Cron 定时任务、Zabbix、Prometheus AlertManager 等监控系统集成。在告警脚本中调用 apprise 命令行工具,实现多通道告警分发,避免告警漏报。

配置模板化

将常用通道配置写入 YAML 文件,实现可复用的通知模板:

# apprise.yml
urls:
  - mailto://alert@example.com
  - ntfy://ntfy.example.com/alerts
  - tgram://123456:ABC-DEF/tg_chat_id

使用 apprise -c apprise.yml 加载配置,简化日常运维中的通知调用。