Tokens

Tokens are placeholders included in a check definition that the agent replaces with entity information before executing the check.
You can use tokens to fine-tune check attributes (like alert thresholds) on a per-entity level while re-using the check definition.

How do tokens work?

When a check is scheduled to be executed by an agent, it first goes through a token substitution step. The agent replaces any tokens with matching attributes from the entity definition, and then the check is executed. Invalid templates or unmatched tokens will return an error, which is logged and sent to the Sensu backend message transport. Checks with token matching errors will not be executed.

Managing entity labels

You can use token substitution with any defined entity attributes, including custom labels.
See the entity reference for information on managing entity labels for proxy entities and agent entities.

Sensu token specification

Sensu Go uses the Go template package to implement token substitution.
Sensu Go token substitution uses double curly braces around the token, and a dot before the attribute to be substituted, such as: {{ .system.hostname }}.

{{ .labels.disk_warning }} would be replaced with a custom label called
disk_warning

Token substitution default values

In the event that an attribute is not provided by the entity, a token’s default
value will be substituted. Token default values are separated by a pipe character and the word default (| default), and can be used to provide a “fallback value” for entities that are missing a specified token attribute.

{{.labels.url | default "https://sensu.io"}} would be replaced with a custom label called url. If no such attribute called url is included in the entity definition, the default (or fallback) value of https://sensu.io will be used to substitute the token.

Unmatched tokens

If a token is unmatched during check preparation, the agent check handler will return an error, and the check will not be executed. Unmatched token errors will look similar to the following:

About Sensu

The Sensu monitoring event pipeline empowers businesses to automate their monitoring workflows and gain deep visibility into their multi-cloud infrastructure, from Kubernetes to bare metal. Companies like Sony, Box.com, and Activision rely on Sensu to help deliver value faster, at scale.