skirl

Template functions

Every function a template can use, with one example each. This page is made from Skirl's own code, so it lists exactly what this version has. How templates work, built up from a real message: Templates.

Each example is run against this message, and the arrow shows what it gives:

{
  "title": "Disk almost full",
  "status": "firing",
  "host": {"name": "pve-01", "disk": {"used": 0.93, "free_gb": 41}},
  "tags": ["storage", "pve"],
  "count": 3,
  "started": "2026-11-26T03:12:00Z",
  "url": "https://grafana.example.com/d/disks"
}

Text#

cat#

Joins values into one text with a space between each, leaving out missing ones.

{{ cat .host.name "has" .host.disk.free_gb "GB free" }} → pve-01 has 41 GB free

contains#

Tells whether text contains a piece (true or false); the piece comes first and the text last.

{{ if contains "full" .title }}Clean up {{ .host.name }}{{ end }} → Clean up pve-01

hasPrefix#

Tells whether text starts with a piece (true or false); the piece comes first and the text last.

{{ hasPrefix "https://" .url }} → true

hasSuffix#

Tells whether text ends with a piece (true or false); the piece comes first and the text last.

{{ hasSuffix "/disks" .url }} → true

indent#

Puts a number of spaces (at most 100) in front of every line of text; the number comes first and the text last.

Tags:\n{{ indent 2 (join "\n" .tags) }} → Tags:⏎ storage⏎ pve

lower#

Turns text into small letters.

{{ lower .title }} → disk almost full

nindent#

The same as indent, but starts with a line break, so the indented text begins on a line of its own.

Tags:{{ nindent 2 (join "\n" .tags) }} → Tags:⏎ storage⏎ pve

plural#

Gives the first word when the count is exactly 1 and the second otherwise; the count comes last and must be a whole number, such as len gives.

{{ len .tags }} {{ plural "tag" "tags" (len .tags) }} → 2 tags

quote#

Puts each value in double quotes, with any quote or backslash inside escaped, and joins them with spaces; a missing value is left out.

{{ quote .host.name .status }} → "pve-01" "firing"

repeat#

Repeats text a number of times, with the count first: at most 10,000 times and under 100,000 bytes in all, or the template stops with an error.

{{ repeat 3 "🔥" }} {{ .title }} → 🔥🔥🔥 Disk almost full

replace#

Replaces every copy of one piece of text with another; the order is old, new, then the text, as in replace "old" "new" .text.

{{ replace "almost" "nearly" .title }} → Disk nearly full

split#

Splits text at each separator into a dictionary whose keys are _0, _1, _2 and so on; the separator comes first and the text last.

{{ (split "." "pve-01.example.com")._0 }} → pve-01

splitList#

Splits text at each separator into a list; the separator comes first and the text last.

{{ splitList "," "storage,pve,backup" }} → [storage pve backup]

splitn#

Splits text at the separator into at most N parts, in a dictionary keyed _0, _1 and so on, the last part keeping the rest; the order is separator, N, then the text.

{{ (splitn ":" 2 "error: disk: full")._1 }} → disk: full

squote#

Puts each value in single quotes, without escaping anything inside, and joins them with spaces; a missing value is left out.

{{ squote .host.name }} → 'pve-01'

substr#

Takes the part of text from one position up to (not including) another, counting from 0 in bytes, with the text last; a negative start means from the beginning, a negative end or one past the end means to the end, and a start past the end stops the template with an error.

{{ substr 5 11 .title }} → almost

title#

Starts each word with a capital and puts the rest of the word in small letters.

{{ title "DISK almost full" }} → Disk Almost Full

trim#

Removes spaces, tabs and line breaks from both ends of text.

[{{ trim " pve-01 " }}] → [pve-01]

trimAll#

Removes any of the given characters from both ends of text; the characters come first and the text last.

{{ trimAll "#*" "##pve-01**" }} → pve-01

trimPrefix#

Removes a piece from the start of text, if the text starts with it; the piece comes first and the text last, as in trimPrefix "v" .version.

{{ trimPrefix "https://" .url }} → grafana.example.com/d/disks

trimSuffix#

Removes a piece from the end of text, if the text ends with it; the piece comes first and the text last.

{{ trimSuffix ".example.com" "pve-01.example.com" }} → pve-01

trunc#

Keeps the first N characters of text, or the last N when N is negative; it counts bytes, so an accented letter or an emoji counts as more than one, and it can cut one in half. In a saved template, shorten cuts by characters and marks the cut.

{{ trunc 4 .title }} → Disk

upper#

Turns text into capitals.

{{ upper .status }} → FIRING

Numbers#

add#

Adds numbers together in whole numbers: anything after the decimal point is dropped first, so add 1.5 1.5 is 2.

{{ add .count 2 }} → 5

add1#

Adds 1 to a whole number (anything after the decimal point is dropped first).

{{ add1 .count }} → 4

atoi#

Turns text into a whole number; text that is not a whole number gives 0.

{{ atoi "0042" }} → 42

biggest#

Another name for max: the largest of the numbers, in whole numbers.

{{ biggest 3 12 7 }} → 12

ceil#

Rounds a number up to the next whole number.

{{ ceil 4.1 }} → 5

div#

Divides the first number by the second in whole numbers, dropping the remainder; dividing by 0 stops the template with an error.

{{ div .host.disk.free_gb 2 }} → 20

floor#

Rounds a number down to the whole number below it.

{{ floor 4.9 }} → 4

max#

Gives the largest of the numbers, in whole numbers (anything after the decimal point is dropped).

{{ max .count 5 1 }} → 5

maxf#

Gives the largest of the numbers, keeping decimals.

{{ maxf .host.disk.used 0.9 }} → 0.93

min#

Gives the smallest of the numbers, in whole numbers (anything after the decimal point is dropped).

{{ min .count 10 }} → 3

minf#

Gives the smallest of the numbers, keeping decimals.

{{ minf .host.disk.used 0.95 }} → 0.93

mod#

The remainder after dividing the first whole number by the second; dividing by 0 stops the template with an error.

{{ mod 17 5 }} → 2

mul#

Multiplies numbers together in whole numbers: anything after the decimal point is dropped first, so 0.93 counts as 0.

{{ mul .host.disk.free_gb 1024 }} MB free → 41984 MB free

randInt#

Picks a random whole number from the first number up to but not including the second; the second must be larger, or the template stops with an error.

{{ randInt 1 100 }}

round#

Rounds a number to the given number of decimal places; a third number sets where rounding up starts (0.5 unless given).

{{ round 3.14159 2 }} → 3.14

sub#

Subtracts the second number from the first, in whole numbers.

{{ sub .count 1 }} more like this → 2 more like this

toDecimal#

Reads a number written in octal (base 8), such as a file permission, and gives it as an ordinary number; 0 if it is not octal.

{{ toDecimal "0755" }} → 493

Lists#

append#

Gives a copy of a list with a value added at the end; the list comes first.

{{ append .tags "urgent" }} → [storage pve urgent]

chunk#

Splits a list into lists of N items, the last one shorter if need be; N comes first.

{{ chunk 2 (list "sda" "sdb" "sdc") }} → [[sda sdb] [sdc]]

compact#

Gives a list without its empty items: empty text, 0, false and missing values.

{{ compact (list .host.name "" .assignee .status) }} → [pve-01 firing]

concat#

Joins several lists into one, of at most 10,000 items.

{{ concat .tags (list "disk" "alert") }} → [storage pve disk alert]

first#

Gives the first item of a list, or nothing for an empty list; something that is not a list stops the template with an error.

{{ first .tags }} → storage

has#

Tells whether a list holds a value (true or false); the value comes first and the list last.

{{ if has "storage" .tags }}For the storage team{{ end }} → For the storage team

index#

Reads one item of a list by its position, counting from 0, or one entry of a dictionary by its key, which also reads keys with dashes or dots in them.

{{ index .tags 0 }} on {{ index .host "name" }} → storage on pve-01

initial#

Gives a list of every item but the last.

{{ initial (list "sda" "sdb" "sdc") }} → [sda sdb]

join#

Joins the items of a list into one text with a separator between them; the separator comes first.

{{ join ", " .tags }} → storage, pve

last#

Gives the last item of a list, or nothing for an empty list; something that is not a list stops the template with an error.

{{ last .tags }} → pve

len#

Counts the items in a list or a dictionary, or the bytes in text.

{{ len .tags }} tags → 2 tags

list#

Makes a list of the values given.

{{ list .host.name .status "disk" }} → [pve-01 firing disk]

mustAppend#

The same as append; both stop the template with an error when the first value is not a list.

{{ mustAppend .tags .host.name }} → [storage pve pve-01]

mustChunk#

The same as chunk; both stop the template with an error when given something that is not a list.

{{ mustChunk 1 .tags }} → [[storage] [pve]]

mustCompact#

The same as compact; both stop the template with an error when given something that is not a list.

{{ mustCompact (list "sda" "" "sdb") }} → [sda sdb]

mustFirst#

The same as first; both stop the template with an error when given something that is not a list.

{{ mustFirst .tags }} → storage

mustHas#

The same as has; both stop the template with an error when the last value is not a list.

{{ mustHas "pve" .tags }} → true

mustInitial#

The same as initial; both stop the template with an error when given something that is not a list.

{{ mustInitial .tags }} → [storage]

mustLast#

The same as last; both stop the template with an error when given something that is not a list.

{{ mustLast (list "sda" "sdb" "sdc") }} → sdc

mustPrepend#

The same as prepend; both stop the template with an error when the first value is not a list.

{{ mustPrepend .tags .host.name }} → [pve-01 storage pve]

mustPush#

The same as push; both stop the template with an error when the first value is not a list.

{{ mustPush .tags .status }} → [storage pve firing]

mustRest#

The same as rest; both stop the template with an error when given something that is not a list.

{{ mustRest .tags }} → [pve]

mustReverse#

The same as reverse; both stop the template with an error when given something that is not a list.

{{ mustReverse (list 1 2 3) }} → [3 2 1]

mustSlice#

The same as slice; both stop the template with an error when given something that is not a list.

{{ mustSlice .tags 1 }} → [pve]

mustUniq#

The same as uniq; both stop the template with an error when given something that is not a list, or more than 10,000 items.

{{ mustUniq (list "sda" "sda" "sdb") }} → [sda sdb]

mustWithout#

The same as without; both stop the template with an error when the first value is not a list.

{{ mustWithout (list "sda" "sdb" "sdc") "sdb" }} → [sda sdc]

prepend#

Gives a copy of a list with a value added at the front; the list comes first.

{{ prepend .tags "alert" }} → [alert storage pve]

push#

Another name for append: a copy of a list with a value added at the end.

{{ push .tags "disk" | join "," }} → storage,pve,disk

rest#

Gives a list of every item but the first.

{{ rest (list "sda" "sdb" "sdc") }} → [sdb sdc]

reverse#

Gives a copy of a list in reverse order.

{{ reverse .tags }} → [pve storage]

seq#

Counts as the Unix seq command does, as text with spaces: seq 5 is 1 to 5, seq 2 5 is 2 to 5, and seq 0 5 20 is 0 to 20 in steps of 5; at most 10,000 numbers.

{{ seq 0 5 20 }} → 0 5 10 15 20

slice#

Takes part of a list: slice L 1 3 gives the items at positions 1 and 2, counting from 0; unlike Go's own slice it does not take text, and a position the list does not have stops the template with an error.

{{ slice (list "sda" "sdb" "sdc" "sdd") 1 3 }} → [sdb sdc]

sortAlpha#

Sorts a list as text, in character order, so capitals come before small letters and 10 before 9.

{{ sortAlpha .tags }} → [pve storage]

tuple#

Another name for list: makes a list of the values given.

{{ tuple .host.name .count }} → [pve-01 3]

uniq#

Gives a list without repeats, keeping the first of each in order; at most 10,000 items.

{{ uniq (list "pve" "storage" "pve") }} → [pve storage]

until#

Makes the list of whole numbers from 0 up to but not including N (counting down when N is negative); at most 10,000 numbers.

{{ until 5 }} → [0 1 2 3 4]

untilStep#

Makes the list of whole numbers from a start up to but not including a stop, in steps of the third number; at most 10,000 steps.

{{ untilStep 0 20 5 }} → [0 5 10 15]

without#

Gives a list without the given values; the list comes first, then the values to leave out.

{{ without .tags "pve" }} → [storage]

Dictionaries#

dict#

Makes a dictionary from pairs of keys and values; a key without a value gets empty text.

{{ dict "host" .host.name "status" .status | toJSON }} → {"host":"pve-01","status":"firing"}

dig#

Reads a value several levels deep: the keys in order, then a default for when one is missing, then the dictionary (. for the whole message); a value on the way that is not a dictionary stops the template with an error.

{{ dig "host" "disk" "free_gb" "unknown" . }} GB free → 41 GB free

get#

Reads one entry of a dictionary by its key, or empty text if there is none; the dictionary comes first.

{{ get .host "name" }} → pve-01

hasKey#

Tells whether a dictionary has a key (true or false); the dictionary comes first.

{{ if hasKey .host "disk" }}Disk report for {{ .host.name }}{{ end }} → Disk report for pve-01

keys#

Gives a list of the keys of one or more dictionaries, in no fixed order (sortAlpha puts them in order); at most 10,000.

{{ keys .host.disk | sortAlpha }} → [free_gb used]

omit#

Gives a new dictionary with all but the given keys of a dictionary; the dictionary comes first.

{{ omit .host "disk" | toJSON }} → {"name":"pve-01"}

pick#

Gives a new dictionary with only the given keys of a dictionary; the dictionary comes first.

{{ pick .host.disk "used" | toJSON }} → {"used":0.93}

pluck#

Gives a list of one key's value in each of several dictionaries, leaving out those without it; the key comes first.

{{ pluck "name" .host (dict "name" "pve-02") (dict "id" 3) }} → [pve-01 pve-02]

set#

Puts a value into a dictionary under a key, changing that dictionary, and gives it back; the order is dictionary, key, value.

{{ set (dict "host" .host.name) "status" "ok" | toJSON }} → {"host":"pve-01","status":"ok"}

unset#

Removes a key from a dictionary, changing that dictionary, and gives it back.

{{ unset (dict "host" .host.name "token" "s3cret") "token" | toJSON }} → {"host":"pve-01"}

values#

Gives a list of the values of a dictionary, in no fixed order.

{{ values .host.disk | sortAlpha }} → [0.93 41]

Dates and times#

ago#

How long ago a time was, to the second, as in 2h5m10s; anything that is not a time counts as now.

{{ ago (toDate "2006-01-02T15:04:05Z07:00" .started) }}

date#

Writes a time in a layout spelled with Go's reference time, Mon Jan 2 15:04:05 2006, in the server's time zone; the layout comes first, and anything that is not a time (a number from the message included) counts as now.

{{ toDate "02/01/2006 15:04" "26/11/2026 03:12" | date "Mon 2 Jan 2006, 15:04" }} → Thu 26 Nov 2026, 03:12

dateInZone#

The same as date, in a named time zone such as Europe/Berlin given last; an unknown zone counts as UTC.

{{ dateInZone "Mon 2 Jan 15:04 MST" (toDate "2006-01-02T15:04:05Z07:00" .started) "Africa/Johannesburg" }} → Thu 26 Nov 05:12 SAST

dateModify#

Moves a time by a length of time such as 2h, -30m or 1h30m; the length comes first, and one that cannot be read leaves the time as it was.

{{ .started | toDate "2006-01-02T15:04:05Z07:00" | dateModify "2h" }} → 2026-11-26 05:12:00 +0000 UTC

duration#

Writes a number of seconds as a length of time such as 1h30m0s; the seconds must be text, since a plain number (one from the message included) counts as 0, so pass a number through toString first.

{{ duration "5400" }} → 1h30m0s

durationRound#

Shortens a length of time such as 2h30m to its largest whole unit (y, mo, d, h, m or s); given a time, it does this to how long ago the time was.

{{ durationRound "2h30m" }} → 2h

htmlDate#

Writes a time as a date in the form 2026-11-26, in the server's time zone; anything that is not a time counts as now.

{{ toDate "02/01/2006" "26/11/2026" | htmlDate }} → 2026-11-26

htmlDateInZone#

The same as htmlDate, in a named time zone given after the time; an unknown zone counts as UTC.

{{ htmlDateInZone (toDate "2006-01-02T15:04:05Z07:00" .started) "America/New_York" }} → 2026-11-25

mustDateModify#

The same as dateModify, but a length of time that cannot be read stops the template with an error.

{{ .started | toDate "2006-01-02T15:04:05Z07:00" | mustDateModify "-30m" }} → 2026-11-26 02:42:00 +0000 UTC

mustToDate#

The same as toDate, but text that does not fit the layout stops the template with an error instead of giving the zero time.

{{ mustToDate "2006-01-02" "2026-11-26" | htmlDate }} → 2026-11-26

now#

The current date and time on the server.

{{ now | date "2006-01-02 15:04" }}

toDate#

Reads text as a time, using a layout spelled with Go's reference time (2006-01-02T15:04:05Z07:00 reads times like .started); the layout comes first, text without its own zone is read in the server's, and text that does not fit gives the zero time, 1 January of year 1.

{{ toDate "2006-01-02T15:04:05Z07:00" .started }} → 2026-11-26 03:12:00 +0000 UTC

unixEpoch#

Turns a time into Unix time: the number of seconds since 1 January 1970, UTC.

{{ toDate "2006-01-02T15:04:05Z07:00" .started | unixEpoch }} → 1795662720

Defaults and conditions#

all#

Tells whether none of its values is empty (true or false).

{{ if all .host.name .url }}Open {{ .url }}{{ end }} → Open https://grafana.example.com/d/disks

any#

Tells whether at least one of its values is not empty (true or false).

{{ any .assignee .host.name }} → true

coalesce#

Gives the first of its values that is not empty, or nothing.

{{ coalesce .assignee .host.name "unknown" }} → pve-01

default#

Gives a value, or the default when the value is missing or empty (empty text, 0, false, an empty list); the default comes first, as in default "none" .x.

{{ .assignee | default "nobody" }} → nobody

empty#

Tells whether a value is missing or empty: nothing, empty text, 0, false, or an empty list or dictionary.

{{ if empty .assignee }}Nobody is on it{{ end }} → Nobody is on it

ternary#

Gives the first value when the condition, which comes last, is true, and the second when it is false.

{{ ternary "🔥" "✅" (eq .status "firing") }} {{ .title }} → 🔥 Disk almost full

Comparisons and logic#

and#

True when all its values are true (not empty): it gives the first empty one, or the last one if none is.

{{ if and (eq .status "firing") (gt .host.disk.used 0.9) }}Act now{{ end }} → Act now

deepEqual#

Tells whether two values are the same all the way through, lists and dictionaries included, and of the same type, so 3 and 3.0 differ.

{{ deepEqual .tags (list "storage" "pve") }} → true

eq#

Tells whether the first value equals the second (or any of the ones after it); numbers in a message are decimals, so compare them with numbers written with a point, like 3.0.

{{ if eq .status "firing" "pending" }}Still a problem{{ end }} → Still a problem

ge#

Tells whether the first value is greater than or equal to the second; as with lt, compare a number from the message with one written with a point.

{{ if ge .count 3.0 }}Seen {{ .count }} times{{ end }} → Seen 3 times

gt#

Tells whether the first value is greater than the second; as with lt, compare a number from the message with one written with a point.

{{ if gt .host.disk.used 0.9 }}Over 90% full{{ end }} → Over 90% full

le#

Tells whether the first value is less than or equal to the second; as with lt, compare a number from the message with one written with a point.

{{ le .count 3.0 }} → true

lt#

Tells whether the first value is less than the second; a number from the message must be compared with one written with a point, like 50.0, or the template stops with an error.

{{ if lt .host.disk.free_gb 50.0 }}Low on space{{ end }} → Low on space

ne#

Tells whether two values differ.

{{ if ne .status "resolved" }}Still open{{ end }} → Still open

not#

Turns true into false and false into true; a missing or empty value counts as false.

{{ if not .assignee }}Unassigned{{ end }} → Unassigned

or#

True when any of its values is true (not empty): it gives the first one that is not empty, or the last one, so it also picks a fallback.

{{ or .assignee "on-call" }} → on-call

Regular expressions#

mustRegexFind#

The same as regexFind; both stop the template with an error when the pattern is not valid.

{{ mustRegexFind "pve-[0-9]+" "alert from pve-01 at 03:12" }} → pve-01

mustRegexFindAll#

The same as regexFindAll; both stop the template with an error when the pattern is not valid.

{{ mustRegexFindAll "[0-9]+" "sda1 sdb2 sdc3" -1 }} → [1 2 3]

mustRegexMatch#

The same as regexMatch, but a pattern that is not valid stops the template with an error instead of giving false.

{{ if mustRegexMatch "(?i)disk" .title }}storage{{ end }} → storage

mustRegexReplaceAll#

The same as regexReplaceAll; both stop the template with an error when the pattern is not valid.

{{ mustRegexReplaceAll " +" "too many spaces" " " }} → too many spaces

mustRegexReplaceAllLiteral#

The same as regexReplaceAllLiteral; both stop the template with an error when the pattern is not valid.

{{ mustRegexReplaceAllLiteral "\\.example\\.com$" "pve-01.example.com" "" }} → pve-01

mustRegexSplit#

The same as regexSplit; both stop the template with an error when the pattern is not valid.

{{ mustRegexSplit " +" "sda sdb sdc" -1 }} → [sda sdb sdc]

regexFind#

Gives the first part of text that matches a pattern, or nothing; the pattern comes first, and a pattern that is not valid stops the template with an error.

{{ regexFind "[0-9]+%" "disk at 93% on pve-01" }} → 93%

regexFindAll#

Gives a list of the parts of text that match a pattern, at most N of them (-1 for all); the order is pattern, text, N, and a pattern that is not valid stops the template with an error.

{{ regexFindAll "sd[a-z][0-9]" "errors on sda1, sdb2 and sdc3" 2 }} → [sda1 sdb2]

regexMatch#

Tells whether text matches a pattern (true or false); the pattern comes first, and a pattern that is not valid gives false.

{{ regexMatch "^pve-[0-9]+$" .host.name }} → true

regexQuoteMeta#

Escapes the characters that have a meaning in a pattern, so that the text is matched exactly as written.

{{ regexQuoteMeta "pve-01.example.com" }} → pve-01\.example\.com

regexReplaceAll#

Replaces every match of a pattern; the order is pattern, text, replacement (the text is in the middle), and in the replacement $1 or ${name} stands for a bracketed part of the match.

{{ regexReplaceAll "pve-([0-9]+)" .host.name "node $1" }} → node 01

regexReplaceAllLiteral#

The same as regexReplaceAll, but the replacement is used exactly as written, so $1 stays $1.

{{ regexReplaceAllLiteral "pve-([0-9]+)" .host.name "$1" }} → $1

regexSplit#

Splits text wherever a pattern matches, into a list of at most N parts (-1 for all); the order is pattern, text, N.

{{ regexSplit "[,;] *" "storage, pve;backup" -1 }} → [storage pve backup]

JSON and encoding#

adler32sum#

Gives the Adler-32 checksum of text, as a number.

{{ adler32sum .host.name }} → 127926746

b32dec#

Decodes Base32 text; text that is not valid Base32 gives the error message in its place.

{{ b32dec "OB3GKLJQGE======" }} → pve-01

b32enc#

Encodes text as Base32.

{{ b32enc .host.name }} → OB3GKLJQGE======

b64dec#

Decodes Base64 text; text that is not valid Base64 gives the error message in its place.

{{ b64dec "RGlzayBhbG1vc3QgZnVsbA==" }} → Disk almost full

b64enc#

Encodes text as Base64.

{{ b64enc .title }} → RGlzayBhbG1vc3QgZnVsbA==

fromJSON#

Reads text written as JSON into values a template can use; nothing if the text is not JSON.

{{ (fromJSON "{\"id\": 42, \"ok\": true}").id }} → 42

mustFromJSON#

The same as fromJSON, but text that is not JSON stops the template with an error instead of giving nothing.

{{ index (mustFromJSON "[\"sda\", \"sdb\"]") 1 }} → sdb

mustToJSON#

The same as toJSON, but a value that cannot be written stops the template with an error instead of giving empty text.

{{ mustToJSON .tags }} → ["storage","pve"]

mustToPrettyJSON#

The same as toPrettyJSON, but a value that cannot be written stops the template with an error instead of giving empty text.

{{ mustToPrettyJSON .tags }} → [⏎ "storage",⏎ "pve"⏎]

mustToRawJSON#

The same as toRawJSON; both stop the template with an error when the value cannot be written.

{{ mustToRawJSON (dict "link" "https://example.com/?a=1&b=2") }} → {"link":"https://example.com/?a=1&b=2"}

sha1sum#

Gives the SHA-1 checksum of text, as 40 hexadecimal characters.

{{ sha1sum .host.name }} → 93223109c7ceaa47a12b14f0ce82cff36d42713d

sha256sum#

Gives the SHA-256 checksum of text, as 64 hexadecimal characters.

{{ sha256sum .host.name }} → 64fd741f6ea2832d67012d15c5ece29eb724b2de34dffde0b8598390736101eb

sha512sum#

Gives the SHA-512 checksum of text, as 128 hexadecimal characters.

{{ sha512sum .host.name | trunc 16 }} → 4daafc032b2c8cf6

toJSON#

Writes a value as compact JSON; empty text if it cannot be written.

{{ toJSON .host }} → {"disk":{"free_gb":41,"used":0.93},"name":"pve-01"}

toPrettyJSON#

Writes a value as JSON spread over lines and indented by two spaces; empty text if it cannot be written.

{{ toPrettyJSON .host.disk }} → {⏎ "free_gb": 41,⏎ "used": 0.93⏎}

toRawJSON#

The same as toJSON, but leaves <, > and & as they are instead of escaping them; a value that cannot be written stops the template with an error.

{{ toRawJSON (dict "check" "free_gb < 50 & used > 0.9") }} → {"check":"free_gb < 50 & used > 0.9"}

Types#

kindIs#

Tells whether a value is of the named kind, as kindOf names it; the kind comes first.

{{ if kindIs "map" .host }}{{ .host.name }}{{ end }} → pve-01

kindOf#

Gives the kind of a value: string, float64, bool, slice for a list, map for a dictionary, or invalid for nothing.

{{ kindOf .tags }} → slice

toString#

Turns any value into text, so that a number can go to a function that takes text.

{{ hasPrefix "0.9" (toString .host.disk.used) }} → true

toStrings#

Turns a list into a list of text, leaving out missing items; a single value becomes a list of one.

{{ toStrings (list .host.name .count .host.disk.used) }} → [pve-01 3 0.93]

typeIs#

Tells whether a value is of the named type, as typeOf names it; the type comes first.

{{ typeIs "string" .host.name }} → true

typeIsLike#

The same as typeIs, but also true for a pointer to that type; for the values in a message it is the same as typeIs.

{{ typeIsLike "float64" .host.disk.used }} → true

typeOf#

Gives the type of a value: string for text, float64 for every number in a message, bool, []interface {} for a list, map[string]interface {} for a dictionary.

{{ typeOf .count }} → float64

Paths#

base#

The last part of a path or web address, after the final slash.

{{ base .url }} → disks

clean#

Tidies a path: removes doubled slashes and works out . and .. parts.

{{ clean "/var//log/../lib/./docker" }} → /var/lib/docker

dir#

Everything in a path but its last part.

{{ dir "/var/log/syslog" }} → /var/log

ext#

The extension of a file name, from its last dot.

{{ ext "backup-2026-11-26.tar.gz" }} → .gz

isAbs#

Tells whether a path starts at the top, with a slash (true or false).

{{ isAbs "/var/log" }} → true

osBase#

The same as base, by the rules of the server's operating system: on Linux and macOS exactly base, on Windows a backslash also separates the parts.

{{ osBase "/srv/backups/pve-01.tar.gz" }} → pve-01.tar.gz

osClean#

The same as clean, by the rules of the server's operating system (on Windows the result uses backslashes).

{{ osClean "/srv//backups/../logs" }} → /srv/logs

osDir#

The same as dir, by the rules of the server's operating system (on Windows a backslash also separates the parts).

{{ osDir "/srv/backups/pve-01.tar.gz" }} → /srv/backups

osExt#

The same as ext, by the rules of the server's operating system.

{{ osExt "/srv/reports/disk-usage.csv" }} → .csv

osIsAbs#

The same as isAbs, by the rules of the server's operating system (on Windows a path needs a drive letter, as in C:, to count).

{{ osIsAbs "backups/today" }} → false

urlJoin#

Builds a web address from a dictionary of parts like the one urlParse gives; each part must be text.

{{ urlJoin (dict "scheme" "https" "host" .host.name "path" "/status" "query" "full=1") }} → https://pve-01/status?full=1

urlParse#

Splits a web address into a dictionary of its parts: scheme, host, hostname, path, query, fragment, userinfo and opaque; an address that cannot be read stops the template with an error.

{{ (urlParse .url).host }} → grafana.example.com

Printing#

print#

Writes its values one after another, with a space only between two values that are both not text.

{{ print .host.name " is " .status }} → pve-01 is firing

printf#

Fills values into a pattern: %s for text, %v for any value, %.2f for a number with two decimals and %% for a percent sign; widths and precisions stay under 1000, and lists and dictionaries are refused.

{{ printf "%s: %.0f GB free (%.2f used)" .host.name .host.disk.free_gb .host.disk.used }} → pve-01: 41 GB free (0.93 used)

println#

Writes its values with a space between each and a line break at the end.

{{ println .host.name .status }}{{ .title }} → pve-01 firing⏎Disk almost full

Errors#

fail#

Stops the template with the given message as its error, so nothing is sent; put it inside an if.

{{ if not .host }}{{ fail "no host in the message" }}{{ end }}

Saved templates only#

auto#

Gives a part of the message as the built-in generic template makes it: what the sender stated in a header or the address (Title, Priority, Tags, Click, ...), else what generic works out from the message's fields with no template written. The parts are title, message, priority, tags, link and sequence_id, so a template can keep the rest and change one.

{{ auto "title" }}

event#

Gives the id of the event the template's event field worked out, such as push, so the title and message can depend on it.

{{ if eq event "push" }}New commits{{ end }}

Reads a header of the request that brought the message, such as X-GitHub-Event; Authorization, cookies and the headers proxies add read as nothing.

{{ header "X-GitHub-Event" }}

shorten#

Shortens text to at most N characters, with the number first: a longer text keeps its first N-1 and ends with …. It counts characters, not bytes, so it never cuts an accented letter or an emoji in half.

{{ shorten 8 .title }} → Disk al…

skip#

Drops the message: nothing is stored or sent, and the sender gets 200 with {"dropped":true,"event":…} in place of the message (or what the template's reply says: ok, or nothing), so it does not try again.

{{ if eq .status "resolved" }}{{ skip }}{{ end }}

This page on GitHub