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作為參數(shù)傳遞給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系馆,打印傳入的參數(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
{}