Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Terraform module to convert Prometheus Alerting rules to Grafana-managed alert rules

License

NotificationsYou must be signed in to change notification settings

mkilchhofer/terraform-grafana-prometheus-alerts

Repository files navigation

Terraform module to convertPrometheus Alerting rules toGrafana-managed alert rules

Motivation / Why using this module

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.

Example usage

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}

Requirements

  • Grafana 8.0+ (Unified alerting)

Limitations

  • Defining multiple alerts with the same name is not supported in Grafana

Overriding definitions of Prometheus Alerting file

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 parameterTypeDescription
alert_thresholdnumberThreshold of the Grafana alert. Defaults to0
exec_err_statestringDescribes what state to enter when the rule's query is invalid and the rule cannot be executed. Options areOK,Error,KeepLast, andAlerting. Defaults toError.
exprstringUse a custom PromQL expression for this Grafana alert.
is_pausedboolSets whether the alert should be paused or not. Defaults tofalse.
no_data_statestringDescribes what state to enter when the rule's query returns No Data. Options areOK,NoData,KeepLast, andAlerting. Defaults toOK.
annotationsmap(string)Extra annotations to add. It is also possible to override already defined annotations likerunbook_url.
labelsmap(string)Extra labels to add. It is also possible to override already defined labels likeseverity.
forstringThe 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.

TF module documentation

Providers

NameVersion
grafana~> 3.2

Inputs

NameDescriptionTypeDefaultRequired
datasource_uidThe UID of the Grafana datasource being queried with the expressions inside the Alerting rule filestringn/ayes
default_evaluation_interval_durationHow often is the rule evaluated by default. (When not defined inside your Alerting rules file)string"5m"no
disable_provenanceAllow modifying the rule group from other sources than Terraform or the Grafana API.boolfalseno
folder_uidThe UID of the Grafana folder that the alerts belongs to.stringn/ayes
org_idThe Organization ID of of the Grafana Alerting rule groups. (Only supported with basic auth, API keys are already org-scoped)stringnullno
overridesOverrides per Alert rule
map(object({
alert_threshold = optional(number)
exec_err_state = optional(string)
expr = optional(string)
is_paused = optional(bool)
no_data_state = optional(string)
labels = optional(map(string))
annotations = optional(map(string))
for = optional(string)
}))
{}no
prometheus_alerts_file_pathPath to the Prometheus Alerting rules filestringn/ayes

Outputs

No outputs.

About

Terraform module to convert Prometheus Alerting rules to Grafana-managed alert rules

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp