Configuring Grafana Webhook and Alert Notifications


1. Open Grafana Dashboard

  • Log in to Grafana.

  • Navigate to Alerting → Contact Points.


2. Create a Webhook Contact Point

  • Click New Contact Point.

  • Enter a name (e.g., custom-webhook-alert).

  • Select Webhook as the integration type.

Webhook Configuration

  • URL → This is the endpoint where Grafana will send alerts. You must provide a reachable API URL (for example, your backend service or webhook receiver).

Example:

http://your-server:50100/webhook

Optional Fields

  • HTTP Method → POST (default).

  • Authentication → Configure if your API requires authentication.

  • Custom Headers → Add headers if required by your API.

Example header:


3. Configure Custom Payload (Optional)

Grafana allows you to customize the JSON payload sent to your webhook.

Example Payload


4. Save the Contact Point

  • Click Save Contact Point.

  • Your webhook notification channel is now ready to use.


5. Create an Alert Rule

  • Go to Alerting → Alert Rules.

  • Click New Alert Rule.

  • Select a data source (e.g., Prometheus).

  • Write a query for the metric you want to monitor.

Example:


6. Define Alert Conditions

Example condition:

This means the alert will trigger if the condition remains true for 5 minutes.


7. Attach the Webhook Contact Point

  • Under Configure Notifications, select the contact point you created (custom-webhook-alert).

  • Save the alert rule.


8. Test the Webhook

  • Go to Contact Points.

  • Select your webhook.

  • Click Test.

Grafana will send a sample JSON payload to your configured endpoint URL.


Example Webhook Payload Sent by Grafana (Simplified)


Example Python Webhook Receiver (Flask)

Prerequisites for Example Webhook Server

  • Python must be installed on the system.

  • The pip package manager must be available.

  • Install the Flask Python module using the following command: pip3 install flask.

  • All commands must be executed on the system where the webhook server will run.


How to Run and test the Webhook Server quickly

  1. Save the above Python code in a file (e.g., server1.py).

  2. Test the webhook:


Expected Result

  • A file named test.json will be created.

  • It will contain the received webhook payload.


  1. Run the following command on your host machine:

  1. Once the server starts, it will be available at:

Use this URL in Grafana as your webhook endpoint.


Example Server Output

This confirms that Grafana successfully sent an alert to your webhook.

Note: Similarly, if you follow the above steps and create a Grafana alert rule (for example, using the MySQL snapshot query), the webhook will receive the actual alert payload. The details will be stored in test.json, confirming that Grafana successfully sent the alert to your webhook.


Last updated

Was this helpful?