An optional context can be used in user macros, allowing to override the default value with a context-specific one.
The context is appended to the macro name; the syntax depends on whether the context is a static text value:
{$MACRO:"static text"}
or a regular expression:
{$MACRO:regex:"regular expression"}
Note that a macro with regular expression context can only be defined in user macro configuration. If the regex: prefix is used elsewhere as user macro context, like in a trigger expression, it will be treated as static context.
Context quoting is optional (see also important notes).
Macro context examples:
| Example | Description |
|---|---|
{$LOW_SPACE_LIMIT} | User macro without context. |
{$LOW_SPACE_LIMIT:/tmp} | User macro with context (static string). |
{$LOW_SPACE_LIMIT:regex:"^/tmp$"} | User macro with context (regular expression). Same as {$LOW_SPACE_LIMIT:/tmp}. |
{$LOW_SPACE_LIMIT:regex:"^/var/log/.*$"} | User macro with context (regular expression). Matches all strings prefixed with /var/log/. |
User macros with context can be defined to accomplish more flexible thresholds in trigger expressions (based on the values retrieved by low-level discovery). For example, you may define the following macros:
Then a low-level discovery macro may be used as macro context in a trigger prototype for mounted file system discovery:
{host:vfs.fs.size[{#FSNAME},pfree].last()}<{$LOW_SPACE_LIMIT:"{#FSNAME}"}
After the discovery different low-space thresholds will apply in triggers depending on the discovered mount points or file system types. Problem events will be generated if:
Technically, macro context is specified using rules similar to item key parameters, except macro context is not parsed as several parameters if there is a , character:
" if the context contains a } character or starts with a " character. Quotes inside quoted context must be escaped with the \ character.\ character itself is not escaped, which means it's impossible to have a quoted context ending with the \ character - the macro {$MACRO:"a:\b\c\"} is invalid.The following macros are all equivalent, because they have the same context: {$MACRO:A}, {$MACRO: A} and {$MACRO:"A"}. This is in contrast with item keys, where 'key[a]', 'key[ a]' and 'key["a"]' are the same semantically, but different for uniqueness purposes.