Skip to content

Configure Notification Templates

Template Syntax (Go Template) Description

The alert notification template uses Go Template syntax to render the template.

The template will be rendered based on the following data.

{
    "status": "firing",
    "labels": {
        "alertgroup": "test-group",           // Alert policy name
        "alertname": "test-rule",          // Alert rule name
        "cluster": "35b54a48-b66c-467b-a8dc-503c40826330",
        "customlabel1": "v1",
        "customlabel2": "v2",
        "endpoint": "https",
        "group_id": "01gypg06fcdf7rmqc4ksv97646",
        "instance": "10.6.152.85:6443",
        "job": "apiserver",
        "namespace": "default",
        "prometheus": "insight-system/insight-agent-kube-prometh-prometheus",
        "prometheus_replica": "prometheus-insight-agent-kube-prometh-prometheus-0",
        "rule_id": "01gypg06fcyn2g9zyehbrvcdfn",
        "service": "kubernetes",
        "severity": "critical",
        "target": "35b54a48-b66c-467b-a8dc-503c40826330",
        "target_type": "cluster"
   },
    "annotations": {
        "customanno1": "v1",
        "customanno2": "v2",
        "description": "This is a test rule, 10.6.152.85:6443 down",
        "value": "1"
    },
    "startsAt": "2023-04-20T07:53:54.637363473Z",
    "endsAt": "0001-01-01T00:00:00Z",
    "generatorURL": "http://vmalert-insight-victoria-metrics-k8s-stack-df987997b-npsl9:8080/vmalert/alert?group_id=16797738747470868115&alert_id=10071735367745833597",
    "fingerprint": "25c8d93d5bf58ac4"
}

Instructions for Use

  1. . character

    Render the specified object in the current scope.

    Example 1: Take all content under the top-level scope, which is all of the context data in the example code.

    {{ . }}
    
  2. Conditional statement if / else

    Use if to check the data and run else if it does not meet.

    {{if .Labels.namespace }}Namespace: {{ .Labels.namespace }} \n{{ end }}
    
  3. Loop feature for

    The for feature is used to repeat the code content.

    Example 1: Traverse the labels list to obtain all label content for alerts.

    {{ for .Labels}} \n {{end}}
    

Threshold Template Description

The built-in webhook alert template in Insight is as follows. Other contents such as email and WeCom are the same, only corresponding adjustments are made for line breaks.

Rule Name: {{ .Labels.alertname }} \n
Policy Name: {{ .Labels.alertgroup }} \n
Alert level: {{ .Labels.severity }} \n
Cluster: {{ .Labels.cluster }} \n
{{if .Labels.namespace }}Namespace: {{ .Labels.namespace }} \n{{ end }}
{{if .Labels.node }}Node: {{ .Labels.node }} \n{{ end }}
Resource Type: {{ .Labels.target_type }} \n
{{if .Labels.target }}Resource Name: {{ .Labels.target }} \n{{ end }}
Trigger Value: {{ .Annotations.value }} \n
Occurred Time: {{ .StartsAt }} \n
{{if ne "0001-01-01T00:00:00Z" .EndsAt }}End Time: {{ .EndsAt }} \n{{ end }}
Description: {{ .Annotations.description }} \n

Email Subject Parameters

Because Insight combines messages generated by the same rule at the same time when sending alert messages, email subjects are different from the four templates above and only use the content of commonLabels in the alert message to render the template. The default template is as follows:

[{{ .status }}] [{{ .severity }}] Alert: {{ .alertname }}

Other fields that can be used as email subjects are as follows:

{{ .status }} Triggering status of the alert message
{{ .alertgroup }} Name of the policy to which the alert belongs
{{ .alertname }} Name of the rule to which the alert belongs
{{ .severity }} Severity level of the alert
{{ .target_type }} Type of resource for which the alert is raised
{{ .target }} Resource object for which the alert is raised
{{ .Custom label key for other rules }}

Comments