Skip to content

imidevops/grafana-webhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Grafana Alert Webhook β†’ SMS Notifier

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.

πŸ“Œ Features

  • 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.

πŸ“‚ Directory Structure

Use code with caution.

grafana-alert-webhook/

β”œβ”€β”€ app.py # Main Flask application (the webhook logic)
β”œβ”€β”€ servers.txt # File containing IP β†’ Service name mappings
β”œβ”€β”€ requirements.txt # Python dependencies
β”œβ”€β”€ README.md # Documentation

πŸ“œ Example servers.txt

Each line contains: <ip>,<service_name>

Example:

*.*.*.157,Database
*.*.*.170,Web Server
*.*.*.180,Application Server

βš™οΈ Installation

  1. Clone this repository
    git clone https://github.com/<your-username>/grafana-alert-webhook.git
    cd grafana-alert-webhook
  2. Install dependencies
    pip install -r requirements.txt
  3. Run the Flask app
    python app.py
    By default, the app runs on http://localhost:5000.

πŸ“‘ Grafana Configuration

  1. Go to Grafana β†’ Alerting β†’ Contact Points.
  2. Add a new Webhook contact point:
    • URL: http://<your-server-ip>:5000/sendsms?number=<your-phone-number>
    • Method: POST
    • Send Full JSON Alert.
  3. Add this contact point to your notification policies.

πŸ“₯ Example Alert Flow

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

πŸ“€ SMS Gateway

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.

πŸ”’ Security Notes

  • 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 behind nginx.

πŸš€ To-Do

  • Dockerize the webhook.
  • Add retry logic if SMS gateway fails.
  • Add logging & monitoring of SMS sends.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages