Syslog-ng는 TCP 프레이밍을 활성화합니다.

Syslog-ng는 TCP 프레이밍을 활성화합니다.

syslog-ng가 컨테이너에 있고 다른 컨테이너로 보내는 TCP를 통해 파일 항목을 메시지로 보내려고 합니다. 나는 문제가 있는 행동을 가지고 두 가지 다른 시도를 했습니다. 첫 번째 구성:

@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() 대상은 RFC5425에 설명된 대로 전송(tcp) 및 전송(tls)에서 옥텟 계산 프레이밍 형식을 사용합니다. 데이터그램이 패킷 경계를 사용하여 메시지를 전달하는 경우 전송(udp) 시 프레이밍을 사용하지 않습니다. UDP 전송은 RFC5426에 설명되어 있습니다.

관련 정보