1.9 KiB
1.9 KiB
Pre-hook command
To the STDIN of the pre-hook command, webhook will pass a JSON string representation of an object with the following properties:
hookID
- ID of the hook that got matchedmethod
- HTTP(s) method used by the client (i.e. GET, POST, etc...)URI
- URI which client requestedhost
- value of theHost
header sent by the clientremoteAddr
- client's IP address and port in theIP:PORT
formatquery
- object with query parameters and their respective valuesheaders
- object with headers and their respective valuesbase64EncodedBody
- base64 encoded request body
Please note! Output of this command MUST be valid JSON string which will be parsed by the webhook and accessible using the pre-hook
as source when referencing values.
Important! Any errors encountered while trying to execute the pre-hook command will prevent the hook from triggering!
Examples
Please note: Following examples use shell scripts as pre-hook commands, but it is possible to use ruby, python, or anything else you like, as long as it outputs a valid JSON string as the result.
Make sure you have the jq
command available, as we're using it to parse the JSON in the pre-hook script.
Getting the IP address of the requester
script.sh
```
#!/bin/bash
ip=$1
echo $ip >> ips.txt
```
prehook.sh
```
#!/bin/bash
context=$(cat)
ip=`echo $context | jq -r '.remoteAddr' | cut -d ':' -f 1`
echo "{\"ip\": \"$ip\"}"
```
hooks.json
```
[
{
"id": "log-ip",
"pre-hook-command": "/home/example/prehook.sh",
"execute-command": "/home/example/script.sh",
"pass-arguments-to-command": [
{ "source": "pre-hook", "name": "ip" }
]
}
]
```