A lightweight Go service that executes commands via webhooks and streams logs to Grafana Loki in real-time.
- 🚀 Execute commands via simple HTTP webhooks
- 🔍 View last N lines of command output via API
- 📊 Real-time log streaming to Loki (port 3100)
- 🔒 Concurrent execution protection (one instance per command)
- ⚙️ YAML configuration for easy setup
- 📈 Grafana dashboard integration
- Go 1.20+
- Grafana Loki (optional)
- Basic terminal knowledge
# Clone the repository
git clone https://github.com/melehin/webhook-executor.git
cd webhook-executor
# Build the binary
go build -o webhook-executor
# Run with default config
./webhook-executorEdit config.yaml to customize your setup:
server:
port: 9000
tail:
lines: 100 # Number of output lines to retain
loki:
enabled: true
url: "http://localhost:3100" # Loki endpoint
batch_wait_seconds: 2
batch_size: 100
timeout_seconds: 10
labels:
job: "webhook-server"
app: "command-executor"
environment: "production"
hooks:
- id: redeploy-webhook
execute-command: "/var/scripts/redeploy.sh"
command-working-directory: "/var/webhook"
- id: backup-db
execute-command: "pg_dump -U user mydb | gzip > backup.sql.gz"
command-working-directory: "/backups"| Endpoint | Method | Description |
|---|---|---|
| /hooks/{hook-id} | GET | Trigger command execution |
| /tail/{hook-id} | GET | View command status and output |
| /hooks | GET | List all available hooks |
- Set up Loki datasource in Grafana pointing to your Loki instance
- Import the dashboard from grafana-dashboard.json
- Query logs with:
{job="webhook-server", hook_id="redeploy-webhook"}- Run behind a reverse proxy with HTTPS
- Add authentication middleware
- Restrict network access to the service
- Set appropriate file permissions for scripts
# /etc/systemd/system/webhook-executor.service
[Unit]
Description=Webhook Command Executor
After=network.target
[Service]
User=webhook
WorkingDirectory=/opt/webhook-executor
ExecStart=/opt/webhook-executor/webhook-executor
Restart=always
[Install]
WantedBy=multi-user.targetdocker build -t webhook-executor .
docker run -d -p 9000:9000 \
-v /path/to/config.yaml:/app/config.yaml \
-v /path/to/scripts:/scripts \
webhook-executor# Run tests
go test ./...
# Build with debug symbols
go build -gcflags="all=-N -l" -o webhook-executor-debug
# Format code
go fmt ./...- For production use, consider adding:
- Request rate limiting
- JWT authentication
- Prometheus metrics endpoint
- Use the
command-working-directoryto properly scope your commands - Test your scripts independently before hooking them up