跳至内容

通知

Composia 为任务结果、备份事件、镜像更新和节点状态变化发送通知。支持三种通知渠道:Alertmanager、SMTP 和 Telegram。

配置

所有渠道均在控制器配置的 notifications 下进行配置:

controller:
  notifications:
    alertmanager:
      enabled: true
      listen_path: "/api/v1/alerts"
    smtp:
      enabled: true
      host: "smtp.example.com"
      port: 587
      encryption: starttls
      username: "alerts@example.com"
      password: "REPLACE"
      from: "alerts@example.com"
      to:
        - "admin@example.com"
      on:
        - task_failed
        - backup_failed
      task_sources:
        - web
        - cli
    telegram:
      enabled: true
      bot_token: "REPLACE"
      chat_id: "REPLACE"
      on:
        - task_completed

事件类型

以下通知事件类型可用:

事件触发条件
task_failed任何任务以 failed 状态结束。
task_cancelled任务在完成前被取消。
task_completed任务成功完成。
task_awaiting_confirmation迁移任务到达确认步骤。
backup_completed备份任务或定时备份成功完成。
backup_failed备份任务或步骤失败。
image_update_available镜像检查发现新版本。
image_update_applied镜像更新已应用。
node_offline节点停止发送心跳。
node_online之前离线的节点恢复心跳。
alertmanager_alert控制器作为 Alertmanager webhook 接收器时收到告警。

每个渠道可以通过 on 列表过滤应处理的事件类型。空的 on 列表表示接收所有事件类型。

任务来源过滤器

SMTP 和 Telegram 渠道支持按触发任务来源进行过滤:

来源描述
web通过 Web UI 触发的操作。
cli通过 CLI 触发的操作。
others其他来源。
schedule调度的任务(备份、维护)。
system系统生成的任务。
auto_deploy自动部署触发器生成的任务。

task_sources 为空时,所有来源类型都会发送通知。

Alertmanager

控制器运行一个内嵌的 Alertmanager webhook 接收器。启用后,接收器在配置的路径上监听:

alertmanager:
  enabled: true
  listen_path: "/api/v1/alerts"
类型描述
enabledbool当该部分存在时默认启用。
listen_pathstring接收 Alertmanager webhook 的 HTTP 路径。默认为 /api/v1/alerts。必须以 / 开头且不含空白字符。

将您的 Alertmanager 实例指向控制器的地址并使用此 webhook URL。告警会根据事件过滤器转发到已配置的通知渠道。

SMTP

SMTP 通过邮件发送通知:

类型启用时必填描述
enabledbool当该部分存在时默认启用。
hoststringSMTP 服务器主机名。
portintSMTP 端口,1 到 65535。
encryptionstringnonestarttlsssl_tls。默认为 starttls
usernamestringSMTP 认证用户名。
passwordstringSMTP 密码。
password_filestring从文件读取密码。
fromstring发件人地址。
to[]string收件人地址列表。
on[]string要通知的事件类型。
task_sources[]string任务来源过滤器。

Telegram

Telegram 通过机器人向聊天发送通知:

类型启用时必填描述
enabledbool当该部分存在时默认启用。
bot_tokenstring从 BotFather 获取的 Telegram 机器人令牌。
bot_token_filestring从文件读取机器人令牌。
chat_idstring目标聊天 ID。
on[]string要通知的事件类型。
task_sources[]string任务来源过滤器。
最后更新于 • Renovate Bot