This project provides a simple Flask-based webhook that listens for Grafana alert notifications, processes the alert data, matches it with services, and sends SMS alerts using an external SMS gateway API.
- Receives Grafana alert webhooks on a custom endpoint.
- Extracts: IP addresses of affected nodes, service names from a
servers.txt
file, and alert values (threshold breaches). - Formats and maps alerts into human-readable messages.
- Sends alerts via HTTP API calls to predefined phone numbers.
Use code with caution.
βββ app.py # Main Flask application (the webhook logic)
βββ servers.txt # File containing IP β Service name mappings
βββ requirements.txt # Python dependencies
βββ README.md # Documentation
Each line contains: <ip>,<service_name>
Example:
*.*.*.157,Database
*.*.*.170,Web Server
*.*.*.180,Application Server
- Clone this repository
git clone https://github.com/<your-username>/grafana-alert-webhook.git cd grafana-alert-webhook
- Install dependencies
pip install -r requirements.txt
- Run the Flask app
By default, the app runs on
python app.py
http://localhost:5000
.
- Go to Grafana β Alerting β Contact Points.
- Add a new Webhook contact point:
- URL:
http://<your-server-ip>:5000/sendsms?number=<your-phone-number>
- Method:
POST
- Send Full JSON Alert.
- URL:
- Add this contact point to your notification policies.
Grafana sends webhook β Flask app receives β Parses alert β Looks up IP in servers.txt
β Builds SMS β Sends via API.
Example message sent via SMS: Grafana_Alert High CPU Usage ..*.157 "Database" is 95
This webhook integrates with an HTTP SMS API (Kannel in this example):
http://<sms-gateway>:13013/cgi-bin/sendsms?username=USER&password=PASS&from=5188&to=<MSISDN>&text=<ALERT_MESSAGE>&MT&charset=utf-8
You can update the noc
list in app.py
with your desired phone numbers.
- Restrict access to the Flask port (e.g., firewall to allow only Grafana).
- Donβt hardcode SMS credentials in code for production.
- Run Flask with a production server like
gunicorn
or behindnginx
.
- Dockerize the webhook.
- Add retry logic if SMS gateway fails.
- Add logging & monitoring of SMS sends.