我正在嘗試透過 TCP 將文件條目作為訊息發送,其中 syslog-ng 位於一個容器中,並且它正在發送到另一個容器。我有過兩次不同的嘗試,但都出現了問題行為。第一個配置:
@version: 3.31
source s_file {
file("/var/log/my_file.json" follow_freq(1) flags(no-parse));
};
template log_template {
template("MSGSTART${MESSAGE}MSGEND");
};
class SngResolver(object):
def init(self, options):
"""
Initializes the parser
"""
self.counter = 0
return True
def parse(self, log_message):
log_message["SYSUPTIME"] = subprocess.check_output(['cat', '/proc/uptime']).decode('utf-8')
log_message["SEQUENCEID"] = str(self.counter)
self.counter += 1
# return True, other way message is dropped
return True
};
parser p_resolver {
python(
class("SngResolver")
);
};
# Define the destination for Suricata logs
destination d_container {
syslog("my_other_container" transport("tcp") port(1234) template(log_template));
};
# Define the log path for Suricata logs
log {
source(s_file);
parser(p_resolver);
destination(d_container);
};
在此方法中,有時接收到的訊息以即將到來的訊息中的位元組數開始,例如400
。其他時候,他們則不這樣做,而是直接查看訊息。
後來,我將目的地更改為使用network
而不是syslog
.現在,沒有框架了。
我不介意是否必須使用 TCP、UDP 等。我有一個連接到 TCP 套接字的 golang,我希望它一次讀取一條訊息並解析它。這是如何實現的?謝謝
答案1
syslog() 目標將在 Transport(tcp) 和 Transport(tls) 上使用八位元組計數的幀格式,如 RFC5425 所述。它不會在傳輸(udp)上使用成幀,因為在這種情況下,資料封包使用資料包邊界來分隔訊息。 RFC5426 中描述了 UDP 傳輸。