- Notifications
You must be signed in to change notification settings - Fork1
Terraform module to convert Prometheus Alerting rules to Grafana-managed alert rules
License
mkilchhofer/terraform-grafana-prometheus-alerts
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Terraform module to convertPrometheus Alerting rules toGrafana-managed alert rules
There are plenty of apps (mostly out of CNCF's ecosystem) where the vendor or the community provides monitoring dashboardsand alerts. Dashboards are normally provided as a JSON file which can be loaded into Grafana. Alerts are mostly providedasPrometheus Alerting rules.
There are users who already operate a Grafana instance or use a managed Grafana instance from a cloud provider (GrafanaCloud, Amazon Managed Grafana, Azure Managed Grafana, etc.). Why not using this Grafana instance for thealerting?
The problem is that Grafana's unified alerting uses another format for the alert definition but the concept with labels,annotations (provide description and runbook URLs) is almost identical.This module allows you to reuse thePrometheus Alerting rules and configure them inside Grafana.
module"cert_manager_rules" {source="github.com/mkilchhofer/terraform-grafana-prometheus-alerts"prometheus_alerts_file_path=file("/path/to/alerts/cert-manager.yaml")folder_uid=grafana_folder.test.uiddatasource_uid=grafana_data_source.prometheus.uid}
- Grafana 8.0+ (Unified alerting)
- Defining multiple alerts with the same name is not supported in Grafana
The alerts defined asPrometheus Alerting rules can be overridden without changing the input file.If your Prometheus Alerting rules YAML contains an alertalert: TooManyWriteErrors
, you can override it like this:
module"cert_manager_rules" {source="github.com/mkilchhofer/terraform-grafana-prometheus-alerts"prometheus_alerts_file_path=file("/path/to/alerts/cert-manager.yaml")folder_uid=grafana_folder.test.uiddatasource_uid=grafana_data_source.prometheus.uid# Overrides per alertoverrides={"TooManyWriteErrors"= { alert_threshold=1 is_paused=true labels= { mycustomlabel="foobar"# Add an extra label severity="notify"# Override severity } } }}
Every alert supports the following overrides:
Override parameter | Type | Description |
---|---|---|
alert_threshold | number | Threshold of the Grafana alert. Defaults to0 |
exec_err_state | string | Describes what state to enter when the rule's query is invalid and the rule cannot be executed. Options areOK ,Error ,KeepLast , andAlerting . Defaults toError . |
expr | string | Use a custom PromQL expression for this Grafana alert. |
is_paused | bool | Sets whether the alert should be paused or not. Defaults tofalse . |
no_data_state | string | Describes what state to enter when the rule's query returns No Data. Options areOK ,NoData ,KeepLast , andAlerting . Defaults toOK . |
annotations | map(string) | Extra annotations to add. It is also possible to override already defined annotations likerunbook_url . |
labels | map(string) | Extra labels to add. It is also possible to override already defined labels likeseverity . |
for | string | The amount of time for which the rule must be breached for the rule to be considered to beFiring. Before this time has elapsed, the rule is only considered to bePending. Defaults to0 . |
Name | Version |
---|---|
grafana | ~> 3.2 |
Name | Description | Type | Default | Required |
---|---|---|---|---|
datasource_uid | The UID of the Grafana datasource being queried with the expressions inside the Alerting rule file | string | n/a | yes |
default_evaluation_interval_duration | How often is the rule evaluated by default. (When not defined inside your Alerting rules file) | string | "5m" | no |
disable_provenance | Allow modifying the rule group from other sources than Terraform or the Grafana API. | bool | false | no |
folder_uid | The UID of the Grafana folder that the alerts belongs to. | string | n/a | yes |
org_id | The Organization ID of of the Grafana Alerting rule groups. (Only supported with basic auth, API keys are already org-scoped) | string | null | no |
overrides | Overrides per Alert rule | map(object({ | {} | no |
prometheus_alerts_file_path | Path to the Prometheus Alerting rules file | string | n/a | yes |
No outputs.
About
Terraform module to convert Prometheus Alerting rules to Grafana-managed alert rules
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.