http://blog.51cto.com/linuxme/950051
Control Structures
RainerScript中的控制结构和C,java,javascript等程序中都非常相似。
if
if ($msg contains "important") then {
if ( $.foo != "" ) then set $.foo = $.bar & $.baz;
action(type="omfile" file="/var/log/important.log" template="outfmt")
}
if/else-if/else
if ($msg contains "important") then {
set $.foo = $.bar & $.baz;
action(type="omfile" file="/var/log/important.log" template="outfmt")
} else if ($msg startswith "slow-query:") then {
action(type="omfile" file="/var/log/slow_log.log" template="outfmt")
} else {
set $.foo = $.quux;
action(type="omfile" file="/var/log/general.log" template="outfmt")
}
foreach
Foreach可以迭代数组和对象。 与数组迭代(有序)相反,对象迭代以任意顺序访问键值(无序)。
对于下面的foreach调用:
foreach ($.i in $.collection) do {
...
}
foreach ($.quux in $!foo) do {
action(type="omfile" file="./rsyslog.out.log" template="quux")
foreach ($.corge in $.quux!bar) do {
reset $.grault = $.corge;
action(type="omfile" file="./rsyslog.out.log" template="grault")
if ($.garply != "") then
set $.garply = $.garply & ", ";
reset $.garply = $.garply & $.grault!baz;
}
}
call
continue
Filter Conditions
没有评论:
发表评论