Template Syntax

The *-syntax options can be used to customize the plugin output.

Here is a list of available syntax options which are common to all check plugins.

OptionDescription
top-syntaxTop-level syntax
ok-syntaxOk syntax
empty-syntaxTemplate syntax used when no item matches a filter.
detail-syntaxDetailed syntax for list items.
perf-syntaxPerformance data syntax

Templates may contain text, conditionals and macros.

Macros

Macros can be used to access attributes of the current check. The form is the same as used in the config file (snclient.ini)

The macro syntax is explained in detail in the macro section of the configuration page.

Supported macro variants:

  • ${macroname}
  • %(macroname)
  • all variants of $ / % and {} / () are interchangeable

Example:

check_memory 'detail-syntax=%(type) = %(used)/%(size) (%(used_pct)%)'

All macros can also make use of macro operators.

For example, the default output applies floating-point formatting to make the output more readable:

check_memory 'detail-syntax=%(type) = %(used)/%(size) (%(used_pct | fmt=%.1f)%)'

Each check’s help page lists its available macros. Another way is to run the check in verbose mode using -vv, which prints the list details as well.

Conditionals

Conditionals can be used to support different output based on expressions.

The basic syntax is:

{{ IF <expression> }}...{{ ELSIF <expression> }}...{{ ELSE }}...{{ END }}

Example:

check_service \
    service=sshd \
    detail-syntax='%(name) - {{ IF state == running }}memory: %(rss:h)B cpu: %(cpu:fmt=%.1f)% - age: %(created:age:duration){{ else }}service is $(state){{ end }}' \
    show-all

This displays a useful message when an error occurs, and performance details otherwise.

For better readability, here is the template again in multiple lines:

%(name) -
{{ IF state == running }}
    memory: %(rss:h)B cpu: %(cpu:fmt=%.1f)% - age: %(created:age:duration)
{{ else }}
    service is $(state)
{{ end }}