You need to enable JavaScript to run this app.
Observability Platform

Observability Platform

Copy page
Download PDF
Notification templates
Extension functions and variables​ for cloud service events
Copy page
Download PDF
Extension functions and variables​ for cloud service events
You can use preset alert variables in notification templates. This topic describes the structure and parameters of preset alert variables for cloud service events.​
Extension functions​
Notification templates support Go Template built-in functions and extension functions. The following table provides the details.​
​
Function​
Description​
Go Template built-in functions​
Notification templates support Go Template built-in functions. For details, see the official documentation.​
translate​
​
Translate the variable value into natural language.​
translate(type string, lang string, val string) string​
  • type: Variable name​
  • Alert templates: Support the Region, Type, Level, and Namespace variables.​
  • Event templates: Support the Region, Type, Level, Source, and Event variables.​
  • Lang: The target language of conversion. Supported languages include zh (Chinese) and en (English).​
  • val: Variable value.​
Integer calculation functions​
  • Sum: add(i ...interface{}) int64​
  • Subtraction: sub(a, b interface{}) int64​
  • Maximum: max(a interface{}, i ...interface{}) int64​
  • Minimum: min(a interface{}, i ...interface{}) int64​
Collection operation functions​
Slicing​
  • slice(list interface{}, indices ...int) interface{}​
map​
  • get(m map[string]interface{}, key string) interface{}​
String functions​
  • Truncate a string: trunc(c int, s string) string​
  • Get a substr: substr(start int, end int, s string) string​
  • Trim whitespaces: trim(s string) string​
  • Check whether a substr is present: contains(substr string, str string) bool​
  • Check whether a prefix is present: hasPrefix(substr string, str string) bool​
  • Check whether a suffix is present: hasSuffix(substr string, str string) bool​
  • Escape a string: quote(str ...interface{}) string​
  • Join strings: join(sep string, v interface{}) string​
  • Replace characters: replace(old string, new string, src string) string​
  • Format as a string: toString(v interface{}) string​
Time functions​
  • If the variable is of type time.Time, you can use the time function .Format to define the time format. For example, {{ .HappenedAt.Format "2006-01-02 15:04:05(UTCZ07:00)" }}.​
JSON operations​
  • JSON: toJson(v interface{}) string​
  • PrettyJSON: toPrettyJson(v interface{}) string​
​
Data structure​
This topic uses the following JSON example to demonstrate the variables, parameters, and data structures supported by cloud service event templates. This helps you understand common Go template syntax and its usage.​
Variable description​
Description​
  • You can use the standard Go Template approach to get values of non-nested variables. For example, you can use {{ .Region }}.​
  • For nested variables, you need to use custom variables to obtain all resources. For example, you define the $rule variable and use iteration to get all resources: {{ range $idx, $rule := .Rules }}. For internal variables, you need to use $rule.fieldName (for example, {{ $rule.RuleId }}) to get variable values.​
The following table provides the parameters and descriptions of preset variables that can be used in a notification template.​
​
Variable name​
Type​
Description​
Sample value​
Example​
Type​
String​
Alert type. The value is Event.​
Event​
  • Render it directly: {{ .Type }}​
  • Use the extension function to translate it into natural language: {{ translate "Type" "zh" .Type }}. For example, render Event as event.​
SiteName​
String​
Site name.​
Cloud Monitor​
{{ .SiteName }}​
AccountName​
String​
Account name.​
user-demo​
{{ .AccountName }}​
AccountId​
String​
Account ID.​
21000*****​
{{ .AccountId }}​
Source​
String​
Event source.​
ecs​
  • Render it directly: {{ .Source }}​
  • Use the extension function to translate it into natural language: {{ translate "Source" "zh" .Source }}. For example, render ecs as Elastic Compute Service.​
Level​
String​
Event level. Possible values:​
  • critical​
  • warning​
  • notice​
tip​
If multiple rules are matched, the highest level is applied.​
critical​
  • Render it directly: {{ .Level }}​
  • Use the extension function to translate into natural language: {{ translate "Level" "zh" .Level }}. For example, render critical as Serious.​
Id​
String​
Event ID.​
1803******​
{{ .Id }}​
Event​
String​
Event type.​
ecs:Instance:RebootInstance.Executing​
  • Render it directly: {{ .Event }}​
  • Translate into natural language: {{ translate "Event" "zh" .Event }}. For example, render ecs:Instance:RebootInstance.Executing as Instance restart: Executing.​
HappenedAt​
time.Time​
The time when the event occurs.​
2025-01-01 00:00:00(UTC+08:00)​
Format the time: {{ .HappenedAt.Format "2006-01-02 15:04:05(UTCZ07:00)" }}​
Region​
String​
Region of the cloud product resource.​
cn-beijing​
  • Render it directly: {{ .Region }}​
  • Use the extension function to translate into natural language: {{ translate "Region" "zh" .Region }}. For example, render cn-beijing as China (Beijing).​
ResourceId​
String​
Cloud product resource ID.​
i-yd9j*****​
{{ .ResourceId }}​
ResourceName​
String​
Cloud product resource name.​
ecs-demo​
{{ .ResourceName }}​
ProjectName​
String​
Name of the project to which the cloud product resource belongs.​
default​
{{ .Project }}​
TagSet​
Array of Tag​
Cloud product resource tags. Each tag consists of a Key and Value.​
-​
Iterate through tags:​
​
{{ range $idx, $tag := .Tags }}​
{{ $tag.Key }}: {{ $tag.Value }}​
{{ end }}​
​
Details​
map[string]interface{}​
Event details.​
tip​
Event formats vary across different cloud products.​
-​
Iterate through details:​
​
{{ range $key, $val := .Details }}​
{{ $key }}: {{ $val }}​
{{ end }}​
​
Rules​
Array of EventRule​
A list of matched event rules.​
-​
Iterate through rules:​
​
{{ range $idx, $rule := .Rules }}​
{{ $rule.RuleName }} ({{ $rule.Level }})​
{{ end }}​
​
HistoryURL​
String​
URL to the Event Center.​
https://console.volcengine.com/observe/cloud-monitor/alert/history​
{{ .HistoryURL }}​
​
EventRule​
​
Variable name​
Type​
Description​
Sample value​
Example​
RuleId​
String​
Event rule ID.​
19251****​
{{ $rule.RuleId }}​
RuleName​
String​
Event rule name.​
event-demo​
{{ $rule.RuleName }}​
Level​
String​
Event rule level. Possible values:​
  • critical​
  • warning​
  • notice​
critical​
  • Render it directly: {{ $rule.Level }}​
  • Use the extension function to translate into natural language: {{ translate "Level" "zh" $rule.Level }}. For example, render critical as Serious.​
RuleURL​
String​
URL to the event rule.​
https://console.volcengine.com/observe/cloud-monitor/event/rules/detail?id=1790****​
{{ $rule.RuleURL }}​
​
Configuration example​
In addition to the preset event templates, you can specify custom content of a notification template based on the data structures of alert variables, Go Template syntax, and Markdown syntax. This section provides a configuration example.​
​
**Event Information**:​
​
---​
​
Alert Type: {{ .Type }}​
Account Name: {{ .AccountName }}​
Account ID: {{ .AccountId }}​
Event Source: {{ .Source }}​
Event Level: {{ .Level }}​
Event ID: {{ .Id }}​
Event Type: {{ .Event }}​
Event Occurrence Time: {{ .HappenedAt }}​
Cloud Product Region: {{ .Region }}​
Cloud Product Resource ID: {{ .ResourceId }}​
Cloud Product Resource Name: {{ .ResourceName }}​
Event Center Link: {{ .HistoryURL }}​
​
---​
​
**Details of Resources Triggering the Event**:​
{{- range $key, $val := .Details }}​
{{ $key }}: {{ $val }}​
{{- end }}​
​
​
Last updated: 2026.09.07 19:40:07