标签:切分 场景 http table 版本 ble log rop code
场景:有一个解析乱七八糟日志的需求,格式由于各种原因改不了,并且日志的目的地只能传输到rsyslog。需求就是从乱七八糟的日志中提取出需要的信息。
解析前的日志如下:
|! |! |!2|!1|!0|!0|! |! |! |! |!0|!0|! |! |! |! |!0|!0|! |!|! |! |!0|!0|! |! |!1.1.1.1|!1540438466000|!1540436316761|!2.2.2.2|!0|!0|!0|!0.0|!6|! |!0|!0|!0|!0|!0.0|!0.0|! |! |! |! |! |! |!0|!0|!0|!0|!0|!0|!0|!0|! |! |! |! |! |! |! |!yxgl-web03 root: 3.3.3.3#0112018-01-25#01111:34:26#011POST#011/index.html#011"http://4.4.4.4/get"#011"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"#011200#011359|!
要的日志:
3.3.3.3#0112018-01-25#01111:34:26#011POST#011/index.html#011"http://4.4.4.4/get"#011"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"#011200#011359
1,rsyslog相关软件版本:
rsyslog-kafka-8.38.0-1.el7.x86_64
rsyslog-8.38.0-1.el7.x86_64
2,配置
set $!usr!one = field($msg, " root: ", 2);
set $!usr!two = field($!usr!one, "|!", 1);
template (name="l7" type="string" string="%$!usr!two%")
local5.info /tmp/1.log;l7
通过field把msg以" root: "为分隔符切分,然后取第二个字段并赋值给\$!usr!one;然后,再把\$!usr!one以"|!"为分隔符切分,取第一个字段即为我们要的数据。
https://www.rsyslog.com/doc/v8-stable/rainerscript/functions/rs-field.html
https://www.rsyslog.com/doc/v8-stable/configuration/templates.html
https://www.rsyslog.com/doc/v8-stable/configuration/properties.html
标签:切分 场景 http table 版本 ble log rop code
原文地址:http://blog.51cto.com/leejia/2309504