Implemented compatibility with frame header. Frame header is for instance used by syslog() driver in syslog-ng server and is used to support RFC5424.
This commit is contained in:
parent
8d48a0ae3e
commit
e3c9709ee9
@ -45,6 +45,17 @@ public class TCPNetSyslogConfig extends AbstractNetSyslogConfig implements TCPNe
|
|||||||
|
|
||||||
protected int freshConnectionInterval = TCP_FRESH_CONNECTION_INTERVAL_DEFAULT;
|
protected int freshConnectionInterval = TCP_FRESH_CONNECTION_INTERVAL_DEFAULT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* useFrameHeader flag enables frame header.
|
||||||
|
*
|
||||||
|
* Frame header is sometimes used when writing the syslog message (for example in syslog-ng server syslog() driver).
|
||||||
|
* It does not allow delimiterSequence; its structure is : digit(size of message byte array) + space + syslog message
|
||||||
|
* e.g. where the size of message (byte array) is 89:
|
||||||
|
* 89 <165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473]
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private boolean useFrameHeader;
|
||||||
|
|
||||||
public TCPNetSyslogConfig() {
|
public TCPNetSyslogConfig() {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
@ -149,6 +160,14 @@ public class TCPNetSyslogConfig extends AbstractNetSyslogConfig implements TCPNe
|
|||||||
public void setFreshConnectionInterval(int freshConnectionInterval) {
|
public void setFreshConnectionInterval(int freshConnectionInterval) {
|
||||||
this.freshConnectionInterval = freshConnectionInterval;
|
this.freshConnectionInterval = freshConnectionInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUseFrameHeader(boolean useFrameHeader) {
|
||||||
|
this.useFrameHeader = useFrameHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUseFrameHeader() {
|
||||||
|
return this.useFrameHeader;
|
||||||
|
}
|
||||||
|
|
||||||
public Class getSyslogWriterClass() {
|
public Class getSyslogWriterClass() {
|
||||||
return TCPNetSyslogWriter.class;
|
return TCPNetSyslogWriter.class;
|
||||||
|
@ -45,4 +45,8 @@ public interface TCPNetSyslogConfigIF extends AbstractNetSyslogConfigIF {
|
|||||||
public int getFreshConnectionInterval();
|
public int getFreshConnectionInterval();
|
||||||
|
|
||||||
public void setFreshConnectionInterval(int interval);
|
public void setFreshConnectionInterval(int interval);
|
||||||
|
|
||||||
|
public void setUseFrameHeader(boolean useFrameHeader);
|
||||||
|
|
||||||
|
public boolean isUseFrameHeader();
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,6 @@ public class TCPNetSyslogWriter extends AbstractSyslogWriter {
|
|||||||
|
|
||||||
public void write(byte[] message) throws SyslogRuntimeException {
|
public void write(byte[] message) throws SyslogRuntimeException {
|
||||||
Socket currentSocket = null;
|
Socket currentSocket = null;
|
||||||
|
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
while (attempts != -1 && attempts < (this.tcpNetSyslogConfig.getWriteRetries() + 1)) {
|
while (attempts != -1 && attempts < (this.tcpNetSyslogConfig.getWriteRetries() + 1)) {
|
||||||
try {
|
try {
|
||||||
@ -140,17 +139,25 @@ public class TCPNetSyslogWriter extends AbstractSyslogWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OutputStream os = currentSocket.getOutputStream();
|
OutputStream os = currentSocket.getOutputStream();
|
||||||
|
|
||||||
if (this.tcpNetSyslogConfig.isSetBufferSize()) {
|
String frameHeader = "";
|
||||||
currentSocket.setSendBufferSize(message.length);
|
if(this.tcpNetSyslogConfig.isUseFrameHeader()){
|
||||||
|
frameHeader = message.length + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.tcpNetSyslogConfig.isSetBufferSize()) {
|
||||||
|
currentSocket.setSendBufferSize(message.length + frameHeader.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
os.write(frameHeader.getBytes());
|
||||||
os.write(message);
|
os.write(message);
|
||||||
|
|
||||||
byte[] delimiterSequence = this.tcpNetSyslogConfig.getDelimiterSequence();
|
if(!this.tcpNetSyslogConfig.isUseFrameHeader()) {
|
||||||
if (delimiterSequence != null && delimiterSequence.length > 0) {
|
byte[] delimiterSequence = this.tcpNetSyslogConfig.getDelimiterSequence();
|
||||||
os.write(delimiterSequence);
|
if (delimiterSequence != null && delimiterSequence.length > 0) {
|
||||||
}
|
os.write(delimiterSequence);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.syslog.setBackLogStatus(false);
|
this.syslog.setBackLogStatus(false);
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.graylog2.syslog4j.impl.unix.socket;
|
package org.graylog2.syslog4j.impl.unix.socket;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.graylog2.syslog4j.SyslogRuntimeException;
|
import org.graylog2.syslog4j.SyslogRuntimeException;
|
||||||
import org.graylog2.syslog4j.impl.AbstractSyslog;
|
import org.graylog2.syslog4j.impl.AbstractSyslog;
|
||||||
@ -39,6 +40,12 @@ public class UnixSocketSyslog extends AbstractSyslog {
|
|||||||
System.arraycopy(sunPath.getBytes(), 0, this.sun_path, 0, sunPath.length());
|
System.arraycopy(sunPath.getBytes(), 0, this.sun_path, 0, sunPath.length());
|
||||||
System.arraycopy(ZERO_BYTE, 0, this.sun_path, sunPath.length(), 1);
|
System.arraycopy(ZERO_BYTE, 0, this.sun_path, sunPath.length(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List getFieldOrder() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected interface CLibrary extends Library {
|
protected interface CLibrary extends Library {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user