# 1 宏函数

#### 概述

{<macro>.<func>(<params>)}

• <macro> - 要自定义的宏（例如{ITEM.VALUE}或{#LLDMACRO}）
• <func> - 要应用的函数
• <params> - 以逗号分隔的函数参数列表。如果参数以“'”（空格）、“或包含”开头，则必须将其引用。

{{TIME}.fmttime(format,time_shift)}
{{ITEM.VALUE}.regsub(pattern, output)}
{{#LLDMACRO}.regsub(pattern, output)}

#### 支持的宏函数

fmtnum(<digits>)

{ITEM.LASTVALUE}

fmttime(<format>，<time\u shift>)

time\u shift-应用于格式化前时间的时间移位；应以
-<N><time\u unit>+<N><time\u unit>开头，其中
N——要加或减的时间单位数

“-1w”-正好7天前
“-1w/w”-前一周的星期一
“-1w/w+1d”-前一周的星期二

{TIME}
iregsub(<pattern>，<output>)

{ITEM.VALUE}
{ITEM.LASTVALUE}

regsub(<pattern>，<output>)

{ITEM.VALUE}
{ITEM.LASTVALUE}

#### 例子

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(%d %B,-1M/M)} 1 September
123Log line {{ITEM.VALUE}.regsub(^[0-9]+, Problem)} 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
customername_1 {{#IFALIAS}.regsub("(.*)_([0-9]+)", \2)} 1
customername_1 {{#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"}
customername_1 {\$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\"}")
customername_1 "{\$MACRO:\"{{#IFALIAS}.regsub(\\"(.*)_([0-9]+\\", \1)}\"}" "{\$MACRO:\"{{#IFALIAS}.regsub(\\"(.*)_([0-9]+\\", \1)}\"}") (invalid regular expression)
##### 查看完整的监控项值

{{ITEM.VALUE}.regsub("(.*)", \1)}
{{ITEM.LASTVALUE}.regsub("(.*)", \1)}

<%= selection %>
To toggle search highlight, press Ctrl+Alt+H
Have an improvement suggestion for this page? Select the text that could be improved and press Ctrl+Enter to send it to the editors.
To toggle search highlight, press Command+Alt+H
Have an improvement suggestion for this page? Select the text that could be improved and press Command+Enter to send it to the editors.
Suggest an example