Komari 探针 使用 WebHook 通过 showdoc 免费服务 实现在微信中推送 Komari 探针消息

项目介绍

Komari

Komari 是一款轻量级服务器探针.

Showdoc

showdoc 推送服务 是 showdoc 旗下的一个独立工具,可以从服务器推送消息到微信. 使用简单、开箱可用、长期维护、持续免费、编程可玩、不限制消息数量、不限制请求数.

教程

Showdoc 的推送很简单 使用 Get 或者 Post 带上titlecontent即可 简单的 WebHook 就可以做到

先在 Showdoc 获取专属推送地址 访问官网 https://push.showdoc.com.cn/ 并扫码登陆 复制地址 他应该长这样

1
https://push.showdoc.com.cn/server/api/push/{key}
提示

不要对外公开你的专属地址. 任何人都可以通过这个地址向你的微信发送任意消息

随后进入 komari 后台 设置->通知 通知渠道选择 WebHook

参数
url 刚刚获取的专属链接
method 选择 Post
content_type application/x-www-form-urlencoded
headers {}

Body 部分可以自定义推送内容

1
title=Komari通知&content={{message}}

title 为标题 content 为正文内容 详见 Showdoc 文档
这里的{{message}}是对应 Komari 中的消息通知模板

详见 https://github.com/komari-monitor/komari/blob/main/internal/messageSender/webhook/webhook.go#L133

1
2
3
4
5
6
7
// replaceTemplate 替换模板中的 {{message}} 和 {{title}} 占位符(不做转义)
func (w *WebhookSender) replaceTemplate(template, message, title string) string {
result := template
result = strings.ReplaceAll(result, "{{message}}", message)
result = strings.ReplaceAll(result, "{{title}}", title)
return result
}

完整的示例如下图

最后 保存并测试发送

完成!