https://github.com/adnanh/webhook/blob/master/docs/Referencing-Request-Values.md
https://www.cnblogs.com/rongfengliang/p/9703525.html
打印整个json
配置
配置hooks.json,将整个payload、headers、query作为参数传递给alert.sh脚本。
[
{
"id": "alertgw",
"execute-command": "/home/ubuntu/alert.sh",
"command-working-directory": "/home/ubuntu",
"pass-arguments-to-command":
[
{
"source": "entire-payload"
},
{
"source": "entire-headers"
},
{
"source": "entire-query"
}
]
}
]
配置alert.sh,打印传入的参数entire-payload、entire-headers、entire-query
#!/bin/bash
echo $1 >> entire-payload
echo $2 >> entire-headers
echo $3 >> entire-query
测试
访问
[root@VM-0-7-centos ~]# curl "http://10.68.100.15:9000/hooks/alertgw" -H "Content-type: application/json" -d '{"extra_vars":{"newpoem":"hello good world","title": {"id": "001","name" : "白菜"},"content": [{"id": "001","value":"你好 白菜"},{"id": "002","value":"你好 萝 卜"]},"extra_vars2":{"newpoem2":"hello good world2"}}'
结果
[webhook] 2020/11/06 13:38:18 Started POST /hooks/alertgw
[webhook] 2020/11/06 13:38:18 [e38ac8] incoming HTTP request from 10.68.0.7:53564
[webhook] 2020/11/06 13:38:18 [e38ac8] alertgw got matched
[webhook] 2020/11/06 13:38:18 [e38ac8] alertgw hook triggered successfully
[webhook] 2020/11/06 13:38:18 Completed 200 OK in 141.114µs
[webhook] 2020/11/06 13:38:18 [e38ac8] executing /home/ubuntu/alert.sh (/home/ubuntu/alert.sh) with arguments ["/home/ubuntu/alert.sh" "{\"extra_vars\":{\"content\":[{\"id\":\"001\",\"value\":\"你好 白菜\"},{\"id\":\"002\",\"value\":\"你好 萝卜\"}],\"newpoem\":\"hello good world\",\"title\":{\"id\":\"001\",\"name\":\"白菜\"}},\"extra_vars2\":{\"newpoem2\":\"hello good world2\"}}" "{\"Accept\":\"*/*\",\"Content-Length\":\"222\",\"Content-Type\":\"application/json\",\"User-Agent\":\"curl/7.61.1\"}" "{}"] and environment [] using /home/ubuntu as cwd
[webhook] 2020/11/06 13:38:18 [e38ac8] command output:
[webhook] 2020/11/06 13:38:18 [e38ac8] finished handling alertgw
ubuntu@VM-100-15-ubuntu:~$ ls
alert.sh entire-headers entire-payload entire-query hooks.json
ubuntu@VM-100-15-ubuntu:~$ cat entire-payload
{"extra_vars":{"content":[{"id":"001","value":"你好 白菜"},{"id":"002","value":"你好 萝卜"}],"newpoem":"hello good world","title":{"id":"001","name":"白菜"}},"extra_vars2":{"newpoem2":"hello good world2"}}
ubuntu@VM-100-15-ubuntu:~$ cat entire-headers
{"Accept":"*/*","Content-Length":"222","Content-Type":"application/json","User-Agent":"curl/7.61.1"}
ubuntu@VM-100-15-ubuntu:~$ cat entire-query
{}