You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b183aba
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: en/monitors/alert-rules/description-template.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ available through the `sprig_` prefix.
51
51
|`$labels`|`map[string]string`| Alert labels. Same data as `.DataLabels`. |
52
52
|`$values`|`map[string]float64`| Numeric values used by alert evaluation. Same data as `.Values`. |
53
53
|`$value`|`float64`| Main alert value. Same data as `.Value`. |
54
-
|`$appendLabels`|`map[string]string`| Extra labels configured on the alert rule. |
54
+
|`$appendLabels`|`map[string]string`| Extra labels configured on the alert rule. Additional labels that use Go templates appear here as raw template text and are rendered only before delivery. See [Additional label syntax](/en/monitors/quickstart/quickstart#append-label-syntax). |
55
55
|`$annotations`|`map[string]string`| Custom rule fields and additional information carried from query results. |
Copy file name to clipboardExpand all lines: en/monitors/alert-rules/query-result-fields.mdx
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,6 +142,37 @@ The `$` prefix identifies query-provided fields. A custom field configured on th
142
142
A No data alert carries the additional information from the last successful result for that alert object. If the query has never returned data, no query-provided additional information is available.
143
143
</Note>
144
144
145
+
<spanid="query-fields-as-labels"></span>
146
+
## Sending additional information as alert labels
147
+
148
+
Additional information reaches On-call with the `__alert_rule_annotation_` prefix, so channel notification templates, escalation rules, and [Alert pipeline](/en/on-call/integration/alert-integration/alert-pipelines) conditions that match ordinary label names (for example `labels.msg`) can't read it. When you need it, use a Go template in the rule's [Additional Labels](/en/monitors/quickstart/quickstart#append-label-syntax) to turn additional information into ordinary labels.
149
+
150
+
For example, to group error logs by service and still keep the latest log line in notifications:
151
+
152
+
```sql
153
+
SELECT service, namespace, COUNT(*) AS value,
154
+
MAX(datetime) AS datetime,
155
+
MAX_BY(msg, datetime) AS msg,
156
+
MAX_BY(trace_id, datetime) AS tid
157
+
FROM error_logs
158
+
WHERE datetime >= NOW() - INTERVAL 1 MINUTE
159
+
GROUP BY service, namespace
160
+
```
161
+
162
+
Select `service` and `namespace` as label fields, so `msg`, `tid`, and `datetime` become additional information. Then configure these additional labels:
163
+
164
+
```text
165
+
msg = {{ index $annotations "$A.msg" }}
166
+
tid = {{ index $annotations "$A.tid" }}
167
+
datetime = {{ index $annotations "$A.datetime" }}
168
+
```
169
+
170
+
Each service then produces one alert instance, and the `msg`, `tid`, and `datetime` sent to On-call carry the latest log line for that service. Existing notification templates and escalation rules keep working without changes.
171
+
172
+
<Note>
173
+
Query-provided additional information requires monit-edge `v0.53.0` or later. Earlier alert engines don't provide it, so templates can't read these values.
174
+
</Note>
175
+
145
176
## Query result row limits
146
177
147
178
Edge limits scheduled alert queries and interactive preview queries separately. The following defaults can be configured independently by the deployer:
Copy file name to clipboardExpand all lines: en/monitors/quickstart/quickstart.mdx
+29-1Lines changed: 29 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,35 @@ The create / edit alert rule page is one form with six sections, from top to bot
76
76
|--------|------|
77
77
|**Group**| The group path of the rule (for example, "Default / Database Alerts"). If the group has been deleted or you cannot access it, go back to the rule list and pick a group again |
78
78
|**Rule Name**| Name of the alert rule; does not support variable references (fixed names facilitate filtering and grouping operations). It must be unique within its group; imports, edits, and moves fail if the target group already contains that name |
79
-
|**Additional Labels**| Similar to `labels` in Prometheus; attached to all alert events for filtering, routing, and inhibition |
79
+
|**Additional Labels**| Similar to `labels` in Prometheus; attached to all alert events for filtering, routing, and inhibition. See below for value syntax |
80
+
81
+
<spanid="append-label-syntax"></span>
82
+
#### Additional label syntax
83
+
84
+
An additional label value takes one of three forms, depending on its content:
85
+
86
+
| Form | Example | Handling |
87
+
|------|---------|----------|
88
+
| Plain text or `${label name}`|`team=ops`, `instance=${host}`| The alert engine replaces `${label name}` with the alert label |
89
+
| Go template containing `{{`|`msg={{ index $annotations "$A.msg" }}`| Rendered before delivery to the channel and sent as an ordinary label |
90
+
| Starts with `[TPL]`|`owner=[TPL]{{ .Labels.team }}`| Passed to On-call as is and rendered by On-call. See [Alert pipeline](/en/on-call/integration/alert-integration/alert-pipelines) for the syntax |
91
+
92
+
Go templates can use these variables:
93
+
94
+
| Variable | Description |
95
+
|----------|-------------|
96
+
|`$labels`| The alert's data labels, for example `{{ $labels.service }}`|
97
+
|`$annotations`| Query-provided additional information and the rule's custom fields. Query-provided keys use `$<query name>.<field name>` and must be read with `index`, for example `{{ index $annotations "$A.msg" }}`. See [Query result field mapping](/en/monitors/alert-rules/query-result-fields#query-fields-as-labels)|
98
+
|`$values`| Values used in alert evaluation, for example `{{ index $values "$A.value" }}`|
99
+
|`$severity`| Alert severity |
100
+
|`$status`|`firing` or `recovered`|
101
+
102
+
- Templates support only `if` / `else` plus `index`, `len`, `printf`, `print`, `replace`, `urlquery`, and the comparison and logical functions. `range`, `with`, and `define` aren't supported.
103
+
- A missing key reads as an empty string in `$labels` and `$annotations`, and as `0` in `$values`. A label that renders to an empty string isn't sent.
104
+
- A single value can't mix `${...}` and `{{...}}`.
105
+
- A label that fails to render isn't sent, and the alert event is still delivered. The error goes to the `__alert_rule_label_template_error` label, which you can see in the alert details.
106
+
- Leading and trailing whitespace in label names is trimmed on save, and the trimmed names must be unique. Label names can't start with `__alert_rule_`. All additional labels together are limited to 1,024 characters as JSON, and `job` and `instance` values to 255 characters.
107
+
- When the alert engine renders descriptions, custom fields, and titles, template labels in `$appendLabels` are still the raw template text. To use query results there, reference `$annotations` directly.
0 commit comments