Overview

    Sometimes a macro may resolve to a value that is not necessarily easy to work with. It may be long or contain a specific substring of interest that you would like to extract. This is where macro functions can be useful.

    The syntax of a macro function is:

    where:

    • <func> - the function to apply

    For example:

    1. {{TIME}.fmttime(format,time_shift)}
    2. {{ITEM.VALUE}.regsub(pattern, output)}

    Supported macro functions

    If pattern is not a correct regular expression then the macro evaluates to ‘UNKNOWN’ (excluding low-level discovery macros where the function will be ignored in that case and macro will remain unexpanded)

    If a macro function is applied to the macro in locations not supporting macro functions then the function is ignored.

    Examples

    The ways in which macro functions can be used to customize macro values is illustrated in the following examples on received values:

    Received valueMacroOutput
    24.3413523{{ITEM.VALUE}.fmtnum(2)}24.34
    24.3413523{{ITEM.VALUE}.fmtnum(0)}24
    12:36:01{{TIME}.fmttime(%B)}October
    12:36:01{{TIME}.fmttime(%B,-1M)}September
    123Log line{{ITEM.VALUE}.regsub(^[0-9]+, Problem)}
    123 Log line{{ITEM.VALUE}.regsub(“^([0-9]+)”, “Problem”)}Problem
    123 Log line{{ITEM.VALUE}.regsub(“^([0-9]+)”, Problem ID: \1)}Problem ID: 123
    Log line{{ITEM.VALUE}.regsub(“.“, “Problem ID: \1”)}Problem ID:
    MySQL crashed errno 123{{ITEM.VALUE}.regsub(“^(\w+).?([0-9]+)”, “ Problem ID: \1\2 “)}Problem ID: MySQL_123 
    123 Log line{{ITEM.VALUE}.regsub(“([1-9]+”, “Problem ID: \1”)}UNKNOWN (invalid regular expression)
    customername_1{{#IFALIAS}.regsub(“(.*)([0-9]+)”, \1)}customername
    customername1{{#IFALIAS}.regsub(“(.*)([0-9]+)”, \2)}
    customername1{{#IFALIAS}.regsub(“(.*)([0-9]+”, \1)}{{#IFALIAS}.regsub(“(.)_([0-9]+”, \1)} (invalid regular expression)
    customername_1{$MACRO:”{{#IFALIAS}.regsub(\”(.)([0-9]+)\”, \1)}”}{$MACRO:”customername”}
    customername_1{$MACRO:”{{#IFALIAS}.regsub(\”(.*)([0-9]+)\”, \2)}”}{$MACRO:”1”}
    customername1{$MACRO:”{{#IFALIAS}.regsub(\”(.*)([0-9]+\”, \1)}”}{$MACRO:”{{#M}.regsub(\”(.)_([0-9]+\”, \1)}”} (invalid regular expression)
    customername_1“{$MACRO:\”{{#IFALIAS}.regsub(\“(.)([0-9]+)\“, \1)}\”}”“{$MACRO:\”customername\”}”
    customername_1“{$MACRO:\”{{#IFALIAS}.regsub(\“(.*)([0-9]+)\“, \2)}\”}”“{$MACRO:\”1\”}”)
    customername1“{$MACRO:\”{{#IFALIAS}.regsub(\“(.*)([0-9]+\“, \1)}\”}” (invalid regular expression)