我们有一个集中的 rsyslog 基础设施,使用 imtcp 模块捕获世界各地设备发送的 TCP 事件。
这个想法是从系统日志(TCP)读取并将事件存储到磁盘,每个事件一行。这些事件稍后由其他消费者处理。
据我们所知,一些事件一旦存储在磁盘上就会被分割成多个事件,从而破坏了我们流程的其余部分。
使用 tcpdump 捕获单个包,我们确认源系统日志正在向我们发送包含多行的整个事件(典型的 Java 异常)。
[root@xx xx.xx.xx.xx]# tcpdump -i bond0 tcp port 50520 -A -c 1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on bond0, link-type EN10MB (Ethernet), capture size 262144 bytes
12:12:26.062110 IP xx.xx.xx.xx.com.41444 > xx.xx.xx.com.50520: Flags [P.], seq 3270590174:3270590613, ack 2646946316, win 27, options [nop,nop,TS val 3937801207 ecr 2623497312], length 439
E....`@.<.ML..A....N...X..>...2......q.....
....._d`<13> xxx #2.0.#2021 02 10 12:19:50:898#+00#Info#com.xx.xx.xx.xx.xx#
##JavaEE/xx#xx#xx#JavaEE/xx#com.xx.xx.xx.xx.APIServiceHandler#xx#xx##xx#xx##0#Thread[HTTP Worker [@xx],5,Dedicated_Application_Thread]#Plain##
Is the user getting thru SSO? xx:true#
1 packet captured
44 packets received by filter
2 packets dropped by kernel
由于这是一个全球系统,我们无法要求设备所有者修改格式,所有操作都应在我们这边进行。
这是我们的 rsyslog.conf 文件
$MaxMessageSize 128k
# Global configuration/modules
module(load="imtcp" MaxListeners="100")
module(load="imfile" mode="inotify")
module(load="impstats" interval="10" resetCounters="on" format="cee" ruleset="monitoring")
module(load="mmjsonparse")
module(load="mmsequence")
module(load="omelasticsearch")
module(load="omudpspoof")
# Include all conf files
$IncludeConfig /etc/rsyslog.d/*.conf
这是我们从 tcp 读取并写入文件(etc/rsyslog.d/template.conf)的模板
template(name="outjsonfmt_device" type="list") {
constant(value="{")
property(outname="device_ip" name="fromhost-ip" format="jsonf")
constant(value=",")
property(outname="time_collect" name="timegenerated" dateFormat="rfc3339" format="jsonf")
constant(value=",")
constant(value="\"device_type\":\"device\"")
constant(value=",")
property(outname="collector_id" name="$myhostname" format="jsonf")
constant(value=",")
property(outname="msg" name="rawmsg-after-pri" format="jsonf" )
constant(value="}\n")
}
template(name="device-out-filename" type="string" string="/data1/input/device/%fromhost-ip%/device_%$now-utc%_%$hour-utc%.log")
ruleset(name="writeRemoteDataToFile_device") {
action(type="omfile" dynaFileCacheSize="10000" dirCreateMode="0700" FileCreateMode="0644" dirOwner="user" dirGroup="logstash" fileOwner="user" fileGroup="user" dynafile="device-out-filename" template="outjsonfmt_device")
}
input(type="imtcp" port="50520" ruleset="writeRemoteDataToFile_device")
在将事件写入磁盘之前,我们如何配置 rsyslog 以在事件中间转义换行符?我们已经尝试过 $EscapeControlCharactersOnReceive 但没有成功以及其他类似的参数
imtcp 有一个模块参数
DisableLFDelimiter
,您可以尝试将其设置为 on
以忽略换行分隔符,假设您的输入具有八位字节计数标头。该页面显示,此模式是非标准模式,可能会带来很多问题。
module(load="imtcp" MaxListeners="100" DisableLFDelimiter="on")
我发现自己也处于同样的情况。 LF 字符作为分隔符应被忽略,但不应被删除。 你找到解决办法了吗?