最近更新时间:2023.11.13 16:31:35
首次发布时间:2023.02.16 18:06:17
本文档介绍事件处理函数的语法与格式、相关的场景示例等。
输出到指定别名的目标主题中。其中,日志主题别名即创建加工任务时指定的目标名称。
e_output(topic="日志主题别名")
参数说明如下:
参数 | 参数类型 | 是否必选 | 默认值 | 取值范围 | 说明 |
---|---|---|---|---|---|
topic | String | 是 | / | / | 日志主题别名。 |
场景:根据日志中字段 is_output
的值判断是否要输出该日志到别名为 target-1 的日志主题中。
加工规则:
c_if(v("is_output"), e_output("target-1"))
日志样例:
[ { "is_output":1, "content":"hello world" }, { "is_output":0, "content":"test content" } ]
加工结果:
[ { "is_output":1, "content":"hello world" } ]
说明
第一条日志输出到别名为 target-1 的日志主题中,第二条日志不输出。
使用分隔符对特定字段进行拆分,拆分结果分裂为多条日志。
e_split(field, sep=",", quote='"', lstrip=Ture, jmes=None, output=None)
分裂规则:
参数说明如下:
参数 | 参数类型 | 是否必选 | 默认值 | 取值范围 | 说明 |
---|---|---|---|---|---|
field | String | 是 | / | / | 待分裂的字段名。 |
sep | String | 否 | , | 任意单字符 | 分隔符。 |
quote | String | 否 | " | 任意单字符 | 用于引用多个值的配对类字符的引用符。 |
lstrip | Boolean | 否 | True | / | 是否将值左边的空格去掉,默认为 True,仅字符串分裂时生效。 |
jmes | String | 否 | None | / | 将字段值转化为 JSON 对象,使用 JMES 提取特定值,再进行分裂操作。 |
output | String | 否 | None | / | 设置一个新的字段名,默认覆盖旧的相同字段。 |
场景:根据字段 city
的值分裂为多条日志。
加工规则:
e_split("city")
日志样例:
{ "content":"hello world", "city":"shanghai,hangzhou,chengdu" }
加工结果:
[ { "content":"hello world", "city":"shanghai" }, { "content":"hello world", "city":"hangzhou" }, { "content":"hello world", "city":"chengdu" } ]
丢弃符合条件的日志。
e_drop(condition=条件)
参数说明如下:
参数 | 参数类型 | 是否必选 | 默认值 | 取值范围 | 说明 |
---|---|---|---|---|---|
condition | Boolean | 否 | True | / | 是否丢弃。 |
场景:根据日志字段 city
的值判断是否丢弃该日志。
加工规则:
c_if(op_eq(v("city"), "shanghai"), e_drop())
日志样例:
[ { "content":"hello world", "city":"shanghai" }, { "content":"hello world", "city":"hangzhou" } ]
加工结果:
{ "content":"hello world", "city":"hangzhou" }
保留符合条件的日志,不符合条件则丢弃。
e_keep(condition=条件)
参数说明如下:
参数 | 参数类型 | 是否必选 | 默认值 | 取值范围 | 说明 |
---|---|---|---|---|---|
condition | Boolean | 否 | True | / | 是否保留。 |
场景:根据日志字段 city
的值判断是否保留该日志。
加工规则:
c_if(op_eq(v("city"), "shanghai"), e_keep())
日志样例:
[ { "content":"hello world", "city":"shanghai" }, { "content":"hello world", "city":"hangzhou" } ]
加工结果:
{ "content":"hello world", "city":"shanghai" }