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/
nexus 数据库备份任务webhook 通知-另外一种方法的更多相关文章
- nexus  数据库备份任务webhook 通知
		
nexus 的数据库备份是比较重要的,可以方便我们在故障的是时候进行应用恢复. 以下使用benthos 组件进行nexus 数据库备份事件的应用通知处理 环境准备 使用docker-compose 运 ...
 - Oracle备份归档日志文件的两种方法比较
		
备份归档日志方式有两种: 1 单独备份归档日志:backup archivelog all 2 在执行备库时一起备份归档日志:backup database plus archivelog; 这 ...
 - 第10章 同步设备I/O和异步设备I/O(3)_接收I/O请求完成通知的4种方法
		
10.5 接收I/O请求完成的通知 (1)I/O请求被加入设备驱动程序的队列,当请求完成以后,设备驱动也要负责通知我们I/O请求己经完成. (2)可以用4种方法来接收I/O请求己经完成的通知 技术 特 ...
 - SQLSERVER数据库中批量导入数据的几种方法
		
第一:使用Select Into 语句 如果企业数据库都是采用SQL Server数据库的话,则可以利用select into语句实现数据的导入. select into语句的作用是把数据从另外一个数 ...
 - 数据库数据用Excel导出的3种方法
		
将数据库数据用Excel导出主要有3种方法:用Excel.Application接口.用OleDB.用HTML的Tabel标签 方法1——Excel.Application接口: 首先,需要要Exce ...
 - 用C#从数据库动态生成AdminLTE菜单的一种方法
		
当前的应用设计风格趋于Flat扁平化,很多基于BootStrap实现了很多UI非常漂亮的管理界面(Bootstrap admin template). 此核心文件开源在Github:https://g ...
 - MS数据库优化查询最常见的几种方法
		
1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列导致查询不优化. 4.内存不足 5.网络速度慢 6.查询出的数据量过大 ...
 - Oracle 数据库中查看表空间的2种方法
		
在Oracle数据库中查看表空间使用状况是我们在实际应用中经常涉及到的,以下的内容就就是对Oracle 数据库中查看表空间使用状况时所要用到的SQL的描述,希望你能从中获得自己想要的东西. Oracl ...
 - MyBatis笔记----MyBatis数据库表格数据修改更新的两种方法:XML与注解
		
继上 http://www.cnblogs.com/tk55/p/6659285.html http://www.cnblogs.com/tk55/p/6660477.html 注解 将id:8 na ...
 
随机推荐
- hadoop.docker.up.problems: Too many levels of symbolic links
			
#root@c7hp:~ excp c78 "zkServer.sh start"[1] 11:49:44 [FAILURE] c78 Exited with error code ...
 - 推理机Jess,Racer,Jena
			
推理机 Jess(Java Expert Shell System)是基于Java语言的CLISP推理机. CLISP是基于产生式的前向推理引擎,许多上层的推理任务,都要映射到这个推理引擎上来运行. ...
 - C语言编译数组中有的加code有的不加,有什么区别
			
像uchar code table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};和uchar ds1302[]={0xfe,0xfd,0xfb,0xf7,0 ...
 - 北大poj- 1034
			
The dog task Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3272 Accepted: 1313 Sp ...
 - springboot +redis配置
			
springboot +redis配置 pom依赖 <dependency> <groupId>org.springframework.boot</groupId> ...
 - css设置文字多余部分显示省略号
			
如果只显示一行,则可以使用以下方法: overflow: hidden; text-overflow:ellipsis; white-space: nowrap; 如果需要显示多行,在需要设置的元素s ...
 - AGV
			
AGV AGV是(Automated Guided Vehicle)的缩写,意即“自动导引运输车”,是指装备有电磁或光学等自动导引装置,它能够沿规定的导引路径行驶,具有安全保护以及各种移载功能的运输车 ...
 - 《Machine Learning Yearing》读书笔记
			
——深度学习的建模.调参思路整合. 写在前面 最近偶尔从师兄那里获取到了吴恩达教授的新书<Machine Learning Yearing>(手稿),该书主要分享了神经网络建模.训练.调节 ...
 - ThinkPHP5 远程代码执行漏洞被入侵日志,升级最新版本解决
			
2018年12月9日,ThinkPHP团队发布了一个补丁更新,修复了一处由于路由解析缺陷导致的代码执行漏洞.该漏洞危害程度非常高,默认环境配置即可导致远程代码执行.经过启明星辰ADLab安全研究员对T ...
 - Sqlite 参数化 模糊查询 解决方案
			
转自:https://codedefault.com/2018/does-dapper-support-the-like-operator-in-csharp-application 问题描述 如题, ...