nexus 数据库备份任务webhook 通知-另外一种方法
使用benthos 做为webhook,是一种方法,功能很强大,但是有点复杂,所以换了一个更简单直接的webhook 工具
根据请求的数据,只处理关于db exporter 任务部分的消息,然后就是调用shell 执行一些逻辑处理
环境处理
使用docker-compose 运行
- docker-compose 文件
version: "3"
services:
webhook:
image: almir/webhook
command: ["-verbose", "-hooks=/etc/webhook/hooks.json","-hotreload"]
volumes:
- "./hooks.json:/etc/webhook/hooks.json"
- "./app.sh:/app.sh"
ports:
- "9000:9000"
nexus:
image: sonatype/nexus3
ports:
- "8081:8081"
volumes:
- ./nexus-data:/nexus-data
- ./backup/:/backup/
- webhook 配置文件
hooks.json 主要是定义webhook 的match 规则,以及匹配规则之后执行的shell,因为是post 请求,所以使用了payload source
[
{
"id": "webhook",
"execute-command": "/app.sh",
"command-working-directory": "/",
"include-command-output-in-response":true,
"pass-arguments-to-command":
[
{
"source": "payload",
"context": "audit.context"
},
{
"source": "payload",
"type": "audit.type"
}
],
"trigger-rule":
{
"and":
[
{
"match":
{
"type": "value",
"value": "Admin - Export databases for backup",
"parameter":
{
"source": "payload",
"name": "audit.context"
}
}
},
{
"match":
{
"type": "value",
"value": "finished",
"parameter":
{
"source": "payload",
"name": "audit.type"
}
}
}
]
}
}
]
- 执行shell
为了测试,很简单,就是echo 信息
#!/bin/sh
echo "this is a demo app"
启动&&测试
- 启动
docker-compose up -d
- 配置nexus webhook (audit) 以及db exporter task
主要是通过global 的webhook 通知db exporter 任务已经完成,然后完成之后可以执行一些固定的shell 脚本
audit 配置,路径是更具json 定义文件编写的
db exporter task 配置,这个可以根据实际自己调整
- 测试
点击db exporter 的run 即可
效果
webhook_1 | [webhook] 2019/04/28 11:45:00 [2bb51c] error extracting command arguments: couldn't retrieve argument for {Source:payload Name: EnvName: Base64Decode:false}
webhook_1 | [webhook] 2019/04/28 11:45:00 [2bb51c] error extracting command arguments: couldn't retrieve argument for {Source:payload Name: EnvName: Base64Decode:false}
webhook_1 | [webhook] 2019/04/28 11:45:00 [2bb51c] executing /app.sh (/app.sh) with arguments ["/app.sh" "" ""] and environment [] using / as cwd
webhook_1 | [webhook] 2019/04/28 11:45:00 [2bb51c] command output: this is a demo app
webhook_1 |
webhook_1 | [webhook] 2019/04/28 11:45:00 [2bb51c] finished handling webhook
webhook_1 | [webhook] 2019/04/28 11:45:00 200 | 2.733775ms | webhook:9000 | POST /hooks/webhook
webhook_1 | [webhook] 2019/04/28 11:50:00 [e1803a] incoming HTTP request from 172.19.0.3:58026
webhook_1 | [webhook] 2019/04/28 11:50:00 [e1803a] webhook got matched
webhook_1 | [webhook] 2019/04/28 11:50:00 [e1803a] webhook got matched, but didn't get triggered because the trigger rules were not satisfied
webhook_1 | [webhook] 2019/04/28 11:50:00 200 | 198.993µs | webhook:9000 | POST /hooks/webhook
webhook_1 | [webhook] 2019/04/28 11:50:00 [3dc5af] incoming HTTP request from 172.19.0.3:58028
webhook_1 | [webhook] 2019/04/28 11:50:00 [3dc5af] webhook got matched
webhook_1 | [webhook] 2019/04/28 11:50:00 [3dc5af] webhook got matched, but didn't get triggered because the trigger rules were not satisfied
webhook_1 | [webhook] 2019/04/28 11:50:00 200 | 143.131µs | webhook:9000 | POST /hooks/webhook
webhook_1 | [webhook] 2019/04/28 11:50:00 [3496eb] incoming HTTP request from 172.19.0.3:58030
webhook_1 | [webhook] 2019/04/28 11:50:00 [3496eb] webhook got matched
webhook_1 | [webhook] 2019/04/28 11:50:00 [3496eb] webhook got matched, but didn't get triggered because the trigger rules were not satisfied
说明
使用adnanh/webhook 比使用benthos 方便简单好多,功能已经够用了
参考资料
https://github.com/rongfengliang/nexus-webhook-dbbackup
https://github.com/adnanh/webhook/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2017-04-28 nginx fastcgi 优化
2014-04-28 转 sql 优化
2014-04-28 ORACLE与SQL SERVER语法区别
2014-04-28 oracle 以及 sql server mysql 空值默认值修改
2014-04-28 Oracle C#处理时间类型的Insert