Skip to content

Commit 7bf3bd6

Browse files
authored
Merge pull request #56 from flashcatcloud/docs/description-template-menu-label
docs: adjust description template menu label
2 parents a1e87dd + b1ff649 commit 7bf3bd6

4 files changed

Lines changed: 19 additions & 10 deletions

File tree

.mintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
# Project documentation (non-mdx files)
55
AGENTS.md
66
README.md
7+
README_zh.md
78
README.en.md

docs.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@
448448
"group": "告警规则",
449449
"icon": "list-check",
450450
"pages": [
451-
"zh/monitors/alert-rules/description-template",
452451
"zh/monitors/alert-rules/prometheus",
453452
"zh/monitors/alert-rules/elasticsearch",
454453
"zh/monitors/alert-rules/loki",
@@ -457,7 +456,8 @@
457456
"zh/monitors/alert-rules/oracle",
458457
"zh/monitors/alert-rules/postgres",
459458
"zh/monitors/alert-rules/sls",
460-
"zh/monitors/alert-rules/victorialogs"
459+
"zh/monitors/alert-rules/victorialogs",
460+
"zh/monitors/alert-rules/description-template"
461461
]
462462
},
463463
{
@@ -1400,7 +1400,6 @@
14001400
"group": "Alert Rules",
14011401
"icon": "list-check",
14021402
"pages": [
1403-
"en/monitors/alert-rules/description-template",
14041403
"en/monitors/alert-rules/prometheus",
14051404
"en/monitors/alert-rules/elasticsearch",
14061405
"en/monitors/alert-rules/loki",
@@ -1409,7 +1408,8 @@
14091408
"en/monitors/alert-rules/oracle",
14101409
"en/monitors/alert-rules/postgres",
14111410
"en/monitors/alert-rules/sls",
1412-
"en/monitors/alert-rules/victorialogs"
1411+
"en/monitors/alert-rules/victorialogs",
1412+
"en/monitors/alert-rules/description-template"
14131413
]
14141414
},
14151415
{

en/monitors/alert-rules/description-template.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
---
2-
title: "Alert Rule Description Templates"
2+
title: "Description Template"
33
description: "Configure Go Template variables, related query results, and Sprig functions for Monitors alert rule descriptions."
44
keywords: ["Description templates", "alert rules", "Go Template", "Sprig", "related queries"]
55
---
66

77
Use an alert rule **Description** to define the text shown on firing and recovery events. You can reference alert labels, query values, related query results, and safe Sprig functions with Go `text/template`, then render the result as Text or Markdown.
88

9+
<Warning>
10+
The template variables, Sprig function names, and behavior where label enrichment runs before `Description` rendering require monit-edge `v0.42.0` or later. On older versions, some variables or functions may be unavailable, and enrichment results may not be available inside Description templates.
11+
</Warning>
12+
913
## How It Works
1014

11-
When a rule fires or recovers, monit-edge passes the full alert event as the template root object and injects short variables for common fields. After rendering, monit-edge writes the result to the event `Description`, then runs label enrichment and sends the event.
15+
When a rule fires or recovers, monit-edge passes the full alert event as the template root object and injects short variables for common fields. After label enrichment completes, monit-edge renders the template with the enriched event, writes the result to the event `Description`, and then sends the event.
1216

1317
<Note>
1418
For day-to-day templates, prefer `$labels`, `$values`, `$value`, `$relates`, `$status`, and `$checkMode`. Use the other short variables only for advanced templates or compatibility cases.
@@ -224,7 +228,7 @@ community_posts.comment_count
224228
| `contains substr text` | Checks whether `text` contains `substr`. | `{{ if contains "Unknown column" $msg }}...{{ end }}` |
225229
| `hasPrefix prefix text` | Checks prefix. | `{{ hasPrefix "prod-" $name }}` |
226230
| `hasSuffix suffix text` | Checks suffix. | `{{ hasSuffix ".log" $file }}` |
227-
| `regexMatch pattern text` | Regex match. | `{{ regexMatch "error|failed" $msg }}` |
231+
| `regexMatch pattern text` | Regex match. | `{{ regexMatch "error\|failed" $msg }}` |
228232
| `regexFind pattern text` | Returns the first full regex match. | `{{ regexFind "trace_id=[a-z0-9]+" $msg }}` |
229233
| `regexFindAll pattern text n` | Returns up to `n` full regex matches. Use `-1` for all. | `{{ regexFindAll "id=[0-9]+" $msg -1 }}` |
230234
| `regexReplaceAll pattern text repl` | Regex replacement. Argument order is `pattern`, `text`, `replacement`. | `{{ regexReplaceAll ".*id=([0-9]+).*" $msg "$1" }}` |

zh/monitors/alert-rules/description-template.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
---
2-
title: "告警规则 Description 模板"
2+
title: "备注模板"
33
description: "配置 Monitors 告警规则备注描述的 Go Template 变量、关联查询结果和 Sprig 函数。"
44
keywords: ["Description 模板", "告警规则", "备注描述", "Go Template", "Sprig", "关联查询"]
55
---
66

77
Monitors 告警规则的 **备注描述(Description)** 用于定义告警和恢复事件中的说明文本。你可以使用 Go `text/template` 引用告警标签、查询值、关联查询结果和安全的 Sprig 函数,生成 Text 或 Markdown 格式的描述内容。
88

9+
<Warning>
10+
本文描述的模板变量、Sprig 函数名和标签增强后再渲染 `Description` 的行为需要 monit-edge `v0.42.0` 或以上版本。低于该版本时,部分变量或函数可能不可用,标签增强结果也可能无法在备注模板中引用。
11+
</Warning>
12+
913
## 工作方式
1014

11-
规则触发或恢复时,monit-edge 会把完整告警事件作为模板根对象,并额外注入一组常用短变量。模板渲染完成后,结果会写入事件的 `Description` 字段,再继续执行标签增强和事件发送
15+
规则触发或恢复时,monit-edge 会把完整告警事件作为模板根对象,并额外注入一组常用短变量。标签增强执行完成后,模板会基于增强后的事件渲染,结果会写入事件的 `Description` 字段,再继续发送事件
1216

1317
<Note>
1418
日常模板建议优先使用 `$labels``$values``$value``$relates``$status``$checkMode`。其他短变量用于高级模板或兼容场景,只有确实需要时再使用。
@@ -215,7 +219,7 @@ community_posts.comment_count
215219
| `contains substr text` | 判断 `text` 是否包含 `substr`| `{{ if contains "Unknown column" $msg }}...{{ end }}` |
216220
| `hasPrefix prefix text` | 判断前缀。 | `{{ hasPrefix "prod-" $name }}` |
217221
| `hasSuffix suffix text` | 判断后缀。 | `{{ hasSuffix ".log" $file }}` |
218-
| `regexMatch pattern text` | 正则匹配。 | `{{ regexMatch "error|failed" $msg }}` |
222+
| `regexMatch pattern text` | 正则匹配。 | `{{ regexMatch "error\|failed" $msg }}` |
219223
| `regexFind pattern text` | 返回第一个完整正则匹配。 | `{{ regexFind "trace_id=[a-z0-9]+" $msg }}` |
220224
| `regexFindAll pattern text n` | 返回最多 `n` 个完整正则匹配。`-1` 表示全部返回。 | `{{ regexFindAll "id=[0-9]+" $msg -1 }}` |
221225
| `regexReplaceAll pattern text repl` | 正则替换。参数顺序是 `pattern``text``replacement`| `{{ regexReplaceAll ".*id=([0-9]+).*" $msg "$1" }}` |

0 commit comments

Comments
 (0)