Skip to content

Commit 565922c

Browse files
committed
feat: improve logs and config
1 parent 56a1cc4 commit 565922c

File tree

5 files changed

+221
-91
lines changed

5 files changed

+221
-91
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.json
2+
.ropeproject

README.md

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Webhook Tester is a lightweight HTTP server that listens for incoming webhook re
1212
- **Real-time Display**: View incoming webhook payloads, headers, and metadata in real-time
1313
- **Signature Verification**: Verify webhook signatures using HMAC-SHA256
1414
- **Data Export**: Save received webhooks to a JSON file for later analysis
15-
- **Customizable**: Configure host, port, and shared secret via command-line options
15+
- **Configurable**: Set host, port, logging level, and shared secret via configuration file
1616

1717
## Requirements
1818

@@ -31,59 +31,68 @@ chmod +x webhook_tester.py
3131

3232
### Basic Usage
3333

34-
Start the webhook receiver on the default port (8000):
34+
Start the webhook receiver with default settings:
3535

3636
```bash
3737
python webhook_tester.py
3838
```
3939

40-
### Command-line Options
40+
This will:
41+
- Start the server on `localhost:7999`
42+
- Save received webhooks to `webhooks.json`
43+
- Use INFO level logging
4144

42-
```bash
43-
python webhook_tester.py [OPTIONS]
44-
```
45+
### Example output:
46+
![Example output](./ksnip_20250423-094034.png)
4547

46-
Available options:
48+
### Configuration File
4749

48-
- `--host HOST`: Host address to bind to (default: localhost)
49-
- `--port PORT`: Port to listen on (default: 8000)
50-
- `--secret SECRET`: Shared secret for signature verification
51-
- `--verbose, -v`: Enable verbose output (shows detailed webhook information)
50+
The script uses a JSON configuration file (default: `webhook_config.json`). If the file doesn't exist, a default one will be created automatically with these settings:
5251

53-
### Examples
54-
55-
Listen on port 9000:
56-
```bash
57-
python webhook_tester.py --port 9000
52+
```json
53+
{
54+
"host": "localhost",
55+
"port": 7999,
56+
"secret": null,
57+
"output_file": "webhooks.json",
58+
"truncate_output": false,
59+
"log_level": "INFO"
60+
}
5861
```
5962

60-
Listen on all interfaces:
61-
```bash
62-
python webhook_tester.py --host 0.0.0.0
63-
```
63+
You can customize:
64+
- `host`: Host address to bind to
65+
- `port`: Port to listen on
66+
- `secret`: Shared secret for signature verification
67+
- `output_file`: Path to save received webhooks
68+
- `truncate_output`: Whether to clear the output file on startup
69+
- `log_level`: Logging level (INFO, DEBUG, ERROR)
70+
71+
### Using a Custom Configuration
6472

65-
Configure a shared secret for signature verification:
6673
```bash
67-
python webhook_tester.py --secret your_webhook_shared_secret
74+
python webhook_tester.py --config my_custom_config.json
6875
```
6976

7077
### Using with External Services
7178

72-
To receive webhooks from external services, you'll need to expose your local server to the internet. You can use a tool like [ngrok](https://ngrok.com/):
79+
To receive webhooks from external services, you'll need to expose your local server to the internet. You can use a tool like [localtunnel](https://theboroer.github.io/localtunnel-www/):
7380

7481
```bash
75-
# Install ngrok if you haven't already
82+
# Install localtunnel if you haven't already
83+
npm install -g localtunnel
84+
7685
# Then expose your webhook tester
77-
ngrok http 8000
86+
lt --port 7999
7887
```
7988

80-
Use the URL provided by ngrok as your webhook endpoint in the external service.
89+
Use the URL provided by localtunnel as your webhook endpoint in the external service.
8190

8291
## Signature Verification
8392

8493
The webhook tester supports signature verification using HMAC-SHA256. To verify signatures:
8594

86-
1. Start the tester with the `--secret` option
95+
1. Add a `secret` value in your configuration file
8796
2. Ensure your webhook source is sending the following headers:
8897
- `x-voltage-signature`: Base64-encoded HMAC-SHA256 signature
8998
- `x-voltage-timestamp`: Timestamp used in the signature calculation
@@ -95,29 +104,33 @@ HMAC-SHA256(shared_secret, payload_string + "." + timestamp)
95104

96105
## Reading Webhook Data
97106

98-
When a webhook is received, the following information is displayed (if verbose mode is enabled):
107+
When a webhook is received, the following information is displayed:
99108

109+
- Webhook number and event type
100110
- Timestamp when the webhook was received
111+
- Signature verification result (if a secret is configured)
112+
113+
In DEBUG mode, additional information is shown:
101114
- Request path
102-
- Event type (from the `x-voltage-event` header)
103115
- All request headers
104116
- Full JSON payload
105-
- Signature verification result (if applicable)
106117

107118
## Saving Webhook Data
108119

109-
When you stop the webhook tester (by pressing Ctrl+C), you'll see a summary of all received webhooks and be prompted to save them to a JSON file. This file can be used for later analysis or debugging.
110-
111-
## Example Output
112-
113-
![example](./ksnip_20250422-170011.png)
114-
115-
120+
Received webhooks are automatically saved to the configured output file in JSON format. Each webhook entry includes:
121+
- Timestamp
122+
- Path
123+
- Headers
124+
- Payload
125+
- Signature details
126+
- Event type
116127

128+
When you stop the webhook tester (by pressing Ctrl+C), you'll see a summary of all received webhooks during that session.
117129

118130
## Troubleshooting
119131

120-
- **No webhooks being displayed**: Make sure verbose mode is enabled
132+
- **Need more detailed information**: Set `log_level` to `"DEBUG"` in your configuration
121133
- **Signature verification fails**: Check that the shared secret matches between sender and receiver
122-
- **Can't receive external webhooks**: Ensure your server is accessible from the internet (e.g., using ngrok)
134+
- **Can't receive external webhooks**: Ensure your server is accessible from the internet (e.g., using localtunnel)
123135
- **JSON parsing errors**: Ensure the webhook payload is valid JSON
136+
- **Need to start fresh**: Set `truncate_output` to `true` in your configuration

ksnip_20250422-170011.png

-69 KB
Binary file not shown.

ksnip_20250423-094034.png

75.6 KB
Loading

0 commit comments

Comments
 (0)