A lightweight Go webhook service that receives alerts from Prometheus Alertmanager and forwards them to Discord channels via webhooks.
- ๐ Lightweight - Minimal resource usage with scratch-based Docker image
- ๐ Real-time Alerts - Instant Discord notifications for firing and resolved alerts
- ๐จ Color-coded Messages - Red for firing alerts, green for resolved
- ๐ Misconfiguration Detection - Warns if receiving raw Prometheus alerts instead of Alertmanager
- ๐ฅ Health Checks - Built-in health endpoint for container orchestration
- ๐ณ Multi-platform - Supports linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
- ๐ Secure - Runs as non-root user in minimal container
This service accepts webhooks from Alertmanager, not directly from Prometheus.
flowchart LR;
Prometheus-->|scrapes metrics|Prometheus;
Prometheus==>|sends alerts|Alertmanager;
Alertmanager==>|webhook|alertmanager-discord;
alertmanager-discord==>|posts|Discord;
flowchart LR;
Prometheus==>|โ WRONG|alertmanager-discord;
alertmanager-discord-.->|misconfiguration warning|Discord;
If you connect Prometheus directly to this service, you'll receive a misconfiguration warning message in Discord.
Pull the latest image from GitHub Container Registry:
docker pull ghcr.io/simplicityguy/alertmanager-discord:latestRun the container:
docker run -d \
--name alertmanager-discord \
-p 9094:9094 \
-e DISCORD_WEBHOOK="https://discord.com/api/webhooks/..." \
ghcr.io/simplicityguy/alertmanager-discord:latestversion: '3.8'
services:
alertmanager-discord:
image: ghcr.io/simplicityguy/alertmanager-discord:latest
ports:
- "9094:9094"
environment:
- DISCORD_WEBHOOK=https://discord.com/api/webhooks/...
- LISTEN_ADDRESS=0.0.0.0:9094
restart: unless-stopped
healthcheck:
test: ["/go/bin/alertmanager-discord", "-healthcheck"]
interval: 30s
timeout: 3s
retries: 3
start_period: 5sDownload the latest release for your platform from the releases page.
# Linux
./alertmanager-discord -webhook.url="https://discord.com/api/webhooks/..."
# macOS
./alertmanager-discord.darwin -webhook.url="https://discord.com/api/webhooks/..."git clone https://github.com/SimplicityGuy/alertmanager-discord.git
cd alertmanager-discord
go build -o alertmanager-discord
./alertmanager-discord -webhook.url="https://discord.com/api/webhooks/..."| Variable | Required | Default | Description |
|---|---|---|---|
DISCORD_WEBHOOK |
Yes | - | Discord webhook URL |
LISTEN_ADDRESS |
No | 127.0.0.1:9094 |
Host and port to listen on |
| Flag | Description | Default |
|---|---|---|
-webhook.url |
Discord webhook URL (overrides env var) | - |
-listen.address |
Listen address (overrides env var) | 127.0.0.1:9094 |
-healthcheck |
Perform health check and exit | - |
Note: Environment variables take precedence over CLI flags.
- Open your Discord server
- Go to Server Settings โ Integrations โ Webhooks
- Click New Webhook
- Name it (e.g., "Alertmanager")
- Select the channel for alerts
- Copy the webhook URL
- Use this URL in your configuration
Configure Prometheus to send alerts to Alertmanager:
# prometheus.yml
alerting:
alertmanagers:
- static_configs:
- targets:
- 'alertmanager:9093'Configure Alertmanager to send webhooks to alertmanager-discord:
# alertmanager.yml
global:
smtp_smarthost: 'localhost:25'
smtp_from: 'alertmanager@example.org'
# The directory from which notification templates are read
templates:
- '/etc/alertmanager/template/*.tmpl'
# The root route on which each incoming alert enters
route:
group_by: ['alertname']
group_wait: 20s
group_interval: 5m
repeat_interval: 3h
receiver: discord_webhook
receivers:
- name: 'discord_webhook'
webhook_configs:
- url: 'http://alertmanager-discord:9094'
send_resolved: trueSend a test webhook to verify the configuration:
curl -X POST http://localhost:9094 \
-H "Content-Type: application/json" \
-d '{
"alerts": [{
"status": "firing",
"labels": {
"alertname": "TestAlert",
"instance": "localhost"
},
"annotations": {
"description": "This is a test alert"
}
}]
}'- Go 1.20 or higher
- Docker (for containerized development)
- pre-commit (optional, for git hooks)
- Clone the repository:
git clone https://github.com/SimplicityGuy/alertmanager-discord.git
cd alertmanager-discord- Install dependencies:
go mod download- Set up pre-commit hooks (optional):
pip install pre-commit
pre-commit install- Run the service:
export DISCORD_WEBHOOK="https://discord.com/api/webhooks/..."
go run main.go detect-misconfig.go# Run all tests
go test -v ./...
# Run tests with coverage
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
# View coverage report
go tool cover -html=coverage.out
# Run benchmarks
go test -bench=. -benchmem ./...# Run all pre-commit hooks
pre-commit run --all-files
# Go formatting
gofmt -l -w .
# Go vet
go vet ./...
# golangci-lint
golangci-lint run --timeout=5m
# Dockerfile linting
hadolint Dockerfile# Build for local platform
docker build -t alertmanager-discord .
# Build for multiple platforms
docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \
-t alertmanager-discord \
.This project uses GitHub Actions for continuous integration and deployment.
| Workflow | Trigger | Purpose |
|---|---|---|
| Code Quality | Push, PR | Runs pre-commit, golangci-lint, and go fmt checks |
| Tests | Push, PR | Runs unit tests with coverage reporting |
| Docker Validate | Push, PR (Docker files) | Validates Dockerfiles and tests builds |
| Build | Push to main, Schedule | Builds and publishes multi-platform Docker images |
| Update Dependencies | Weekly, Manual | Automated dependency updates via PR |
| Cleanup Cache | PR closed | Removes caches for closed PRs |
| Cleanup Images | Monthly, Manual | Removes old Docker images from GHCR |
- โ Dependency Updates - Weekly automated PRs for Go module updates
- โ Code Coverage - Automatic coverage reports on PRs via Codecov
- โ Multi-platform Builds - Automatic builds for 4 architectures
- โ Cache Management - Automatic cleanup of stale caches and images
- โ Quality Gates - All PRs must pass linting, tests, and formatting
- โ Discord Notifications - Build status notifications to Discord
alertmanager-discord/
โโโ main.go # Main service with webhook receiver
โโโ detect-misconfig.go # Misconfiguration detection logic
โโโ go.mod # Go module definition
โโโ go.sum # Go module checksums
โโโ Dockerfile # Multi-stage Docker build
โโโ .dockerignore # Docker build exclusions
โโโ .gitignore # Git exclusions
โโโ .pre-commit-config.yaml # Pre-commit hook configuration
โโโ .yamllint # YAML linting rules
โโโ .github/
โ โโโ workflows/ # GitHub Actions workflows
โโโ images/ # Documentation images
โโโ README.md # This file
- Webhook Receiver - HTTP server listening on configured address (default:
127.0.0.1:9094) - Alert Parser - Unmarshals Alertmanager JSON into Go structures
- Misconfiguration Detector - Validates incoming payloads are from Alertmanager
- Discord Formatter - Transforms alerts into Discord embeds with color coding:
- ๐ด Red (0x992D22) - Firing alerts
- ๐ข Green (0x2ECC71) - Resolved alerts
- โช Grey (0x95A5A6) - Unknown status
- Alert Grouper - Groups alerts by status before sending to Discord
The service includes a built-in health check endpoint:
# HTTP endpoint
curl http://localhost:9094/health
# Returns: {"status":"ok"}
# Docker health check
docker exec alertmanager-discord /go/bin/alertmanager-discord -healthcheck
# Exit code 0 = healthy, 1 = unhealthyContributions are welcome! Please follow these guidelines:
- Fork the repository and create a feature branch
- Install pre-commit hooks:
pre-commit install - Write tests for new functionality
- Ensure all tests pass:
go test ./... - Run code quality checks:
pre-commit run --all-files - Commit with conventional commits:
feat:,fix:,docs:, etc. - Submit a pull request with a clear description
- Follow Go Code Review Comments
- Use
gofmtfor formatting - Run
golangci-lintand address all issues - Maintain test coverage above 80%
- Add documentation for public APIs
- Use conventional commit messages
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
- Original inspiration from benjojo/alertmanager-discord
- Built with Go and love for the monitoring community
- Thanks to all contributors and users
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Security: Please report security issues privately via GitHub Security Advisories
- Docker Images: GHCR Package
- Source Code: GitHub Repository
- CI/CD: GitHub Actions
- Prometheus: prometheus.io
- Alertmanager: Alertmanager Documentation
- Discord Webhooks: Discord Webhook Guide
