From f7070df4d34e2f6564ce9fc6323982255d01cf5a Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:44:10 +0200 Subject: [PATCH] [v10.4.x] Alerting docs: add `Template variable interpolation` section in file provisioning (#85745) Alerting docs: add `Template variable interpolation` section in file provisioning (#84106) * Alerting docs: add `Template variable interpolation` section in file provisioning * Update docs/sources/alerting/set-up/provision-alerting-resources/file-provisioning/index.md Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com> * Update docs/sources/alerting/set-up/provision-alerting-resources/file-provisioning/index.md Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com> * Update docs/sources/alerting/set-up/provision-alerting-resources/file-provisioning/index.md Co-authored-by: Matthew Jacobson --------- Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com> Co-authored-by: Matthew Jacobson (cherry picked from commit 0672bdf397b68cf81bb9e1f4e2265b05a828b769) Co-authored-by: Pepe Cano <825430+ppcano@users.noreply.github.com> --- .../file-provisioning/index.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/sources/alerting/set-up/provision-alerting-resources/file-provisioning/index.md b/docs/sources/alerting/set-up/provision-alerting-resources/file-provisioning/index.md index e5f2c33bb7c..8986febb57c 100644 --- a/docs/sources/alerting/set-up/provision-alerting-resources/file-provisioning/index.md +++ b/docs/sources/alerting/set-up/provision-alerting-resources/file-provisioning/index.md @@ -799,6 +799,40 @@ deleteMuteTimes: name: mti_1 ``` +## Template variable interpolation + +Provisioning interpolates environment variables using the `$variable` syntax. + +```yaml +contactPoints: + - orgId: 1 + name: My Contact Email Point + receivers: + - uid: 1 + type: email + settings: + addresses: $EMAIL +``` + +In this example, provisioning replaces `$EMAIL` with the value of the `EMAIL` environment variable or an empty string if it is not present. For more information, refer to [Using environment variables in the Provision documentation][provisioning_env_vars]. + +In alerting resources, most properties support template variable interpolation, with a few exceptions: + +- Alert rule annotations: `groups[].rules[].annotations` +- Alert rule time range: `groups[].rules[].relativeTimeRange` +- Alert rule query model: `groups[].rules[].data.model` +- Mute timings name: `muteTimes[].name` +- Mute timings time intervals: `muteTimes[].time_intervals[]` +- Notification template name: `templates[].name` +- Notification template content: `templates[].template` + +Note for properties that support interpolation, you may unexpectedly substitute template variables when not intended. To avoid this, you can escape the `$variable` with `$$variable`. + +For example, when provisioning a `subject` property in a `contactPoints.receivers.settings` object that is meant to use the `$labels` variable. + +1. `subject: '{{ $labels }}'` will interpolate, incorrectly defining the subject as `subject: '{{ }}'`. +1. `subject: '{{ $$labels }}'` will not interpolate, correctly defining the subject as `subject: '{{ $labels }}'`. + ## More examples For more examples on the concept of this guide: @@ -825,6 +859,7 @@ For more examples on the concept of this guide: [export_mute_timings]: "/docs/grafana-cloud/ -> /docs/grafana-cloud/alerting-and-irm/alerting/set-up/provision-alerting-resources/export-alerting-resources#export-mute-timings" [provisioning]: "/docs/ -> /docs/grafana//administration/provisioning" +[provisioning_env_vars]: "/docs/ -> /docs/grafana//administration/provisioning#using-environment-variables" [reload-provisioning-configurations]: "/docs/ -> /docs/grafana//developers/http_api/admin#reload-provisioning-configurations"