Skip to main content
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.
The base template variables, Sprig function names, and behavior where label enrichment runs before Description rendering require monit-edge v0.42.0 or later. Reading query-provided additional information from $annotations with $<query name>.<field name> keys requires monit-edge v0.53.0 or later. Upgrade the alert engine before using this capability.

How It Works

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.
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.

Sprig Function Names

monit-edge registers safe Sprig functions with their standard Sprig names. The same supported functions are also registered with a sprig_ prefix so templates can avoid naming conflicts when needed. Use:
The prefixed form is also valid:
If a standard Sprig name conflicts with a monit-edge custom function, the monit-edge custom function keeps the standard name and the Sprig function remains available through the sprig_ prefix.

Built-in Variables

Example:

Additional information from query results

When a primary query explicitly selects label fields, its other non-value fields become additional information in $annotations. Query-provided information always uses $<query name>.<field name> as its key:
The syntax is the same for one or multiple queries and for Threshold evaluation, Data exists, and No data modes. The $ prefix is reserved for query fields, so a custom field configured on the rule cannot begin with $. See Query Result Field Mapping for field classification.

Custom Fields

Custom fields configured on the rule are carried into the alert event’s $annotations. The field value itself also supports variables and template rendering:
  • Simple variables: ${label_name} forms (e.g., ${service}) are replaced with the corresponding label value of the alert event at render time. For example, a value of https://a.com/runbook/${service} has ${service} replaced with the alert event’s service label value.
  • Go template: When the value contains {{, the whole value is rendered with the same Go template rules as the Description, so you can use the built-in variables and functions documented on this page.
  • title field: A field named title uses its rendered value as the event title.
Examples:

Root Object Fields

Access root object fields with .FieldName. Query objects in .Queries have .Name, .Expr, .LabelFields, .ValueFields, and .Args. RelateQuery objects in .RelateQueries have .Name, .Expr, and .Args. Related query results are available through $relates. The map key is the related query name, such as R1. Example:

Go Template Built-in Functions

These functions are provided by Go text/template.

monit-edge Custom Functions

These functions are registered by monit-edge without a prefix.

Sprig Functions

monit-edge registers safe Sprig functions with standard Sprig names and also with a sprig_ prefix. Sprig functions come from Masterminds/sprig. Check that repository for upstream function behavior. Common examples:
Important regex note: regexFind and sprig_regexFind return the full matched substring. They do not return a capture group. To extract a capture group, use regexReplaceAll or sprig_regexReplaceAll:
The result is:

Common Sprig Functions

The same functions can also be called with sprig_ prefixes, such as sprig_contains and sprig_regexReplaceAll.

Disabled Sprig Functions

For predictable and safe alert rendering, monit-edge does not register Sprig functions that can read process environment variables, perform DNS lookup, generate random output, create credentials or certificates, encrypt or decrypt data, or intentionally fail rendering. The following Sprig functions are unavailable in both standard and sprig_ forms:
If a template uses one of these functions, parsing fails with an error like function "env" not defined or function "sprig_env" not defined.

Complete Example: Extract MySQL Unknown Column

Troubleshooting

function "contains" not defined means the rule is running on an older monit-edge build that has not enabled standard Sprig names. Upgrade monit-edge, or use sprig_contains as a compatibility workaround if that build supports the prefixed form. function "env" not defined or function "sprig_env" not defined means the template used a disabled Sprig function. Remove it or replace it with deterministic template logic. regexFind or sprig_regexFind returning Unknown column 'x' instead of x is expected. Use regexReplaceAll or sprig_regexReplaceAll to extract capture groups.