Merge branch 'reformat'
This commit is contained in:
commit
7380b94581
@ -14,20 +14,20 @@ import org.graylog2.syslog4j.util.SyslogUtility;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a Singleton interface for Syslog4j client implementations.
|
* This class provides a Singleton interface for Syslog4j client implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Usage examples:</p>
|
* <p>Usage examples:</p>
|
||||||
*
|
* <p/>
|
||||||
* <b>Direct</b>
|
* <b>Direct</b>
|
||||||
* <pre>
|
* <pre>
|
||||||
* Syslog.getInstance("udp").info("log message");
|
* Syslog.getInstance("udp").info("log message");
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
* <p/>
|
||||||
* <b>Via Instance</b>
|
* <b>Via Instance</b>
|
||||||
* <pre>
|
* <pre>
|
||||||
* SyslogIF syslog = Syslog.getInstance("udp");
|
* SyslogIF syslog = Syslog.getInstance("udp");
|
||||||
* syslog.info();
|
* syslog.info();
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
@ -36,283 +36,283 @@ import org.graylog2.syslog4j.util.SyslogUtility;
|
|||||||
* @version $Id: Syslog.java,v 1.23 2011/01/23 20:49:12 cvs Exp $
|
* @version $Id: Syslog.java,v 1.23 2011/01/23 20:49:12 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public final class Syslog implements SyslogConstants {
|
public final class Syslog implements SyslogConstants {
|
||||||
private static final long serialVersionUID = -4662318148650646144L;
|
private static final long serialVersionUID = -4662318148650646144L;
|
||||||
|
|
||||||
private static boolean SUPPRESS_RUNTIME_EXCEPTIONS = false;
|
private static boolean SUPPRESS_RUNTIME_EXCEPTIONS = false;
|
||||||
|
|
||||||
protected static final Map instances = new Hashtable();
|
protected static final Map instances = new Hashtable();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syslog is a singleton.
|
* Syslog is a singleton.
|
||||||
*/
|
*/
|
||||||
private Syslog() {
|
private Syslog() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the current version identifier for Syslog4j.
|
* @return Returns the current version identifier for Syslog4j.
|
||||||
*/
|
*/
|
||||||
public static final String getVersion() {
|
public static final String getVersion() {
|
||||||
return Syslog4jVersion.VERSION;
|
return Syslog4jVersion.VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param suppress - true to suppress throwing SyslogRuntimeException in many methods of this class, false to throw exceptions (default)
|
* @param suppress - true to suppress throwing SyslogRuntimeException in many methods of this class, false to throw exceptions (default)
|
||||||
*/
|
*/
|
||||||
public static void setSuppressRuntimeExceptions(boolean suppress) {
|
public static void setSuppressRuntimeExceptions(boolean suppress) {
|
||||||
SUPPRESS_RUNTIME_EXCEPTIONS = suppress;
|
SUPPRESS_RUNTIME_EXCEPTIONS = suppress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns whether or not to suppress throwing SyslogRuntimeException in many methods of this class.
|
* @return Returns whether or not to suppress throwing SyslogRuntimeException in many methods of this class.
|
||||||
*/
|
*/
|
||||||
public static boolean getSuppressRuntimeExceptions() {
|
public static boolean getSuppressRuntimeExceptions() {
|
||||||
return SUPPRESS_RUNTIME_EXCEPTIONS;
|
return SUPPRESS_RUNTIME_EXCEPTIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws SyslogRuntimeException unless it has been suppressed via setSuppressRuntimeException(boolean).
|
* Throws SyslogRuntimeException unless it has been suppressed via setSuppressRuntimeException(boolean).
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
* @throws SyslogRuntimeException
|
* @throws SyslogRuntimeException
|
||||||
*/
|
*/
|
||||||
private static void throwRuntimeException(String message) throws SyslogRuntimeException {
|
private static void throwRuntimeException(String message) throws SyslogRuntimeException {
|
||||||
if (SUPPRESS_RUNTIME_EXCEPTIONS) {
|
if (SUPPRESS_RUNTIME_EXCEPTIONS) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new SyslogRuntimeException(message.toString());
|
throw new SyslogRuntimeException(message.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use getInstance(protocol) as the starting point for Syslog4j.
|
* Use getInstance(protocol) as the starting point for Syslog4j.
|
||||||
*
|
*
|
||||||
* @param protocol - the Syslog protocol to use, e.g. "udp", "tcp", "unix_syslog", "unix_socket", or a custom protocol
|
* @param protocol - the Syslog protocol to use, e.g. "udp", "tcp", "unix_syslog", "unix_socket", or a custom protocol
|
||||||
* @return Returns an instance of SyslogIF.
|
* @return Returns an instance of SyslogIF.
|
||||||
* @throws SyslogRuntimeException
|
* @throws SyslogRuntimeException
|
||||||
*/
|
*/
|
||||||
public static final SyslogIF getInstance(String protocol) throws SyslogRuntimeException {
|
public static final SyslogIF getInstance(String protocol) throws SyslogRuntimeException {
|
||||||
String _protocol = protocol.toLowerCase();
|
String _protocol = protocol.toLowerCase();
|
||||||
|
|
||||||
if (instances.containsKey(_protocol)) {
|
if (instances.containsKey(_protocol)) {
|
||||||
return (SyslogIF) instances.get(_protocol);
|
return (SyslogIF) instances.get(_protocol);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
StringBuffer message = new StringBuffer("Syslog protocol \"" + protocol + "\" not defined; call Syslogger.createSyslogInstance(protocol,config) first");
|
StringBuffer message = new StringBuffer("Syslog protocol \"" + protocol + "\" not defined; call Syslogger.createSyslogInstance(protocol,config) first");
|
||||||
|
|
||||||
if (instances.size() > 0) {
|
if (instances.size() > 0) {
|
||||||
message.append(" or use one of the following instances: ");
|
message.append(" or use one of the following instances: ");
|
||||||
|
|
||||||
Iterator i = instances.keySet().iterator();
|
Iterator i = instances.keySet().iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
String k = (String) i.next();
|
String k = (String) i.next();
|
||||||
|
|
||||||
message.append(k);
|
message.append(k);
|
||||||
if (i.hasNext()) {
|
if (i.hasNext()) {
|
||||||
message.append(' ');
|
message.append(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throwRuntimeException(message.toString());
|
throwRuntimeException(message.toString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use createInstance(protocol,config) to create your own Syslog instance.
|
* Use createInstance(protocol,config) to create your own Syslog instance.
|
||||||
*
|
* <p/>
|
||||||
* <p>First, create an implementation of SyslogConfigIF, such as UdpNetSyslogConfig.</p>
|
* <p>First, create an implementation of SyslogConfigIF, such as UdpNetSyslogConfig.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Second, configure that configuration instance.</p>
|
* <p>Second, configure that configuration instance.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Third, call createInstance(protocol,config) using a short & simple
|
* <p>Third, call createInstance(protocol,config) using a short & simple
|
||||||
* String for the protocol argument.</p>
|
* String for the protocol argument.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Fourth, either use the returned instance of SyslogIF, or in later code
|
* <p>Fourth, either use the returned instance of SyslogIF, or in later code
|
||||||
* call getInstance(protocol) with the protocol chosen in the previous step.</p>
|
* call getInstance(protocol) with the protocol chosen in the previous step.</p>
|
||||||
*
|
*
|
||||||
* @param protocol
|
* @param protocol
|
||||||
* @param config
|
* @param config
|
||||||
* @return Returns an instance of SyslogIF.
|
* @return Returns an instance of SyslogIF.
|
||||||
* @throws SyslogRuntimeException
|
* @throws SyslogRuntimeException
|
||||||
*/
|
*/
|
||||||
public static final SyslogIF createInstance(String protocol, SyslogConfigIF config) throws SyslogRuntimeException {
|
public static final SyslogIF createInstance(String protocol, SyslogConfigIF config) throws SyslogRuntimeException {
|
||||||
if (protocol == null || "".equals(protocol.trim())) {
|
if (protocol == null || "".equals(protocol.trim())) {
|
||||||
throwRuntimeException("Instance protocol cannot be null or empty");
|
throwRuntimeException("Instance protocol cannot be null or empty");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
throwRuntimeException("SyslogConfig cannot be null");
|
throwRuntimeException("SyslogConfig cannot be null");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String syslogProtocol = protocol.toLowerCase();
|
String syslogProtocol = protocol.toLowerCase();
|
||||||
|
|
||||||
SyslogIF syslog = null;
|
SyslogIF syslog = null;
|
||||||
|
|
||||||
synchronized(instances) {
|
synchronized (instances) {
|
||||||
if (instances.containsKey(syslogProtocol)) {
|
if (instances.containsKey(syslogProtocol)) {
|
||||||
throwRuntimeException("Syslog protocol \"" + protocol + "\" already defined");
|
throwRuntimeException("Syslog protocol \"" + protocol + "\" already defined");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class syslogClass = config.getSyslogClass();
|
Class syslogClass = config.getSyslogClass();
|
||||||
|
|
||||||
syslog = (SyslogIF) syslogClass.newInstance();
|
syslog = (SyslogIF) syslogClass.newInstance();
|
||||||
|
|
||||||
} catch (ClassCastException cse) {
|
} catch (ClassCastException cse) {
|
||||||
if (!config.isThrowExceptionOnInitialize()) {
|
if (!config.isThrowExceptionOnInitialize()) {
|
||||||
throw new SyslogRuntimeException(cse);
|
throw new SyslogRuntimeException(cse);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IllegalAccessException iae) {
|
} catch (IllegalAccessException iae) {
|
||||||
if (!config.isThrowExceptionOnInitialize()) {
|
if (!config.isThrowExceptionOnInitialize()) {
|
||||||
throw new SyslogRuntimeException(iae);
|
throw new SyslogRuntimeException(iae);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InstantiationException ie) {
|
} catch (InstantiationException ie) {
|
||||||
if (!config.isThrowExceptionOnInitialize()) {
|
if (!config.isThrowExceptionOnInitialize()) {
|
||||||
throw new SyslogRuntimeException(ie);
|
throw new SyslogRuntimeException(ie);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog.initialize(syslogProtocol,config);
|
syslog.initialize(syslogProtocol, config);
|
||||||
|
|
||||||
instances.put(syslogProtocol,syslog);
|
instances.put(syslogProtocol, syslog);
|
||||||
}
|
}
|
||||||
|
|
||||||
return syslog;
|
return syslog;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize() sets up the default TCP and UDP Syslog protocols, as
|
* initialize() sets up the default TCP and UDP Syslog protocols, as
|
||||||
* well as UNIX_SYSLOG and UNIX_SOCKET (if running on a Unix-based system).
|
* well as UNIX_SYSLOG and UNIX_SOCKET (if running on a Unix-based system).
|
||||||
*/
|
*/
|
||||||
public synchronized static final void initialize() {
|
public synchronized static final void initialize() {
|
||||||
createInstance(UDP,new UDPNetSyslogConfig());
|
createInstance(UDP, new UDPNetSyslogConfig());
|
||||||
createInstance(TCP,new TCPNetSyslogConfig());
|
createInstance(TCP, new TCPNetSyslogConfig());
|
||||||
|
|
||||||
if (OSDetectUtility.isUnix() && SyslogUtility.isClassExists(JNA_NATIVE_CLASS)) {
|
if (OSDetectUtility.isUnix() && SyslogUtility.isClassExists(JNA_NATIVE_CLASS)) {
|
||||||
createInstance(UNIX_SYSLOG,new UnixSyslogConfig());
|
createInstance(UNIX_SYSLOG, new UnixSyslogConfig());
|
||||||
createInstance(UNIX_SOCKET,new UnixSocketSyslogConfig());
|
createInstance(UNIX_SOCKET, new UnixSocketSyslogConfig());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param protocol - Syslog protocol
|
* @param protocol - Syslog protocol
|
||||||
* @return Returns whether the protocol has been previously defined.
|
* @return Returns whether the protocol has been previously defined.
|
||||||
*/
|
*/
|
||||||
public static final boolean exists(String protocol) {
|
public static final boolean exists(String protocol) {
|
||||||
if (protocol == null || "".equals(protocol.trim())) {
|
if (protocol == null || "".equals(protocol.trim())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return instances.containsKey(protocol.toLowerCase());
|
return instances.containsKey(protocol.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shutdown() gracefully shuts down all defined Syslog protocols,
|
* shutdown() gracefully shuts down all defined Syslog protocols,
|
||||||
* which includes flushing all queues and connections and finally
|
* which includes flushing all queues and connections and finally
|
||||||
* clearing all instances (including those initialized by default).
|
* clearing all instances (including those initialized by default).
|
||||||
*/
|
*/
|
||||||
public synchronized static final void shutdown() {
|
public synchronized static final void shutdown() {
|
||||||
Set protocols = instances.keySet();
|
Set protocols = instances.keySet();
|
||||||
|
|
||||||
if (protocols.size() > 0) {
|
if (protocols.size() > 0) {
|
||||||
Iterator i = protocols.iterator();
|
Iterator i = protocols.iterator();
|
||||||
|
|
||||||
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
||||||
|
|
||||||
while(i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
String protocol = (String) i.next();
|
String protocol = (String) i.next();
|
||||||
|
|
||||||
SyslogIF syslog = (SyslogIF) instances.get(protocol);
|
SyslogIF syslog = (SyslogIF) instances.get(protocol);
|
||||||
|
|
||||||
syslog.shutdown();
|
syslog.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
instances.clear();
|
instances.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destroyInstance() gracefully shuts down the specified Syslog protocol and
|
* destroyInstance() gracefully shuts down the specified Syslog protocol and
|
||||||
* removes the instance from Syslog4j.
|
* removes the instance from Syslog4j.
|
||||||
*
|
*
|
||||||
* @param protocol - the Syslog protocol to destroy
|
* @param protocol - the Syslog protocol to destroy
|
||||||
* @throws SyslogRuntimeException
|
* @throws SyslogRuntimeException
|
||||||
*/
|
*/
|
||||||
public synchronized static final void destroyInstance(String protocol) throws SyslogRuntimeException {
|
public synchronized static final void destroyInstance(String protocol) throws SyslogRuntimeException {
|
||||||
if (protocol == null || "".equals(protocol.trim())) {
|
if (protocol == null || "".equals(protocol.trim())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _protocol = protocol.toLowerCase();
|
String _protocol = protocol.toLowerCase();
|
||||||
|
|
||||||
if (instances.containsKey(_protocol)) {
|
if (instances.containsKey(_protocol)) {
|
||||||
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
||||||
|
|
||||||
SyslogIF syslog = (SyslogIF) instances.get(_protocol);
|
SyslogIF syslog = (SyslogIF) instances.get(_protocol);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
syslog.shutdown();
|
syslog.shutdown();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
instances.remove(_protocol);
|
instances.remove(_protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throwRuntimeException("Cannot destroy protocol \"" + protocol + "\" instance; call shutdown instead");
|
throwRuntimeException("Cannot destroy protocol \"" + protocol + "\" instance; call shutdown instead");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destroyInstance() gracefully shuts down the specified Syslog instance and
|
* destroyInstance() gracefully shuts down the specified Syslog instance and
|
||||||
* removes it from Syslog4j.
|
* removes it from Syslog4j.
|
||||||
*
|
*
|
||||||
* @param syslog - the Syslog instance to destroy
|
* @param syslog - the Syslog instance to destroy
|
||||||
* @throws SyslogRuntimeException
|
* @throws SyslogRuntimeException
|
||||||
*/
|
*/
|
||||||
public synchronized static final void destroyInstance(SyslogIF syslog) throws SyslogRuntimeException {
|
public synchronized static final void destroyInstance(SyslogIF syslog) throws SyslogRuntimeException {
|
||||||
if (syslog == null) {
|
if (syslog == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String protocol = syslog.getProtocol().toLowerCase();
|
String protocol = syslog.getProtocol().toLowerCase();
|
||||||
|
|
||||||
if (instances.containsKey(protocol)) {
|
if (instances.containsKey(protocol)) {
|
||||||
try {
|
try {
|
||||||
syslog.shutdown();
|
syslog.shutdown();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
instances.remove(protocol);
|
instances.remove(protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throwRuntimeException("Cannot destroy protocol \"" + protocol + "\" instance; call shutdown instead");
|
throwRuntimeException("Cannot destroy protocol \"" + protocol + "\" instance; call shutdown instead");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
SyslogMain.main(args);
|
SyslogMain.main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package org.graylog2.syslog4j;
|
package org.graylog2.syslog4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syslog4jVersion provides a unique version identifier that is created during
|
* Syslog4jVersion provides a unique version identifier that is created during
|
||||||
* the build process.
|
* the build process.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: Syslog4jVersion.java,v 1.2 2008/10/28 01:07:06 cvs Exp $
|
* @version $Id: Syslog4jVersion.java,v 1.2 2008/10/28 01:07:06 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public final class Syslog4jVersion {
|
public final class Syslog4jVersion {
|
||||||
public static final String VERSION = "Syslog4j-graylog2 0.9.48 kroepke";
|
public static final String VERSION = "Syslog4j-graylog2 0.9.48 kroepke";
|
||||||
}
|
}
|
||||||
|
@ -1,51 +1,51 @@
|
|||||||
package org.graylog2.syslog4j;
|
package org.graylog2.syslog4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogBackLogHandlerIF provides a last-chance mechanism to log messages that fail
|
* SyslogBackLogHandlerIF provides a last-chance mechanism to log messages that fail
|
||||||
* (for whatever reason) within the rest of Syslog.
|
* (for whatever reason) within the rest of Syslog.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Implementing the down(SyslogIF) method is an excellent way to add some sort of notification to
|
* <p>Implementing the down(SyslogIF) method is an excellent way to add some sort of notification to
|
||||||
* your application when a Syslog service is unavailable.</p>
|
* your application when a Syslog service is unavailable.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Implementing the up(SyslogIF) method can be used to notify your application when a Syslog
|
* <p>Implementing the up(SyslogIF) method can be used to notify your application when a Syslog
|
||||||
* service has returned.</p>
|
* service has returned.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogBackLogHandlerIF.java,v 1.2 2009/01/28 15:13:52 cvs Exp $
|
* @version $Id: SyslogBackLogHandlerIF.java,v 1.2 2009/01/28 15:13:52 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogBackLogHandlerIF {
|
public interface SyslogBackLogHandlerIF {
|
||||||
/**
|
/**
|
||||||
* Implement initialize() to handle one-time set-up for this backLog handler.
|
* Implement initialize() to handle one-time set-up for this backLog handler.
|
||||||
*
|
*
|
||||||
* @throws SyslogRuntimeException
|
* @throws SyslogRuntimeException
|
||||||
*/
|
*/
|
||||||
public void initialize() throws SyslogRuntimeException;
|
public void initialize() throws SyslogRuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement down(syslog,reason) to notify/log when the syslog protocol is unavailable.
|
* Implement down(syslog,reason) to notify/log when the syslog protocol is unavailable.
|
||||||
*
|
*
|
||||||
* @param syslog - SyslogIF instance causing this down condition
|
* @param syslog - SyslogIF instance causing this down condition
|
||||||
* @param reason - reason given for the down condition
|
* @param reason - reason given for the down condition
|
||||||
*/
|
*/
|
||||||
public void down(SyslogIF syslog, String reason);
|
public void down(SyslogIF syslog, String reason);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement up(syslog) to notify/log when the syslog protocol becomes available after a down condition.
|
* Implement up(syslog) to notify/log when the syslog protocol becomes available after a down condition.
|
||||||
*
|
*
|
||||||
* @param syslog - SyslogIF instance which is now available
|
* @param syslog - SyslogIF instance which is now available
|
||||||
*/
|
*/
|
||||||
public void up(SyslogIF syslog);
|
public void up(SyslogIF syslog);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param syslog - SyslogIF instance which cannot handle this log event
|
* @param syslog - SyslogIF instance which cannot handle this log event
|
||||||
* @param level - message level
|
* @param level - message level
|
||||||
* @param message - message (in String form)
|
* @param message - message (in String form)
|
||||||
* @param reason - reason given for why this message could not be handled
|
* @param reason - reason given for why this message could not be handled
|
||||||
* @throws SyslogRuntimeException - throwing this Exception activates the next backlogHandler in the chain
|
* @throws SyslogRuntimeException - throwing this Exception activates the next backlogHandler in the chain
|
||||||
*/
|
*/
|
||||||
public void log(SyslogIF syslog, int level, String message, String reason) throws SyslogRuntimeException;
|
public void log(SyslogIF syslog, int level, String message, String reason) throws SyslogRuntimeException;
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,18 @@ package org.graylog2.syslog4j;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogCharSetIF provides control of the encoding character set within
|
* SyslogCharSetIF provides control of the encoding character set within
|
||||||
* several class of Syslog4j.
|
* several class of Syslog4j.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogCharSetIF.java,v 1.3 2008/11/07 15:15:41 cvs Exp $
|
* @version $Id: SyslogCharSetIF.java,v 1.3 2008/11/07 15:15:41 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogCharSetIF extends Serializable {
|
public interface SyslogCharSetIF extends Serializable {
|
||||||
public String getCharSet();
|
public String getCharSet();
|
||||||
public void setCharSet(String charSet);
|
|
||||||
|
public void setCharSet(String charSet);
|
||||||
}
|
}
|
||||||
|
@ -1,69 +1,90 @@
|
|||||||
package org.graylog2.syslog4j;
|
package org.graylog2.syslog4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogConfigIF provides a common, extensible configuration interface for all
|
* SyslogConfigIF provides a common, extensible configuration interface for all
|
||||||
* implementations of SyslogIF.
|
* implementations of SyslogIF.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogConfigIF.java,v 1.19 2010/11/28 04:15:18 cvs Exp $
|
* @version $Id: SyslogConfigIF.java,v 1.19 2010/11/28 04:15:18 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogConfigIF extends SyslogConstants, SyslogCharSetIF {
|
public interface SyslogConfigIF extends SyslogConstants, SyslogCharSetIF {
|
||||||
public Class getSyslogClass();
|
public Class getSyslogClass();
|
||||||
|
|
||||||
public int getFacility();
|
public int getFacility();
|
||||||
public void setFacility(int facility);
|
|
||||||
public void setFacility(String facilityName);
|
|
||||||
|
|
||||||
public int getPort();
|
public void setFacility(int facility);
|
||||||
public void setPort(int port) throws SyslogRuntimeException;
|
|
||||||
|
|
||||||
public String getLocalName();
|
public void setFacility(String facilityName);
|
||||||
public void setLocalName(String localName) throws SyslogRuntimeException;
|
|
||||||
|
|
||||||
public String getHost();
|
public int getPort();
|
||||||
public void setHost(String host) throws SyslogRuntimeException;
|
|
||||||
|
|
||||||
public String getIdent();
|
public void setPort(int port) throws SyslogRuntimeException;
|
||||||
public void setIdent(String ident);
|
|
||||||
|
|
||||||
public String getCharSet();
|
public String getLocalName();
|
||||||
public void setCharSet(String charSet);
|
|
||||||
|
|
||||||
public boolean isIncludeIdentInMessageModifier();
|
public void setLocalName(String localName) throws SyslogRuntimeException;
|
||||||
public void setIncludeIdentInMessageModifier(boolean throwExceptionOnInitialize);
|
|
||||||
|
|
||||||
public boolean isThrowExceptionOnInitialize();
|
public String getHost();
|
||||||
public void setThrowExceptionOnInitialize(boolean throwExceptionOnInitialize);
|
|
||||||
|
|
||||||
public boolean isThrowExceptionOnWrite();
|
public void setHost(String host) throws SyslogRuntimeException;
|
||||||
public void setThrowExceptionOnWrite(boolean throwExceptionOnWrite);
|
|
||||||
|
|
||||||
public boolean isSendLocalTimestamp();
|
public String getIdent();
|
||||||
public void setSendLocalTimestamp(boolean sendLocalTimestamp);
|
|
||||||
|
|
||||||
public boolean isSendLocalName();
|
public void setIdent(String ident);
|
||||||
public void setSendLocalName(boolean sendLocalName);
|
|
||||||
|
|
||||||
public boolean isTruncateMessage();
|
public String getCharSet();
|
||||||
public void setTruncateMessage(boolean truncateMessage);
|
|
||||||
|
|
||||||
public boolean isUseStructuredData();
|
public void setCharSet(String charSet);
|
||||||
public void setUseStructuredData(boolean useStructuredData);
|
|
||||||
|
|
||||||
public int getMaxMessageLength();
|
public boolean isIncludeIdentInMessageModifier();
|
||||||
public void setMaxMessageLength(int maxMessageLength);
|
|
||||||
|
|
||||||
public void addMessageModifier(SyslogMessageModifierIF messageModifier);
|
public void setIncludeIdentInMessageModifier(boolean throwExceptionOnInitialize);
|
||||||
public void insertMessageModifier(int index, SyslogMessageModifierIF messageModifier);
|
|
||||||
public void removeMessageModifier(SyslogMessageModifierIF messageModifier);
|
|
||||||
public void removeAllMessageModifiers();
|
|
||||||
|
|
||||||
public void addBackLogHandler(SyslogBackLogHandlerIF backLogHandler);
|
public boolean isThrowExceptionOnInitialize();
|
||||||
public void insertBackLogHandler(int index, SyslogBackLogHandlerIF backLogHandler);
|
|
||||||
public void removeBackLogHandler(SyslogBackLogHandlerIF backLogHandler);
|
public void setThrowExceptionOnInitialize(boolean throwExceptionOnInitialize);
|
||||||
public void removeAllBackLogHandlers();
|
|
||||||
|
public boolean isThrowExceptionOnWrite();
|
||||||
|
|
||||||
|
public void setThrowExceptionOnWrite(boolean throwExceptionOnWrite);
|
||||||
|
|
||||||
|
public boolean isSendLocalTimestamp();
|
||||||
|
|
||||||
|
public void setSendLocalTimestamp(boolean sendLocalTimestamp);
|
||||||
|
|
||||||
|
public boolean isSendLocalName();
|
||||||
|
|
||||||
|
public void setSendLocalName(boolean sendLocalName);
|
||||||
|
|
||||||
|
public boolean isTruncateMessage();
|
||||||
|
|
||||||
|
public void setTruncateMessage(boolean truncateMessage);
|
||||||
|
|
||||||
|
public boolean isUseStructuredData();
|
||||||
|
|
||||||
|
public void setUseStructuredData(boolean useStructuredData);
|
||||||
|
|
||||||
|
public int getMaxMessageLength();
|
||||||
|
|
||||||
|
public void setMaxMessageLength(int maxMessageLength);
|
||||||
|
|
||||||
|
public void addMessageModifier(SyslogMessageModifierIF messageModifier);
|
||||||
|
|
||||||
|
public void insertMessageModifier(int index, SyslogMessageModifierIF messageModifier);
|
||||||
|
|
||||||
|
public void removeMessageModifier(SyslogMessageModifierIF messageModifier);
|
||||||
|
|
||||||
|
public void removeAllMessageModifiers();
|
||||||
|
|
||||||
|
public void addBackLogHandler(SyslogBackLogHandlerIF backLogHandler);
|
||||||
|
|
||||||
|
public void insertBackLogHandler(int index, SyslogBackLogHandlerIF backLogHandler);
|
||||||
|
|
||||||
|
public void removeBackLogHandler(SyslogBackLogHandlerIF backLogHandler);
|
||||||
|
|
||||||
|
public void removeAllBackLogHandlers();
|
||||||
}
|
}
|
||||||
|
@ -3,162 +3,162 @@ package org.graylog2.syslog4j;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogConstants provides several global constant values for several
|
* SyslogConstants provides several global constant values for several
|
||||||
* classes within Syslog4j.
|
* classes within Syslog4j.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogConstants.java,v 1.33 2011/01/11 05:11:13 cvs Exp $
|
* @version $Id: SyslogConstants.java,v 1.33 2011/01/11 05:11:13 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogConstants extends Serializable {
|
public interface SyslogConstants extends Serializable {
|
||||||
public static final String SYSLOG_PATH_DEFAULT = "/dev/log";
|
public static final String SYSLOG_PATH_DEFAULT = "/dev/log";
|
||||||
public static final String SYSLOG_HOST_DEFAULT = "localhost";
|
public static final String SYSLOG_HOST_DEFAULT = "localhost";
|
||||||
public static final int SYSLOG_PORT_DEFAULT = 514;
|
public static final int SYSLOG_PORT_DEFAULT = 514;
|
||||||
public static final int SYSLOG_BUFFER_SIZE = 1024;
|
public static final int SYSLOG_BUFFER_SIZE = 1024;
|
||||||
public static final int SERVER_SOCKET_BACKLOG_DEFAULT = 50;
|
public static final int SERVER_SOCKET_BACKLOG_DEFAULT = 50;
|
||||||
|
|
||||||
public static final String SYSLOG_DATEFORMAT = "MMM dd HH:mm:ss ";
|
public static final String SYSLOG_DATEFORMAT = "MMM dd HH:mm:ss ";
|
||||||
|
|
||||||
public static final String STRUCTURED_DATA_NILVALUE = "-";
|
public static final String STRUCTURED_DATA_NILVALUE = "-";
|
||||||
public static final String STRUCTURED_DATA_EMPTY_VALUE = "[0@0]";
|
public static final String STRUCTURED_DATA_EMPTY_VALUE = "[0@0]";
|
||||||
|
|
||||||
public static final String CHAR_SET_DEFAULT = "UTF-8";
|
public static final String CHAR_SET_DEFAULT = "UTF-8";
|
||||||
|
|
||||||
public static final byte[] LF = "\n".getBytes();
|
public static final byte[] LF = "\n".getBytes();
|
||||||
public static final byte[] CRLF = "\r\n".getBytes();
|
public static final byte[] CRLF = "\r\n".getBytes();
|
||||||
|
|
||||||
public static final byte[] TCP_DELIMITER_SEQUENCE_DEFAULT = LF;
|
public static final byte[] TCP_DELIMITER_SEQUENCE_DEFAULT = LF;
|
||||||
|
|
||||||
public static final boolean THREADED_DEFAULT = true;
|
public static final boolean THREADED_DEFAULT = true;
|
||||||
public static final long THREAD_LOOP_INTERVAL_DEFAULT = 500;
|
public static final long THREAD_LOOP_INTERVAL_DEFAULT = 500;
|
||||||
|
|
||||||
public static final boolean SEND_LOCAL_NAME_DEFAULT = true;
|
public static final boolean SEND_LOCAL_NAME_DEFAULT = true;
|
||||||
public static final boolean SEND_LOCAL_TIMESTAMP_DEFAULT = true;
|
public static final boolean SEND_LOCAL_TIMESTAMP_DEFAULT = true;
|
||||||
public static final boolean CACHE_HOST_ADDRESS_DEFAULT = true;
|
public static final boolean CACHE_HOST_ADDRESS_DEFAULT = true;
|
||||||
|
|
||||||
public static final int MAX_MESSAGE_LENGTH_DEFAULT = 1024;
|
public static final int MAX_MESSAGE_LENGTH_DEFAULT = 1024;
|
||||||
|
|
||||||
public static final boolean INCLUDE_IDENT_IN_MESSAGE_MODIFIER_DEFAULT = false;
|
public static final boolean INCLUDE_IDENT_IN_MESSAGE_MODIFIER_DEFAULT = false;
|
||||||
public static final boolean THROW_EXCEPTION_ON_INITIALIZE_DEFAULT = true;
|
public static final boolean THROW_EXCEPTION_ON_INITIALIZE_DEFAULT = true;
|
||||||
public static final boolean THROW_EXCEPTION_ON_WRITE_DEFAULT = false;
|
public static final boolean THROW_EXCEPTION_ON_WRITE_DEFAULT = false;
|
||||||
public static final boolean USE_STRUCTURED_DATA_DEFAULT = false;
|
public static final boolean USE_STRUCTURED_DATA_DEFAULT = false;
|
||||||
public static final String STRUCTURED_DATA_APP_NAME_DEFAULT_VALUE = "unknown";
|
public static final String STRUCTURED_DATA_APP_NAME_DEFAULT_VALUE = "unknown";
|
||||||
public static final String STRUCTURED_DATA_PROCESS_ID_DEFAULT_VALUE = STRUCTURED_DATA_NILVALUE;
|
public static final String STRUCTURED_DATA_PROCESS_ID_DEFAULT_VALUE = STRUCTURED_DATA_NILVALUE;
|
||||||
|
|
||||||
public static final boolean USE_DAEMON_THREAD_DEFAULT = true;
|
public static final boolean USE_DAEMON_THREAD_DEFAULT = true;
|
||||||
public static final int THREAD_PRIORITY_DEFAULT = -1;
|
public static final int THREAD_PRIORITY_DEFAULT = -1;
|
||||||
|
|
||||||
public static final boolean TRUNCATE_MESSAGE_DEFAULT = false;
|
public static final boolean TRUNCATE_MESSAGE_DEFAULT = false;
|
||||||
|
|
||||||
public static final String SPLIT_MESSAGE_BEGIN_TEXT_DEFAULT = "...";
|
public static final String SPLIT_MESSAGE_BEGIN_TEXT_DEFAULT = "...";
|
||||||
public static final String SPLIT_MESSAGE_END_TEXT_DEFAULT = "...";
|
public static final String SPLIT_MESSAGE_END_TEXT_DEFAULT = "...";
|
||||||
|
|
||||||
public static final String SEND_LOCAL_NAME_DEFAULT_VALUE = "unknown";
|
public static final String SEND_LOCAL_NAME_DEFAULT_VALUE = "unknown";
|
||||||
|
|
||||||
public static final String TCP = "tcp";
|
public static final String TCP = "tcp";
|
||||||
public static final String UDP = "udp";
|
public static final String UDP = "udp";
|
||||||
public static final String UNIX_SYSLOG = "unix_syslog";
|
public static final String UNIX_SYSLOG = "unix_syslog";
|
||||||
public static final String UNIX_SOCKET = "unix_socket";
|
public static final String UNIX_SOCKET = "unix_socket";
|
||||||
|
|
||||||
public static final boolean TCP_PERSISTENT_CONNECTION_DEFAULT = true;
|
public static final boolean TCP_PERSISTENT_CONNECTION_DEFAULT = true;
|
||||||
public static final boolean TCP_SO_LINGER_DEFAULT = true;
|
public static final boolean TCP_SO_LINGER_DEFAULT = true;
|
||||||
public static final int TCP_SO_LINGER_SECONDS_DEFAULT = 1;
|
public static final int TCP_SO_LINGER_SECONDS_DEFAULT = 1;
|
||||||
public static final boolean TCP_KEEP_ALIVE_DEFAULT = true;
|
public static final boolean TCP_KEEP_ALIVE_DEFAULT = true;
|
||||||
public static final boolean TCP_REUSE_ADDRESS_DEFAULT = true;
|
public static final boolean TCP_REUSE_ADDRESS_DEFAULT = true;
|
||||||
public static final boolean TCP_SET_BUFFER_SIZE_DEFAULT = true;
|
public static final boolean TCP_SET_BUFFER_SIZE_DEFAULT = true;
|
||||||
public static final int TCP_FRESH_CONNECTION_INTERVAL_DEFAULT = -1;
|
public static final int TCP_FRESH_CONNECTION_INTERVAL_DEFAULT = -1;
|
||||||
|
|
||||||
public static final int TCP_MAX_ACTIVE_SOCKETS_DEFAULT = 0;
|
public static final int TCP_MAX_ACTIVE_SOCKETS_DEFAULT = 0;
|
||||||
public static final byte TCP_MAX_ACTIVE_SOCKETS_BEHAVIOR_DEFAULT = 0;
|
public static final byte TCP_MAX_ACTIVE_SOCKETS_BEHAVIOR_DEFAULT = 0;
|
||||||
|
|
||||||
public static final int FACILITY_KERN = 0;
|
public static final int FACILITY_KERN = 0;
|
||||||
public static final int FACILITY_USER = 1<<3;
|
public static final int FACILITY_USER = 1 << 3;
|
||||||
public static final int FACILITY_MAIL = 2<<3;
|
public static final int FACILITY_MAIL = 2 << 3;
|
||||||
public static final int FACILITY_DAEMON = 3<<3;
|
public static final int FACILITY_DAEMON = 3 << 3;
|
||||||
public static final int FACILITY_AUTH = 4<<3;
|
public static final int FACILITY_AUTH = 4 << 3;
|
||||||
public static final int FACILITY_SYSLOG = 5<<3;
|
public static final int FACILITY_SYSLOG = 5 << 3;
|
||||||
|
|
||||||
public static final int FACILITY_LPR = 6<<3;
|
public static final int FACILITY_LPR = 6 << 3;
|
||||||
public static final int FACILITY_NEWS = 7<<3;
|
public static final int FACILITY_NEWS = 7 << 3;
|
||||||
public static final int FACILITY_UUCP = 8<<3;
|
public static final int FACILITY_UUCP = 8 << 3;
|
||||||
public static final int FACILITY_CRON = 9<<3;
|
public static final int FACILITY_CRON = 9 << 3;
|
||||||
public static final int FACILITY_AUTHPRIV = 10<<3;
|
public static final int FACILITY_AUTHPRIV = 10 << 3;
|
||||||
public static final int FACILITY_FTP = 11<<3;
|
public static final int FACILITY_FTP = 11 << 3;
|
||||||
|
|
||||||
public static final int FACILITY_LOCAL0 = 16<<3;
|
public static final int FACILITY_LOCAL0 = 16 << 3;
|
||||||
public static final int FACILITY_LOCAL1 = 17<<3;
|
public static final int FACILITY_LOCAL1 = 17 << 3;
|
||||||
public static final int FACILITY_LOCAL2 = 18<<3;
|
public static final int FACILITY_LOCAL2 = 18 << 3;
|
||||||
public static final int FACILITY_LOCAL3 = 19<<3;
|
public static final int FACILITY_LOCAL3 = 19 << 3;
|
||||||
public static final int FACILITY_LOCAL4 = 20<<3;
|
public static final int FACILITY_LOCAL4 = 20 << 3;
|
||||||
public static final int FACILITY_LOCAL5 = 21<<3;
|
public static final int FACILITY_LOCAL5 = 21 << 3;
|
||||||
public static final int FACILITY_LOCAL6 = 22<<3;
|
public static final int FACILITY_LOCAL6 = 22 << 3;
|
||||||
public static final int FACILITY_LOCAL7 = 23<<3;
|
public static final int FACILITY_LOCAL7 = 23 << 3;
|
||||||
|
|
||||||
public static final int SYSLOG_FACILITY_DEFAULT = FACILITY_USER;
|
public static final int SYSLOG_FACILITY_DEFAULT = FACILITY_USER;
|
||||||
|
|
||||||
public static final int LEVEL_DEBUG = 7;
|
public static final int LEVEL_DEBUG = 7;
|
||||||
public static final int LEVEL_INFO = 6;
|
public static final int LEVEL_INFO = 6;
|
||||||
public static final int LEVEL_NOTICE = 5;
|
public static final int LEVEL_NOTICE = 5;
|
||||||
public static final int LEVEL_WARN = 4;
|
public static final int LEVEL_WARN = 4;
|
||||||
public static final int LEVEL_ERROR = 3;
|
public static final int LEVEL_ERROR = 3;
|
||||||
public static final int LEVEL_CRITICAL = 2;
|
public static final int LEVEL_CRITICAL = 2;
|
||||||
public static final int LEVEL_ALERT = 1;
|
public static final int LEVEL_ALERT = 1;
|
||||||
public static final int LEVEL_EMERGENCY = 0;
|
public static final int LEVEL_EMERGENCY = 0;
|
||||||
|
|
||||||
public static final int OPTION_NONE = 0;
|
public static final int OPTION_NONE = 0;
|
||||||
public static final int OPTION_LOG_CONS = 1;
|
public static final int OPTION_LOG_CONS = 1;
|
||||||
public static final int OPTION_LOG_NDELAY = 2;
|
public static final int OPTION_LOG_NDELAY = 2;
|
||||||
public static final int OPTION_LOG_NOWAIT = 4;
|
public static final int OPTION_LOG_NOWAIT = 4;
|
||||||
public static final int OPTION_LOG_ODELAY = 8;
|
public static final int OPTION_LOG_ODELAY = 8;
|
||||||
public static final int OPTION_LOG_PERROR = 16;
|
public static final int OPTION_LOG_PERROR = 16;
|
||||||
public static final int OPTION_LOG_PID = 32;
|
public static final int OPTION_LOG_PID = 32;
|
||||||
|
|
||||||
public static final int SOCK_STREAM = 1;
|
public static final int SOCK_STREAM = 1;
|
||||||
public static final int SOCK_DGRAM = 2;
|
public static final int SOCK_DGRAM = 2;
|
||||||
|
|
||||||
public static final short AF_UNIX = 1;
|
public static final short AF_UNIX = 1;
|
||||||
|
|
||||||
public static final int WRITE_RETRIES_DEFAULT = 2;
|
public static final int WRITE_RETRIES_DEFAULT = 2;
|
||||||
public static final int MAX_SHUTDOWN_WAIT_DEFAULT = 30000;
|
public static final int MAX_SHUTDOWN_WAIT_DEFAULT = 30000;
|
||||||
public static final long SHUTDOWN_INTERVAL = 100;
|
public static final long SHUTDOWN_INTERVAL = 100;
|
||||||
public static final int MAX_QUEUE_SIZE_DEFAULT = -1;
|
public static final int MAX_QUEUE_SIZE_DEFAULT = -1;
|
||||||
|
|
||||||
public static final long SERVER_SHUTDOWN_WAIT_DEFAULT = 500;
|
public static final long SERVER_SHUTDOWN_WAIT_DEFAULT = 500;
|
||||||
|
|
||||||
public static final String SYSLOG_LIBRARY_DEFAULT = "c";
|
public static final String SYSLOG_LIBRARY_DEFAULT = "c";
|
||||||
|
|
||||||
public static final int SYSLOG_SOCKET_TYPE_DEFAULT = SOCK_DGRAM;
|
public static final int SYSLOG_SOCKET_TYPE_DEFAULT = SOCK_DGRAM;
|
||||||
public static final short SYSLOG_SOCKET_FAMILY_DEFAULT = AF_UNIX;
|
public static final short SYSLOG_SOCKET_FAMILY_DEFAULT = AF_UNIX;
|
||||||
public static final String SYSLOG_SOCKET_LIBRARY_DEFAULT = "c";
|
public static final String SYSLOG_SOCKET_LIBRARY_DEFAULT = "c";
|
||||||
public static final int SYSLOG_SOCKET_PROTOCOL_DEFAULT = 0;
|
public static final int SYSLOG_SOCKET_PROTOCOL_DEFAULT = 0;
|
||||||
public static final String SYSLOG_SOCKET_PATH_DEFAULT = "/dev/log";
|
public static final String SYSLOG_SOCKET_PATH_DEFAULT = "/dev/log";
|
||||||
|
|
||||||
public static final String JNA_NATIVE_CLASS = "com.sun.jna.Native";
|
public static final String JNA_NATIVE_CLASS = "com.sun.jna.Native";
|
||||||
|
|
||||||
public static final String IDENT_SUFFIX_DEFAULT = ": ";
|
public static final String IDENT_SUFFIX_DEFAULT = ": ";
|
||||||
|
|
||||||
public static final String SYSLOG_MESSAGE_MODIFIER_PREFIX_DEFAULT = " {";
|
public static final String SYSLOG_MESSAGE_MODIFIER_PREFIX_DEFAULT = " {";
|
||||||
public static final String SYSLOG_MESSAGE_MODIFIER_SUFFIX_DEFAULT = "}";
|
public static final String SYSLOG_MESSAGE_MODIFIER_SUFFIX_DEFAULT = "}";
|
||||||
|
|
||||||
public static final String SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_PREFIX_DEFAULT = " #";
|
public static final String SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_PREFIX_DEFAULT = " #";
|
||||||
public static final String SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_SUFFIX_DEFAULT = "";
|
public static final String SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_SUFFIX_DEFAULT = "";
|
||||||
public static final long SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_FIRST_NUMBER_DEFAULT = 0;
|
public static final long SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_FIRST_NUMBER_DEFAULT = 0;
|
||||||
public static final long SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_LAST_NUMBER_DEFAULT = 9999;
|
public static final long SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_LAST_NUMBER_DEFAULT = 9999;
|
||||||
public static final char SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_PAD_CHAR_DEFAULT = '0';
|
public static final char SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_PAD_CHAR_DEFAULT = '0';
|
||||||
public static final boolean SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_USE_PADDING_DEFAULT = true;
|
public static final boolean SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_USE_PADDING_DEFAULT = true;
|
||||||
|
|
||||||
public static final int SYSLOG_POOL_CONFIG_MAX_ACTIVE_DEFAULT = 4;
|
public static final int SYSLOG_POOL_CONFIG_MAX_ACTIVE_DEFAULT = 4;
|
||||||
public static final int SYSLOG_POOL_CONFIG_MAX_IDLE_DEFAULT = 4;
|
public static final int SYSLOG_POOL_CONFIG_MAX_IDLE_DEFAULT = 4;
|
||||||
public static final int SYSLOG_POOL_CONFIG_MAX_WAIT_DEFAULT = 1000;
|
public static final int SYSLOG_POOL_CONFIG_MAX_WAIT_DEFAULT = 1000;
|
||||||
public static final int SYSLOG_POOL_CONFIG_NUM_TESTS_PER_EVICTION_RUN_DEFAULT = 0;
|
public static final int SYSLOG_POOL_CONFIG_NUM_TESTS_PER_EVICTION_RUN_DEFAULT = 0;
|
||||||
public static final int SYSLOG_POOL_CONFIG_MIN_IDLE_DEFAULT = 4;
|
public static final int SYSLOG_POOL_CONFIG_MIN_IDLE_DEFAULT = 4;
|
||||||
public static final int SYSLOG_POOL_CONFIG_MIN_EVICTABLE_IDLE_TIME_MILLIS_DEFAULT = 0;
|
public static final int SYSLOG_POOL_CONFIG_MIN_EVICTABLE_IDLE_TIME_MILLIS_DEFAULT = 0;
|
||||||
public static final int SYSLOG_POOL_CONFIG_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS_DEFAULT = 0;
|
public static final int SYSLOG_POOL_CONFIG_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS_DEFAULT = 0;
|
||||||
public static final int SYSLOG_POOL_CONFIG_TIME_BETWEEN_EVICTION_RUNS_MILLIS_DEFAULT = 0;
|
public static final int SYSLOG_POOL_CONFIG_TIME_BETWEEN_EVICTION_RUNS_MILLIS_DEFAULT = 0;
|
||||||
public static final boolean SYSLOG_POOL_CONFIG_TEST_ON_BORROW_DEFAULT = false;
|
public static final boolean SYSLOG_POOL_CONFIG_TEST_ON_BORROW_DEFAULT = false;
|
||||||
public static final boolean SYSLOG_POOL_CONFIG_TEST_ON_RETURN_DEFAULT = false;
|
public static final boolean SYSLOG_POOL_CONFIG_TEST_ON_RETURN_DEFAULT = false;
|
||||||
public static final boolean SYSLOG_POOL_CONFIG_TEST_WHILE_IDLE_DEFAULT = false;
|
public static final boolean SYSLOG_POOL_CONFIG_TEST_WHILE_IDLE_DEFAULT = false;
|
||||||
}
|
}
|
||||||
|
@ -1,52 +1,71 @@
|
|||||||
package org.graylog2.syslog4j;
|
package org.graylog2.syslog4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogIF provides a common interface for all Syslog4j client implementations.
|
* SyslogIF provides a common interface for all Syslog4j client implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogIF.java,v 1.9 2010/02/11 04:59:22 cvs Exp $
|
* @version $Id: SyslogIF.java,v 1.9 2010/02/11 04:59:22 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogIF extends SyslogConstants {
|
public interface SyslogIF extends SyslogConstants {
|
||||||
public void initialize(String protocol, SyslogConfigIF config) throws SyslogRuntimeException;
|
public void initialize(String protocol, SyslogConfigIF config) throws SyslogRuntimeException;
|
||||||
|
|
||||||
public String getProtocol();
|
public String getProtocol();
|
||||||
public SyslogConfigIF getConfig();
|
|
||||||
|
|
||||||
public void backLog(int level, String message, Throwable reasonThrowable);
|
public SyslogConfigIF getConfig();
|
||||||
public void backLog(int level, String message, String reason);
|
|
||||||
|
|
||||||
public void log(int level, String message);
|
public void backLog(int level, String message, Throwable reasonThrowable);
|
||||||
|
|
||||||
public void debug(String message);
|
public void backLog(int level, String message, String reason);
|
||||||
public void info(String message);
|
|
||||||
public void notice(String message);
|
|
||||||
public void warn(String message);
|
|
||||||
public void error(String message);
|
|
||||||
public void critical(String message);
|
|
||||||
public void alert(String message);
|
|
||||||
public void emergency(String message);
|
|
||||||
|
|
||||||
public void log(int level, SyslogMessageIF message);
|
public void log(int level, String message);
|
||||||
|
|
||||||
public void debug(SyslogMessageIF message);
|
public void debug(String message);
|
||||||
public void info(SyslogMessageIF message);
|
|
||||||
public void notice(SyslogMessageIF message);
|
|
||||||
public void warn(SyslogMessageIF message);
|
|
||||||
public void error(SyslogMessageIF message);
|
|
||||||
public void critical(SyslogMessageIF message);
|
|
||||||
public void alert(SyslogMessageIF message);
|
|
||||||
public void emergency(SyslogMessageIF message);
|
|
||||||
|
|
||||||
public void flush() throws SyslogRuntimeException;
|
public void info(String message);
|
||||||
public void shutdown() throws SyslogRuntimeException;
|
|
||||||
|
|
||||||
public void setMessageProcessor(SyslogMessageProcessorIF messageProcessor);
|
public void notice(String message);
|
||||||
public SyslogMessageProcessorIF getMessageProcessor();
|
|
||||||
|
|
||||||
public void setStructuredMessageProcessor(SyslogMessageProcessorIF messageProcessor);
|
public void warn(String message);
|
||||||
public SyslogMessageProcessorIF getStructuredMessageProcessor();
|
|
||||||
|
public void error(String message);
|
||||||
|
|
||||||
|
public void critical(String message);
|
||||||
|
|
||||||
|
public void alert(String message);
|
||||||
|
|
||||||
|
public void emergency(String message);
|
||||||
|
|
||||||
|
public void log(int level, SyslogMessageIF message);
|
||||||
|
|
||||||
|
public void debug(SyslogMessageIF message);
|
||||||
|
|
||||||
|
public void info(SyslogMessageIF message);
|
||||||
|
|
||||||
|
public void notice(SyslogMessageIF message);
|
||||||
|
|
||||||
|
public void warn(SyslogMessageIF message);
|
||||||
|
|
||||||
|
public void error(SyslogMessageIF message);
|
||||||
|
|
||||||
|
public void critical(SyslogMessageIF message);
|
||||||
|
|
||||||
|
public void alert(SyslogMessageIF message);
|
||||||
|
|
||||||
|
public void emergency(SyslogMessageIF message);
|
||||||
|
|
||||||
|
public void flush() throws SyslogRuntimeException;
|
||||||
|
|
||||||
|
public void shutdown() throws SyslogRuntimeException;
|
||||||
|
|
||||||
|
public void setMessageProcessor(SyslogMessageProcessorIF messageProcessor);
|
||||||
|
|
||||||
|
public SyslogMessageProcessorIF getMessageProcessor();
|
||||||
|
|
||||||
|
public void setStructuredMessageProcessor(SyslogMessageProcessorIF messageProcessor);
|
||||||
|
|
||||||
|
public SyslogMessageProcessorIF getStructuredMessageProcessor();
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import java.io.InputStreamReader;
|
|||||||
/**
|
/**
|
||||||
* This class provides a command-line interface for Syslog4j
|
* This class provides a command-line interface for Syslog4j
|
||||||
* server implementations.
|
* server implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
@ -19,180 +19,226 @@ import java.io.InputStreamReader;
|
|||||||
* @version $Id: SyslogMain.java,v 1.4 2010/11/28 01:38:08 cvs Exp $
|
* @version $Id: SyslogMain.java,v 1.4 2010/11/28 01:38:08 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SyslogMain {
|
public class SyslogMain {
|
||||||
public static boolean CALL_SYSTEM_EXIT_ON_FAILURE = true;
|
public static boolean CALL_SYSTEM_EXIT_ON_FAILURE = true;
|
||||||
|
|
||||||
public static class Options {
|
public static class Options {
|
||||||
public String host = null;
|
public String host = null;
|
||||||
public String port = null;
|
public String port = null;
|
||||||
public String level = "INFO";
|
public String level = "INFO";
|
||||||
public String facility = "USER";
|
public String facility = "USER";
|
||||||
public String protocol = null;
|
public String protocol = null;
|
||||||
public String message = null;
|
public String message = null;
|
||||||
public String fileName = null;
|
public String fileName = null;
|
||||||
|
|
||||||
public boolean quiet = false;
|
public boolean quiet = false;
|
||||||
|
|
||||||
public String usage = null;
|
public String usage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void usage(String problem) {
|
public static void usage(String problem) {
|
||||||
if (problem != null) {
|
if (problem != null) {
|
||||||
System.out.println("Error: " + problem);
|
System.out.println("Error: " + problem);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Usage:");
|
System.out.println("Usage:");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Syslog [-h <host>] [-p <port>] [-l <level>] [-f <facility>]");
|
System.out.println("Syslog [-h <host>] [-p <port>] [-l <level>] [-f <facility>]");
|
||||||
System.out.println(" <protocol>");
|
System.out.println(" <protocol>");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Syslog [-h <host>] [-p <port>] [-l <level>] [-f <facility>]");
|
System.out.println("Syslog [-h <host>] [-p <port>] [-l <level>] [-f <facility>]");
|
||||||
System.out.println(" <protocol> [message...]");
|
System.out.println(" <protocol> [message...]");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Syslog [-h <host>] [-p <port>] [-l <level>] [-f <facility>]");
|
System.out.println("Syslog [-h <host>] [-p <port>] [-l <level>] [-f <facility>]");
|
||||||
System.out.println(" -i <file> <protocol>");
|
System.out.println(" -i <file> <protocol>");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("-h <host> host or IP to send message (default: localhost)");
|
System.out.println("-h <host> host or IP to send message (default: localhost)");
|
||||||
System.out.println("-p <port> port to send message (default: 514)");
|
System.out.println("-p <port> port to send message (default: 514)");
|
||||||
System.out.println("-l <level> syslog level to use (default: INFO)");
|
System.out.println("-l <level> syslog level to use (default: INFO)");
|
||||||
System.out.println("-f <facility> syslog facility to use (default: USER)");
|
System.out.println("-f <facility> syslog facility to use (default: USER)");
|
||||||
System.out.println("-i <file> input taken from the specified file");
|
System.out.println("-i <file> input taken from the specified file");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("-q do not write anything to standard out");
|
System.out.println("-q do not write anything to standard out");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("protocol Syslog4j protocol implementation");
|
System.out.println("protocol Syslog4j protocol implementation");
|
||||||
System.out.println("message syslog message text");
|
System.out.println("message syslog message text");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Notes:");
|
System.out.println("Notes:");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Additional message arguments will be concatenated into the same");
|
System.out.println("Additional message arguments will be concatenated into the same");
|
||||||
System.out.println("syslog message; calling SyslogMain will only send one message per call.");
|
System.out.println("syslog message; calling SyslogMain will only send one message per call.");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("If the message argument is ommited, lines will be taken from the");
|
System.out.println("If the message argument is ommited, lines will be taken from the");
|
||||||
System.out.println("standard input.");
|
System.out.println("standard input.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Options parseOptions(String[] args) {
|
public static Options parseOptions(String[] args) {
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i < args.length) {
|
while (i < args.length) {
|
||||||
String arg = args[i++];
|
String arg = args[i++];
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
|
|
||||||
if ("-h".equals(arg)) { if (i == args.length) { options.usage = "Must specify host with -h"; return options; } match = true; options.host = args[i++]; }
|
if ("-h".equals(arg)) {
|
||||||
if ("-p".equals(arg)) { if (i == args.length) { options.usage = "Must specify port with -p"; return options; } match = true; options.port = args[i++]; }
|
if (i == args.length) {
|
||||||
if ("-l".equals(arg)) { if (i == args.length) { options.usage = "Must specify level with -l"; return options; } match = true; options.level = args[i++]; }
|
options.usage = "Must specify host with -h";
|
||||||
if ("-f".equals(arg)) { if (i == args.length) { options.usage = "Must specify facility with -f"; return options; } match = true; options.facility = args[i++]; }
|
return options;
|
||||||
if ("-i".equals(arg)) { if (i == args.length) { options.usage = "Must specify file with -i"; return options; } match = true; options.fileName = args[i++]; }
|
}
|
||||||
|
match = true;
|
||||||
|
options.host = args[i++];
|
||||||
|
}
|
||||||
|
if ("-p".equals(arg)) {
|
||||||
|
if (i == args.length) {
|
||||||
|
options.usage = "Must specify port with -p";
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
match = true;
|
||||||
|
options.port = args[i++];
|
||||||
|
}
|
||||||
|
if ("-l".equals(arg)) {
|
||||||
|
if (i == args.length) {
|
||||||
|
options.usage = "Must specify level with -l";
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
match = true;
|
||||||
|
options.level = args[i++];
|
||||||
|
}
|
||||||
|
if ("-f".equals(arg)) {
|
||||||
|
if (i == args.length) {
|
||||||
|
options.usage = "Must specify facility with -f";
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
match = true;
|
||||||
|
options.facility = args[i++];
|
||||||
|
}
|
||||||
|
if ("-i".equals(arg)) {
|
||||||
|
if (i == args.length) {
|
||||||
|
options.usage = "Must specify file with -i";
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
match = true;
|
||||||
|
options.fileName = args[i++];
|
||||||
|
}
|
||||||
|
|
||||||
if ("-q".equals(arg)) { match = true; options.quiet = true; }
|
if ("-q".equals(arg)) {
|
||||||
|
match = true;
|
||||||
|
options.quiet = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.protocol == null && !match) {
|
if (options.protocol == null && !match) {
|
||||||
match = true;
|
match = true;
|
||||||
options.protocol = arg;
|
options.protocol = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
if (options.message == null) {
|
if (options.message == null) {
|
||||||
options.message = arg;
|
options.message = arg;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
options.message += " " + arg;
|
options.message += " " + arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.protocol == null) {
|
if (options.protocol == null) {
|
||||||
options.usage = "Must specify protocol";
|
options.usage = "Must specify protocol";
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.message != null && options.fileName != null) {
|
if (options.message != null && options.fileName != null) {
|
||||||
options.usage = "Must specify either -i <file> or <message>, not both";
|
options.usage = "Must specify either -i <file> or <message>, not both";
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
main(args,true);
|
main(args, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args, boolean shutdown) throws Exception {
|
public static void main(String[] args, boolean shutdown) throws Exception {
|
||||||
Options options = parseOptions(args);
|
Options options = parseOptions(args);
|
||||||
|
|
||||||
if (options.usage != null) {
|
if (options.usage != null) {
|
||||||
usage(options.usage);
|
usage(options.usage);
|
||||||
if (CALL_SYSTEM_EXIT_ON_FAILURE) { System.exit(1); } else { return; }
|
if (CALL_SYSTEM_EXIT_ON_FAILURE) {
|
||||||
}
|
System.exit(1);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println("Syslog " + Syslog.getVersion());
|
System.out.println("Syslog " + Syslog.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Syslog.exists(options.protocol)) {
|
if (!Syslog.exists(options.protocol)) {
|
||||||
usage("Protocol \"" + options.protocol + "\" not supported");
|
usage("Protocol \"" + options.protocol + "\" not supported");
|
||||||
if (CALL_SYSTEM_EXIT_ON_FAILURE) { System.exit(1); } else { return; }
|
if (CALL_SYSTEM_EXIT_ON_FAILURE) {
|
||||||
}
|
System.exit(1);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SyslogIF syslog = Syslog.getInstance(options.protocol);
|
SyslogIF syslog = Syslog.getInstance(options.protocol);
|
||||||
|
|
||||||
SyslogConfigIF syslogConfig = syslog.getConfig();
|
SyslogConfigIF syslogConfig = syslog.getConfig();
|
||||||
|
|
||||||
if (options.host != null) {
|
if (options.host != null) {
|
||||||
syslogConfig.setHost(options.host);
|
syslogConfig.setHost(options.host);
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println("Sending to host: " + options.host);
|
System.out.println("Sending to host: " + options.host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.port != null) {
|
if (options.port != null) {
|
||||||
syslogConfig.setPort(Integer.parseInt(options.port));
|
syslogConfig.setPort(Integer.parseInt(options.port));
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println("Sending to port: " + options.port);
|
System.out.println("Sending to port: " + options.port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int level = SyslogUtility.getLevel(options.level);
|
int level = SyslogUtility.getLevel(options.level);
|
||||||
|
|
||||||
syslogConfig.setFacility(options.facility);
|
syslogConfig.setFacility(options.facility);
|
||||||
|
|
||||||
if (options.message != null) {
|
if (options.message != null) {
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println("Sending " + options.facility + "." + options.level + " message \"" + options.message + "\"");
|
System.out.println("Sending " + options.facility + "." + options.level + " message \"" + options.message + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog.log(level,options.message);
|
syslog.log(level, options.message);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
|
||||||
if (options.fileName != null) {
|
if (options.fileName != null) {
|
||||||
is = new FileInputStream(options.fileName);
|
is = new FileInputStream(options.fileName);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
is = System.in;
|
is = System.in;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||||
|
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
|
|
||||||
while(line != null && line.length() > 0) {
|
while (line != null && line.length() > 0) {
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println("Sending " + options.facility + "." + options.level + " message \"" + line + "\"");
|
System.out.println("Sending " + options.facility + "." + options.level + " message \"" + line + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog.log(level,line);
|
syslog.log(level, line);
|
||||||
|
|
||||||
line = br.readLine();
|
line = br.readLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shutdown) {
|
if (shutdown) {
|
||||||
Syslog.shutdown();
|
Syslog.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,15 @@ package org.graylog2.syslog4j;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogMessageIF provides a common interface for all Syslog4j event implementations.
|
* SyslogMessageIF provides a common interface for all Syslog4j event implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogMessageIF.java,v 1.1 2008/11/10 04:38:37 cvs Exp $
|
* @version $Id: SyslogMessageIF.java,v 1.1 2008/11/10 04:38:37 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogMessageIF extends Serializable {
|
public interface SyslogMessageIF extends Serializable {
|
||||||
public String createMessage();
|
public String createMessage();
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
package org.graylog2.syslog4j;
|
package org.graylog2.syslog4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogMessageModifierConfigIF provides a common configuration interface for all
|
* SyslogMessageModifierConfigIF provides a common configuration interface for all
|
||||||
* Syslog4j message modifier implementations.
|
* Syslog4j message modifier implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogMessageModifierConfigIF.java,v 1.3 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: SyslogMessageModifierConfigIF.java,v 1.3 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogMessageModifierConfigIF extends SyslogConstants, SyslogCharSetIF {
|
public interface SyslogMessageModifierConfigIF extends SyslogConstants, SyslogCharSetIF {
|
||||||
public String getPrefix();
|
public String getPrefix();
|
||||||
public void setPrefix(String prefix);
|
|
||||||
|
|
||||||
public String getSuffix();
|
public void setPrefix(String prefix);
|
||||||
public void setSuffix(String suffix);
|
|
||||||
|
public String getSuffix();
|
||||||
|
|
||||||
|
public void setSuffix(String suffix);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
package org.graylog2.syslog4j;
|
package org.graylog2.syslog4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogMessageModifierIF provides a common interface for all
|
* SyslogMessageModifierIF provides a common interface for all
|
||||||
* Syslog4j message modifier implementations.
|
* Syslog4j message modifier implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogMessageModifierIF.java,v 1.4 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: SyslogMessageModifierIF.java,v 1.4 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogMessageModifierIF extends SyslogConstants {
|
public interface SyslogMessageModifierIF extends SyslogConstants {
|
||||||
public String modify(SyslogIF syslog, int facility, int level, String message);
|
public String modify(SyslogIF syslog, int facility, int level, String message);
|
||||||
public boolean verify(String message);
|
|
||||||
|
public boolean verify(String message);
|
||||||
}
|
}
|
||||||
|
@ -3,20 +3,20 @@ package org.graylog2.syslog4j;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogMessageProcessorIF provides an extensible interface for writing custom
|
* SyslogMessageProcessorIF provides an extensible interface for writing custom
|
||||||
* Syslog4j message processors.
|
* Syslog4j message processors.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogMessageProcessorIF.java,v 1.4 2010/11/28 04:15:18 cvs Exp $
|
* @version $Id: SyslogMessageProcessorIF.java,v 1.4 2010/11/28 04:15:18 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogMessageProcessorIF extends Serializable {
|
public interface SyslogMessageProcessorIF extends Serializable {
|
||||||
public String createSyslogHeader(int facility, int level, String localName, boolean sendLocalTimestamp, boolean sendLocalName);
|
public String createSyslogHeader(int facility, int level, String localName, boolean sendLocalTimestamp, boolean sendLocalName);
|
||||||
|
|
||||||
public byte[] createPacketData(byte[] header, byte[] message, int start, int length);
|
public byte[] createPacketData(byte[] header, byte[] message, int start, int length);
|
||||||
|
|
||||||
public byte[] createPacketData(byte[] header, byte[] message, int start, int length, byte[] splitBeginText, byte[] splitEndText);
|
public byte[] createPacketData(byte[] header, byte[] message, int start, int length, byte[] splitBeginText, byte[] splitEndText);
|
||||||
}
|
}
|
||||||
|
@ -3,50 +3,62 @@ package org.graylog2.syslog4j;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogPoolConfigIF is an interface which provides configuration support
|
* SyslogPoolConfigIF is an interface which provides configuration support
|
||||||
* for the Apache Commons Pool.
|
* for the Apache Commons Pool.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogPoolConfigIF.java,v 1.2 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: SyslogPoolConfigIF.java,v 1.2 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogPoolConfigIF extends Serializable {
|
public interface SyslogPoolConfigIF extends Serializable {
|
||||||
public int getMaxActive();
|
public int getMaxActive();
|
||||||
public void setMaxActive(int maxActive);
|
|
||||||
|
|
||||||
public int getMaxIdle();
|
public void setMaxActive(int maxActive);
|
||||||
public void setMaxIdle(int maxIdle);
|
|
||||||
|
|
||||||
public long getMaxWait();
|
public int getMaxIdle();
|
||||||
public void setMaxWait(long maxWait);
|
|
||||||
|
|
||||||
public long getMinEvictableIdleTimeMillis();
|
public void setMaxIdle(int maxIdle);
|
||||||
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis);
|
|
||||||
|
|
||||||
public int getMinIdle();
|
public long getMaxWait();
|
||||||
public void setMinIdle(int minIdle);
|
|
||||||
|
|
||||||
public int getNumTestsPerEvictionRun();
|
public void setMaxWait(long maxWait);
|
||||||
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun);
|
|
||||||
|
|
||||||
public long getSoftMinEvictableIdleTimeMillis();
|
public long getMinEvictableIdleTimeMillis();
|
||||||
public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis);
|
|
||||||
|
|
||||||
public boolean isTestOnBorrow();
|
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis);
|
||||||
public void setTestOnBorrow(boolean testOnBorrow);
|
|
||||||
|
|
||||||
public boolean isTestOnReturn();
|
public int getMinIdle();
|
||||||
public void setTestOnReturn(boolean testOnReturn);
|
|
||||||
|
|
||||||
public boolean isTestWhileIdle();
|
public void setMinIdle(int minIdle);
|
||||||
public void setTestWhileIdle(boolean testWhileIdle);
|
|
||||||
|
|
||||||
public long getTimeBetweenEvictionRunsMillis();
|
public int getNumTestsPerEvictionRun();
|
||||||
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis);
|
|
||||||
|
|
||||||
public byte getWhenExhaustedAction();
|
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun);
|
||||||
public void setWhenExhaustedAction(byte whenExhaustedAction);
|
|
||||||
|
public long getSoftMinEvictableIdleTimeMillis();
|
||||||
|
|
||||||
|
public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis);
|
||||||
|
|
||||||
|
public boolean isTestOnBorrow();
|
||||||
|
|
||||||
|
public void setTestOnBorrow(boolean testOnBorrow);
|
||||||
|
|
||||||
|
public boolean isTestOnReturn();
|
||||||
|
|
||||||
|
public void setTestOnReturn(boolean testOnReturn);
|
||||||
|
|
||||||
|
public boolean isTestWhileIdle();
|
||||||
|
|
||||||
|
public void setTestWhileIdle(boolean testWhileIdle);
|
||||||
|
|
||||||
|
public long getTimeBetweenEvictionRunsMillis();
|
||||||
|
|
||||||
|
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis);
|
||||||
|
|
||||||
|
public byte getWhenExhaustedAction();
|
||||||
|
|
||||||
|
public void setWhenExhaustedAction(byte whenExhaustedAction);
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
package org.graylog2.syslog4j;
|
package org.graylog2.syslog4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogRuntimeException provides an extension of RuntimeException thrown
|
* SyslogRuntimeException provides an extension of RuntimeException thrown
|
||||||
* by the majority of the classes within Syslog4j.
|
* by the majority of the classes within Syslog4j.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogRuntimeException.java,v 1.3 2008/11/13 14:48:36 cvs Exp $
|
* @version $Id: SyslogRuntimeException.java,v 1.3 2008/11/13 14:48:36 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SyslogRuntimeException extends RuntimeException {
|
public class SyslogRuntimeException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 7278123987654320379L;
|
private static final long serialVersionUID = 7278123987654320379L;
|
||||||
|
|
||||||
public SyslogRuntimeException(String arg0) {
|
public SyslogRuntimeException(String arg0) {
|
||||||
super(arg0);
|
super(arg0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyslogRuntimeException(Throwable arg0) {
|
public SyslogRuntimeException(Throwable arg0) {
|
||||||
super(arg0);
|
super(arg0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,378 +17,378 @@ import org.graylog2.syslog4j.impl.message.structured.StructuredSyslogMessageIF;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslog provides a base abstract implementation of the SyslogIF.
|
* AbstractSyslog provides a base abstract implementation of the SyslogIF.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslog.java,v 1.29 2011/01/11 04:58:52 cvs Exp $
|
* @version $Id: AbstractSyslog.java,v 1.29 2011/01/11 04:58:52 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslog implements SyslogIF {
|
public abstract class AbstractSyslog implements SyslogIF {
|
||||||
private static final long serialVersionUID = 2632017043774808264L;
|
private static final long serialVersionUID = 2632017043774808264L;
|
||||||
|
|
||||||
protected String syslogProtocol = null;
|
protected String syslogProtocol = null;
|
||||||
|
|
||||||
protected AbstractSyslogConfigIF syslogConfig = null;
|
protected AbstractSyslogConfigIF syslogConfig = null;
|
||||||
|
|
||||||
protected SyslogMessageProcessorIF syslogMessageProcessor = null;
|
protected SyslogMessageProcessorIF syslogMessageProcessor = null;
|
||||||
protected SyslogMessageProcessorIF structuredSyslogMessageProcessor = null;
|
protected SyslogMessageProcessorIF structuredSyslogMessageProcessor = null;
|
||||||
|
|
||||||
protected Object backLogStatusSyncObject = new Object();
|
protected Object backLogStatusSyncObject = new Object();
|
||||||
|
|
||||||
protected boolean backLogStatus = false;
|
protected boolean backLogStatus = false;
|
||||||
protected List notifiedBackLogHandlers = new ArrayList();
|
protected List notifiedBackLogHandlers = new ArrayList();
|
||||||
|
|
||||||
protected boolean getBackLogStatus() {
|
protected boolean getBackLogStatus() {
|
||||||
synchronized(this.backLogStatusSyncObject) {
|
synchronized (this.backLogStatusSyncObject) {
|
||||||
return this.backLogStatus;
|
return this.backLogStatus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param backLogStatus - true if in a "down" backLog state, false if in an "up" (operational) non-backLog state
|
* @param backLogStatus - true if in a "down" backLog state, false if in an "up" (operational) non-backLog state
|
||||||
*/
|
*/
|
||||||
public void setBackLogStatus(boolean backLogStatus) {
|
public void setBackLogStatus(boolean backLogStatus) {
|
||||||
if (this.backLogStatus != backLogStatus) {
|
if (this.backLogStatus != backLogStatus) {
|
||||||
synchronized(this.backLogStatusSyncObject) {
|
synchronized (this.backLogStatusSyncObject) {
|
||||||
if (!backLogStatus) {
|
if (!backLogStatus) {
|
||||||
for(int i=0; i<this.notifiedBackLogHandlers.size(); i++) {
|
for (int i = 0; i < this.notifiedBackLogHandlers.size(); i++) {
|
||||||
SyslogBackLogHandlerIF backLogHandler = (SyslogBackLogHandlerIF) this.notifiedBackLogHandlers.get(i);
|
SyslogBackLogHandlerIF backLogHandler = (SyslogBackLogHandlerIF) this.notifiedBackLogHandlers.get(i);
|
||||||
|
|
||||||
backLogHandler.up(this);
|
backLogHandler.up(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.notifiedBackLogHandlers.clear();
|
this.notifiedBackLogHandlers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.backLogStatus = backLogStatus;
|
this.backLogStatus = backLogStatus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(String protocol, SyslogConfigIF config) throws SyslogRuntimeException {
|
public void initialize(String protocol, SyslogConfigIF config) throws SyslogRuntimeException {
|
||||||
this.syslogProtocol = protocol;
|
this.syslogProtocol = protocol;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.syslogConfig = (AbstractSyslogConfigIF) config;
|
this.syslogConfig = (AbstractSyslogConfigIF) config;
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("provided config must implement AbstractSyslogConfigIF");
|
throw new SyslogRuntimeException("provided config must implement AbstractSyslogConfigIF");
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyslogMessageProcessorIF getMessageProcessor() {
|
public SyslogMessageProcessorIF getMessageProcessor() {
|
||||||
if (this.syslogMessageProcessor == null) {
|
if (this.syslogMessageProcessor == null) {
|
||||||
this.syslogMessageProcessor = SyslogMessageProcessor.getDefault();
|
this.syslogMessageProcessor = SyslogMessageProcessor.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.syslogMessageProcessor;
|
return this.syslogMessageProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyslogMessageProcessorIF getStructuredMessageProcessor() {
|
public SyslogMessageProcessorIF getStructuredMessageProcessor() {
|
||||||
if (this.structuredSyslogMessageProcessor == null) {
|
if (this.structuredSyslogMessageProcessor == null) {
|
||||||
this.structuredSyslogMessageProcessor = StructuredSyslogMessageProcessor.getDefault();
|
this.structuredSyslogMessageProcessor = StructuredSyslogMessageProcessor.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.structuredSyslogMessageProcessor;
|
return this.structuredSyslogMessageProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessageProcessor(SyslogMessageProcessorIF messageProcessor) {
|
public void setMessageProcessor(SyslogMessageProcessorIF messageProcessor) {
|
||||||
this.syslogMessageProcessor = messageProcessor;
|
this.syslogMessageProcessor = messageProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStructuredMessageProcessor(SyslogMessageProcessorIF messageProcessor) {
|
public void setStructuredMessageProcessor(SyslogMessageProcessorIF messageProcessor) {
|
||||||
this.structuredSyslogMessageProcessor = messageProcessor;
|
this.structuredSyslogMessageProcessor = messageProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProtocol() {
|
public String getProtocol() {
|
||||||
return this.syslogProtocol;
|
return this.syslogProtocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyslogConfigIF getConfig() {
|
public SyslogConfigIF getConfig() {
|
||||||
return this.syslogConfig;
|
return this.syslogConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(int level, String message) {
|
public void log(int level, String message) {
|
||||||
if (this.syslogConfig.isUseStructuredData()) {
|
if (this.syslogConfig.isUseStructuredData()) {
|
||||||
StructuredSyslogMessageIF structuredMessage = new StructuredSyslogMessage(null,null,message);
|
StructuredSyslogMessageIF structuredMessage = new StructuredSyslogMessage(null, null, message);
|
||||||
|
|
||||||
log(getStructuredMessageProcessor(),level,structuredMessage.createMessage());
|
log(getStructuredMessageProcessor(), level, structuredMessage.createMessage());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log(getMessageProcessor(),level,message);
|
log(getMessageProcessor(), level, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(int level, SyslogMessageIF message) {
|
public void log(int level, SyslogMessageIF message) {
|
||||||
if (message instanceof StructuredSyslogMessageIF) {
|
if (message instanceof StructuredSyslogMessageIF) {
|
||||||
if (getMessageProcessor() instanceof StructuredSyslogMessageProcessor) {
|
if (getMessageProcessor() instanceof StructuredSyslogMessageProcessor) {
|
||||||
log(getMessageProcessor(),level,message.createMessage());
|
log(getMessageProcessor(), level, message.createMessage());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log(getStructuredMessageProcessor(),level,message.createMessage());
|
log(getStructuredMessageProcessor(), level, message.createMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log(getMessageProcessor(),level,message.createMessage());
|
log(getMessageProcessor(), level, message.createMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(String message) {
|
public void debug(String message) {
|
||||||
log(LEVEL_DEBUG,message);
|
log(LEVEL_DEBUG, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notice(String message) {
|
public void notice(String message) {
|
||||||
log(LEVEL_NOTICE,message);
|
log(LEVEL_NOTICE, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void info(String message) {
|
public void info(String message) {
|
||||||
log(LEVEL_INFO,message);
|
log(LEVEL_INFO, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warn(String message) {
|
public void warn(String message) {
|
||||||
log(LEVEL_WARN,message);
|
log(LEVEL_WARN, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void error(String message) {
|
public void error(String message) {
|
||||||
log(LEVEL_ERROR,message);
|
log(LEVEL_ERROR, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void critical(String message) {
|
public void critical(String message) {
|
||||||
log(LEVEL_CRITICAL,message);
|
log(LEVEL_CRITICAL, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void alert(String message) {
|
public void alert(String message) {
|
||||||
log(LEVEL_ALERT,message);
|
log(LEVEL_ALERT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void emergency(String message) {
|
public void emergency(String message) {
|
||||||
log(LEVEL_EMERGENCY,message);
|
log(LEVEL_EMERGENCY, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(SyslogMessageIF message) {
|
public void debug(SyslogMessageIF message) {
|
||||||
log(LEVEL_DEBUG,message);
|
log(LEVEL_DEBUG, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notice(SyslogMessageIF message) {
|
public void notice(SyslogMessageIF message) {
|
||||||
log(LEVEL_NOTICE,message);
|
log(LEVEL_NOTICE, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void info(SyslogMessageIF message) {
|
public void info(SyslogMessageIF message) {
|
||||||
log(LEVEL_INFO,message);
|
log(LEVEL_INFO, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warn(SyslogMessageIF message) {
|
public void warn(SyslogMessageIF message) {
|
||||||
log(LEVEL_WARN,message);
|
log(LEVEL_WARN, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void error(SyslogMessageIF message) {
|
public void error(SyslogMessageIF message) {
|
||||||
log(LEVEL_ERROR,message);
|
log(LEVEL_ERROR, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void critical(SyslogMessageIF message) {
|
public void critical(SyslogMessageIF message) {
|
||||||
log(LEVEL_CRITICAL,message);
|
log(LEVEL_CRITICAL, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void alert(SyslogMessageIF message) {
|
public void alert(SyslogMessageIF message) {
|
||||||
log(LEVEL_ALERT,message);
|
log(LEVEL_ALERT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void emergency(SyslogMessageIF message) {
|
public void emergency(SyslogMessageIF message) {
|
||||||
log(LEVEL_EMERGENCY,message);
|
log(LEVEL_EMERGENCY, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String prefixMessage(String message, String suffix) {
|
protected String prefixMessage(String message, String suffix) {
|
||||||
String ident = this.syslogConfig.getIdent();
|
String ident = this.syslogConfig.getIdent();
|
||||||
|
|
||||||
String _message = ((ident == null || "".equals(ident.trim())) ? "" : (ident + suffix)) + message;
|
String _message = ((ident == null || "".equals(ident.trim())) ? "" : (ident + suffix)) + message;
|
||||||
|
|
||||||
return _message;
|
return _message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(SyslogMessageProcessorIF messageProcessor, int level, String message) {
|
public void log(SyslogMessageProcessorIF messageProcessor, int level, String message) {
|
||||||
String _message = null;
|
String _message = null;
|
||||||
|
|
||||||
if (this.syslogConfig.isIncludeIdentInMessageModifier()) {
|
if (this.syslogConfig.isIncludeIdentInMessageModifier()) {
|
||||||
_message = prefixMessage(message,IDENT_SUFFIX_DEFAULT);
|
_message = prefixMessage(message, IDENT_SUFFIX_DEFAULT);
|
||||||
_message = modifyMessage(level,_message);
|
_message = modifyMessage(level, _message);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_message = modifyMessage(level,message);
|
_message = modifyMessage(level, message);
|
||||||
_message = prefixMessage(_message,IDENT_SUFFIX_DEFAULT);
|
_message = prefixMessage(_message, IDENT_SUFFIX_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
write(messageProcessor, level,_message);
|
write(messageProcessor, level, _message);
|
||||||
|
|
||||||
} catch (SyslogRuntimeException sre) {
|
} catch (SyslogRuntimeException sre) {
|
||||||
if (sre.getCause() != null) {
|
if (sre.getCause() != null) {
|
||||||
backLog(level,_message,sre.getCause());
|
backLog(level, _message, sre.getCause());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
backLog(level,_message,sre);
|
backLog(level, _message, sre);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.syslogConfig.isThrowExceptionOnWrite()) {
|
if (this.syslogConfig.isThrowExceptionOnWrite()) {
|
||||||
throw sre;
|
throw sre;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void write(SyslogMessageProcessorIF messageProcessor, int level, String message) throws SyslogRuntimeException {
|
protected void write(SyslogMessageProcessorIF messageProcessor, int level, String message) throws SyslogRuntimeException {
|
||||||
String header = messageProcessor.createSyslogHeader(this.syslogConfig.getFacility(),level,this.syslogConfig.getLocalName(),this.syslogConfig.isSendLocalTimestamp(),this.syslogConfig.isSendLocalName());
|
String header = messageProcessor.createSyslogHeader(this.syslogConfig.getFacility(), level, this.syslogConfig.getLocalName(), this.syslogConfig.isSendLocalTimestamp(), this.syslogConfig.isSendLocalName());
|
||||||
|
|
||||||
byte[] h = SyslogUtility.getBytes(this.syslogConfig,header);
|
byte[] h = SyslogUtility.getBytes(this.syslogConfig, header);
|
||||||
byte[] m = SyslogUtility.getBytes(this.syslogConfig,message);
|
byte[] m = SyslogUtility.getBytes(this.syslogConfig, message);
|
||||||
|
|
||||||
int mLength = m.length;
|
int mLength = m.length;
|
||||||
|
|
||||||
int availableLen = this.syslogConfig.getMaxMessageLength() - h.length;
|
int availableLen = this.syslogConfig.getMaxMessageLength() - h.length;
|
||||||
|
|
||||||
if (this.syslogConfig.isTruncateMessage()) {
|
if (this.syslogConfig.isTruncateMessage()) {
|
||||||
if (availableLen > 0 && mLength > availableLen) {
|
if (availableLen > 0 && mLength > availableLen) {
|
||||||
mLength = availableLen;
|
mLength = availableLen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mLength <= availableLen) {
|
if (mLength <= availableLen) {
|
||||||
byte[] data = messageProcessor.createPacketData(h,m,0,mLength);
|
byte[] data = messageProcessor.createPacketData(h, m, 0, mLength);
|
||||||
|
|
||||||
write(level,data);
|
write(level, data);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
byte[] splitBeginText = this.syslogConfig.getSplitMessageBeginText();
|
byte[] splitBeginText = this.syslogConfig.getSplitMessageBeginText();
|
||||||
byte[] splitEndText = this.syslogConfig.getSplitMessageEndText();
|
byte[] splitEndText = this.syslogConfig.getSplitMessageEndText();
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int left = mLength;
|
int left = mLength;
|
||||||
|
|
||||||
while(left > 0) {
|
while (left > 0) {
|
||||||
boolean firstTime = (pos == 0);
|
boolean firstTime = (pos == 0);
|
||||||
|
|
||||||
boolean doSplitBeginText = splitBeginText != null && !firstTime;
|
boolean doSplitBeginText = splitBeginText != null && !firstTime;
|
||||||
boolean doSplitEndText = splitBeginText != null && (firstTime || (left > (availableLen - splitBeginText.length)));
|
boolean doSplitEndText = splitBeginText != null && (firstTime || (left > (availableLen - splitBeginText.length)));
|
||||||
|
|
||||||
int actualAvailableLen = availableLen;
|
int actualAvailableLen = availableLen;
|
||||||
|
|
||||||
actualAvailableLen -= (splitBeginText != null && doSplitBeginText) ? splitBeginText.length : 0;
|
actualAvailableLen -= (splitBeginText != null && doSplitBeginText) ? splitBeginText.length : 0;
|
||||||
actualAvailableLen -= (splitEndText != null && doSplitEndText) ? splitEndText.length : 0;
|
actualAvailableLen -= (splitEndText != null && doSplitEndText) ? splitEndText.length : 0;
|
||||||
|
|
||||||
if (actualAvailableLen > left) {
|
if (actualAvailableLen > left) {
|
||||||
actualAvailableLen = left;
|
actualAvailableLen = left;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actualAvailableLen < 0) {
|
if (actualAvailableLen < 0) {
|
||||||
throw new SyslogRuntimeException("Message length < 0; recommendation: increase the size of maxMessageLength");
|
throw new SyslogRuntimeException("Message length < 0; recommendation: increase the size of maxMessageLength");
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] data = messageProcessor.createPacketData(h,m,pos,actualAvailableLen,doSplitBeginText ? splitBeginText : null,doSplitEndText ? splitEndText : null);
|
byte[] data = messageProcessor.createPacketData(h, m, pos, actualAvailableLen, doSplitBeginText ? splitBeginText : null, doSplitEndText ? splitEndText : null);
|
||||||
|
|
||||||
write(level,data);
|
write(level, data);
|
||||||
|
|
||||||
pos += actualAvailableLen;
|
pos += actualAvailableLen;
|
||||||
left -= actualAvailableLen;
|
left -= actualAvailableLen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void initialize() throws SyslogRuntimeException;
|
protected abstract void initialize() throws SyslogRuntimeException;
|
||||||
|
|
||||||
protected abstract void write(int level, byte[] message) throws SyslogRuntimeException;
|
protected abstract void write(int level, byte[] message) throws SyslogRuntimeException;
|
||||||
|
|
||||||
protected String modifyMessage(int level, String message) {
|
protected String modifyMessage(int level, String message) {
|
||||||
List _messageModifiers = this.syslogConfig.getMessageModifiers();
|
List _messageModifiers = this.syslogConfig.getMessageModifiers();
|
||||||
|
|
||||||
if (_messageModifiers == null || _messageModifiers.size() < 1) {
|
if (_messageModifiers == null || _messageModifiers.size() < 1) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _message = message;
|
String _message = message;
|
||||||
|
|
||||||
int facility = this.syslogConfig.getFacility();
|
int facility = this.syslogConfig.getFacility();
|
||||||
|
|
||||||
for(int i=0; i<_messageModifiers.size(); i++) {
|
for (int i = 0; i < _messageModifiers.size(); i++) {
|
||||||
SyslogMessageModifierIF messageModifier = (SyslogMessageModifierIF) _messageModifiers.get(i);
|
SyslogMessageModifierIF messageModifier = (SyslogMessageModifierIF) _messageModifiers.get(i);
|
||||||
|
|
||||||
_message = messageModifier.modify(this, facility, level, _message);
|
_message = messageModifier.modify(this, facility, level, _message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _message;
|
return _message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void backLog(int level, String message, Throwable reasonThrowable) {
|
public void backLog(int level, String message, Throwable reasonThrowable) {
|
||||||
backLog(level,message,reasonThrowable != null ? reasonThrowable.toString() : "UNKNOWN");
|
backLog(level, message, reasonThrowable != null ? reasonThrowable.toString() : "UNKNOWN");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void backLog(int level, String message, String reason) {
|
public void backLog(int level, String message, String reason) {
|
||||||
boolean status = getBackLogStatus();
|
boolean status = getBackLogStatus();
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
setBackLogStatus(true);
|
setBackLogStatus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
List backLogHandlers = this.syslogConfig.getBackLogHandlers();
|
List backLogHandlers = this.syslogConfig.getBackLogHandlers();
|
||||||
|
|
||||||
for(int i=0; i<backLogHandlers.size(); i++) {
|
for (int i = 0; i < backLogHandlers.size(); i++) {
|
||||||
SyslogBackLogHandlerIF backLogHandler = (SyslogBackLogHandlerIF) backLogHandlers.get(i);
|
SyslogBackLogHandlerIF backLogHandler = (SyslogBackLogHandlerIF) backLogHandlers.get(i);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!status) {
|
if (!status) {
|
||||||
backLogHandler.down(this, reason);
|
backLogHandler.down(this, reason);
|
||||||
this.notifiedBackLogHandlers.add(backLogHandler);
|
this.notifiedBackLogHandlers.add(backLogHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
backLogHandler.log(this,level,message,reason);
|
backLogHandler.log(this, level, message, reason);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Ignore this Exception and go onto next backLogHandler
|
// Ignore this Exception and go onto next backLogHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract AbstractSyslogWriter getWriter();
|
public abstract AbstractSyslogWriter getWriter();
|
||||||
|
|
||||||
public abstract void returnWriter(AbstractSyslogWriter syslogWriter);
|
public abstract void returnWriter(AbstractSyslogWriter syslogWriter);
|
||||||
|
|
||||||
public Thread createWriterThread(AbstractSyslogWriter syslogWriter) {
|
public Thread createWriterThread(AbstractSyslogWriter syslogWriter) {
|
||||||
Thread newWriterThread = new Thread(syslogWriter);
|
Thread newWriterThread = new Thread(syslogWriter);
|
||||||
newWriterThread.setName("SyslogWriter: " + getProtocol());
|
newWriterThread.setName("SyslogWriter: " + getProtocol());
|
||||||
newWriterThread.setDaemon(syslogConfig.isUseDaemonThread());
|
newWriterThread.setDaemon(syslogConfig.isUseDaemonThread());
|
||||||
if (syslogConfig.getThreadPriority() > -1) {
|
if (syslogConfig.getThreadPriority() > -1) {
|
||||||
newWriterThread.setPriority(syslogConfig.getThreadPriority());
|
newWriterThread.setPriority(syslogConfig.getThreadPriority());
|
||||||
}
|
}
|
||||||
syslogWriter.setThread(newWriterThread);
|
syslogWriter.setThread(newWriterThread);
|
||||||
newWriterThread.start();
|
newWriterThread.start();
|
||||||
|
|
||||||
return newWriterThread;
|
return newWriterThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AbstractSyslogWriter createWriter(){
|
public AbstractSyslogWriter createWriter() {
|
||||||
Class clazz = this.syslogConfig.getSyslogWriterClass();
|
Class clazz = this.syslogConfig.getSyslogWriterClass();
|
||||||
|
|
||||||
AbstractSyslogWriter newWriter = null;
|
AbstractSyslogWriter newWriter = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
newWriter = (AbstractSyslogWriter) clazz.newInstance();
|
newWriter = (AbstractSyslogWriter) clazz.newInstance();
|
||||||
newWriter.initialize(this);
|
newWriter.initialize(this);
|
||||||
|
|
||||||
} catch (InstantiationException ie) {
|
} catch (InstantiationException ie) {
|
||||||
if (this.syslogConfig.isThrowExceptionOnInitialize()) {
|
if (this.syslogConfig.isThrowExceptionOnInitialize()) {
|
||||||
throw new SyslogRuntimeException(ie);
|
throw new SyslogRuntimeException(ie);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IllegalAccessException iae) {
|
} catch (IllegalAccessException iae) {
|
||||||
if (this.syslogConfig.isThrowExceptionOnInitialize()) {
|
if (this.syslogConfig.isThrowExceptionOnInitialize()) {
|
||||||
throw new SyslogRuntimeException(iae);
|
throw new SyslogRuntimeException(iae);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newWriter;
|
return newWriter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,369 +10,369 @@ import org.graylog2.syslog4j.impl.backlog.printstream.SystemErrSyslogBackLogHand
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslog provides a base abstract implementation of the SyslogConfigIF
|
* AbstractSyslog provides a base abstract implementation of the SyslogConfigIF
|
||||||
* configuration interface.
|
* configuration interface.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogConfig.java,v 1.24 2010/11/28 04:43:31 cvs Exp $
|
* @version $Id: AbstractSyslogConfig.java,v 1.24 2010/11/28 04:43:31 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslogConfig implements AbstractSyslogConfigIF {
|
public abstract class AbstractSyslogConfig implements AbstractSyslogConfigIF {
|
||||||
private static final long serialVersionUID = -3728308557871358111L;
|
private static final long serialVersionUID = -3728308557871358111L;
|
||||||
|
|
||||||
protected final static List defaultBackLogHandlers = new ArrayList();
|
protected final static List defaultBackLogHandlers = new ArrayList();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
defaultBackLogHandlers.add(new SystemErrSyslogBackLogHandler());
|
defaultBackLogHandlers.add(new SystemErrSyslogBackLogHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int facility = SYSLOG_FACILITY_DEFAULT;
|
protected int facility = SYSLOG_FACILITY_DEFAULT;
|
||||||
|
|
||||||
protected String charSet = CHAR_SET_DEFAULT;
|
protected String charSet = CHAR_SET_DEFAULT;
|
||||||
|
|
||||||
protected String ident = "";
|
protected String ident = "";
|
||||||
|
|
||||||
protected String localName = null;
|
protected String localName = null;
|
||||||
|
|
||||||
protected boolean sendLocalTimestamp = SEND_LOCAL_TIMESTAMP_DEFAULT;
|
protected boolean sendLocalTimestamp = SEND_LOCAL_TIMESTAMP_DEFAULT;
|
||||||
protected boolean sendLocalName = SEND_LOCAL_NAME_DEFAULT;
|
protected boolean sendLocalName = SEND_LOCAL_NAME_DEFAULT;
|
||||||
|
|
||||||
protected boolean includeIdentInMessageModifier = INCLUDE_IDENT_IN_MESSAGE_MODIFIER_DEFAULT;
|
protected boolean includeIdentInMessageModifier = INCLUDE_IDENT_IN_MESSAGE_MODIFIER_DEFAULT;
|
||||||
protected boolean throwExceptionOnWrite = THROW_EXCEPTION_ON_WRITE_DEFAULT;
|
protected boolean throwExceptionOnWrite = THROW_EXCEPTION_ON_WRITE_DEFAULT;
|
||||||
protected boolean throwExceptionOnInitialize = THROW_EXCEPTION_ON_INITIALIZE_DEFAULT;
|
protected boolean throwExceptionOnInitialize = THROW_EXCEPTION_ON_INITIALIZE_DEFAULT;
|
||||||
|
|
||||||
protected int maxMessageLength = MAX_MESSAGE_LENGTH_DEFAULT;
|
protected int maxMessageLength = MAX_MESSAGE_LENGTH_DEFAULT;
|
||||||
protected byte[] splitMessageBeginText = SPLIT_MESSAGE_BEGIN_TEXT_DEFAULT.getBytes();
|
protected byte[] splitMessageBeginText = SPLIT_MESSAGE_BEGIN_TEXT_DEFAULT.getBytes();
|
||||||
protected byte[] splitMessageEndText = SPLIT_MESSAGE_END_TEXT_DEFAULT.getBytes();
|
protected byte[] splitMessageEndText = SPLIT_MESSAGE_END_TEXT_DEFAULT.getBytes();
|
||||||
|
|
||||||
protected List messageModifiers = null;
|
protected List messageModifiers = null;
|
||||||
protected List backLogHandlers = null;
|
protected List backLogHandlers = null;
|
||||||
|
|
||||||
protected boolean threaded = THREADED_DEFAULT;
|
protected boolean threaded = THREADED_DEFAULT;
|
||||||
protected boolean useDaemonThread = USE_DAEMON_THREAD_DEFAULT;
|
protected boolean useDaemonThread = USE_DAEMON_THREAD_DEFAULT;
|
||||||
protected int threadPriority = THREAD_PRIORITY_DEFAULT;
|
protected int threadPriority = THREAD_PRIORITY_DEFAULT;
|
||||||
protected long threadLoopInterval = THREAD_LOOP_INTERVAL_DEFAULT;
|
protected long threadLoopInterval = THREAD_LOOP_INTERVAL_DEFAULT;
|
||||||
|
|
||||||
protected int writeRetries = WRITE_RETRIES_DEFAULT;
|
protected int writeRetries = WRITE_RETRIES_DEFAULT;
|
||||||
protected long maxShutdownWait = MAX_SHUTDOWN_WAIT_DEFAULT;
|
protected long maxShutdownWait = MAX_SHUTDOWN_WAIT_DEFAULT;
|
||||||
|
|
||||||
protected boolean truncateMessage = TRUNCATE_MESSAGE_DEFAULT;
|
protected boolean truncateMessage = TRUNCATE_MESSAGE_DEFAULT;
|
||||||
protected boolean useStructuredData = USE_STRUCTURED_DATA_DEFAULT;
|
protected boolean useStructuredData = USE_STRUCTURED_DATA_DEFAULT;
|
||||||
|
|
||||||
public abstract Class getSyslogClass();
|
public abstract Class getSyslogClass();
|
||||||
|
|
||||||
public String getCharSet() {
|
public String getCharSet() {
|
||||||
return this.charSet;
|
return this.charSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCharSet(String charSet) {
|
public void setCharSet(String charSet) {
|
||||||
this.charSet = charSet;
|
this.charSet = charSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocalName() {
|
public String getLocalName() {
|
||||||
return localName;
|
return localName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocalName(String localName) {
|
public void setLocalName(String localName) {
|
||||||
this.localName = localName;
|
this.localName = localName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isThrowExceptionOnWrite() {
|
public boolean isThrowExceptionOnWrite() {
|
||||||
return this.throwExceptionOnWrite;
|
return this.throwExceptionOnWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThrowExceptionOnWrite(boolean throwExceptionOnWrite) {
|
public void setThrowExceptionOnWrite(boolean throwExceptionOnWrite) {
|
||||||
this.throwExceptionOnWrite = throwExceptionOnWrite;
|
this.throwExceptionOnWrite = throwExceptionOnWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isThrowExceptionOnInitialize() {
|
public boolean isThrowExceptionOnInitialize() {
|
||||||
return this.throwExceptionOnInitialize;
|
return this.throwExceptionOnInitialize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThrowExceptionOnInitialize(boolean throwExceptionOnInitialize) {
|
public void setThrowExceptionOnInitialize(boolean throwExceptionOnInitialize) {
|
||||||
this.throwExceptionOnInitialize = throwExceptionOnInitialize;
|
this.throwExceptionOnInitialize = throwExceptionOnInitialize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getSplitMessageBeginText() {
|
public byte[] getSplitMessageBeginText() {
|
||||||
return this.splitMessageBeginText;
|
return this.splitMessageBeginText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSplitMessageBeginText(byte[] splitMessageBeginText) {
|
public void setSplitMessageBeginText(byte[] splitMessageBeginText) {
|
||||||
this.splitMessageBeginText = splitMessageBeginText;
|
this.splitMessageBeginText = splitMessageBeginText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSplitMessageBeginText(String splitMessageBeginText) throws SyslogRuntimeException {
|
public void setSplitMessageBeginText(String splitMessageBeginText) throws SyslogRuntimeException {
|
||||||
this.splitMessageBeginText = SyslogUtility.getBytes(this,splitMessageBeginText);
|
this.splitMessageBeginText = SyslogUtility.getBytes(this, splitMessageBeginText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getSplitMessageEndText() {
|
public byte[] getSplitMessageEndText() {
|
||||||
return this.splitMessageEndText;
|
return this.splitMessageEndText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSplitMessageEndText(byte[] splitMessageEndText) {
|
public void setSplitMessageEndText(byte[] splitMessageEndText) {
|
||||||
this.splitMessageEndText = splitMessageEndText;
|
this.splitMessageEndText = splitMessageEndText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSplitMessageEndText(String splitMessageEndText) throws SyslogRuntimeException {
|
public void setSplitMessageEndText(String splitMessageEndText) throws SyslogRuntimeException {
|
||||||
this.splitMessageEndText = SyslogUtility.getBytes(this,splitMessageEndText);
|
this.splitMessageEndText = SyslogUtility.getBytes(this, splitMessageEndText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxMessageLength() {
|
public int getMaxMessageLength() {
|
||||||
return this.maxMessageLength;
|
return this.maxMessageLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxMessageLength(int maxMessageLength) {
|
public void setMaxMessageLength(int maxMessageLength) {
|
||||||
this.maxMessageLength = maxMessageLength;
|
this.maxMessageLength = maxMessageLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSendLocalTimestamp() {
|
public boolean isSendLocalTimestamp() {
|
||||||
return this.sendLocalTimestamp;
|
return this.sendLocalTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSendLocalTimestamp(boolean sendLocalTimestamp) {
|
public void setSendLocalTimestamp(boolean sendLocalTimestamp) {
|
||||||
this.sendLocalTimestamp = sendLocalTimestamp;
|
this.sendLocalTimestamp = sendLocalTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSendLocalName() {
|
public boolean isSendLocalName() {
|
||||||
return this.sendLocalName;
|
return this.sendLocalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSendLocalName(boolean sendLocalName) {
|
public void setSendLocalName(boolean sendLocalName) {
|
||||||
this.sendLocalName = sendLocalName;
|
this.sendLocalName = sendLocalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFacility() {
|
public int getFacility() {
|
||||||
return this.facility;
|
return this.facility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacility(int facility) {
|
public void setFacility(int facility) {
|
||||||
this.facility = facility;
|
this.facility = facility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacility(String facilityName) {
|
public void setFacility(String facilityName) {
|
||||||
this.facility = SyslogUtility.getFacility(facilityName);
|
this.facility = SyslogUtility.getFacility(facilityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdent() {
|
public String getIdent() {
|
||||||
return this.ident;
|
return this.ident;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdent(String ident) {
|
public void setIdent(String ident) {
|
||||||
this.ident = ident;
|
this.ident = ident;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized List _getMessageModifiers() {
|
protected synchronized List _getMessageModifiers() {
|
||||||
if (this.messageModifiers == null) {
|
if (this.messageModifiers == null) {
|
||||||
this.messageModifiers = new ArrayList();
|
this.messageModifiers = new ArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.messageModifiers;
|
return this.messageModifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMessageModifier(SyslogMessageModifierIF messageModifier) {
|
public void addMessageModifier(SyslogMessageModifierIF messageModifier) {
|
||||||
if (messageModifier == null) {
|
if (messageModifier == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List _messageModifiers = _getMessageModifiers();
|
List _messageModifiers = _getMessageModifiers();
|
||||||
|
|
||||||
synchronized(_messageModifiers) {
|
synchronized (_messageModifiers) {
|
||||||
_messageModifiers.add(messageModifier);
|
_messageModifiers.add(messageModifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertMessageModifier(int index, SyslogMessageModifierIF messageModifier) {
|
public void insertMessageModifier(int index, SyslogMessageModifierIF messageModifier) {
|
||||||
if (messageModifier == null) {
|
if (messageModifier == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List _messageModifiers = _getMessageModifiers();
|
List _messageModifiers = _getMessageModifiers();
|
||||||
|
|
||||||
synchronized(_messageModifiers) {
|
synchronized (_messageModifiers) {
|
||||||
try {
|
try {
|
||||||
_messageModifiers.add(index,messageModifier);
|
_messageModifiers.add(index, messageModifier);
|
||||||
|
|
||||||
} catch (IndexOutOfBoundsException ioobe) {
|
} catch (IndexOutOfBoundsException ioobe) {
|
||||||
throw new SyslogRuntimeException(ioobe);
|
throw new SyslogRuntimeException(ioobe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMessageModifier(SyslogMessageModifierIF messageModifier) {
|
public void removeMessageModifier(SyslogMessageModifierIF messageModifier) {
|
||||||
if (messageModifier == null) {
|
if (messageModifier == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List _messageModifiers = _getMessageModifiers();
|
List _messageModifiers = _getMessageModifiers();
|
||||||
|
|
||||||
synchronized(_messageModifiers) {
|
synchronized (_messageModifiers) {
|
||||||
_messageModifiers.remove(messageModifier);
|
_messageModifiers.remove(messageModifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getMessageModifiers() {
|
public List getMessageModifiers() {
|
||||||
return this.messageModifiers;
|
return this.messageModifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessageModifiers(List messageModifiers) {
|
public void setMessageModifiers(List messageModifiers) {
|
||||||
this.messageModifiers = messageModifiers;
|
this.messageModifiers = messageModifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllMessageModifiers() {
|
public void removeAllMessageModifiers() {
|
||||||
if (this.messageModifiers == null || this.messageModifiers.isEmpty()) {
|
if (this.messageModifiers == null || this.messageModifiers.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messageModifiers.clear();
|
this.messageModifiers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized List _getBackLogHandlers() {
|
protected synchronized List _getBackLogHandlers() {
|
||||||
if (this.backLogHandlers == null) {
|
if (this.backLogHandlers == null) {
|
||||||
this.backLogHandlers = new ArrayList();
|
this.backLogHandlers = new ArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.backLogHandlers;
|
return this.backLogHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBackLogHandler(SyslogBackLogHandlerIF backLogHandler) {
|
public void addBackLogHandler(SyslogBackLogHandlerIF backLogHandler) {
|
||||||
if (backLogHandler == null) {
|
if (backLogHandler == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List _backLogHandlers = _getBackLogHandlers();
|
List _backLogHandlers = _getBackLogHandlers();
|
||||||
|
|
||||||
synchronized(_backLogHandlers) {
|
synchronized (_backLogHandlers) {
|
||||||
backLogHandler.initialize();
|
backLogHandler.initialize();
|
||||||
_backLogHandlers.add(backLogHandler);
|
_backLogHandlers.add(backLogHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertBackLogHandler(int index, SyslogBackLogHandlerIF backLogHandler) {
|
public void insertBackLogHandler(int index, SyslogBackLogHandlerIF backLogHandler) {
|
||||||
if (backLogHandler == null) {
|
if (backLogHandler == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List _backLogHandlers = _getBackLogHandlers();
|
List _backLogHandlers = _getBackLogHandlers();
|
||||||
|
|
||||||
synchronized(_backLogHandlers) {
|
synchronized (_backLogHandlers) {
|
||||||
try {
|
try {
|
||||||
backLogHandler.initialize();
|
backLogHandler.initialize();
|
||||||
_backLogHandlers.add(index,backLogHandler);
|
_backLogHandlers.add(index, backLogHandler);
|
||||||
|
|
||||||
} catch (IndexOutOfBoundsException ioobe) {
|
} catch (IndexOutOfBoundsException ioobe) {
|
||||||
throw new SyslogRuntimeException(ioobe);
|
throw new SyslogRuntimeException(ioobe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeBackLogHandler(SyslogBackLogHandlerIF backLogHandler) {
|
public void removeBackLogHandler(SyslogBackLogHandlerIF backLogHandler) {
|
||||||
if (backLogHandler == null) {
|
if (backLogHandler == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List _backLogHandlers = _getBackLogHandlers();
|
List _backLogHandlers = _getBackLogHandlers();
|
||||||
|
|
||||||
synchronized(_backLogHandlers) {
|
synchronized (_backLogHandlers) {
|
||||||
_backLogHandlers.remove(backLogHandler);
|
_backLogHandlers.remove(backLogHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getBackLogHandlers() {
|
public List getBackLogHandlers() {
|
||||||
if (this.backLogHandlers == null || this.backLogHandlers.size() < 1) {
|
if (this.backLogHandlers == null || this.backLogHandlers.size() < 1) {
|
||||||
return defaultBackLogHandlers;
|
return defaultBackLogHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.backLogHandlers;
|
return this.backLogHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackLogHandlers(List backLogHandlers) {
|
public void setBackLogHandlers(List backLogHandlers) {
|
||||||
this.backLogHandlers = backLogHandlers;
|
this.backLogHandlers = backLogHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllBackLogHandlers() {
|
public void removeAllBackLogHandlers() {
|
||||||
if (this.backLogHandlers == null || this.backLogHandlers.isEmpty()) {
|
if (this.backLogHandlers == null || this.backLogHandlers.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.backLogHandlers.clear();
|
this.backLogHandlers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIncludeIdentInMessageModifier() {
|
public boolean isIncludeIdentInMessageModifier() {
|
||||||
return this.includeIdentInMessageModifier;
|
return this.includeIdentInMessageModifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIncludeIdentInMessageModifier(boolean includeIdentInMessageModifier) {
|
public void setIncludeIdentInMessageModifier(boolean includeIdentInMessageModifier) {
|
||||||
this.includeIdentInMessageModifier = includeIdentInMessageModifier;
|
this.includeIdentInMessageModifier = includeIdentInMessageModifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isThreaded() {
|
public boolean isThreaded() {
|
||||||
return this.threaded;
|
return this.threaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThreaded(boolean threaded) {
|
public void setThreaded(boolean threaded) {
|
||||||
this.threaded = threaded;
|
this.threaded = threaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseDaemonThread() {
|
public boolean isUseDaemonThread() {
|
||||||
return useDaemonThread;
|
return useDaemonThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseDaemonThread(boolean useDaemonThread) {
|
public void setUseDaemonThread(boolean useDaemonThread) {
|
||||||
this.useDaemonThread = useDaemonThread;
|
this.useDaemonThread = useDaemonThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getThreadPriority() {
|
public int getThreadPriority() {
|
||||||
return threadPriority;
|
return threadPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThreadPriority(int threadPriority) {
|
public void setThreadPriority(int threadPriority) {
|
||||||
this.threadPriority = threadPriority;
|
this.threadPriority = threadPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getThreadLoopInterval() {
|
public long getThreadLoopInterval() {
|
||||||
return this.threadLoopInterval;
|
return this.threadLoopInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThreadLoopInterval(long threadLoopInterval) {
|
public void setThreadLoopInterval(long threadLoopInterval) {
|
||||||
this.threadLoopInterval = threadLoopInterval;
|
this.threadLoopInterval = threadLoopInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxShutdownWait() {
|
public long getMaxShutdownWait() {
|
||||||
return this.maxShutdownWait;
|
return this.maxShutdownWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxShutdownWait(long maxShutdownWait) {
|
public void setMaxShutdownWait(long maxShutdownWait) {
|
||||||
this.maxShutdownWait = maxShutdownWait;
|
this.maxShutdownWait = maxShutdownWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWriteRetries() {
|
public int getWriteRetries() {
|
||||||
return this.writeRetries;
|
return this.writeRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWriteRetries(int writeRetries) {
|
public void setWriteRetries(int writeRetries) {
|
||||||
this.writeRetries = writeRetries;
|
this.writeRetries = writeRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTruncateMessage() {
|
public boolean isTruncateMessage() {
|
||||||
return this.truncateMessage;
|
return this.truncateMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTruncateMessage(boolean truncateMessage) {
|
public void setTruncateMessage(boolean truncateMessage) {
|
||||||
this.truncateMessage = truncateMessage;
|
this.truncateMessage = truncateMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseStructuredData() {
|
public boolean isUseStructuredData() {
|
||||||
return this.useStructuredData;
|
return this.useStructuredData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseStructuredData(boolean useStructuredData) {
|
public void setUseStructuredData(boolean useStructuredData) {
|
||||||
this.useStructuredData = useStructuredData;
|
this.useStructuredData = useStructuredData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogWriterClass() {
|
public Class getSyslogWriterClass() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,52 +5,61 @@ import java.util.List;
|
|||||||
import org.graylog2.syslog4j.SyslogConfigIF;
|
import org.graylog2.syslog4j.SyslogConfigIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslogConfigIF provides an interface for all Abstract Syslog
|
* AbstractSyslogConfigIF provides an interface for all Abstract Syslog
|
||||||
* configuration implementations.
|
* configuration implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogConfigIF.java,v 1.7 2010/10/29 03:14:20 cvs Exp $
|
* @version $Id: AbstractSyslogConfigIF.java,v 1.7 2010/10/29 03:14:20 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface AbstractSyslogConfigIF extends SyslogConfigIF {
|
public interface AbstractSyslogConfigIF extends SyslogConfigIF {
|
||||||
public Class getSyslogWriterClass();
|
public Class getSyslogWriterClass();
|
||||||
|
|
||||||
public List getBackLogHandlers();
|
public List getBackLogHandlers();
|
||||||
|
|
||||||
public List getMessageModifiers();
|
public List getMessageModifiers();
|
||||||
|
|
||||||
public byte[] getSplitMessageBeginText();
|
public byte[] getSplitMessageBeginText();
|
||||||
public void setSplitMessageBeginText(byte[] beginText);
|
|
||||||
|
|
||||||
public byte[] getSplitMessageEndText();
|
public void setSplitMessageBeginText(byte[] beginText);
|
||||||
public void setSplitMessageEndText(byte[] endText);
|
|
||||||
|
|
||||||
public boolean isThreaded();
|
public byte[] getSplitMessageEndText();
|
||||||
public void setThreaded(boolean threaded);
|
|
||||||
|
|
||||||
public boolean isUseDaemonThread();
|
public void setSplitMessageEndText(byte[] endText);
|
||||||
public void setUseDaemonThread(boolean useDaemonThread);
|
|
||||||
|
|
||||||
public int getThreadPriority();
|
public boolean isThreaded();
|
||||||
public void setThreadPriority(int threadPriority);
|
|
||||||
|
|
||||||
public long getThreadLoopInterval();
|
public void setThreaded(boolean threaded);
|
||||||
public void setThreadLoopInterval(long threadLoopInterval);
|
|
||||||
|
|
||||||
public long getMaxShutdownWait();
|
public boolean isUseDaemonThread();
|
||||||
public void setMaxShutdownWait(long maxShutdownWait);
|
|
||||||
|
|
||||||
public int getWriteRetries();
|
public void setUseDaemonThread(boolean useDaemonThread);
|
||||||
public void setWriteRetries(int writeRetries);
|
|
||||||
|
|
||||||
public int getMaxQueueSize();
|
public int getThreadPriority();
|
||||||
/**
|
|
||||||
* Use the (default) value of -1 to allow for a queue of indefinite depth (size).
|
public void setThreadPriority(int threadPriority);
|
||||||
*
|
|
||||||
* @param maxQueueSize
|
public long getThreadLoopInterval();
|
||||||
*/
|
|
||||||
public void setMaxQueueSize(int maxQueueSize);
|
public void setThreadLoopInterval(long threadLoopInterval);
|
||||||
|
|
||||||
|
public long getMaxShutdownWait();
|
||||||
|
|
||||||
|
public void setMaxShutdownWait(long maxShutdownWait);
|
||||||
|
|
||||||
|
public int getWriteRetries();
|
||||||
|
|
||||||
|
public void setWriteRetries(int writeRetries);
|
||||||
|
|
||||||
|
public int getMaxQueueSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the (default) value of -1 to allow for a queue of indefinite depth (size).
|
||||||
|
*
|
||||||
|
* @param maxQueueSize
|
||||||
|
*/
|
||||||
|
public void setMaxQueueSize(int maxQueueSize);
|
||||||
}
|
}
|
||||||
|
@ -9,101 +9,101 @@ import org.graylog2.syslog4j.SyslogRuntimeException;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslogWriter is an implementation of Runnable that supports sending
|
* AbstractSyslogWriter is an implementation of Runnable that supports sending
|
||||||
* syslog messages within a separate Thread or an object pool.
|
* syslog messages within a separate Thread or an object pool.
|
||||||
*
|
* <p/>
|
||||||
* <p>When used in "threaded" mode (see TCPNetSyslogConfig for the option),
|
* <p>When used in "threaded" mode (see TCPNetSyslogConfig for the option),
|
||||||
* a queuing mechanism is used (via LinkedList).</p>
|
* a queuing mechanism is used (via LinkedList).</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogWriter.java,v 1.9 2010/10/25 03:50:25 cvs Exp $
|
* @version $Id: AbstractSyslogWriter.java,v 1.9 2010/10/25 03:50:25 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslogWriter implements Runnable, Serializable {
|
public abstract class AbstractSyslogWriter implements Runnable, Serializable {
|
||||||
private static final long serialVersionUID = 836468466009035847L;
|
private static final long serialVersionUID = 836468466009035847L;
|
||||||
|
|
||||||
protected AbstractSyslog syslog = null;
|
protected AbstractSyslog syslog = null;
|
||||||
|
|
||||||
protected List queuedMessages = null;
|
protected List queuedMessages = null;
|
||||||
|
|
||||||
protected Thread thread = null;
|
protected Thread thread = null;
|
||||||
|
|
||||||
protected AbstractSyslogConfigIF syslogConfig = null;
|
protected AbstractSyslogConfigIF syslogConfig = null;
|
||||||
|
|
||||||
protected boolean shutdown = false;
|
protected boolean shutdown = false;
|
||||||
|
|
||||||
public void initialize(AbstractSyslog abstractSyslog) {
|
public void initialize(AbstractSyslog abstractSyslog) {
|
||||||
this.syslog = abstractSyslog;
|
this.syslog = abstractSyslog;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.syslogConfig = (AbstractSyslogConfigIF) this.syslog.getConfig();
|
this.syslogConfig = (AbstractSyslogConfigIF) this.syslog.getConfig();
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("config must implement interface AbstractSyslogConfigIF");
|
throw new SyslogRuntimeException("config must implement interface AbstractSyslogConfigIF");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.syslogConfig.isThreaded()) {
|
if (this.syslogConfig.isThreaded()) {
|
||||||
this.queuedMessages = new LinkedList();
|
this.queuedMessages = new LinkedList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queue(int level, byte[] message) {
|
public void queue(int level, byte[] message) {
|
||||||
synchronized(this.queuedMessages) {
|
synchronized (this.queuedMessages) {
|
||||||
if (this.syslogConfig.getMaxQueueSize() == -1 || this.queuedMessages.size() < this.syslogConfig.getMaxQueueSize()) {
|
if (this.syslogConfig.getMaxQueueSize() == -1 || this.queuedMessages.size() < this.syslogConfig.getMaxQueueSize()) {
|
||||||
this.queuedMessages.add(message);
|
this.queuedMessages.add(message);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.syslog.backLog(level,SyslogUtility.newString(syslogConfig,message),"MaxQueueSize (" + this.syslogConfig.getMaxQueueSize() + ") reached");
|
this.syslog.backLog(level, SyslogUtility.newString(syslogConfig, message), "MaxQueueSize (" + this.syslogConfig.getMaxQueueSize() + ") reached");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThread(Thread thread) {
|
public void setThread(Thread thread) {
|
||||||
this.thread = thread;
|
this.thread = thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasThread() {
|
public boolean hasThread() {
|
||||||
return this.thread != null && this.thread.isAlive();
|
return this.thread != null && this.thread.isAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void write(byte[] message);
|
public abstract void write(byte[] message);
|
||||||
|
|
||||||
public abstract void flush();
|
public abstract void flush();
|
||||||
|
|
||||||
public abstract void shutdown();
|
public abstract void shutdown();
|
||||||
|
|
||||||
protected abstract void runCompleted();
|
protected abstract void runCompleted();
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
while(!this.shutdown || !this.queuedMessages.isEmpty()) {
|
while (!this.shutdown || !this.queuedMessages.isEmpty()) {
|
||||||
List queuedMessagesCopy = null;
|
List queuedMessagesCopy = null;
|
||||||
|
|
||||||
synchronized(this.queuedMessages) {
|
synchronized (this.queuedMessages) {
|
||||||
queuedMessagesCopy = new LinkedList(this.queuedMessages);
|
queuedMessagesCopy = new LinkedList(this.queuedMessages);
|
||||||
this.queuedMessages.clear();
|
this.queuedMessages.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queuedMessagesCopy != null) {
|
if (queuedMessagesCopy != null) {
|
||||||
while(!queuedMessagesCopy.isEmpty()) {
|
while (!queuedMessagesCopy.isEmpty()) {
|
||||||
byte[] message = (byte[]) queuedMessagesCopy.remove(0);
|
byte[] message = (byte[]) queuedMessagesCopy.remove(0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
write(message);
|
write(message);
|
||||||
|
|
||||||
this.syslog.setBackLogStatus(false);
|
this.syslog.setBackLogStatus(false);
|
||||||
|
|
||||||
} catch (SyslogRuntimeException sre) {
|
} catch (SyslogRuntimeException sre) {
|
||||||
this.syslog.backLog(SyslogConstants.LEVEL_INFO,SyslogUtility.newString(this.syslog.getConfig(),message),sre);
|
this.syslog.backLog(SyslogConstants.LEVEL_INFO, SyslogUtility.newString(this.syslog.getConfig(), message), sre);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SyslogUtility.sleep(this.syslogConfig.getThreadLoopInterval());
|
SyslogUtility.sleep(this.syslogConfig.getThreadLoopInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
runCompleted();
|
runCompleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,32 +5,32 @@ import org.graylog2.syslog4j.SyslogIF;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslogBackLogHandler is an implementation of SyslogBackLogHandlerIF
|
* AbstractSyslogBackLogHandler is an implementation of SyslogBackLogHandlerIF
|
||||||
* that mainly provides the helpful "combine" method for handling the "reason"
|
* that mainly provides the helpful "combine" method for handling the "reason"
|
||||||
* why a BackLog has occurred.
|
* why a BackLog has occurred.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogBackLogHandler.java,v 1.1 2009/01/24 22:00:18 cvs Exp $
|
* @version $Id: AbstractSyslogBackLogHandler.java,v 1.1 2009/01/24 22:00:18 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslogBackLogHandler implements SyslogBackLogHandlerIF {
|
public abstract class AbstractSyslogBackLogHandler implements SyslogBackLogHandlerIF {
|
||||||
protected boolean appendReason = true;
|
protected boolean appendReason = true;
|
||||||
|
|
||||||
protected String combine(SyslogIF syslog, int level, String message, String reason) {
|
protected String combine(SyslogIF syslog, int level, String message, String reason) {
|
||||||
// Note: syslog is explicitly ignored by default
|
// Note: syslog is explicitly ignored by default
|
||||||
|
|
||||||
String _message = message != null ? message : "UNKNOWN";
|
String _message = message != null ? message : "UNKNOWN";
|
||||||
String _reason = reason != null ? reason : "UNKNOWN";
|
String _reason = reason != null ? reason : "UNKNOWN";
|
||||||
|
|
||||||
String combinedMessage = SyslogUtility.getLevelString(level) + " " + _message;
|
String combinedMessage = SyslogUtility.getLevelString(level) + " " + _message;
|
||||||
|
|
||||||
if (this.appendReason) {
|
if (this.appendReason) {
|
||||||
combinedMessage += " [" + _reason + "]";
|
combinedMessage += " [" + _reason + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
return combinedMessage;
|
return combinedMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,32 +4,32 @@ import org.graylog2.syslog4j.SyslogBackLogHandlerIF;
|
|||||||
import org.graylog2.syslog4j.SyslogIF;
|
import org.graylog2.syslog4j.SyslogIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NullSyslogBackLogHandler can be used if there's no need for a last-chance
|
* NullSyslogBackLogHandler can be used if there's no need for a last-chance
|
||||||
* logging mechanism whenever the Syslog protocol fails.
|
* logging mechanism whenever the Syslog protocol fails.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: NullSyslogBackLogHandler.java,v 1.2 2010/10/25 03:50:25 cvs Exp $
|
* @version $Id: NullSyslogBackLogHandler.java,v 1.2 2010/10/25 03:50:25 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class NullSyslogBackLogHandler implements SyslogBackLogHandlerIF {
|
public class NullSyslogBackLogHandler implements SyslogBackLogHandlerIF {
|
||||||
public static final NullSyslogBackLogHandler INSTANCE = new NullSyslogBackLogHandler();
|
public static final NullSyslogBackLogHandler INSTANCE = new NullSyslogBackLogHandler();
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public void down(SyslogIF syslog, String reason) {
|
public void down(SyslogIF syslog, String reason) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public void up(SyslogIF syslog) {
|
public void up(SyslogIF syslog) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(SyslogIF syslog, int level, String message, String reason) {
|
public void log(SyslogIF syslog, int level, String message, String reason) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,62 +6,62 @@ import org.graylog2.syslog4j.SyslogIF;
|
|||||||
import org.graylog2.syslog4j.SyslogRuntimeException;
|
import org.graylog2.syslog4j.SyslogRuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syslog4jBackLogHandler is used to send Syslog backLog messages to
|
* Syslog4jBackLogHandler is used to send Syslog backLog messages to
|
||||||
* another Syslog4j protocol whenever the main Syslog protocol fails.
|
* another Syslog4j protocol whenever the main Syslog protocol fails.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: Syslog4jBackLogHandler.java,v 1.1 2009/07/25 18:42:47 cvs Exp $
|
* @version $Id: Syslog4jBackLogHandler.java,v 1.1 2009/07/25 18:42:47 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class Syslog4jBackLogHandler extends AbstractSyslogBackLogHandler {
|
public class Syslog4jBackLogHandler extends AbstractSyslogBackLogHandler {
|
||||||
protected SyslogIF syslog = null;
|
protected SyslogIF syslog = null;
|
||||||
protected int downLevel = SyslogConstants.LEVEL_WARN;
|
protected int downLevel = SyslogConstants.LEVEL_WARN;
|
||||||
protected int upLevel = SyslogConstants.LEVEL_WARN;
|
protected int upLevel = SyslogConstants.LEVEL_WARN;
|
||||||
|
|
||||||
public Syslog4jBackLogHandler(String protocol) {
|
public Syslog4jBackLogHandler(String protocol) {
|
||||||
this.syslog = Syslog.getInstance(protocol);
|
this.syslog = Syslog.getInstance(protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Syslog4jBackLogHandler(String protocol, boolean appendReason) {
|
public Syslog4jBackLogHandler(String protocol, boolean appendReason) {
|
||||||
this.syslog = Syslog.getInstance(protocol);
|
this.syslog = Syslog.getInstance(protocol);
|
||||||
this.appendReason = appendReason;
|
this.appendReason = appendReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Syslog4jBackLogHandler(SyslogIF syslog) {
|
public Syslog4jBackLogHandler(SyslogIF syslog) {
|
||||||
this.syslog = syslog;
|
this.syslog = syslog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Syslog4jBackLogHandler(SyslogIF syslog, boolean appendReason) {
|
public Syslog4jBackLogHandler(SyslogIF syslog, boolean appendReason) {
|
||||||
this.syslog = syslog;
|
this.syslog = syslog;
|
||||||
this.appendReason = appendReason;
|
this.appendReason = appendReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(SyslogIF syslog, int level, String message, String reason) throws SyslogRuntimeException {
|
public void log(SyslogIF syslog, int level, String message, String reason) throws SyslogRuntimeException {
|
||||||
if (this.syslog.getProtocol().equals(syslog.getProtocol())) {
|
if (this.syslog.getProtocol().equals(syslog.getProtocol())) {
|
||||||
throw new SyslogRuntimeException("Ignoring this log entry since the backLog protocol \"" + this.syslog.getProtocol() + "\" is the same as the main protocol");
|
throw new SyslogRuntimeException("Ignoring this log entry since the backLog protocol \"" + this.syslog.getProtocol() + "\" is the same as the main protocol");
|
||||||
}
|
}
|
||||||
|
|
||||||
String combinedMessage = combine(syslog,level,message,reason);
|
String combinedMessage = combine(syslog, level, message, reason);
|
||||||
|
|
||||||
this.syslog.log(level,combinedMessage);
|
this.syslog.log(level, combinedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void down(SyslogIF syslog, String reason) {
|
public void down(SyslogIF syslog, String reason) {
|
||||||
if (!this.syslog.getProtocol().equals(syslog.getProtocol())) {
|
if (!this.syslog.getProtocol().equals(syslog.getProtocol())) {
|
||||||
this.syslog.log(this.downLevel,"Syslog protocol \"" + syslog.getProtocol() + "\" is down: " + reason);
|
this.syslog.log(this.downLevel, "Syslog protocol \"" + syslog.getProtocol() + "\" is down: " + reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void up(SyslogIF syslog) {
|
public void up(SyslogIF syslog) {
|
||||||
if (!this.syslog.getProtocol().equals(syslog.getProtocol())) {
|
if (!this.syslog.getProtocol().equals(syslog.getProtocol())) {
|
||||||
this.syslog.log(this.downLevel,"Syslog protocol \"" + syslog.getProtocol() + "\" is up");
|
this.syslog.log(this.downLevel, "Syslog protocol \"" + syslog.getProtocol() + "\" is up");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,140 +9,148 @@ import org.graylog2.syslog4j.SyslogRuntimeException;
|
|||||||
import org.graylog2.syslog4j.impl.backlog.AbstractSyslogBackLogHandler;
|
import org.graylog2.syslog4j.impl.backlog.AbstractSyslogBackLogHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log4jSyslogBackLogHandler is used to send Syslog backLog messages to
|
* Log4jSyslogBackLogHandler is used to send Syslog backLog messages to
|
||||||
* Log4j whenever the Syslog protocol fails.
|
* Log4j whenever the Syslog protocol fails.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: Log4jSyslogBackLogHandler.java,v 1.2 2009/07/22 15:54:23 cvs Exp $
|
* @version $Id: Log4jSyslogBackLogHandler.java,v 1.2 2009/07/22 15:54:23 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class Log4jSyslogBackLogHandler extends AbstractSyslogBackLogHandler {
|
public class Log4jSyslogBackLogHandler extends AbstractSyslogBackLogHandler {
|
||||||
protected Logger logger = null;
|
protected Logger logger = null;
|
||||||
protected Level downLevel = Level.WARN;
|
protected Level downLevel = Level.WARN;
|
||||||
protected Level upLevel = Level.WARN;
|
protected Level upLevel = Level.WARN;
|
||||||
|
|
||||||
public Log4jSyslogBackLogHandler(Logger logger) throws SyslogRuntimeException {
|
public Log4jSyslogBackLogHandler(Logger logger) throws SyslogRuntimeException {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log4jSyslogBackLogHandler(Logger logger, boolean appendReason) {
|
public Log4jSyslogBackLogHandler(Logger logger, boolean appendReason) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.appendReason = appendReason;
|
this.appendReason = appendReason;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log4jSyslogBackLogHandler(Class loggerClass) {
|
public Log4jSyslogBackLogHandler(Class loggerClass) {
|
||||||
if (loggerClass == null) {
|
if (loggerClass == null) {
|
||||||
throw new SyslogRuntimeException("loggerClass cannot be null");
|
throw new SyslogRuntimeException("loggerClass cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger = Logger.getLogger(loggerClass);
|
this.logger = Logger.getLogger(loggerClass);
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log4jSyslogBackLogHandler(Class loggerClass, boolean appendReason) {
|
public Log4jSyslogBackLogHandler(Class loggerClass, boolean appendReason) {
|
||||||
if (loggerClass == null) {
|
if (loggerClass == null) {
|
||||||
throw new SyslogRuntimeException("loggerClass cannot be null");
|
throw new SyslogRuntimeException("loggerClass cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger = Logger.getLogger(loggerClass);
|
this.logger = Logger.getLogger(loggerClass);
|
||||||
this.appendReason = appendReason;
|
this.appendReason = appendReason;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log4jSyslogBackLogHandler(String loggerName) {
|
public Log4jSyslogBackLogHandler(String loggerName) {
|
||||||
if (loggerName == null) {
|
if (loggerName == null) {
|
||||||
throw new SyslogRuntimeException("loggerName cannot be null");
|
throw new SyslogRuntimeException("loggerName cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger = Logger.getLogger(loggerName);
|
this.logger = Logger.getLogger(loggerName);
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log4jSyslogBackLogHandler(String loggerName, boolean appendReason) {
|
public Log4jSyslogBackLogHandler(String loggerName, boolean appendReason) {
|
||||||
if (loggerName == null) {
|
if (loggerName == null) {
|
||||||
throw new SyslogRuntimeException("loggerName cannot be null");
|
throw new SyslogRuntimeException("loggerName cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger = Logger.getLogger(loggerName);
|
this.logger = Logger.getLogger(loggerName);
|
||||||
this.appendReason = appendReason;
|
this.appendReason = appendReason;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log4jSyslogBackLogHandler(String loggerName, LoggerFactory loggerFactory) {
|
public Log4jSyslogBackLogHandler(String loggerName, LoggerFactory loggerFactory) {
|
||||||
if (loggerName == null) {
|
if (loggerName == null) {
|
||||||
throw new SyslogRuntimeException("loggerName cannot be null");
|
throw new SyslogRuntimeException("loggerName cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loggerFactory == null) {
|
if (loggerFactory == null) {
|
||||||
throw new SyslogRuntimeException("loggerFactory cannot be null");
|
throw new SyslogRuntimeException("loggerFactory cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger = Logger.getLogger(loggerName,loggerFactory);
|
this.logger = Logger.getLogger(loggerName, loggerFactory);
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log4jSyslogBackLogHandler(String loggerName, LoggerFactory loggerFactory, boolean appendReason) {
|
public Log4jSyslogBackLogHandler(String loggerName, LoggerFactory loggerFactory, boolean appendReason) {
|
||||||
if (loggerName == null) {
|
if (loggerName == null) {
|
||||||
throw new SyslogRuntimeException("loggerName cannot be null");
|
throw new SyslogRuntimeException("loggerName cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loggerFactory == null) {
|
if (loggerFactory == null) {
|
||||||
throw new SyslogRuntimeException("loggerFactory cannot be null");
|
throw new SyslogRuntimeException("loggerFactory cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger = Logger.getLogger(loggerName,loggerFactory);
|
this.logger = Logger.getLogger(loggerName, loggerFactory);
|
||||||
this.appendReason = appendReason;
|
this.appendReason = appendReason;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
if (this.logger == null) {
|
if (this.logger == null) {
|
||||||
throw new SyslogRuntimeException("logger cannot be null");
|
throw new SyslogRuntimeException("logger cannot be null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Level getLog4jLevel(int level) {
|
protected static Level getLog4jLevel(int level) {
|
||||||
switch(level) {
|
switch (level) {
|
||||||
case SyslogConstants.LEVEL_DEBUG: return Level.DEBUG;
|
case SyslogConstants.LEVEL_DEBUG:
|
||||||
case SyslogConstants.LEVEL_INFO: return Level.INFO;
|
return Level.DEBUG;
|
||||||
case SyslogConstants.LEVEL_NOTICE: return Level.INFO;
|
case SyslogConstants.LEVEL_INFO:
|
||||||
case SyslogConstants.LEVEL_WARN: return Level.WARN;
|
return Level.INFO;
|
||||||
case SyslogConstants.LEVEL_ERROR: return Level.ERROR;
|
case SyslogConstants.LEVEL_NOTICE:
|
||||||
case SyslogConstants.LEVEL_CRITICAL: return Level.ERROR;
|
return Level.INFO;
|
||||||
case SyslogConstants.LEVEL_ALERT: return Level.ERROR;
|
case SyslogConstants.LEVEL_WARN:
|
||||||
case SyslogConstants.LEVEL_EMERGENCY: return Level.FATAL;
|
return Level.WARN;
|
||||||
|
case SyslogConstants.LEVEL_ERROR:
|
||||||
|
return Level.ERROR;
|
||||||
|
case SyslogConstants.LEVEL_CRITICAL:
|
||||||
|
return Level.ERROR;
|
||||||
|
case SyslogConstants.LEVEL_ALERT:
|
||||||
|
return Level.ERROR;
|
||||||
|
case SyslogConstants.LEVEL_EMERGENCY:
|
||||||
|
return Level.FATAL;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return Level.WARN;
|
return Level.WARN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void down(SyslogIF syslog, String reason) {
|
public void down(SyslogIF syslog, String reason) {
|
||||||
this.logger.log(this.downLevel,"Syslog protocol \"" + syslog.getProtocol() + "\" is down: " + reason);
|
this.logger.log(this.downLevel, "Syslog protocol \"" + syslog.getProtocol() + "\" is down: " + reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void up(SyslogIF syslog) {
|
public void up(SyslogIF syslog) {
|
||||||
this.logger.log(this.upLevel,"Syslog protocol \"" + syslog.getProtocol() + "\" is up");
|
this.logger.log(this.upLevel, "Syslog protocol \"" + syslog.getProtocol() + "\" is up");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(SyslogIF syslog, int level, String message, String reason) throws SyslogRuntimeException {
|
public void log(SyslogIF syslog, int level, String message, String reason) throws SyslogRuntimeException {
|
||||||
Level log4jLevel = getLog4jLevel(level);
|
Level log4jLevel = getLog4jLevel(level);
|
||||||
|
|
||||||
String combinedMessage = combine(syslog,level,message,reason);
|
String combinedMessage = combine(syslog, level, message, reason);
|
||||||
|
|
||||||
this.logger.log(log4jLevel,combinedMessage);
|
this.logger.log(log4jLevel, combinedMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,63 +7,63 @@ import org.graylog2.syslog4j.SyslogRuntimeException;
|
|||||||
import org.graylog2.syslog4j.impl.backlog.AbstractSyslogBackLogHandler;
|
import org.graylog2.syslog4j.impl.backlog.AbstractSyslogBackLogHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PrintStreamSyslogBackLogHandler provides a last-chance mechanism to log messages that fail
|
* PrintStreamSyslogBackLogHandler provides a last-chance mechanism to log messages that fail
|
||||||
* (for whatever reason) within the rest of Syslog to a PrintStream.
|
* (for whatever reason) within the rest of Syslog to a PrintStream.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: PrintStreamSyslogBackLogHandler.java,v 1.1 2009/01/24 22:00:18 cvs Exp $
|
* @version $Id: PrintStreamSyslogBackLogHandler.java,v 1.1 2009/01/24 22:00:18 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class PrintStreamSyslogBackLogHandler extends AbstractSyslogBackLogHandler {
|
public class PrintStreamSyslogBackLogHandler extends AbstractSyslogBackLogHandler {
|
||||||
protected PrintStream printStream = null;
|
protected PrintStream printStream = null;
|
||||||
protected boolean appendLinefeed = false;
|
protected boolean appendLinefeed = false;
|
||||||
|
|
||||||
public PrintStreamSyslogBackLogHandler(PrintStream printStream) {
|
public PrintStreamSyslogBackLogHandler(PrintStream printStream) {
|
||||||
this.printStream = printStream;
|
this.printStream = printStream;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrintStreamSyslogBackLogHandler(PrintStream printStream, boolean appendLinefeed) {
|
public PrintStreamSyslogBackLogHandler(PrintStream printStream, boolean appendLinefeed) {
|
||||||
this.printStream = printStream;
|
this.printStream = printStream;
|
||||||
this.appendLinefeed = appendLinefeed;
|
this.appendLinefeed = appendLinefeed;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrintStreamSyslogBackLogHandler(PrintStream printStream, boolean appendLinefeed, boolean appendReason) {
|
public PrintStreamSyslogBackLogHandler(PrintStream printStream, boolean appendLinefeed, boolean appendReason) {
|
||||||
this.printStream = printStream;
|
this.printStream = printStream;
|
||||||
this.appendLinefeed = appendLinefeed;
|
this.appendLinefeed = appendLinefeed;
|
||||||
this.appendReason = appendReason;
|
this.appendReason = appendReason;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
if (this.printStream == null) {
|
if (this.printStream == null) {
|
||||||
throw new SyslogRuntimeException("PrintStream cannot be null");
|
throw new SyslogRuntimeException("PrintStream cannot be null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void down(SyslogIF syslog, String reason) {
|
public void down(SyslogIF syslog, String reason) {
|
||||||
this.printStream.println(syslog.getProtocol() + ": DOWN" + (reason != null && !"".equals(reason.trim()) ? " (" + reason + ")" : ""));
|
this.printStream.println(syslog.getProtocol() + ": DOWN" + (reason != null && !"".equals(reason.trim()) ? " (" + reason + ")" : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void up(SyslogIF syslog) {
|
public void up(SyslogIF syslog) {
|
||||||
this.printStream.println(syslog.getProtocol() + ": UP");
|
this.printStream.println(syslog.getProtocol() + ": UP");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(SyslogIF syslog, int level, String message, String reason) {
|
public void log(SyslogIF syslog, int level, String message, String reason) {
|
||||||
String combinedMessage = combine(syslog,level,message,reason);
|
String combinedMessage = combine(syslog, level, message, reason);
|
||||||
|
|
||||||
if (this.appendLinefeed) {
|
if (this.appendLinefeed) {
|
||||||
this.printStream.println(combinedMessage);
|
this.printStream.println(combinedMessage);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.printStream.print(combinedMessage);
|
this.printStream.print(combinedMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,25 +3,26 @@ package org.graylog2.syslog4j.impl.backlog.printstream;
|
|||||||
import org.graylog2.syslog4j.SyslogBackLogHandlerIF;
|
import org.graylog2.syslog4j.SyslogBackLogHandlerIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SystemErrSyslogBackLogHandler provides a last-chance mechanism to log messages that fail
|
* SystemErrSyslogBackLogHandler provides a last-chance mechanism to log messages that fail
|
||||||
* (for whatever reason) within the rest of Syslog to System.err.
|
* (for whatever reason) within the rest of Syslog to System.err.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SystemErrSyslogBackLogHandler.java,v 1.2 2009/03/29 17:38:59 cvs Exp $
|
* @version $Id: SystemErrSyslogBackLogHandler.java,v 1.2 2009/03/29 17:38:59 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SystemErrSyslogBackLogHandler extends PrintStreamSyslogBackLogHandler {
|
public class SystemErrSyslogBackLogHandler extends PrintStreamSyslogBackLogHandler {
|
||||||
public static final SyslogBackLogHandlerIF create() {
|
public static final SyslogBackLogHandlerIF create() {
|
||||||
return new SystemErrSyslogBackLogHandler();
|
return new SystemErrSyslogBackLogHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SystemErrSyslogBackLogHandler() {
|
public SystemErrSyslogBackLogHandler() {
|
||||||
super(System.err,true);
|
super(System.err, true);
|
||||||
}
|
}
|
||||||
public SystemErrSyslogBackLogHandler(boolean appendReason) {
|
|
||||||
super(System.err,true,appendReason);
|
public SystemErrSyslogBackLogHandler(boolean appendReason) {
|
||||||
}
|
super(System.err, true, appendReason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,25 +3,26 @@ package org.graylog2.syslog4j.impl.backlog.printstream;
|
|||||||
import org.graylog2.syslog4j.SyslogBackLogHandlerIF;
|
import org.graylog2.syslog4j.SyslogBackLogHandlerIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SystemOutSyslogBackLogHandler provides a last-chance mechanism to log messages that fail
|
* SystemOutSyslogBackLogHandler provides a last-chance mechanism to log messages that fail
|
||||||
* (for whatever reason) within the rest of Syslog to System.out.
|
* (for whatever reason) within the rest of Syslog to System.out.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SystemOutSyslogBackLogHandler.java,v 1.2 2009/03/29 17:38:59 cvs Exp $
|
* @version $Id: SystemOutSyslogBackLogHandler.java,v 1.2 2009/03/29 17:38:59 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SystemOutSyslogBackLogHandler extends PrintStreamSyslogBackLogHandler {
|
public class SystemOutSyslogBackLogHandler extends PrintStreamSyslogBackLogHandler {
|
||||||
public static final SyslogBackLogHandlerIF create() {
|
public static final SyslogBackLogHandlerIF create() {
|
||||||
return new SystemOutSyslogBackLogHandler();
|
return new SystemOutSyslogBackLogHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SystemOutSyslogBackLogHandler() {
|
public SystemOutSyslogBackLogHandler() {
|
||||||
super(System.out,true);
|
super(System.out, true);
|
||||||
}
|
}
|
||||||
public SystemOutSyslogBackLogHandler(boolean appendReason) {
|
|
||||||
super(System.out,true,appendReason);
|
public SystemOutSyslogBackLogHandler(boolean appendReason) {
|
||||||
}
|
super(System.out, true, appendReason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,45 +4,45 @@ import org.apache.log4j.helpers.LogLog;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Syslog4jAppender provides a Log4j Appender wrapper for Syslog4j.
|
* Syslog4jAppender provides a Log4j Appender wrapper for Syslog4j.
|
||||||
*
|
* <p/>
|
||||||
* <p>Note: Syslog4jAppender does NOT extend Log4j's SyslogAppender.</p>
|
* <p>Note: Syslog4jAppender does NOT extend Log4j's SyslogAppender.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Example log4j.xml configuration:</p>
|
* <p>Example log4j.xml configuration:</p>
|
||||||
*
|
* <p/>
|
||||||
* <pre>
|
* <pre>
|
||||||
* <code>
|
* <code>
|
||||||
<appender name="Syslog4j" class="org.graylog2.syslog4j.impl.log4j.Syslog4jAppender">
|
* <appender name="Syslog4j" class="org.graylog2.syslog4j.impl.log4j.Syslog4jAppender">
|
||||||
<param name="Facility" value="user"/>
|
* <param name="Facility" value="user"/>
|
||||||
<param name="Protocol" value="tcp"/>
|
* <param name="Protocol" value="tcp"/>
|
||||||
<param name="Host" value="192.168.0.1"/>
|
* <param name="Host" value="192.168.0.1"/>
|
||||||
<layout class="org.apache.log4j.PatternLayout">
|
* <layout class="org.apache.log4j.PatternLayout">
|
||||||
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m"/>
|
* <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m"/>
|
||||||
</layout>
|
* </layout>
|
||||||
</appender>
|
* </appender>
|
||||||
* </code>
|
* </code>
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
* <p/>
|
||||||
* <p>All available parameters are:</p>
|
* <p>All available parameters are:</p>
|
||||||
*
|
* <p/>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>ident</li>
|
* <li>ident</li>
|
||||||
* <li>localName</li>
|
* <li>localName</li>
|
||||||
* <li>protocol</li>
|
* <li>protocol</li>
|
||||||
* <li>facility</li>
|
* <li>facility</li>
|
||||||
* <li>host</li>
|
* <li>host</li>
|
||||||
* <li>port</li>
|
* <li>port</li>
|
||||||
* <li>charSet</li>
|
* <li>charSet</li>
|
||||||
* <li>threaded</li>
|
* <li>threaded</li>
|
||||||
* <li>threadLoopInterval</li>
|
* <li>threadLoopInterval</li>
|
||||||
* <li>splitMessageBeginText</li>
|
* <li>splitMessageBeginText</li>
|
||||||
* <li>splitMessageEndText</li>
|
* <li>splitMessageEndText</li>
|
||||||
* <li>maxMessageLength</li>
|
* <li>maxMessageLength</li>
|
||||||
* <li>maxShutdownWait</li>
|
* <li>maxShutdownWait</li>
|
||||||
* <li>writeRetries</li>
|
* <li>writeRetries</li>
|
||||||
* <li>truncateMessage</li>
|
* <li>truncateMessage</li>
|
||||||
* <li>useStructuredData</li>
|
* <li>useStructuredData</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
@ -51,29 +51,29 @@ import org.apache.log4j.helpers.LogLog;
|
|||||||
* @version $Id: Syslog4jAppender.java,v 1.2 2011/01/23 20:49:12 cvs Exp $
|
* @version $Id: Syslog4jAppender.java,v 1.2 2011/01/23 20:49:12 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class Syslog4jAppender extends Syslog4jAppenderSkeleton {
|
public class Syslog4jAppender extends Syslog4jAppenderSkeleton {
|
||||||
private static final long serialVersionUID = -6072552977605816670L;
|
private static final long serialVersionUID = -6072552977605816670L;
|
||||||
|
|
||||||
public String initialize() {
|
public String initialize() {
|
||||||
if (this.protocol == null) {
|
if (this.protocol == null) {
|
||||||
this.protocol = UDP;
|
this.protocol = UDP;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.protocol;
|
return this.protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getHeader() {
|
public boolean getHeader() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeader(boolean header) {
|
public void setHeader(boolean header) {
|
||||||
LogLog.warn("Syslog4jAppender ignores the \"Header\" parameter.");
|
LogLog.warn("Syslog4jAppender ignores the \"Header\" parameter.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSyslogHost() {
|
public String getSyslogHost() {
|
||||||
return this.host;
|
return this.host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSyslogHost(String host) {
|
public void setSyslogHost(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,10 @@ import org.graylog2.syslog4j.util.SyslogUtility;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Syslog4jAppenderSkeleton provides an extensible Log4j Appender wrapper for Syslog4j.
|
* Syslog4jAppenderSkeleton provides an extensible Log4j Appender wrapper for Syslog4j.
|
||||||
*
|
* <p/>
|
||||||
* <p>Classes which inherit Syslog4jAppenderSkeleton must implement the "initialize()" method,
|
* <p>Classes which inherit Syslog4jAppenderSkeleton must implement the "initialize()" method,
|
||||||
* which sets up Syslog4j for use by the Log4j Appender.</p>
|
* which sets up Syslog4j for use by the Log4j Appender.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
@ -24,308 +24,308 @@ import org.graylog2.syslog4j.util.SyslogUtility;
|
|||||||
* @version $Id: Syslog4jAppenderSkeleton.java,v 1.8 2011/01/23 20:49:12 cvs Exp $
|
* @version $Id: Syslog4jAppenderSkeleton.java,v 1.8 2011/01/23 20:49:12 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class Syslog4jAppenderSkeleton extends AppenderSkeleton implements SyslogConstants {
|
public abstract class Syslog4jAppenderSkeleton extends AppenderSkeleton implements SyslogConstants {
|
||||||
private static final long serialVersionUID = 5520555788232095628L;
|
private static final long serialVersionUID = 5520555788232095628L;
|
||||||
|
|
||||||
protected SyslogIF syslog = null;
|
protected SyslogIF syslog = null;
|
||||||
|
|
||||||
protected String ident = null;
|
protected String ident = null;
|
||||||
protected String localName = null;
|
protected String localName = null;
|
||||||
protected String protocol = null;
|
protected String protocol = null;
|
||||||
protected String facility = null;
|
protected String facility = null;
|
||||||
protected String host = null;
|
protected String host = null;
|
||||||
protected String port = null;
|
protected String port = null;
|
||||||
protected String charSet = null;
|
protected String charSet = null;
|
||||||
protected String threaded = null;
|
protected String threaded = null;
|
||||||
protected String threadLoopInterval = null;
|
protected String threadLoopInterval = null;
|
||||||
protected String splitMessageBeginText = null;
|
protected String splitMessageBeginText = null;
|
||||||
protected String splitMessageEndText = null;
|
protected String splitMessageEndText = null;
|
||||||
protected String maxMessageLength = null;
|
protected String maxMessageLength = null;
|
||||||
protected String maxShutdownWait = null;
|
protected String maxShutdownWait = null;
|
||||||
protected String writeRetries = null;
|
protected String writeRetries = null;
|
||||||
protected String truncateMessage = null;
|
protected String truncateMessage = null;
|
||||||
protected String useStructuredData = null;
|
protected String useStructuredData = null;
|
||||||
|
|
||||||
protected boolean initialized = false;
|
protected boolean initialized = false;
|
||||||
|
|
||||||
public abstract String initialize() throws SyslogRuntimeException;
|
public abstract String initialize() throws SyslogRuntimeException;
|
||||||
|
|
||||||
protected static boolean isTrueOrOn(String value) {
|
protected static boolean isTrueOrOn(String value) {
|
||||||
boolean trueOrOn = false;
|
boolean trueOrOn = false;
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if ("true".equalsIgnoreCase(value.trim()) || "on".equalsIgnoreCase(value.trim())) {
|
if ("true".equalsIgnoreCase(value.trim()) || "on".equalsIgnoreCase(value.trim())) {
|
||||||
trueOrOn = true;
|
trueOrOn = true;
|
||||||
|
|
||||||
} else if ("false".equalsIgnoreCase(value.trim()) || "off".equalsIgnoreCase(value.trim())) {
|
} else if ("false".equalsIgnoreCase(value.trim()) || "off".equalsIgnoreCase(value.trim())) {
|
||||||
trueOrOn = false;
|
trueOrOn = false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LogLog.error("Value \"" + value + "\" not true, on, false, or off -- assuming false");
|
LogLog.error("Value \"" + value + "\" not true, on, false, or off -- assuming false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return trueOrOn;
|
return trueOrOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void _initialize() {
|
protected void _initialize() {
|
||||||
String initializedProtocol = initialize();
|
String initializedProtocol = initialize();
|
||||||
|
|
||||||
if (initializedProtocol != null && this.protocol == null) {
|
if (initializedProtocol != null && this.protocol == null) {
|
||||||
this.protocol = initializedProtocol;
|
this.protocol = initializedProtocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.protocol != null) {
|
if (this.protocol != null) {
|
||||||
try {
|
try {
|
||||||
this.syslog = Syslog.getInstance(this.protocol);
|
this.syslog = Syslog.getInstance(this.protocol);
|
||||||
if (this.host != null) {
|
if (this.host != null) {
|
||||||
this.syslog.getConfig().setHost(this.host);
|
this.syslog.getConfig().setHost(this.host);
|
||||||
}
|
}
|
||||||
if (this.facility != null) {
|
if (this.facility != null) {
|
||||||
this.syslog.getConfig().setFacility(SyslogUtility.getFacility(this.facility));
|
this.syslog.getConfig().setFacility(SyslogUtility.getFacility(this.facility));
|
||||||
}
|
}
|
||||||
if (this.port != null) {
|
if (this.port != null) {
|
||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(this.port);
|
int i = Integer.parseInt(this.port);
|
||||||
this.syslog.getConfig().setPort(i);
|
this.syslog.getConfig().setPort(i);
|
||||||
|
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
LogLog.error(nfe.toString());
|
LogLog.error(nfe.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.charSet != null) {
|
if (this.charSet != null) {
|
||||||
this.syslog.getConfig().setCharSet(this.charSet);
|
this.syslog.getConfig().setCharSet(this.charSet);
|
||||||
}
|
}
|
||||||
if (this.ident != null) {
|
if (this.ident != null) {
|
||||||
this.syslog.getConfig().setIdent(this.ident);
|
this.syslog.getConfig().setIdent(this.ident);
|
||||||
}
|
}
|
||||||
if (this.localName != null) {
|
if (this.localName != null) {
|
||||||
this.syslog.getConfig().setLocalName(this.localName);
|
this.syslog.getConfig().setLocalName(this.localName);
|
||||||
}
|
}
|
||||||
if (this.truncateMessage != null && !"".equals(this.truncateMessage.trim())) {
|
if (this.truncateMessage != null && !"".equals(this.truncateMessage.trim())) {
|
||||||
this.syslog.getConfig().setTruncateMessage(isTrueOrOn(this.truncateMessage));
|
this.syslog.getConfig().setTruncateMessage(isTrueOrOn(this.truncateMessage));
|
||||||
}
|
}
|
||||||
if (this.maxMessageLength != null && this.maxMessageLength.length() > 0) {
|
if (this.maxMessageLength != null && this.maxMessageLength.length() > 0) {
|
||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(this.maxMessageLength.trim());
|
int i = Integer.parseInt(this.maxMessageLength.trim());
|
||||||
this.syslog.getConfig().setMaxMessageLength(i);
|
this.syslog.getConfig().setMaxMessageLength(i);
|
||||||
|
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
LogLog.error(nfe.toString());
|
LogLog.error(nfe.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.useStructuredData != null) {
|
if (this.useStructuredData != null) {
|
||||||
this.syslog.getConfig().setUseStructuredData(isTrueOrOn(this.useStructuredData));
|
this.syslog.getConfig().setUseStructuredData(isTrueOrOn(this.useStructuredData));
|
||||||
}
|
}
|
||||||
if (this.syslog.getConfig() instanceof AbstractSyslogConfigIF) {
|
if (this.syslog.getConfig() instanceof AbstractSyslogConfigIF) {
|
||||||
AbstractSyslogConfigIF abstractSyslogConfig = (AbstractSyslogConfigIF) this.syslog.getConfig();
|
AbstractSyslogConfigIF abstractSyslogConfig = (AbstractSyslogConfigIF) this.syslog.getConfig();
|
||||||
|
|
||||||
if (this.threaded != null && !"".equals(this.threaded.trim())) {
|
if (this.threaded != null && !"".equals(this.threaded.trim())) {
|
||||||
abstractSyslogConfig.setThreaded(isTrueOrOn(this.threaded));
|
abstractSyslogConfig.setThreaded(isTrueOrOn(this.threaded));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.threadLoopInterval != null && this.threadLoopInterval.length() > 0) {
|
if (this.threadLoopInterval != null && this.threadLoopInterval.length() > 0) {
|
||||||
try {
|
try {
|
||||||
long l = Long.parseLong(this.threadLoopInterval.trim());
|
long l = Long.parseLong(this.threadLoopInterval.trim());
|
||||||
abstractSyslogConfig.setThreadLoopInterval(l);
|
abstractSyslogConfig.setThreadLoopInterval(l);
|
||||||
|
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
LogLog.error(nfe.toString());
|
LogLog.error(nfe.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.splitMessageBeginText != null) {
|
if (this.splitMessageBeginText != null) {
|
||||||
abstractSyslogConfig.setSplitMessageBeginText(SyslogUtility.getBytes(abstractSyslogConfig,this.splitMessageBeginText));
|
abstractSyslogConfig.setSplitMessageBeginText(SyslogUtility.getBytes(abstractSyslogConfig, this.splitMessageBeginText));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.splitMessageEndText != null) {
|
if (this.splitMessageEndText != null) {
|
||||||
abstractSyslogConfig.setSplitMessageEndText(SyslogUtility.getBytes(abstractSyslogConfig,this.splitMessageEndText));
|
abstractSyslogConfig.setSplitMessageEndText(SyslogUtility.getBytes(abstractSyslogConfig, this.splitMessageEndText));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.maxShutdownWait != null && this.maxShutdownWait.length() > 0) {
|
if (this.maxShutdownWait != null && this.maxShutdownWait.length() > 0) {
|
||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(this.maxShutdownWait.trim());
|
int i = Integer.parseInt(this.maxShutdownWait.trim());
|
||||||
abstractSyslogConfig.setMaxShutdownWait(i);
|
abstractSyslogConfig.setMaxShutdownWait(i);
|
||||||
|
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
LogLog.error(nfe.toString());
|
LogLog.error(nfe.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.writeRetries != null && this.writeRetries.length() > 0) {
|
if (this.writeRetries != null && this.writeRetries.length() > 0) {
|
||||||
try {
|
try {
|
||||||
int i = Integer.parseInt(this.writeRetries.trim());
|
int i = Integer.parseInt(this.writeRetries.trim());
|
||||||
abstractSyslogConfig.setWriteRetries(i);
|
abstractSyslogConfig.setWriteRetries(i);
|
||||||
|
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
LogLog.error(nfe.toString());
|
LogLog.error(nfe.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
|
|
||||||
} catch (SyslogRuntimeException sre) {
|
} catch (SyslogRuntimeException sre) {
|
||||||
LogLog.error(sre.toString());
|
LogLog.error(sre.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProtocol() {
|
public String getProtocol() {
|
||||||
return this.protocol;
|
return this.protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProtocol(String protocol) {
|
public void setProtocol(String protocol) {
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void append(LoggingEvent event) {
|
protected void append(LoggingEvent event) {
|
||||||
if (!this.initialized) {
|
if (!this.initialized) {
|
||||||
_initialize();
|
_initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.initialized) {
|
if (this.initialized) {
|
||||||
int level = event.getLevel().getSyslogEquivalent();
|
int level = event.getLevel().getSyslogEquivalent();
|
||||||
|
|
||||||
if (this.layout != null) {
|
if (this.layout != null) {
|
||||||
String message = this.layout.format(event);
|
String message = this.layout.format(event);
|
||||||
|
|
||||||
this.syslog.log(level,message);
|
this.syslog.log(level, message);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String message = event.getRenderedMessage();
|
String message = event.getRenderedMessage();
|
||||||
|
|
||||||
this.syslog.log(level,message);
|
this.syslog.log(level, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (this.syslog != null) {
|
if (this.syslog != null) {
|
||||||
this.syslog.flush();
|
this.syslog.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFacility() {
|
public String getFacility() {
|
||||||
return this.facility;
|
return this.facility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacility(String facility) {
|
public void setFacility(String facility) {
|
||||||
this.facility = facility;
|
this.facility = facility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return this.host;
|
return this.host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) {
|
public void setHost(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocalName() {
|
public String getLocalName() {
|
||||||
return localName;
|
return localName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocalName(String localName) {
|
public void setLocalName(String localName) {
|
||||||
this.localName = localName;
|
this.localName = localName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPort() {
|
public String getPort() {
|
||||||
return this.port;
|
return this.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(String port) {
|
public void setPort(String port) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCharSet() {
|
public String getCharSet() {
|
||||||
return this.charSet;
|
return this.charSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCharSet(String charSet) {
|
public void setCharSet(String charSet) {
|
||||||
this.charSet = charSet;
|
this.charSet = charSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdent() {
|
public String getIdent() {
|
||||||
return this.ident;
|
return this.ident;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdent(String ident) {
|
public void setIdent(String ident) {
|
||||||
this.ident = ident;
|
this.ident = ident;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getThreaded() {
|
public String getThreaded() {
|
||||||
return this.threaded;
|
return this.threaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThreaded(String threaded) {
|
public void setThreaded(String threaded) {
|
||||||
this.threaded = threaded;
|
this.threaded = threaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requiresLayout() {
|
public boolean requiresLayout() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getThreadLoopInterval() {
|
public String getThreadLoopInterval() {
|
||||||
return this.threadLoopInterval;
|
return this.threadLoopInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThreadLoopInterval(String threadLoopInterval) {
|
public void setThreadLoopInterval(String threadLoopInterval) {
|
||||||
this.threadLoopInterval = threadLoopInterval;
|
this.threadLoopInterval = threadLoopInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSplitMessageBeginText() {
|
public String getSplitMessageBeginText() {
|
||||||
return this.splitMessageBeginText;
|
return this.splitMessageBeginText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSplitMessageBeginText(String splitMessageBeginText) {
|
public void setSplitMessageBeginText(String splitMessageBeginText) {
|
||||||
this.splitMessageBeginText = splitMessageBeginText;
|
this.splitMessageBeginText = splitMessageBeginText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSplitMessageEndText() {
|
public String getSplitMessageEndText() {
|
||||||
return this.splitMessageEndText;
|
return this.splitMessageEndText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSplitMessageEndText(String splitMessageEndText) {
|
public void setSplitMessageEndText(String splitMessageEndText) {
|
||||||
this.splitMessageEndText = splitMessageEndText;
|
this.splitMessageEndText = splitMessageEndText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMaxMessageLength() {
|
public String getMaxMessageLength() {
|
||||||
return this.maxMessageLength;
|
return this.maxMessageLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxMessageLength(String maxMessageLength) {
|
public void setMaxMessageLength(String maxMessageLength) {
|
||||||
this.maxMessageLength = maxMessageLength;
|
this.maxMessageLength = maxMessageLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMaxShutdownWait() {
|
public String getMaxShutdownWait() {
|
||||||
return this.maxShutdownWait;
|
return this.maxShutdownWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxShutdownWait(String maxShutdownWait) {
|
public void setMaxShutdownWait(String maxShutdownWait) {
|
||||||
this.maxShutdownWait = maxShutdownWait;
|
this.maxShutdownWait = maxShutdownWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWriteRetries() {
|
public String getWriteRetries() {
|
||||||
return this.writeRetries;
|
return this.writeRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWriteRetries(String writeRetries) {
|
public void setWriteRetries(String writeRetries) {
|
||||||
this.writeRetries = writeRetries;
|
this.writeRetries = writeRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTruncateMessage() {
|
public String getTruncateMessage() {
|
||||||
return this.truncateMessage;
|
return this.truncateMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTruncateMessage(String truncateMessage) {
|
public void setTruncateMessage(String truncateMessage) {
|
||||||
this.truncateMessage = truncateMessage;
|
this.truncateMessage = truncateMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUseStructuredData() {
|
public String getUseStructuredData() {
|
||||||
return useStructuredData;
|
return useStructuredData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseStructuredData(String useStructuredData) {
|
public void setUseStructuredData(String useStructuredData) {
|
||||||
this.useStructuredData = useStructuredData;
|
this.useStructuredData = useStructuredData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,94 +8,94 @@ import java.util.Date;
|
|||||||
import org.graylog2.syslog4j.SyslogMessageIF;
|
import org.graylog2.syslog4j.SyslogMessageIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslogMessage provides support for turning POJO (Plain Ol'
|
* AbstractSyslogMessage provides support for turning POJO (Plain Ol'
|
||||||
* Java Objects) into Syslog messages.
|
* Java Objects) into Syslog messages.
|
||||||
*
|
* <p/>
|
||||||
* <p>More information on the PCI DSS specification is available here:</p>
|
* <p>More information on the PCI DSS specification is available here:</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>https://www.pcisecuritystandards.org/security_standards/pci_dss.shtml</p>
|
* <p>https://www.pcisecuritystandards.org/security_standards/pci_dss.shtml</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogMessage.java,v 1.2 2009/04/17 02:37:04 cvs Exp $
|
* @version $Id: AbstractSyslogMessage.java,v 1.2 2009/04/17 02:37:04 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslogMessage implements SyslogMessageIF {
|
public abstract class AbstractSyslogMessage implements SyslogMessageIF {
|
||||||
private static final long serialVersionUID = 414124277626756491L;
|
private static final long serialVersionUID = 414124277626756491L;
|
||||||
|
|
||||||
public static final String UNDEFINED = "undefined";
|
public static final String UNDEFINED = "undefined";
|
||||||
|
|
||||||
public static final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd";
|
public static final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd";
|
||||||
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
|
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
|
||||||
|
|
||||||
public static final char DEFAULT_DELIMITER = ' ';
|
public static final char DEFAULT_DELIMITER = ' ';
|
||||||
public static final String DEFAULT_REPLACE_DELIMITER = "_";
|
public static final String DEFAULT_REPLACE_DELIMITER = "_";
|
||||||
|
|
||||||
protected char getDelimiter() {
|
protected char getDelimiter() {
|
||||||
return DEFAULT_DELIMITER;
|
return DEFAULT_DELIMITER;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getReplaceDelimiter() {
|
protected String getReplaceDelimiter() {
|
||||||
return DEFAULT_REPLACE_DELIMITER;
|
return DEFAULT_REPLACE_DELIMITER;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getDateFormat() {
|
protected String getDateFormat() {
|
||||||
return DEFAULT_DATE_FORMAT;
|
return DEFAULT_DATE_FORMAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getTimeFormat() {
|
protected String getTimeFormat() {
|
||||||
return DEFAULT_TIME_FORMAT;
|
return DEFAULT_TIME_FORMAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateDate() {
|
protected String generateDate() {
|
||||||
String date = new SimpleDateFormat(getDateFormat()).format(new Date());
|
String date = new SimpleDateFormat(getDateFormat()).format(new Date());
|
||||||
|
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateTime() {
|
protected String generateTime() {
|
||||||
String time = new SimpleDateFormat(getTimeFormat()).format(new Date());
|
String time = new SimpleDateFormat(getTimeFormat()).format(new Date());
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] generateDateAndTime(Date date) {
|
protected String[] generateDateAndTime(Date date) {
|
||||||
String[] dateAndTime = new String[2];
|
String[] dateAndTime = new String[2];
|
||||||
|
|
||||||
dateAndTime[0] = new SimpleDateFormat(getDateFormat()).format(date);
|
dateAndTime[0] = new SimpleDateFormat(getDateFormat()).format(date);
|
||||||
dateAndTime[1] = new SimpleDateFormat(getTimeFormat()).format(date);
|
dateAndTime[1] = new SimpleDateFormat(getTimeFormat()).format(date);
|
||||||
|
|
||||||
return dateAndTime;
|
return dateAndTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateLocalHostName() {
|
protected String generateLocalHostName() {
|
||||||
String localHostName = UNDEFINED;
|
String localHostName = UNDEFINED;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
localHostName = InetAddress.getLocalHost().getHostName();
|
localHostName = InetAddress.getLocalHost().getHostName();
|
||||||
|
|
||||||
} catch (UnknownHostException uhe) {
|
} catch (UnknownHostException uhe) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
return localHostName;
|
return localHostName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean nullOrEmpty(String value) {
|
protected boolean nullOrEmpty(String value) {
|
||||||
return (value == null || "".equals(value.trim()));
|
return (value == null || "".equals(value.trim()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String replaceDelimiter(String fieldName, String fieldValue, char delimiter, String replaceDelimiter) {
|
protected String replaceDelimiter(String fieldName, String fieldValue, char delimiter, String replaceDelimiter) {
|
||||||
if (replaceDelimiter == null || replaceDelimiter.length() < 1 || fieldValue == null || fieldValue.length() < 1) {
|
if (replaceDelimiter == null || replaceDelimiter.length() < 1 || fieldValue == null || fieldValue.length() < 1) {
|
||||||
return fieldValue;
|
return fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String newFieldValue = fieldValue.replaceAll("\\" + delimiter, replaceDelimiter);
|
String newFieldValue = fieldValue.replaceAll("\\" + delimiter, replaceDelimiter);
|
||||||
|
|
||||||
return newFieldValue;
|
return newFieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String createMessage();
|
public abstract String createMessage();
|
||||||
}
|
}
|
||||||
|
@ -4,60 +4,60 @@ import org.graylog2.syslog4j.SyslogMessageModifierConfigIF;
|
|||||||
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
||||||
|
|
||||||
public abstract class AbstractSyslogMessageModifier implements SyslogMessageModifierIF {
|
public abstract class AbstractSyslogMessageModifier implements SyslogMessageModifierIF {
|
||||||
private static final long serialVersionUID = 7632959170109372003L;
|
private static final long serialVersionUID = 7632959170109372003L;
|
||||||
|
|
||||||
protected SyslogMessageModifierConfigIF messageModifierConfig = null;
|
protected SyslogMessageModifierConfigIF messageModifierConfig = null;
|
||||||
|
|
||||||
public AbstractSyslogMessageModifier(SyslogMessageModifierConfigIF messageModifierConfig) {
|
public AbstractSyslogMessageModifier(SyslogMessageModifierConfigIF messageModifierConfig) {
|
||||||
this.messageModifierConfig = messageModifierConfig;
|
this.messageModifierConfig = messageModifierConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] parseInlineModifier(String message) {
|
public String[] parseInlineModifier(String message) {
|
||||||
return parseInlineModifier(message,this.messageModifierConfig.getPrefix(),this.messageModifierConfig.getSuffix());
|
return parseInlineModifier(message, this.messageModifierConfig.getPrefix(), this.messageModifierConfig.getSuffix());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] parseInlineModifier(String message, String prefix, String suffix) {
|
public static String[] parseInlineModifier(String message, String prefix, String suffix) {
|
||||||
String[] messageAndModifier = null;
|
String[] messageAndModifier = null;
|
||||||
|
|
||||||
if (message == null || "".equals(message.trim())) {
|
if (message == null || "".equals(message.trim())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefix == null || "".equals(prefix)) {
|
if (prefix == null || "".equals(prefix)) {
|
||||||
prefix = " ";
|
prefix = " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suffix == null || "".equals(suffix)) {
|
if (suffix == null || "".equals(suffix)) {
|
||||||
int pi = message.lastIndexOf(prefix);
|
int pi = message.lastIndexOf(prefix);
|
||||||
|
|
||||||
if (pi > -1) {
|
if (pi > -1) {
|
||||||
messageAndModifier = new String[] { message.substring(0,pi), message.substring(pi+prefix.length()) };
|
messageAndModifier = new String[]{message.substring(0, pi), message.substring(pi + prefix.length())};
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int si = message.lastIndexOf(suffix);
|
int si = message.lastIndexOf(suffix);
|
||||||
|
|
||||||
if (si > -1) {
|
if (si > -1) {
|
||||||
int pi = message.lastIndexOf(prefix,si);
|
int pi = message.lastIndexOf(prefix, si);
|
||||||
|
|
||||||
if (pi > -1) {
|
if (pi > -1) {
|
||||||
messageAndModifier = new String[] { message.substring(0,pi), message.substring(pi+prefix.length(),si) };
|
messageAndModifier = new String[]{message.substring(0, pi), message.substring(pi + prefix.length(), si)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return messageAndModifier;
|
return messageAndModifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean verify(String message, String modifier);
|
protected abstract boolean verify(String message, String modifier);
|
||||||
|
|
||||||
public boolean verify(String message) {
|
public boolean verify(String message) {
|
||||||
String[] messageAndModifier = parseInlineModifier(message);
|
String[] messageAndModifier = parseInlineModifier(message);
|
||||||
|
|
||||||
if (messageAndModifier == null || messageAndModifier.length != 2) {
|
if (messageAndModifier == null || messageAndModifier.length != 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return verify(messageAndModifier[0],messageAndModifier[1]);
|
return verify(messageAndModifier[0], messageAndModifier[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,54 +5,54 @@ import org.graylog2.syslog4j.SyslogConstants;
|
|||||||
import org.graylog2.syslog4j.SyslogMessageModifierConfigIF;
|
import org.graylog2.syslog4j.SyslogMessageModifierConfigIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslogMessageModifierConfig provides a base abstract implementation of the
|
* AbstractSyslogMessageModifierConfig provides a base abstract implementation of the
|
||||||
* SyslogMessageModifierConfigIF.
|
* SyslogMessageModifierConfigIF.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogMessageModifierConfig.java,v 1.4 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: AbstractSyslogMessageModifierConfig.java,v 1.4 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslogMessageModifierConfig implements SyslogMessageModifierConfigIF, SyslogCharSetIF {
|
public abstract class AbstractSyslogMessageModifierConfig implements SyslogMessageModifierConfigIF, SyslogCharSetIF {
|
||||||
private static final long serialVersionUID = 5036574188079124884L;
|
private static final long serialVersionUID = 5036574188079124884L;
|
||||||
|
|
||||||
protected String prefix = SYSLOG_MESSAGE_MODIFIER_PREFIX_DEFAULT;
|
protected String prefix = SYSLOG_MESSAGE_MODIFIER_PREFIX_DEFAULT;
|
||||||
protected String suffix = SYSLOG_MESSAGE_MODIFIER_SUFFIX_DEFAULT;
|
protected String suffix = SYSLOG_MESSAGE_MODIFIER_SUFFIX_DEFAULT;
|
||||||
protected String charSet = SyslogConstants.CHAR_SET_DEFAULT;
|
protected String charSet = SyslogConstants.CHAR_SET_DEFAULT;
|
||||||
|
|
||||||
public String getPrefix() {
|
public String getPrefix() {
|
||||||
return this.prefix;
|
return this.prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSuffix() {
|
public String getSuffix() {
|
||||||
return this.suffix;
|
return this.suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrefix(String prefix) {
|
public void setPrefix(String prefix) {
|
||||||
if (prefix == null) {
|
if (prefix == null) {
|
||||||
this.prefix = "";
|
this.prefix = "";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSuffix(String suffix) {
|
public void setSuffix(String suffix) {
|
||||||
if (suffix == null) {
|
if (suffix == null) {
|
||||||
this.suffix = "";
|
this.suffix = "";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.suffix = suffix;
|
this.suffix = suffix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCharSet() {
|
public String getCharSet() {
|
||||||
return charSet;
|
return charSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCharSet(String charSet) {
|
public void setCharSet(String charSet) {
|
||||||
this.charSet = charSet;
|
this.charSet = charSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,96 +6,97 @@ import org.graylog2.syslog4j.impl.message.modifier.AbstractSyslogMessageModifier
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ChecksumSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
* ChecksumSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
||||||
* that provides support for Java Checksum algorithms (java.util.zip.Checksum).
|
* that provides support for Java Checksum algorithms (java.util.zip.Checksum).
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: ChecksumSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: ChecksumSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class ChecksumSyslogMessageModifier extends AbstractSyslogMessageModifier {
|
public class ChecksumSyslogMessageModifier extends AbstractSyslogMessageModifier {
|
||||||
private static final long serialVersionUID = -3268914290497005065L;
|
private static final long serialVersionUID = -3268914290497005065L;
|
||||||
|
|
||||||
protected ChecksumSyslogMessageModifierConfig config = null;
|
protected ChecksumSyslogMessageModifierConfig config = null;
|
||||||
|
|
||||||
public static final ChecksumSyslogMessageModifier createCRC32() {
|
public static final ChecksumSyslogMessageModifier createCRC32() {
|
||||||
ChecksumSyslogMessageModifier crc32 = new ChecksumSyslogMessageModifier(ChecksumSyslogMessageModifierConfig.createCRC32());
|
ChecksumSyslogMessageModifier crc32 = new ChecksumSyslogMessageModifier(ChecksumSyslogMessageModifierConfig.createCRC32());
|
||||||
|
|
||||||
return crc32;
|
return crc32;
|
||||||
}
|
}
|
||||||
public static final ChecksumSyslogMessageModifier createADLER32() {
|
|
||||||
ChecksumSyslogMessageModifier adler32 = new ChecksumSyslogMessageModifier(ChecksumSyslogMessageModifierConfig.createADLER32());
|
|
||||||
|
|
||||||
return adler32;
|
public static final ChecksumSyslogMessageModifier createADLER32() {
|
||||||
}
|
ChecksumSyslogMessageModifier adler32 = new ChecksumSyslogMessageModifier(ChecksumSyslogMessageModifierConfig.createADLER32());
|
||||||
|
|
||||||
public ChecksumSyslogMessageModifier(ChecksumSyslogMessageModifierConfig config) {
|
return adler32;
|
||||||
super(config);
|
}
|
||||||
|
|
||||||
this.config = config;
|
public ChecksumSyslogMessageModifier(ChecksumSyslogMessageModifierConfig config) {
|
||||||
|
super(config);
|
||||||
|
|
||||||
if (this.config == null) {
|
this.config = config;
|
||||||
throw new SyslogRuntimeException("Checksum config object cannot be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.config.getChecksum() == null) {
|
if (this.config == null) {
|
||||||
throw new SyslogRuntimeException("Checksum object cannot be null");
|
throw new SyslogRuntimeException("Checksum config object cannot be null");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public ChecksumSyslogMessageModifierConfig getConfig() {
|
if (this.config.getChecksum() == null) {
|
||||||
return this.config;
|
throw new SyslogRuntimeException("Checksum object cannot be null");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void continuousCheckForVerify() {
|
public ChecksumSyslogMessageModifierConfig getConfig() {
|
||||||
if (this.config.isContinuous()) {
|
return this.config;
|
||||||
throw new SyslogRuntimeException(this.getClass().getName() + ".verify(..) does not work with isContinuous() returning true");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
protected void continuousCheckForVerify() {
|
||||||
|
if (this.config.isContinuous()) {
|
||||||
|
throw new SyslogRuntimeException(this.getClass().getName() + ".verify(..) does not work with isContinuous() returning true");
|
||||||
|
}
|
||||||
|
|
||||||
public boolean verify(String message, String hexChecksum) {
|
}
|
||||||
continuousCheckForVerify();
|
|
||||||
|
|
||||||
long checksum = Long.parseLong(hexChecksum,16);
|
public boolean verify(String message, String hexChecksum) {
|
||||||
|
continuousCheckForVerify();
|
||||||
|
|
||||||
return verify(message,checksum);
|
long checksum = Long.parseLong(hexChecksum, 16);
|
||||||
}
|
|
||||||
|
|
||||||
public boolean verify(String message, long checksum) {
|
return verify(message, checksum);
|
||||||
continuousCheckForVerify();
|
}
|
||||||
|
|
||||||
synchronized(this.config.getChecksum()) {
|
public boolean verify(String message, long checksum) {
|
||||||
this.config.getChecksum().reset();
|
continuousCheckForVerify();
|
||||||
|
|
||||||
byte[] messageBytes = SyslogUtility.getBytes(this.config,message);
|
synchronized (this.config.getChecksum()) {
|
||||||
|
this.config.getChecksum().reset();
|
||||||
|
|
||||||
this.config.getChecksum().update(messageBytes,0,message.length());
|
byte[] messageBytes = SyslogUtility.getBytes(this.config, message);
|
||||||
|
|
||||||
return this.config.getChecksum().getValue() == checksum;
|
this.config.getChecksum().update(messageBytes, 0, message.length());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
return this.config.getChecksum().getValue() == checksum;
|
||||||
synchronized(this.config.getChecksum()) {
|
}
|
||||||
StringBuffer messageBuffer = new StringBuffer(message);
|
}
|
||||||
|
|
||||||
byte[] messageBytes = SyslogUtility.getBytes(syslog.getConfig(),message);
|
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
||||||
|
synchronized (this.config.getChecksum()) {
|
||||||
|
StringBuffer messageBuffer = new StringBuffer(message);
|
||||||
|
|
||||||
if (!this.config.isContinuous()) {
|
byte[] messageBytes = SyslogUtility.getBytes(syslog.getConfig(), message);
|
||||||
this.config.getChecksum().reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.config.getChecksum().update(messageBytes,0,message.length());
|
if (!this.config.isContinuous()) {
|
||||||
|
this.config.getChecksum().reset();
|
||||||
|
}
|
||||||
|
|
||||||
messageBuffer.append(this.config.getPrefix());
|
this.config.getChecksum().update(messageBytes, 0, message.length());
|
||||||
messageBuffer.append(Long.toHexString(this.config.getChecksum().getValue()).toUpperCase());
|
|
||||||
messageBuffer.append(this.config.getSuffix());
|
|
||||||
|
|
||||||
return messageBuffer.toString();
|
messageBuffer.append(this.config.getPrefix());
|
||||||
}
|
messageBuffer.append(Long.toHexString(this.config.getChecksum().getValue()).toUpperCase());
|
||||||
}
|
messageBuffer.append(this.config.getSuffix());
|
||||||
|
|
||||||
|
return messageBuffer.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,51 +7,51 @@ import java.util.zip.Checksum;
|
|||||||
import org.graylog2.syslog4j.impl.message.modifier.AbstractSyslogMessageModifierConfig;
|
import org.graylog2.syslog4j.impl.message.modifier.AbstractSyslogMessageModifierConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ChecksumSyslogMessageModifierConfig is an implementation of AbstractSyslogMessageModifierConfig
|
* ChecksumSyslogMessageModifierConfig is an implementation of AbstractSyslogMessageModifierConfig
|
||||||
* that provides configuration for ChecksumSyslogMessageModifier.
|
* that provides configuration for ChecksumSyslogMessageModifier.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: ChecksumSyslogMessageModifierConfig.java,v 1.2 2010/02/04 03:41:38 cvs Exp $
|
* @version $Id: ChecksumSyslogMessageModifierConfig.java,v 1.2 2010/02/04 03:41:38 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class ChecksumSyslogMessageModifierConfig extends AbstractSyslogMessageModifierConfig {
|
public class ChecksumSyslogMessageModifierConfig extends AbstractSyslogMessageModifierConfig {
|
||||||
private static final long serialVersionUID = -8298600135683882489L;
|
private static final long serialVersionUID = -8298600135683882489L;
|
||||||
|
|
||||||
protected Checksum checksum = null;
|
protected Checksum checksum = null;
|
||||||
protected boolean continuous = false;
|
protected boolean continuous = false;
|
||||||
|
|
||||||
public static final ChecksumSyslogMessageModifierConfig createCRC32() {
|
public static final ChecksumSyslogMessageModifierConfig createCRC32() {
|
||||||
ChecksumSyslogMessageModifierConfig crc32 = new ChecksumSyslogMessageModifierConfig(new CRC32());
|
ChecksumSyslogMessageModifierConfig crc32 = new ChecksumSyslogMessageModifierConfig(new CRC32());
|
||||||
|
|
||||||
return crc32;
|
return crc32;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ChecksumSyslogMessageModifierConfig createADLER32() {
|
public static final ChecksumSyslogMessageModifierConfig createADLER32() {
|
||||||
ChecksumSyslogMessageModifierConfig adler32 = new ChecksumSyslogMessageModifierConfig(new Adler32());
|
ChecksumSyslogMessageModifierConfig adler32 = new ChecksumSyslogMessageModifierConfig(new Adler32());
|
||||||
|
|
||||||
return adler32;
|
return adler32;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChecksumSyslogMessageModifierConfig(Checksum checksum) {
|
public ChecksumSyslogMessageModifierConfig(Checksum checksum) {
|
||||||
this.checksum = checksum;
|
this.checksum = checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Checksum getChecksum() {
|
public Checksum getChecksum() {
|
||||||
return this.checksum;
|
return this.checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChecksum(Checksum checksum) {
|
public void setChecksum(Checksum checksum) {
|
||||||
this.checksum = checksum;
|
this.checksum = checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isContinuous() {
|
public boolean isContinuous() {
|
||||||
return continuous;
|
return continuous;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContinuous(boolean continuous) {
|
public void setContinuous(boolean continuous) {
|
||||||
this.continuous = continuous;
|
this.continuous = continuous;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,77 +4,77 @@ import org.graylog2.syslog4j.SyslogIF;
|
|||||||
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTMLEntityEscapeSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
* HTMLEntityEscapeSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
||||||
* that safely escapes HTML entity characters.
|
* that safely escapes HTML entity characters.
|
||||||
*
|
* <p/>
|
||||||
* <p>This modifier is useful for applications that display log content in browsers without
|
* <p>This modifier is useful for applications that display log content in browsers without
|
||||||
* properly escaping HTML characters.</p>
|
* properly escaping HTML characters.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: HTMLEntityEscapeSyslogMessageModifier.java,v 1.4 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: HTMLEntityEscapeSyslogMessageModifier.java,v 1.4 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class HTMLEntityEscapeSyslogMessageModifier implements SyslogMessageModifierIF {
|
public class HTMLEntityEscapeSyslogMessageModifier implements SyslogMessageModifierIF {
|
||||||
private static final long serialVersionUID = -8481773209240762293L;
|
private static final long serialVersionUID = -8481773209240762293L;
|
||||||
|
|
||||||
public static final SyslogMessageModifierIF createDefault() {
|
public static final SyslogMessageModifierIF createDefault() {
|
||||||
return new HTMLEntityEscapeSyslogMessageModifier();
|
return new HTMLEntityEscapeSyslogMessageModifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
||||||
if (message != null && !"".equals(message.trim())) {
|
if (message != null && !"".equals(message.trim())) {
|
||||||
String escapedMessage = escapeHtml(message);
|
String escapedMessage = escapeHtml(message);
|
||||||
|
|
||||||
return escapedMessage;
|
return escapedMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify(String message) {
|
public boolean verify(String message) {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* escapeHtml(String) is based partly on the article posted here: http://www.owasp.org/index.php/How_to_perform_HTML_entity_encoding_in_Java
|
* escapeHtml(String) is based partly on the article posted here: http://www.owasp.org/index.php/How_to_perform_HTML_entity_encoding_in_Java
|
||||||
* with the addition of common characters and modifications for Java 1.4 support.
|
* with the addition of common characters and modifications for Java 1.4 support.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
* @return Returns a message where any HTML entity characters are escaped.
|
* @return Returns a message where any HTML entity characters are escaped.
|
||||||
*/
|
*/
|
||||||
public static String escapeHtml(String message) {
|
public static String escapeHtml(String message) {
|
||||||
StringBuffer b = new StringBuffer(message.length());
|
StringBuffer b = new StringBuffer(message.length());
|
||||||
|
|
||||||
for (int i = 0; i < message.length(); i++) {
|
for (int i = 0; i < message.length(); i++) {
|
||||||
char ch = message.charAt(i);
|
char ch = message.charAt(i);
|
||||||
|
|
||||||
if (ch == '<') {
|
if (ch == '<') {
|
||||||
b.append("<");
|
b.append("<");
|
||||||
} else if (ch == '>') {
|
} else if (ch == '>') {
|
||||||
b.append(">");
|
b.append(">");
|
||||||
} else if (ch == '"') {
|
} else if (ch == '"') {
|
||||||
b.append(""");
|
b.append(""");
|
||||||
} else if (ch == '\'') {
|
} else if (ch == '\'') {
|
||||||
b.append("'");
|
b.append("'");
|
||||||
} else if (ch == '&') {
|
} else if (ch == '&') {
|
||||||
b.append("&");
|
b.append("&");
|
||||||
} else if (ch >= ' ' && ch <= '~') {
|
} else if (ch >= ' ' && ch <= '~') {
|
||||||
b.append(ch);
|
b.append(ch);
|
||||||
} else if (Character.isWhitespace(ch)) {
|
} else if (Character.isWhitespace(ch)) {
|
||||||
b.append("&#").append((int) ch).append(";");
|
b.append("&#").append((int) ch).append(";");
|
||||||
} else if (Character.isISOControl(ch)) {
|
} else if (Character.isISOControl(ch)) {
|
||||||
// Ignore character
|
// Ignore character
|
||||||
} else if (Character.isDefined(ch)) {
|
} else if (Character.isDefined(ch)) {
|
||||||
b.append("&#").append((int) ch).append(";");
|
b.append("&#").append((int) ch).append(";");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.toString();
|
return b.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,122 +11,122 @@ import org.graylog2.syslog4j.util.Base64;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HashSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
* HashSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
||||||
* that provides support for Java Cryptographic hashes (MD5, SHA1, SHA256, etc.).
|
* that provides support for Java Cryptographic hashes (MD5, SHA1, SHA256, etc.).
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: HashSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: HashSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class HashSyslogMessageModifier extends AbstractSyslogMessageModifier {
|
public class HashSyslogMessageModifier extends AbstractSyslogMessageModifier {
|
||||||
private static final long serialVersionUID = 7335757344826206953L;
|
private static final long serialVersionUID = 7335757344826206953L;
|
||||||
|
|
||||||
protected HashSyslogMessageModifierConfig config = null;
|
protected HashSyslogMessageModifierConfig config = null;
|
||||||
|
|
||||||
public static final HashSyslogMessageModifier createMD5() {
|
public static final HashSyslogMessageModifier createMD5() {
|
||||||
HashSyslogMessageModifier md5 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createMD5());
|
HashSyslogMessageModifier md5 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createMD5());
|
||||||
|
|
||||||
return md5;
|
return md5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifier createSHA1() {
|
public static final HashSyslogMessageModifier createSHA1() {
|
||||||
HashSyslogMessageModifier sha1 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createSHA1());
|
HashSyslogMessageModifier sha1 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createSHA1());
|
||||||
|
|
||||||
return sha1;
|
return sha1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifier createSHA160() {
|
public static final HashSyslogMessageModifier createSHA160() {
|
||||||
return createSHA1();
|
return createSHA1();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifier createSHA256() {
|
public static final HashSyslogMessageModifier createSHA256() {
|
||||||
HashSyslogMessageModifier sha256 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createSHA256());
|
HashSyslogMessageModifier sha256 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createSHA256());
|
||||||
|
|
||||||
return sha256;
|
return sha256;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifier createSHA384() {
|
public static final HashSyslogMessageModifier createSHA384() {
|
||||||
HashSyslogMessageModifier sha384 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createSHA384());
|
HashSyslogMessageModifier sha384 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createSHA384());
|
||||||
|
|
||||||
return sha384;
|
return sha384;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifier createSHA512() {
|
public static final HashSyslogMessageModifier createSHA512() {
|
||||||
HashSyslogMessageModifier sha512 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createSHA512());
|
HashSyslogMessageModifier sha512 = new HashSyslogMessageModifier(HashSyslogMessageModifierConfig.createSHA512());
|
||||||
|
|
||||||
return sha512;
|
return sha512;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSyslogMessageModifier(HashSyslogMessageModifierConfig config) throws SyslogRuntimeException {
|
public HashSyslogMessageModifier(HashSyslogMessageModifierConfig config) throws SyslogRuntimeException {
|
||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
if (this.config == null) {
|
if (this.config == null) {
|
||||||
throw new SyslogRuntimeException("Hash config object cannot be null");
|
throw new SyslogRuntimeException("Hash config object cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.getHashAlgorithm() == null) {
|
if (this.config.getHashAlgorithm() == null) {
|
||||||
throw new SyslogRuntimeException("Hash algorithm cannot be null");
|
throw new SyslogRuntimeException("Hash algorithm cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MessageDigest.getInstance(config.getHashAlgorithm());
|
MessageDigest.getInstance(config.getHashAlgorithm());
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException nsae){
|
} catch (NoSuchAlgorithmException nsae) {
|
||||||
throw new SyslogRuntimeException(nsae);
|
throw new SyslogRuntimeException(nsae);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MessageDigest obtainMessageDigest() {
|
protected MessageDigest obtainMessageDigest() {
|
||||||
MessageDigest digest = null;
|
MessageDigest digest = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
digest = MessageDigest.getInstance(this.config.getHashAlgorithm());
|
digest = MessageDigest.getInstance(this.config.getHashAlgorithm());
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException nsae) {
|
} catch (NoSuchAlgorithmException nsae) {
|
||||||
throw new SyslogRuntimeException(nsae);
|
throw new SyslogRuntimeException(nsae);
|
||||||
}
|
}
|
||||||
|
|
||||||
return digest;
|
return digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSyslogMessageModifierConfig getConfig() {
|
public HashSyslogMessageModifierConfig getConfig() {
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
||||||
byte[] messageBytes = SyslogUtility.getBytes(syslog.getConfig(),message);
|
byte[] messageBytes = SyslogUtility.getBytes(syslog.getConfig(), message);
|
||||||
|
|
||||||
MessageDigest digest = obtainMessageDigest();
|
MessageDigest digest = obtainMessageDigest();
|
||||||
byte[] digestBytes = digest.digest(messageBytes);
|
byte[] digestBytes = digest.digest(messageBytes);
|
||||||
|
|
||||||
String digestString = Base64.encodeBytes(digestBytes,Base64.DONT_BREAK_LINES);
|
String digestString = Base64.encodeBytes(digestBytes, Base64.DONT_BREAK_LINES);
|
||||||
|
|
||||||
StringBuffer buffer = new StringBuffer(message);
|
StringBuffer buffer = new StringBuffer(message);
|
||||||
|
|
||||||
buffer.append(this.config.getPrefix());
|
buffer.append(this.config.getPrefix());
|
||||||
buffer.append(digestString);
|
buffer.append(digestString);
|
||||||
buffer.append(this.config.getSuffix());
|
buffer.append(this.config.getSuffix());
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify(String message, String base64Hash) {
|
public boolean verify(String message, String base64Hash) {
|
||||||
byte[] hash = Base64.decode(base64Hash);
|
byte[] hash = Base64.decode(base64Hash);
|
||||||
|
|
||||||
return verify(message,hash);
|
return verify(message, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify(String message, byte[] hash) {
|
public boolean verify(String message, byte[] hash) {
|
||||||
byte[] messageBytes = SyslogUtility.getBytes(this.config,message);
|
byte[] messageBytes = SyslogUtility.getBytes(this.config, message);
|
||||||
|
|
||||||
MessageDigest digest = obtainMessageDigest();
|
MessageDigest digest = obtainMessageDigest();
|
||||||
byte[] digestBytes = digest.digest(messageBytes);
|
byte[] digestBytes = digest.digest(messageBytes);
|
||||||
|
|
||||||
return Arrays.equals(digestBytes,hash);
|
return Arrays.equals(digestBytes, hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,64 +3,64 @@ package org.graylog2.syslog4j.impl.message.modifier.hash;
|
|||||||
import org.graylog2.syslog4j.impl.message.modifier.AbstractSyslogMessageModifierConfig;
|
import org.graylog2.syslog4j.impl.message.modifier.AbstractSyslogMessageModifierConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HashSyslogMessageModifierConfig is an implementation of AbstractSyslogMessageModifierConfig
|
* HashSyslogMessageModifierConfig is an implementation of AbstractSyslogMessageModifierConfig
|
||||||
* that provides configuration for HashSyslogMessageModifier.
|
* that provides configuration for HashSyslogMessageModifier.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: HashSyslogMessageModifierConfig.java,v 1.1 2008/11/10 04:38:37 cvs Exp $
|
* @version $Id: HashSyslogMessageModifierConfig.java,v 1.1 2008/11/10 04:38:37 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class HashSyslogMessageModifierConfig extends AbstractSyslogMessageModifierConfig {
|
public class HashSyslogMessageModifierConfig extends AbstractSyslogMessageModifierConfig {
|
||||||
private static final long serialVersionUID = -3148300281439874231L;
|
private static final long serialVersionUID = -3148300281439874231L;
|
||||||
|
|
||||||
protected String hashAlgorithm = null;
|
protected String hashAlgorithm = null;
|
||||||
|
|
||||||
public static final HashSyslogMessageModifierConfig createMD5() {
|
public static final HashSyslogMessageModifierConfig createMD5() {
|
||||||
HashSyslogMessageModifierConfig md5 = new HashSyslogMessageModifierConfig("MD5");
|
HashSyslogMessageModifierConfig md5 = new HashSyslogMessageModifierConfig("MD5");
|
||||||
|
|
||||||
return md5;
|
return md5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifierConfig createSHA1() {
|
public static final HashSyslogMessageModifierConfig createSHA1() {
|
||||||
HashSyslogMessageModifierConfig sha1 = new HashSyslogMessageModifierConfig("SHA1");
|
HashSyslogMessageModifierConfig sha1 = new HashSyslogMessageModifierConfig("SHA1");
|
||||||
|
|
||||||
return sha1;
|
return sha1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifierConfig createSHA160() {
|
public static final HashSyslogMessageModifierConfig createSHA160() {
|
||||||
return createSHA1();
|
return createSHA1();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifierConfig createSHA256() {
|
public static final HashSyslogMessageModifierConfig createSHA256() {
|
||||||
HashSyslogMessageModifierConfig sha256 = new HashSyslogMessageModifierConfig("SHA-256");
|
HashSyslogMessageModifierConfig sha256 = new HashSyslogMessageModifierConfig("SHA-256");
|
||||||
|
|
||||||
return sha256;
|
return sha256;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifierConfig createSHA384() {
|
public static final HashSyslogMessageModifierConfig createSHA384() {
|
||||||
HashSyslogMessageModifierConfig sha384 = new HashSyslogMessageModifierConfig("SHA-384");
|
HashSyslogMessageModifierConfig sha384 = new HashSyslogMessageModifierConfig("SHA-384");
|
||||||
|
|
||||||
return sha384;
|
return sha384;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HashSyslogMessageModifierConfig createSHA512() {
|
public static final HashSyslogMessageModifierConfig createSHA512() {
|
||||||
HashSyslogMessageModifierConfig sha512 = new HashSyslogMessageModifierConfig("SHA-512");
|
HashSyslogMessageModifierConfig sha512 = new HashSyslogMessageModifierConfig("SHA-512");
|
||||||
|
|
||||||
return sha512;
|
return sha512;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSyslogMessageModifierConfig(String hashAlgorithm) {
|
public HashSyslogMessageModifierConfig(String hashAlgorithm) {
|
||||||
this.hashAlgorithm = hashAlgorithm;
|
this.hashAlgorithm = hashAlgorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHashAlgorithm() {
|
public String getHashAlgorithm() {
|
||||||
return this.hashAlgorithm;
|
return this.hashAlgorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHashAlgorithm(String hashAlgorithm) {
|
public void setHashAlgorithm(String hashAlgorithm) {
|
||||||
this.hashAlgorithm = hashAlgorithm;
|
this.hashAlgorithm = hashAlgorithm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,107 +14,107 @@ import org.graylog2.syslog4j.util.Base64;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MacSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
* MacSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
||||||
* that provides support for Java Cryptographic signed hashes (HmacSHA1, etc.)
|
* that provides support for Java Cryptographic signed hashes (HmacSHA1, etc.)
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: MacSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: MacSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class MacSyslogMessageModifier extends AbstractSyslogMessageModifier {
|
public class MacSyslogMessageModifier extends AbstractSyslogMessageModifier {
|
||||||
private static final long serialVersionUID = 5054979194802197540L;
|
private static final long serialVersionUID = 5054979194802197540L;
|
||||||
|
|
||||||
protected MacSyslogMessageModifierConfig config = null;
|
protected MacSyslogMessageModifierConfig config = null;
|
||||||
|
|
||||||
protected Mac mac = null;
|
protected Mac mac = null;
|
||||||
|
|
||||||
public MacSyslogMessageModifier(MacSyslogMessageModifierConfig config) throws SyslogRuntimeException {
|
public MacSyslogMessageModifier(MacSyslogMessageModifierConfig config) throws SyslogRuntimeException {
|
||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.mac = Mac.getInstance(config.getMacAlgorithm());
|
this.mac = Mac.getInstance(config.getMacAlgorithm());
|
||||||
this.mac.init(config.getKey());
|
this.mac.init(config.getKey());
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException nsae) {
|
} catch (NoSuchAlgorithmException nsae) {
|
||||||
throw new SyslogRuntimeException(nsae);
|
throw new SyslogRuntimeException(nsae);
|
||||||
|
|
||||||
} catch (InvalidKeyException ike) {
|
} catch (InvalidKeyException ike) {
|
||||||
throw new SyslogRuntimeException(ike);
|
throw new SyslogRuntimeException(ike);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifier createHmacSHA1(Key key) {
|
public static MacSyslogMessageModifier createHmacSHA1(Key key) {
|
||||||
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA1(key));
|
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA1(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifier createHmacSHA1(String base64Key) {
|
public static MacSyslogMessageModifier createHmacSHA1(String base64Key) {
|
||||||
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA1(base64Key));
|
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA1(base64Key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifier createHmacSHA256(Key key) {
|
public static MacSyslogMessageModifier createHmacSHA256(Key key) {
|
||||||
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA256(key));
|
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA256(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifier createHmacSHA256(String base64Key) {
|
public static MacSyslogMessageModifier createHmacSHA256(String base64Key) {
|
||||||
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA256(base64Key));
|
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA256(base64Key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifier createHmacSHA512(Key key) {
|
public static MacSyslogMessageModifier createHmacSHA512(Key key) {
|
||||||
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA512(key));
|
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA512(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifier createHmacSHA512(String base64Key) {
|
public static MacSyslogMessageModifier createHmacSHA512(String base64Key) {
|
||||||
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA512(base64Key));
|
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacSHA512(base64Key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifier createHmacMD5(Key key) {
|
public static MacSyslogMessageModifier createHmacMD5(Key key) {
|
||||||
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacMD5(key));
|
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacMD5(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifier createHmacMD5(String base64Key) {
|
public static MacSyslogMessageModifier createHmacMD5(String base64Key) {
|
||||||
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacMD5(base64Key));
|
return new MacSyslogMessageModifier(MacSyslogMessageModifierConfig.createHmacMD5(base64Key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MacSyslogMessageModifierConfig getConfig() {
|
public MacSyslogMessageModifierConfig getConfig() {
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
||||||
synchronized(this.mac) {
|
synchronized (this.mac) {
|
||||||
byte[] messageBytes = SyslogUtility.getBytes(syslog.getConfig(),message);
|
byte[] messageBytes = SyslogUtility.getBytes(syslog.getConfig(), message);
|
||||||
|
|
||||||
StringBuffer buffer = new StringBuffer(message);
|
StringBuffer buffer = new StringBuffer(message);
|
||||||
|
|
||||||
byte[] macBytes = this.mac.doFinal(messageBytes);
|
byte[] macBytes = this.mac.doFinal(messageBytes);
|
||||||
|
|
||||||
String macString = Base64.encodeBytes(macBytes,Base64.DONT_BREAK_LINES);
|
String macString = Base64.encodeBytes(macBytes, Base64.DONT_BREAK_LINES);
|
||||||
|
|
||||||
buffer.append(this.config.getPrefix());
|
buffer.append(this.config.getPrefix());
|
||||||
buffer.append(macString);
|
buffer.append(macString);
|
||||||
buffer.append(this.config.getSuffix());
|
buffer.append(this.config.getSuffix());
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify(String message, String base64Signature) {
|
public boolean verify(String message, String base64Signature) {
|
||||||
byte[] signature = Base64.decode(base64Signature);
|
byte[] signature = Base64.decode(base64Signature);
|
||||||
|
|
||||||
return verify(message,signature);
|
return verify(message, signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify(String message, byte[] signature) {
|
public boolean verify(String message, byte[] signature) {
|
||||||
synchronized(this.mac) {
|
synchronized (this.mac) {
|
||||||
byte[] messageBytes = SyslogUtility.getBytes(this.config,message);
|
byte[] messageBytes = SyslogUtility.getBytes(this.config, message);
|
||||||
|
|
||||||
byte[] macBytes = this.mac.doFinal(messageBytes);
|
byte[] macBytes = this.mac.doFinal(messageBytes);
|
||||||
|
|
||||||
return Arrays.equals(macBytes,signature);
|
return Arrays.equals(macBytes, signature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,100 +9,100 @@ import org.graylog2.syslog4j.impl.message.modifier.AbstractSyslogMessageModifier
|
|||||||
import org.graylog2.syslog4j.util.Base64;
|
import org.graylog2.syslog4j.util.Base64;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MacSyslogMessageModifierConfig is an implementation of AbstractSyslogMessageModifierConfig
|
* MacSyslogMessageModifierConfig is an implementation of AbstractSyslogMessageModifierConfig
|
||||||
* that provides configuration for HashSyslogMessageModifier.
|
* that provides configuration for HashSyslogMessageModifier.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: MacSyslogMessageModifierConfig.java,v 1.3 2009/04/17 02:37:04 cvs Exp $
|
* @version $Id: MacSyslogMessageModifierConfig.java,v 1.3 2009/04/17 02:37:04 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class MacSyslogMessageModifierConfig extends AbstractSyslogMessageModifierConfig {
|
public class MacSyslogMessageModifierConfig extends AbstractSyslogMessageModifierConfig {
|
||||||
private static final long serialVersionUID = 4524180892377960695L;
|
private static final long serialVersionUID = 4524180892377960695L;
|
||||||
|
|
||||||
protected String macAlgorithm = null;
|
protected String macAlgorithm = null;
|
||||||
protected String keyAlgorithm = null;
|
protected String keyAlgorithm = null;
|
||||||
protected Key key = null;
|
protected Key key = null;
|
||||||
|
|
||||||
public MacSyslogMessageModifierConfig(String macAlgorithm, String keyAlgorithm, Key key) {
|
public MacSyslogMessageModifierConfig(String macAlgorithm, String keyAlgorithm, Key key) {
|
||||||
this.macAlgorithm = macAlgorithm;
|
this.macAlgorithm = macAlgorithm;
|
||||||
this.keyAlgorithm = keyAlgorithm;
|
this.keyAlgorithm = keyAlgorithm;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MacSyslogMessageModifierConfig(String macAlgorithm, String keyAlgorithm, byte[] keyBytes) {
|
public MacSyslogMessageModifierConfig(String macAlgorithm, String keyAlgorithm, byte[] keyBytes) {
|
||||||
this.macAlgorithm = macAlgorithm;
|
this.macAlgorithm = macAlgorithm;
|
||||||
this.keyAlgorithm = keyAlgorithm;
|
this.keyAlgorithm = keyAlgorithm;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.key = new SecretKeySpec(keyBytes,keyAlgorithm);
|
this.key = new SecretKeySpec(keyBytes, keyAlgorithm);
|
||||||
|
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
throw new SyslogRuntimeException(iae);
|
throw new SyslogRuntimeException(iae);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MacSyslogMessageModifierConfig(String macAlgorithm, String keyAlgorithm, String base64Key) {
|
public MacSyslogMessageModifierConfig(String macAlgorithm, String keyAlgorithm, String base64Key) {
|
||||||
this.macAlgorithm = macAlgorithm;
|
this.macAlgorithm = macAlgorithm;
|
||||||
this.keyAlgorithm = keyAlgorithm;
|
this.keyAlgorithm = keyAlgorithm;
|
||||||
|
|
||||||
byte[] keyBytes = Base64.decode(base64Key);
|
byte[] keyBytes = Base64.decode(base64Key);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.key = new SecretKeySpec(keyBytes,keyAlgorithm);
|
this.key = new SecretKeySpec(keyBytes, keyAlgorithm);
|
||||||
|
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
throw new SyslogRuntimeException(iae);
|
throw new SyslogRuntimeException(iae);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifierConfig createHmacSHA1(Key key) {
|
public static MacSyslogMessageModifierConfig createHmacSHA1(Key key) {
|
||||||
return new MacSyslogMessageModifierConfig("HmacSHA1","SHA1",key);
|
return new MacSyslogMessageModifierConfig("HmacSHA1", "SHA1", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifierConfig createHmacSHA1(String base64Key) {
|
public static MacSyslogMessageModifierConfig createHmacSHA1(String base64Key) {
|
||||||
return new MacSyslogMessageModifierConfig("HmacSHA1","SHA1",base64Key);
|
return new MacSyslogMessageModifierConfig("HmacSHA1", "SHA1", base64Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifierConfig createHmacSHA256(Key key) {
|
public static MacSyslogMessageModifierConfig createHmacSHA256(Key key) {
|
||||||
return new MacSyslogMessageModifierConfig("HmacSHA256","SHA-256",key);
|
return new MacSyslogMessageModifierConfig("HmacSHA256", "SHA-256", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifierConfig createHmacSHA256(String base64Key) {
|
public static MacSyslogMessageModifierConfig createHmacSHA256(String base64Key) {
|
||||||
return new MacSyslogMessageModifierConfig("HmacSHA256","SHA-256",base64Key);
|
return new MacSyslogMessageModifierConfig("HmacSHA256", "SHA-256", base64Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifierConfig createHmacSHA512(Key key) {
|
public static MacSyslogMessageModifierConfig createHmacSHA512(Key key) {
|
||||||
return new MacSyslogMessageModifierConfig("HmacSHA512","SHA-512",key);
|
return new MacSyslogMessageModifierConfig("HmacSHA512", "SHA-512", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifierConfig createHmacSHA512(String base64Key) {
|
public static MacSyslogMessageModifierConfig createHmacSHA512(String base64Key) {
|
||||||
return new MacSyslogMessageModifierConfig("HmacSHA512","SHA-512",base64Key);
|
return new MacSyslogMessageModifierConfig("HmacSHA512", "SHA-512", base64Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifierConfig createHmacMD5(Key key) {
|
public static MacSyslogMessageModifierConfig createHmacMD5(Key key) {
|
||||||
return new MacSyslogMessageModifierConfig("HmacMD5","MD5",key);
|
return new MacSyslogMessageModifierConfig("HmacMD5", "MD5", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MacSyslogMessageModifierConfig createHmacMD5(String base64Key) {
|
public static MacSyslogMessageModifierConfig createHmacMD5(String base64Key) {
|
||||||
return new MacSyslogMessageModifierConfig("HmacMD5","MD5",base64Key);
|
return new MacSyslogMessageModifierConfig("HmacMD5", "MD5", base64Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMacAlgorithm() {
|
public String getMacAlgorithm() {
|
||||||
return this.macAlgorithm;
|
return this.macAlgorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyAlgorithm() {
|
public String getKeyAlgorithm() {
|
||||||
return this.keyAlgorithm;
|
return this.keyAlgorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Key getKey() {
|
public Key getKey() {
|
||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(Key key) {
|
public void setKey(Key key) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,98 +4,98 @@ import org.graylog2.syslog4j.SyslogIF;
|
|||||||
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SequentialSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
* SequentialSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
||||||
* that adds an incremented number at the end.
|
* that adds an incremented number at the end.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SequentialSyslogMessageModifier.java,v 1.8 2010/11/28 04:43:31 cvs Exp $
|
* @version $Id: SequentialSyslogMessageModifier.java,v 1.8 2010/11/28 04:43:31 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SequentialSyslogMessageModifier implements SyslogMessageModifierIF {
|
public class SequentialSyslogMessageModifier implements SyslogMessageModifierIF {
|
||||||
private static final long serialVersionUID = 6107735010240030785L;
|
private static final long serialVersionUID = 6107735010240030785L;
|
||||||
|
|
||||||
protected SequentialSyslogMessageModifierConfig config = null;
|
protected SequentialSyslogMessageModifierConfig config = null;
|
||||||
|
|
||||||
protected long currentSequence[] = new long[LEVEL_DEBUG + 1];
|
protected long currentSequence[] = new long[LEVEL_DEBUG + 1];
|
||||||
|
|
||||||
public static final SequentialSyslogMessageModifier createDefault() {
|
public static final SequentialSyslogMessageModifier createDefault() {
|
||||||
SequentialSyslogMessageModifier modifier = new SequentialSyslogMessageModifier(SequentialSyslogMessageModifierConfig.createDefault());
|
SequentialSyslogMessageModifier modifier = new SequentialSyslogMessageModifier(SequentialSyslogMessageModifierConfig.createDefault());
|
||||||
|
|
||||||
return modifier;
|
return modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SequentialSyslogMessageModifier(SequentialSyslogMessageModifierConfig config) {
|
public SequentialSyslogMessageModifier(SequentialSyslogMessageModifierConfig config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
for(int i=0; i<(LEVEL_DEBUG + 1); i++) {
|
for (int i = 0; i < (LEVEL_DEBUG + 1); i++) {
|
||||||
this.currentSequence[i] = config.getFirstNumber();
|
this.currentSequence[i] = config.getFirstNumber();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String pad(long number) {
|
protected String pad(long number) {
|
||||||
StringBuffer buffer = new StringBuffer(Long.toString(number));
|
StringBuffer buffer = new StringBuffer(Long.toString(number));
|
||||||
|
|
||||||
while (buffer.length() < this.config.getLastNumberDigits()) {
|
while (buffer.length() < this.config.getLastNumberDigits()) {
|
||||||
buffer.insert(0,this.config.getPadChar());
|
buffer.insert(0, this.config.getPadChar());
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNextSequence(int level, long nextSequence) {
|
public void setNextSequence(int level, long nextSequence) {
|
||||||
if (nextSequence >= this.config.getFirstNumber() && nextSequence < this.config.getLastNumber()) {
|
if (nextSequence >= this.config.getFirstNumber() && nextSequence < this.config.getLastNumber()) {
|
||||||
synchronized(this) {
|
synchronized (this) {
|
||||||
this.currentSequence[level] = nextSequence;
|
this.currentSequence[level] = nextSequence;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String nextSequence(int level) {
|
protected String nextSequence(int level) {
|
||||||
long sequence = -1;
|
long sequence = -1;
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized (this) {
|
||||||
sequence = this.currentSequence[level];
|
sequence = this.currentSequence[level];
|
||||||
|
|
||||||
if (this.currentSequence[level] >= this.config.getLastNumber()) {
|
if (this.currentSequence[level] >= this.config.getLastNumber()) {
|
||||||
this.currentSequence[level] = this.config.getFirstNumber();
|
this.currentSequence[level] = this.config.getFirstNumber();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.currentSequence[level]++;
|
this.currentSequence[level]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _sequence = null;
|
String _sequence = null;
|
||||||
|
|
||||||
if (this.config.isUsePadding()) {
|
if (this.config.isUsePadding()) {
|
||||||
_sequence = pad(sequence);
|
_sequence = pad(sequence);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_sequence = Long.toString(sequence);
|
_sequence = Long.toString(sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _sequence;
|
return _sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SequentialSyslogMessageModifierConfig getConfig() {
|
public SequentialSyslogMessageModifierConfig getConfig() {
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
||||||
StringBuffer buffer = new StringBuffer(message);
|
StringBuffer buffer = new StringBuffer(message);
|
||||||
|
|
||||||
buffer.append(this.config.getPrefix());
|
buffer.append(this.config.getPrefix());
|
||||||
buffer.append(nextSequence(level));
|
buffer.append(nextSequence(level));
|
||||||
buffer.append(this.config.getSuffix());
|
buffer.append(this.config.getSuffix());
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify(String message) {
|
public boolean verify(String message) {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,72 +3,72 @@ package org.graylog2.syslog4j.impl.message.modifier.sequential;
|
|||||||
import org.graylog2.syslog4j.impl.message.modifier.AbstractSyslogMessageModifierConfig;
|
import org.graylog2.syslog4j.impl.message.modifier.AbstractSyslogMessageModifierConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SequentialSyslogMessageModifierConfig is an implementation of AbstractSyslogMessageModifierConfig
|
* SequentialSyslogMessageModifierConfig is an implementation of AbstractSyslogMessageModifierConfig
|
||||||
* that provides configuration for SequentialSyslogMessageModifier.
|
* that provides configuration for SequentialSyslogMessageModifier.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SequentialSyslogMessageModifierConfig.java,v 1.4 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: SequentialSyslogMessageModifierConfig.java,v 1.4 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SequentialSyslogMessageModifierConfig extends AbstractSyslogMessageModifierConfig {
|
public class SequentialSyslogMessageModifierConfig extends AbstractSyslogMessageModifierConfig {
|
||||||
private static final long serialVersionUID = 1570930406228960303L;
|
private static final long serialVersionUID = 1570930406228960303L;
|
||||||
|
|
||||||
protected long firstNumber = SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_FIRST_NUMBER_DEFAULT;
|
protected long firstNumber = SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_FIRST_NUMBER_DEFAULT;
|
||||||
protected long lastNumber = SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_LAST_NUMBER_DEFAULT;
|
protected long lastNumber = SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_LAST_NUMBER_DEFAULT;
|
||||||
protected char padChar = SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_PAD_CHAR_DEFAULT;
|
protected char padChar = SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_PAD_CHAR_DEFAULT;
|
||||||
protected boolean usePadding = SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_USE_PADDING_DEFAULT;
|
protected boolean usePadding = SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_USE_PADDING_DEFAULT;
|
||||||
|
|
||||||
public static final SequentialSyslogMessageModifierConfig createDefault() {
|
public static final SequentialSyslogMessageModifierConfig createDefault() {
|
||||||
SequentialSyslogMessageModifierConfig modifierConfig = new SequentialSyslogMessageModifierConfig();
|
SequentialSyslogMessageModifierConfig modifierConfig = new SequentialSyslogMessageModifierConfig();
|
||||||
|
|
||||||
return modifierConfig;
|
return modifierConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SequentialSyslogMessageModifierConfig() {
|
public SequentialSyslogMessageModifierConfig() {
|
||||||
setPrefix(SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_PREFIX_DEFAULT);
|
setPrefix(SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_PREFIX_DEFAULT);
|
||||||
setSuffix(SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_SUFFIX_DEFAULT);
|
setSuffix(SYSLOG_SEQUENTIAL_MESSAGE_MODIFIER_SUFFIX_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastNumberDigits() {
|
public long getLastNumberDigits() {
|
||||||
return Long.toString(this.lastNumber).length();
|
return Long.toString(this.lastNumber).length();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getFirstNumber() {
|
public long getFirstNumber() {
|
||||||
return this.firstNumber;
|
return this.firstNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstNumber(long firstNumber) {
|
public void setFirstNumber(long firstNumber) {
|
||||||
if (firstNumber < this.lastNumber) {
|
if (firstNumber < this.lastNumber) {
|
||||||
this.firstNumber = firstNumber;
|
this.firstNumber = firstNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastNumber() {
|
public long getLastNumber() {
|
||||||
return this.lastNumber;
|
return this.lastNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastNumber(long lastNumber) {
|
public void setLastNumber(long lastNumber) {
|
||||||
if (lastNumber > this.firstNumber) {
|
if (lastNumber > this.firstNumber) {
|
||||||
this.lastNumber = lastNumber;
|
this.lastNumber = lastNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUsePadding() {
|
public boolean isUsePadding() {
|
||||||
return this.usePadding;
|
return this.usePadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsePadding(boolean usePadding) {
|
public void setUsePadding(boolean usePadding) {
|
||||||
this.usePadding = usePadding;
|
this.usePadding = usePadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public char getPadChar() {
|
public char getPadChar() {
|
||||||
return this.padChar;
|
return this.padChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPadChar(char padChar) {
|
public void setPadChar(char padChar) {
|
||||||
this.padChar = padChar;
|
this.padChar = padChar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,56 +4,56 @@ import org.graylog2.syslog4j.SyslogIF;
|
|||||||
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PrefixSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
* PrefixSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
||||||
* that provides support for adding static text to the beginning of a Syslog message.
|
* that provides support for adding static text to the beginning of a Syslog message.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: PrefixSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: PrefixSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class PrefixSyslogMessageModifier implements SyslogMessageModifierIF {
|
public class PrefixSyslogMessageModifier implements SyslogMessageModifierIF {
|
||||||
private static final long serialVersionUID = 6718826215583513972L;
|
private static final long serialVersionUID = 6718826215583513972L;
|
||||||
|
|
||||||
protected String prefix = null;
|
protected String prefix = null;
|
||||||
protected String delimiter = " ";
|
protected String delimiter = " ";
|
||||||
|
|
||||||
public PrefixSyslogMessageModifier() {
|
public PrefixSyslogMessageModifier() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrefixSyslogMessageModifier(String prefix) {
|
public PrefixSyslogMessageModifier(String prefix) {
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrefixSyslogMessageModifier(String prefix, String delimiter) {
|
public PrefixSyslogMessageModifier(String prefix, String delimiter) {
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
if (delimiter != null) {
|
if (delimiter != null) {
|
||||||
this.delimiter = delimiter;
|
this.delimiter = delimiter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrefix() {
|
public String getPrefix() {
|
||||||
return this.prefix;
|
return this.prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrefix(String prefix) {
|
public void setPrefix(String prefix) {
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
||||||
if (this.prefix == null || "".equals(this.prefix.trim())) {
|
if (this.prefix == null || "".equals(this.prefix.trim())) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.prefix + this.delimiter + message;
|
return this.prefix + this.delimiter + message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify(String message) {
|
public boolean verify(String message) {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,54 +5,54 @@ import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
|||||||
import org.graylog2.syslog4j.SyslogRuntimeException;
|
import org.graylog2.syslog4j.SyslogRuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StringCaseSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
* StringCaseSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
||||||
* that provides support for shifting a Syslog message to all upper case or all
|
* that provides support for shifting a Syslog message to all upper case or all
|
||||||
* lower case.
|
* lower case.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: StringCaseSyslogMessageModifier.java,v 1.3 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: StringCaseSyslogMessageModifier.java,v 1.3 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class StringCaseSyslogMessageModifier implements SyslogMessageModifierIF {
|
public class StringCaseSyslogMessageModifier implements SyslogMessageModifierIF {
|
||||||
private static final long serialVersionUID = 8383234811585957460L;
|
private static final long serialVersionUID = 8383234811585957460L;
|
||||||
|
|
||||||
public static final byte LOWER_CASE = 0;
|
public static final byte LOWER_CASE = 0;
|
||||||
public static final byte UPPER_CASE = 1;
|
public static final byte UPPER_CASE = 1;
|
||||||
|
|
||||||
public static final StringCaseSyslogMessageModifier LOWER = new StringCaseSyslogMessageModifier(LOWER_CASE);
|
public static final StringCaseSyslogMessageModifier LOWER = new StringCaseSyslogMessageModifier(LOWER_CASE);
|
||||||
public static final StringCaseSyslogMessageModifier UPPER = new StringCaseSyslogMessageModifier(UPPER_CASE);
|
public static final StringCaseSyslogMessageModifier UPPER = new StringCaseSyslogMessageModifier(UPPER_CASE);
|
||||||
|
|
||||||
protected byte stringCase = LOWER_CASE;
|
protected byte stringCase = LOWER_CASE;
|
||||||
|
|
||||||
public StringCaseSyslogMessageModifier(byte stringCase) {
|
public StringCaseSyslogMessageModifier(byte stringCase) {
|
||||||
this.stringCase = stringCase;
|
this.stringCase = stringCase;
|
||||||
|
|
||||||
if (stringCase < LOWER_CASE || stringCase > UPPER_CASE) {
|
if (stringCase < LOWER_CASE || stringCase > UPPER_CASE) {
|
||||||
throw new SyslogRuntimeException("stringCase must be LOWER_CASE (0) or UPPER_CASE (1)");
|
throw new SyslogRuntimeException("stringCase must be LOWER_CASE (0) or UPPER_CASE (1)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
||||||
String _message = message;
|
String _message = message;
|
||||||
|
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
if (this.stringCase == LOWER_CASE) {
|
if (this.stringCase == LOWER_CASE) {
|
||||||
_message = _message.toLowerCase();
|
_message = _message.toLowerCase();
|
||||||
|
|
||||||
} else if (this.stringCase == UPPER_CASE) {
|
} else if (this.stringCase == UPPER_CASE) {
|
||||||
_message = _message.toUpperCase();
|
_message = _message.toUpperCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _message;
|
return _message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify(String message) {
|
public boolean verify(String message) {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,56 +4,56 @@ import org.graylog2.syslog4j.SyslogIF;
|
|||||||
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SuffixSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
* SuffixSyslogMessageModifier is an implementation of SyslogMessageModifierIF
|
||||||
* that provides support for adding static text to the end of a Syslog message.
|
* that provides support for adding static text to the end of a Syslog message.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SuffixSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: SuffixSyslogMessageModifier.java,v 1.5 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SuffixSyslogMessageModifier implements SyslogMessageModifierIF {
|
public class SuffixSyslogMessageModifier implements SyslogMessageModifierIF {
|
||||||
private static final long serialVersionUID = 7160593302741507576L;
|
private static final long serialVersionUID = 7160593302741507576L;
|
||||||
|
|
||||||
protected String suffix = null;
|
protected String suffix = null;
|
||||||
protected String delimiter = " ";
|
protected String delimiter = " ";
|
||||||
|
|
||||||
public SuffixSyslogMessageModifier() {
|
public SuffixSyslogMessageModifier() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuffixSyslogMessageModifier(String suffix) {
|
public SuffixSyslogMessageModifier(String suffix) {
|
||||||
this.suffix = suffix;
|
this.suffix = suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuffixSyslogMessageModifier(String suffix, String delimiter) {
|
public SuffixSyslogMessageModifier(String suffix, String delimiter) {
|
||||||
this.suffix = suffix;
|
this.suffix = suffix;
|
||||||
if (delimiter != null) {
|
if (delimiter != null) {
|
||||||
this.delimiter = delimiter;
|
this.delimiter = delimiter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSuffix() {
|
public String getSuffix() {
|
||||||
return this.suffix;
|
return this.suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSuffix(String suffix) {
|
public void setSuffix(String suffix) {
|
||||||
this.suffix = suffix;
|
this.suffix = suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
public String modify(SyslogIF syslog, int facility, int level, String message) {
|
||||||
if (this.suffix == null || "".equals(this.suffix.trim())) {
|
if (this.suffix == null || "".equals(this.suffix.trim())) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return message + this.delimiter + this.suffix;
|
return message + this.delimiter + this.suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify(String message) {
|
public boolean verify(String message) {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,251 +6,275 @@ import java.util.Map;
|
|||||||
import org.graylog2.syslog4j.impl.message.AbstractSyslogMessage;
|
import org.graylog2.syslog4j.impl.message.AbstractSyslogMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PCISyslogMessage provides support for audit trails defined by section
|
* PCISyslogMessage provides support for audit trails defined by section
|
||||||
* 10.3 of the PCI Data Security Standard (PCI DSS) versions 1.1 and 1.2.
|
* 10.3 of the PCI Data Security Standard (PCI DSS) versions 1.1 and 1.2.
|
||||||
*
|
* <p/>
|
||||||
* <p>More information on the PCI DSS specification is available here:</p>
|
* <p>More information on the PCI DSS specification is available here:</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>https://www.pcisecuritystandards.org/security_standards/pci_dss.shtml</p>
|
* <p>https://www.pcisecuritystandards.org/security_standards/pci_dss.shtml</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>The PCI DSS specification is Copyright 2008 PCI Security Standards
|
* <p>The PCI DSS specification is Copyright 2008 PCI Security Standards
|
||||||
* Council LLC.</p>
|
* Council LLC.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: PCISyslogMessage.java,v 1.3 2008/11/14 04:32:00 cvs Exp $
|
* @version $Id: PCISyslogMessage.java,v 1.3 2008/11/14 04:32:00 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class PCISyslogMessage extends AbstractSyslogMessage implements PCISyslogMessageIF {
|
public class PCISyslogMessage extends AbstractSyslogMessage implements PCISyslogMessageIF {
|
||||||
private static final long serialVersionUID = 3571696218386879119L;
|
private static final long serialVersionUID = 3571696218386879119L;
|
||||||
|
|
||||||
public static final String USER_ID = "userId";
|
public static final String USER_ID = "userId";
|
||||||
public static final String EVENT_TYPE = "eventType";
|
public static final String EVENT_TYPE = "eventType";
|
||||||
public static final String DATE = "date";
|
public static final String DATE = "date";
|
||||||
public static final String TIME = "time";
|
public static final String TIME = "time";
|
||||||
public static final String STATUS = "status";
|
public static final String STATUS = "status";
|
||||||
public static final String ORIGINATION = "origination";
|
public static final String ORIGINATION = "origination";
|
||||||
public static final String AFFECTED_RESOURCE = "affectedResource";
|
public static final String AFFECTED_RESOURCE = "affectedResource";
|
||||||
|
|
||||||
protected String userId = UNDEFINED; // 10.3.1 "User Identification"
|
protected String userId = UNDEFINED; // 10.3.1 "User Identification"
|
||||||
protected String eventType = UNDEFINED; // 10.3.2 "Type of event"
|
protected String eventType = UNDEFINED; // 10.3.2 "Type of event"
|
||||||
protected String date = null; // 10.3.3 "Date and time" (date)
|
protected String date = null; // 10.3.3 "Date and time" (date)
|
||||||
protected String time = null; // 10.3.3 "Date and time" (time)
|
protected String time = null; // 10.3.3 "Date and time" (time)
|
||||||
protected String status = UNDEFINED; // 10.3.4 "Success or failure indication"
|
protected String status = UNDEFINED; // 10.3.4 "Success or failure indication"
|
||||||
protected String origination = null; // 10.3.5 "Origination of Event"
|
protected String origination = null; // 10.3.5 "Origination of Event"
|
||||||
protected String affectedResource = UNDEFINED; // 10.3.6 "Identity or name of affected data, system component, or resource"
|
protected String affectedResource = UNDEFINED; // 10.3.6 "Identity or name of affected data, system component, or resource"
|
||||||
|
|
||||||
public PCISyslogMessage() {
|
public PCISyslogMessage() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public PCISyslogMessage(PCISyslogMessageIF message) {
|
public PCISyslogMessage(PCISyslogMessageIF message) {
|
||||||
init(message);
|
init(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PCISyslogMessage(Map fields) {
|
public PCISyslogMessage(Map fields) {
|
||||||
init(fields);
|
init(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init(PCISyslogMessageIF message) {
|
protected void init(PCISyslogMessageIF message) {
|
||||||
this.userId = message.getUserId();
|
this.userId = message.getUserId();
|
||||||
this.eventType = message.getEventType();
|
this.eventType = message.getEventType();
|
||||||
this.date = message.getDate();
|
this.date = message.getDate();
|
||||||
this.time = message.getTime();
|
this.time = message.getTime();
|
||||||
this.status = message.getStatus();
|
this.status = message.getStatus();
|
||||||
this.origination = message.getOrigination();
|
this.origination = message.getOrigination();
|
||||||
this.affectedResource = message.getAffectedResource();
|
this.affectedResource = message.getAffectedResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init(Map fields) {
|
protected void init(Map fields) {
|
||||||
if (fields.containsKey(USER_ID)) { this.userId = (String) fields.get(USER_ID); };
|
if (fields.containsKey(USER_ID)) {
|
||||||
if (fields.containsKey(EVENT_TYPE)) { this.eventType = (String) fields.get(EVENT_TYPE); };
|
this.userId = (String) fields.get(USER_ID);
|
||||||
if (fields.containsKey(DATE) && fields.get(DATE) instanceof String) { this.date = (String) fields.get(DATE); };
|
}
|
||||||
if (fields.containsKey(DATE) && fields.get(DATE) instanceof Date) { setDate((Date) fields.get(DATE)); };
|
;
|
||||||
if (fields.containsKey(TIME)) { this.time = (String) fields.get(TIME); };
|
if (fields.containsKey(EVENT_TYPE)) {
|
||||||
if (fields.containsKey(STATUS)) { this.status = (String) fields.get(STATUS); };
|
this.eventType = (String) fields.get(EVENT_TYPE);
|
||||||
if (fields.containsKey(ORIGINATION)) { this.origination = (String) fields.get(ORIGINATION); };
|
}
|
||||||
if (fields.containsKey(AFFECTED_RESOURCE)) { this.affectedResource = (String) fields.get(AFFECTED_RESOURCE); };
|
;
|
||||||
}
|
if (fields.containsKey(DATE) && fields.get(DATE) instanceof String) {
|
||||||
|
this.date = (String) fields.get(DATE);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
if (fields.containsKey(DATE) && fields.get(DATE) instanceof Date) {
|
||||||
|
setDate((Date) fields.get(DATE));
|
||||||
|
}
|
||||||
|
;
|
||||||
|
if (fields.containsKey(TIME)) {
|
||||||
|
this.time = (String) fields.get(TIME);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
if (fields.containsKey(STATUS)) {
|
||||||
|
this.status = (String) fields.get(STATUS);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
if (fields.containsKey(ORIGINATION)) {
|
||||||
|
this.origination = (String) fields.get(ORIGINATION);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
if (fields.containsKey(AFFECTED_RESOURCE)) {
|
||||||
|
this.affectedResource = (String) fields.get(AFFECTED_RESOURCE);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
public PCISyslogMessage(String userId, String eventType, String status, String affectedResource) {
|
public PCISyslogMessage(String userId, String eventType, String status, String affectedResource) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.affectedResource = affectedResource;
|
this.affectedResource = affectedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PCISyslogMessage(String userId, String eventType, String status, String origination, String affectedResource) {
|
public PCISyslogMessage(String userId, String eventType, String status, String origination, String affectedResource) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.origination = origination;
|
this.origination = origination;
|
||||||
this.affectedResource = affectedResource;
|
this.affectedResource = affectedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PCISyslogMessage(String userId, String eventType, String date, String time, String status, String affectedResource) {
|
public PCISyslogMessage(String userId, String eventType, String date, String time, String status, String affectedResource) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.affectedResource = affectedResource;
|
this.affectedResource = affectedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PCISyslogMessage(String userId, String eventType, String date, String time, String status, String origination, String affectedResource) {
|
public PCISyslogMessage(String userId, String eventType, String date, String time, String status, String origination, String affectedResource) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.origination = origination;
|
this.origination = origination;
|
||||||
this.affectedResource = affectedResource;
|
this.affectedResource = affectedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PCISyslogMessage(String userId, String eventType, Date date, String status, String affectedResource) {
|
public PCISyslogMessage(String userId, String eventType, Date date, String status, String affectedResource) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
|
|
||||||
String[] dateAndTime = generateDateAndTime(date);
|
String[] dateAndTime = generateDateAndTime(date);
|
||||||
this.date = dateAndTime[0];
|
this.date = dateAndTime[0];
|
||||||
this.time = dateAndTime[1];
|
this.time = dateAndTime[1];
|
||||||
|
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.affectedResource = affectedResource;
|
this.affectedResource = affectedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PCISyslogMessage(String userId, String eventType, Date date, String status, String origination, String affectedResource) {
|
public PCISyslogMessage(String userId, String eventType, Date date, String status, String origination, String affectedResource) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
|
|
||||||
String[] dateAndTime = generateDateAndTime(date);
|
String[] dateAndTime = generateDateAndTime(date);
|
||||||
this.date = dateAndTime[0];
|
this.date = dateAndTime[0];
|
||||||
this.time = dateAndTime[1];
|
this.time = dateAndTime[1];
|
||||||
|
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.origination = origination;
|
this.origination = origination;
|
||||||
this.affectedResource = affectedResource;
|
this.affectedResource = affectedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserId() {
|
public String getUserId() {
|
||||||
if (nullOrEmpty(this.userId)) {
|
if (nullOrEmpty(this.userId)) {
|
||||||
return UNDEFINED;
|
return UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.userId;
|
return this.userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserId(String userId) {
|
public void setUserId(String userId) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEventType() {
|
public String getEventType() {
|
||||||
if (nullOrEmpty(this.eventType)) {
|
if (nullOrEmpty(this.eventType)) {
|
||||||
return UNDEFINED;
|
return UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.eventType;
|
return this.eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEventType(String eventType) {
|
public void setEventType(String eventType) {
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDate() {
|
public String getDate() {
|
||||||
if (nullOrEmpty(this.date)) {
|
if (nullOrEmpty(this.date)) {
|
||||||
String dateNow = generateDate();
|
String dateNow = generateDate();
|
||||||
|
|
||||||
return dateNow;
|
return dateNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.date;
|
return this.date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDate(String date) {
|
public void setDate(String date) {
|
||||||
this.date = date;
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDate(Date date) {
|
public void setDate(Date date) {
|
||||||
String[] d = generateDateAndTime(date);
|
String[] d = generateDateAndTime(date);
|
||||||
|
|
||||||
this.date = d[0];
|
this.date = d[0];
|
||||||
this.time = d[1];
|
this.time = d[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTime() {
|
public String getTime() {
|
||||||
if (nullOrEmpty(this.time)) {
|
if (nullOrEmpty(this.time)) {
|
||||||
String timeNow = generateTime();
|
String timeNow = generateTime();
|
||||||
|
|
||||||
return timeNow;
|
return timeNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(String time) {
|
public void setTime(String time) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
if (nullOrEmpty(this.status)) {
|
if (nullOrEmpty(this.status)) {
|
||||||
return UNDEFINED;
|
return UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.status;
|
return this.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(String status) {
|
public void setStatus(String status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOrigination() {
|
public String getOrigination() {
|
||||||
if (nullOrEmpty(this.origination)) {
|
if (nullOrEmpty(this.origination)) {
|
||||||
String originationHere = generateLocalHostName();
|
String originationHere = generateLocalHostName();
|
||||||
|
|
||||||
return originationHere;
|
return originationHere;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.origination;
|
return this.origination;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrigination(String origination) {
|
public void setOrigination(String origination) {
|
||||||
this.origination = origination;
|
this.origination = origination;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAffectedResource() {
|
public String getAffectedResource() {
|
||||||
if (nullOrEmpty(this.affectedResource)) {
|
if (nullOrEmpty(this.affectedResource)) {
|
||||||
return UNDEFINED;
|
return UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.affectedResource;
|
return this.affectedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAffectedResource(String affectedResource) {
|
public void setAffectedResource(String affectedResource) {
|
||||||
this.affectedResource = affectedResource;
|
this.affectedResource = affectedResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createMessage() {
|
public String createMessage() {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
char delimiter = getDelimiter();
|
char delimiter = getDelimiter();
|
||||||
String replaceDelimiter = getReplaceDelimiter();
|
String replaceDelimiter = getReplaceDelimiter();
|
||||||
|
|
||||||
buffer.append(replaceDelimiter(USER_ID,getUserId(),delimiter,replaceDelimiter));
|
buffer.append(replaceDelimiter(USER_ID, getUserId(), delimiter, replaceDelimiter));
|
||||||
buffer.append(delimiter);
|
buffer.append(delimiter);
|
||||||
buffer.append(replaceDelimiter(EVENT_TYPE,getEventType(),delimiter,replaceDelimiter));
|
buffer.append(replaceDelimiter(EVENT_TYPE, getEventType(), delimiter, replaceDelimiter));
|
||||||
buffer.append(delimiter);
|
buffer.append(delimiter);
|
||||||
buffer.append(replaceDelimiter(DATE,getDate(),delimiter,replaceDelimiter));
|
buffer.append(replaceDelimiter(DATE, getDate(), delimiter, replaceDelimiter));
|
||||||
buffer.append(delimiter);
|
buffer.append(delimiter);
|
||||||
buffer.append(replaceDelimiter(TIME,getTime(),delimiter,replaceDelimiter));
|
buffer.append(replaceDelimiter(TIME, getTime(), delimiter, replaceDelimiter));
|
||||||
buffer.append(delimiter);
|
buffer.append(delimiter);
|
||||||
buffer.append(replaceDelimiter(STATUS,getStatus(),delimiter,replaceDelimiter));
|
buffer.append(replaceDelimiter(STATUS, getStatus(), delimiter, replaceDelimiter));
|
||||||
buffer.append(delimiter);
|
buffer.append(delimiter);
|
||||||
buffer.append(replaceDelimiter(ORIGINATION,getOrigination(),delimiter,replaceDelimiter));
|
buffer.append(replaceDelimiter(ORIGINATION, getOrigination(), delimiter, replaceDelimiter));
|
||||||
buffer.append(delimiter);
|
buffer.append(delimiter);
|
||||||
buffer.append(replaceDelimiter(AFFECTED_RESOURCE,getAffectedResource(),delimiter,replaceDelimiter));
|
buffer.append(replaceDelimiter(AFFECTED_RESOURCE, getAffectedResource(), delimiter, replaceDelimiter));
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,36 @@
|
|||||||
package org.graylog2.syslog4j.impl.message.pci;
|
package org.graylog2.syslog4j.impl.message.pci;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PCISyslogMessageIF provides a definition of the fields for audit trails
|
* PCISyslogMessageIF provides a definition of the fields for audit trails
|
||||||
* defined by section 10.3 of the PCI Data Security Standard (PCI DSS)
|
* defined by section 10.3 of the PCI Data Security Standard (PCI DSS)
|
||||||
* versions 1.1 and 1.2.
|
* versions 1.1 and 1.2.
|
||||||
*
|
* <p/>
|
||||||
* <p>More information on the PCI DSS specification is available here:</p>
|
* <p>More information on the PCI DSS specification is available here:</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>https://www.pcisecuritystandards.org/security_standards/pci_dss.shtml</p>
|
* <p>https://www.pcisecuritystandards.org/security_standards/pci_dss.shtml</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>The PCI DSS specification is Copyright 2008 PCI Security Standards
|
* <p>The PCI DSS specification is Copyright 2008 PCI Security Standards
|
||||||
* Council LLC.</p>
|
* Council LLC.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: PCISyslogMessageIF.java,v 1.1 2008/11/10 04:38:37 cvs Exp $
|
* @version $Id: PCISyslogMessageIF.java,v 1.1 2008/11/10 04:38:37 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface PCISyslogMessageIF {
|
public interface PCISyslogMessageIF {
|
||||||
public String getUserId();
|
public String getUserId();
|
||||||
public String getEventType();
|
|
||||||
public String getDate();
|
public String getEventType();
|
||||||
public String getTime();
|
|
||||||
public String getStatus();
|
public String getDate();
|
||||||
public String getOrigination();
|
|
||||||
public String getAffectedResource();
|
public String getTime();
|
||||||
|
|
||||||
|
public String getStatus();
|
||||||
|
|
||||||
|
public String getOrigination();
|
||||||
|
|
||||||
|
public String getAffectedResource();
|
||||||
}
|
}
|
||||||
|
@ -9,110 +9,110 @@ import org.graylog2.syslog4j.SyslogMessageProcessorIF;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslogMessageProcessor provides the ability to split a syslog message
|
* AbstractSyslogMessageProcessor provides the ability to split a syslog message
|
||||||
* into multiple messages when the message is greater than the syslog
|
* into multiple messages when the message is greater than the syslog
|
||||||
* maximum message length (1024 bytes including the header).
|
* maximum message length (1024 bytes including the header).
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogMessageProcessor.java,v 1.2 2010/11/28 04:15:18 cvs Exp $
|
* @version $Id: AbstractSyslogMessageProcessor.java,v 1.2 2010/11/28 04:15:18 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslogMessageProcessor implements SyslogMessageProcessorIF, SyslogConstants {
|
public abstract class AbstractSyslogMessageProcessor implements SyslogMessageProcessorIF, SyslogConstants {
|
||||||
private static final long serialVersionUID = -5413127301924500938L;
|
private static final long serialVersionUID = -5413127301924500938L;
|
||||||
protected String localName = null;
|
protected String localName = null;
|
||||||
|
|
||||||
public AbstractSyslogMessageProcessor() {
|
public AbstractSyslogMessageProcessor() {
|
||||||
this.localName = SyslogUtility.getLocalName();
|
this.localName = SyslogUtility.getLocalName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] createPacketData(byte[] header, byte[] message, int start, int length) {
|
public byte[] createPacketData(byte[] header, byte[] message, int start, int length) {
|
||||||
return createPacketData(header,message,start,length,null,null);
|
return createPacketData(header, message, start, length, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] createPacketData(byte[] header, byte[] message, int start, int length, byte[] splitBeginText, byte[] splitEndText) {
|
public byte[] createPacketData(byte[] header, byte[] message, int start, int length, byte[] splitBeginText, byte[] splitEndText) {
|
||||||
if (header == null || message == null || start < 0 || length < 0) {
|
if (header == null || message == null || start < 0 || length < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dataLength = header.length + length;
|
int dataLength = header.length + length;
|
||||||
|
|
||||||
if (splitBeginText != null) {
|
if (splitBeginText != null) {
|
||||||
dataLength += splitBeginText.length;
|
dataLength += splitBeginText.length;
|
||||||
}
|
}
|
||||||
if (splitEndText != null) {
|
if (splitEndText != null) {
|
||||||
dataLength += splitEndText.length;
|
dataLength += splitEndText.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] data = new byte[dataLength];
|
byte[] data = new byte[dataLength];
|
||||||
|
|
||||||
System.arraycopy(header,0,data,0,header.length);
|
System.arraycopy(header, 0, data, 0, header.length);
|
||||||
int pos = header.length;
|
int pos = header.length;
|
||||||
|
|
||||||
if (splitBeginText != null) {
|
if (splitBeginText != null) {
|
||||||
System.arraycopy(splitBeginText,0,data,pos,splitBeginText.length);
|
System.arraycopy(splitBeginText, 0, data, pos, splitBeginText.length);
|
||||||
pos += splitBeginText.length;
|
pos += splitBeginText.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.arraycopy(message,start,data,pos,length);
|
System.arraycopy(message, start, data, pos, length);
|
||||||
pos += length;
|
pos += length;
|
||||||
|
|
||||||
if (splitEndText != null) {
|
if (splitEndText != null) {
|
||||||
System.arraycopy(splitEndText,0,data,pos,splitEndText.length);
|
System.arraycopy(splitEndText, 0, data, pos, splitEndText.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void appendPriority(StringBuffer buffer, int facility, int level) {
|
protected void appendPriority(StringBuffer buffer, int facility, int level) {
|
||||||
int priority = facility | level;
|
int priority = facility | level;
|
||||||
|
|
||||||
buffer.append("<");
|
buffer.append("<");
|
||||||
buffer.append(priority);
|
buffer.append(priority);
|
||||||
buffer.append(">");
|
buffer.append(">");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void appendLocalTimestamp(StringBuffer buffer) {
|
protected void appendLocalTimestamp(StringBuffer buffer) {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat(SYSLOG_DATEFORMAT,Locale.ENGLISH);
|
SimpleDateFormat dateFormat = new SimpleDateFormat(SYSLOG_DATEFORMAT, Locale.ENGLISH);
|
||||||
|
|
||||||
String datePrefix = dateFormat.format(new Date());
|
String datePrefix = dateFormat.format(new Date());
|
||||||
|
|
||||||
int pos = buffer.length() + 4;
|
int pos = buffer.length() + 4;
|
||||||
|
|
||||||
buffer.append(datePrefix);
|
buffer.append(datePrefix);
|
||||||
|
|
||||||
// RFC 3164 requires leading space for days 1-9
|
// RFC 3164 requires leading space for days 1-9
|
||||||
if (buffer.charAt(pos) == '0') {
|
if (buffer.charAt(pos) == '0') {
|
||||||
buffer.setCharAt(pos,' ');
|
buffer.setCharAt(pos, ' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void appendLocalName(StringBuffer buffer, String localName) {
|
protected void appendLocalName(StringBuffer buffer, String localName) {
|
||||||
if (localName != null) {
|
if (localName != null) {
|
||||||
buffer.append(localName);
|
buffer.append(localName);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
buffer.append(this.localName);
|
buffer.append(this.localName);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.append(' ');
|
buffer.append(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createSyslogHeader(int facility, int level, String localName, boolean sendLocalTimestamp, boolean sendLocalName) {
|
public String createSyslogHeader(int facility, int level, String localName, boolean sendLocalTimestamp, boolean sendLocalName) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
appendPriority(buffer,facility,level);
|
appendPriority(buffer, facility, level);
|
||||||
|
|
||||||
if (sendLocalTimestamp) {
|
if (sendLocalTimestamp) {
|
||||||
appendLocalTimestamp(buffer);
|
appendLocalTimestamp(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendLocalName) {
|
if (sendLocalName) {
|
||||||
appendLocalName(buffer,localName);
|
appendLocalName(buffer, localName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,34 +2,34 @@ package org.graylog2.syslog4j.impl.message.processor;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogMessageProcessor wraps AbstractSyslogMessageProcessor.
|
* SyslogMessageProcessor wraps AbstractSyslogMessageProcessor.
|
||||||
*
|
* <p/>
|
||||||
* <p>Those wishing to replace (or improve upon) this implementation
|
* <p>Those wishing to replace (or improve upon) this implementation
|
||||||
* can write a custom SyslogMessageProcessorIF and set it per
|
* can write a custom SyslogMessageProcessorIF and set it per
|
||||||
* instance via the SyslogIF.setMessageProcessor(..) method or set it globally
|
* instance via the SyslogIF.setMessageProcessor(..) method or set it globally
|
||||||
* via the SyslogMessageProcessor.setDefault(..) method.</p>
|
* via the SyslogMessageProcessor.setDefault(..) method.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogMessageProcessor.java,v 1.7 2010/02/04 03:41:37 cvs Exp $
|
* @version $Id: SyslogMessageProcessor.java,v 1.7 2010/02/04 03:41:37 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SyslogMessageProcessor extends AbstractSyslogMessageProcessor {
|
public class SyslogMessageProcessor extends AbstractSyslogMessageProcessor {
|
||||||
private static final long serialVersionUID = -4232803978024990353L;
|
private static final long serialVersionUID = -4232803978024990353L;
|
||||||
|
|
||||||
private static final SyslogMessageProcessor INSTANCE = new SyslogMessageProcessor();
|
private static final SyslogMessageProcessor INSTANCE = new SyslogMessageProcessor();
|
||||||
|
|
||||||
protected static SyslogMessageProcessor defaultInstance = INSTANCE;
|
protected static SyslogMessageProcessor defaultInstance = INSTANCE;
|
||||||
|
|
||||||
public static void setDefault(SyslogMessageProcessor messageProcessor) {
|
public static void setDefault(SyslogMessageProcessor messageProcessor) {
|
||||||
if (messageProcessor != null) {
|
if (messageProcessor != null) {
|
||||||
defaultInstance = messageProcessor;
|
defaultInstance = messageProcessor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SyslogMessageProcessor getDefault() {
|
public static SyslogMessageProcessor getDefault() {
|
||||||
return defaultInstance;
|
return defaultInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,14 @@ import org.graylog2.syslog4j.impl.message.structured.StructuredSyslogMessage;
|
|||||||
* than the syslog maximum message length (1024 bytes including the header). It
|
* than the syslog maximum message length (1024 bytes including the header). It
|
||||||
* adds support for structured syslog messages as specified by
|
* adds support for structured syslog messages as specified by
|
||||||
* draft-ietf-syslog-protocol-23. More information here:
|
* draft-ietf-syslog-protocol-23. More information here:
|
||||||
*
|
* <p/>
|
||||||
* <p>http://tools.ietf.org/html/draft-ietf-syslog-protocol-23</p>
|
* <p>http://tools.ietf.org/html/draft-ietf-syslog-protocol-23</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Those wishing to replace (or improve upon) this implementation
|
* <p>Those wishing to replace (or improve upon) this implementation
|
||||||
* can write a custom SyslogMessageProcessorIF and set it per
|
* can write a custom SyslogMessageProcessorIF and set it per
|
||||||
* instance via the SyslogIF.setStructuredMessageProcessor(..) method or set it globally
|
* instance via the SyslogIF.setStructuredMessageProcessor(..) method or set it globally
|
||||||
* via the StructuredSyslogMessageProcessor.setDefault(..) method.</p>
|
* via the StructuredSyslogMessageProcessor.setDefault(..) method.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p>
|
||||||
* Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy of the
|
* Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy of the
|
||||||
* LGPL license is available in the META-INF folder in all distributions of
|
* LGPL license is available in the META-INF folder in all distributions of
|
||||||
@ -29,78 +29,78 @@ import org.graylog2.syslog4j.impl.message.structured.StructuredSyslogMessage;
|
|||||||
* @version $Id: StructuredSyslogMessageProcessor.java,v 1.4 2011/01/11 05:11:13 cvs Exp $
|
* @version $Id: StructuredSyslogMessageProcessor.java,v 1.4 2011/01/11 05:11:13 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class StructuredSyslogMessageProcessor extends AbstractSyslogMessageProcessor {
|
public class StructuredSyslogMessageProcessor extends AbstractSyslogMessageProcessor {
|
||||||
private static final long serialVersionUID = -1563777226913475257L;
|
private static final long serialVersionUID = -1563777226913475257L;
|
||||||
|
|
||||||
public static String VERSION = "1";
|
public static String VERSION = "1";
|
||||||
|
|
||||||
private static final StructuredSyslogMessageProcessor INSTANCE = new StructuredSyslogMessageProcessor();
|
private static final StructuredSyslogMessageProcessor INSTANCE = new StructuredSyslogMessageProcessor();
|
||||||
protected static StructuredSyslogMessageProcessor defaultInstance = INSTANCE;
|
protected static StructuredSyslogMessageProcessor defaultInstance = INSTANCE;
|
||||||
|
|
||||||
private String applicationName = STRUCTURED_DATA_APP_NAME_DEFAULT_VALUE;
|
private String applicationName = STRUCTURED_DATA_APP_NAME_DEFAULT_VALUE;
|
||||||
private String processId = STRUCTURED_DATA_PROCESS_ID_DEFAULT_VALUE;
|
private String processId = STRUCTURED_DATA_PROCESS_ID_DEFAULT_VALUE;
|
||||||
|
|
||||||
private DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
|
private DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
|
||||||
|
|
||||||
public static void setDefault(StructuredSyslogMessageProcessor messageProcessor) {
|
public static void setDefault(StructuredSyslogMessageProcessor messageProcessor) {
|
||||||
if (messageProcessor != null) {
|
if (messageProcessor != null) {
|
||||||
defaultInstance = messageProcessor;
|
defaultInstance = messageProcessor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StructuredSyslogMessageProcessor getDefault() {
|
public static StructuredSyslogMessageProcessor getDefault() {
|
||||||
return defaultInstance;
|
return defaultInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructuredSyslogMessageProcessor() {
|
public StructuredSyslogMessageProcessor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructuredSyslogMessageProcessor(final String applicationName) {
|
public StructuredSyslogMessageProcessor(final String applicationName) {
|
||||||
super();
|
super();
|
||||||
this.applicationName = applicationName;
|
this.applicationName = applicationName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTimeFormatter getDateTimeFormatter() {
|
public DateTimeFormatter getDateTimeFormatter() {
|
||||||
return dateTimeFormatter;
|
return dateTimeFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDateTimeFormatter(DateTimeFormatter dateTimeFormatter) {
|
public void setDateTimeFormatter(DateTimeFormatter dateTimeFormatter) {
|
||||||
this.dateTimeFormatter = dateTimeFormatter;
|
this.dateTimeFormatter = dateTimeFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getApplicationName() {
|
public String getApplicationName() {
|
||||||
return this.applicationName;
|
return this.applicationName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApplicationName(String applicationName) {
|
public void setApplicationName(String applicationName) {
|
||||||
this.applicationName = applicationName;
|
this.applicationName = applicationName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProcessId() {
|
public String getProcessId() {
|
||||||
return this.processId;
|
return this.processId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProcessId(String processId) {
|
public void setProcessId(String processId) {
|
||||||
this.processId = processId;
|
this.processId = processId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createSyslogHeader(final int facility, final int level, String localName, final boolean sendLocalTimestamp, final boolean sendLocalName) {
|
public String createSyslogHeader(final int facility, final int level, String localName, final boolean sendLocalTimestamp, final boolean sendLocalName) {
|
||||||
final StringBuffer buffer = new StringBuffer();
|
final StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
appendPriority(buffer,facility,level);
|
appendPriority(buffer, facility, level);
|
||||||
buffer.append(VERSION);
|
buffer.append(VERSION);
|
||||||
buffer.append(' ');
|
buffer.append(' ');
|
||||||
|
|
||||||
getDateTimeFormatter().printTo(buffer,System.currentTimeMillis());
|
getDateTimeFormatter().printTo(buffer, System.currentTimeMillis());
|
||||||
buffer.append(' ');
|
buffer.append(' ');
|
||||||
|
|
||||||
appendLocalName(buffer,localName);
|
appendLocalName(buffer, localName);
|
||||||
|
|
||||||
buffer.append(StructuredSyslogMessage.nilProtect(this.applicationName))
|
buffer.append(StructuredSyslogMessage.nilProtect(this.applicationName))
|
||||||
.append(' ');
|
.append(' ');
|
||||||
|
|
||||||
buffer.append(StructuredSyslogMessage.nilProtect(this.processId)).append(' ');
|
buffer.append(StructuredSyslogMessage.nilProtect(this.processId)).append(' ');
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ import org.graylog2.syslog4j.impl.message.AbstractSyslogMessage;
|
|||||||
* support for turning POJO (Plain Ol' Java Objects) into Syslog messages. It
|
* support for turning POJO (Plain Ol' Java Objects) into Syslog messages. It
|
||||||
* adds support for structured syslog messages as specified by
|
* adds support for structured syslog messages as specified by
|
||||||
* draft-ietf-syslog-protocol-23. More information here:
|
* draft-ietf-syslog-protocol-23. More information here:
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p>
|
||||||
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
||||||
* </p>
|
* </p>
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p>
|
||||||
* Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy of the
|
* Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy of the
|
||||||
* LGPL license is available in the META-INF folder in all distributions of
|
* LGPL license is available in the META-INF folder in all distributions of
|
||||||
@ -28,364 +28,364 @@ import org.graylog2.syslog4j.impl.message.AbstractSyslogMessage;
|
|||||||
* @version $Id: StructuredSyslogMessage.java,v 1.5 2010/09/11 16:49:24 cvs Exp $
|
* @version $Id: StructuredSyslogMessage.java,v 1.5 2010/09/11 16:49:24 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class StructuredSyslogMessage extends AbstractSyslogMessage implements StructuredSyslogMessageIF {
|
public class StructuredSyslogMessage extends AbstractSyslogMessage implements StructuredSyslogMessageIF {
|
||||||
private static final long serialVersionUID = 3669887659567965965L;
|
private static final long serialVersionUID = 3669887659567965965L;
|
||||||
|
|
||||||
private String messageId;
|
private String messageId;
|
||||||
private Map structuredData;
|
private Map structuredData;
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
private StructuredSyslogMessage() {
|
private StructuredSyslogMessage() {
|
||||||
this.messageId = null;
|
this.messageId = null;
|
||||||
this.message = null;
|
this.message = null;
|
||||||
this.structuredData = null;
|
this.structuredData = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the {@link StructuredSyslogMessage} using MSGID,
|
* Constructs the {@link StructuredSyslogMessage} using MSGID,
|
||||||
* STRUCTURED-DATA and MSG fields, as described in:
|
* STRUCTURED-DATA and MSG fields, as described in:
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p>
|
||||||
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
||||||
* </p>
|
* </p>
|
||||||
*
|
* <p/>
|
||||||
* The Map must be a String -> (Map of String -> String), which encompasses
|
* The Map must be a String -> (Map of String -> String), which encompasses
|
||||||
* the STRUCTURED-DATA field described in above document.
|
* the STRUCTURED-DATA field described in above document.
|
||||||
*
|
*
|
||||||
* @param messageId
|
* @param messageId
|
||||||
* @param structuredData
|
* @param structuredData
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
public StructuredSyslogMessage(final String messageId,
|
public StructuredSyslogMessage(final String messageId,
|
||||||
final Map structuredData, final String message) {
|
final Map structuredData, final String message) {
|
||||||
super();
|
super();
|
||||||
this.messageId = messageId;
|
this.messageId = messageId;
|
||||||
this.structuredData = structuredData;
|
this.structuredData = structuredData;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
|
||||||
ensureCorrectMapType();
|
ensureCorrectMapType();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureCorrectMapType() {
|
private void ensureCorrectMapType() {
|
||||||
if (!(getStructuredData() == null)) {
|
if (!(getStructuredData() == null)) {
|
||||||
Set sdEntrySet = getStructuredData().entrySet();
|
Set sdEntrySet = getStructuredData().entrySet();
|
||||||
for (Iterator it = sdEntrySet.iterator(); it.hasNext();) {
|
for (Iterator it = sdEntrySet.iterator(); it.hasNext(); ) {
|
||||||
Map.Entry sdEntry = (Map.Entry) it.next();
|
Map.Entry sdEntry = (Map.Entry) it.next();
|
||||||
if (!(sdEntry.getKey() instanceof String)) {
|
if (!(sdEntry.getKey() instanceof String)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Structured data map must be a map of String -> (Map of String,String)");
|
"Structured data map must be a map of String -> (Map of String,String)");
|
||||||
}
|
}
|
||||||
if (!(sdEntry.getValue() instanceof Map)) {
|
if (!(sdEntry.getValue() instanceof Map)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Structured data map must be a map of String -> (Map of String,String)");
|
"Structured data map must be a map of String -> (Map of String,String)");
|
||||||
}
|
}
|
||||||
|
|
||||||
Set entrySet = ((Map) sdEntry.getValue()).entrySet();
|
Set entrySet = ((Map) sdEntry.getValue()).entrySet();
|
||||||
for (Iterator it2 = entrySet.iterator(); it2.hasNext();) {
|
for (Iterator it2 = entrySet.iterator(); it2.hasNext(); ) {
|
||||||
Map.Entry entry = (Map.Entry) it2.next();
|
Map.Entry entry = (Map.Entry) it2.next();
|
||||||
|
|
||||||
if (!(entry.getKey() instanceof String)) {
|
if (!(entry.getKey() instanceof String)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Structured data map must be a map of String -> (Map of String,String)");
|
"Structured data map must be a map of String -> (Map of String,String)");
|
||||||
}
|
}
|
||||||
if (!(entry.getValue() instanceof String)) {
|
if (!(entry.getValue() instanceof String)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Structured data map must be a map of String -> (Map of String,String)");
|
"Structured data map must be a map of String -> (Map of String,String)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses and loads a {@link StructuredSyslogMessage} from string.
|
* Parses and loads a {@link StructuredSyslogMessage} from string.
|
||||||
*
|
*
|
||||||
* @param syslogMessageStr
|
* @param syslogMessageStr
|
||||||
* @return Returns an instance of StructuredSyslogMessage.
|
* @return Returns an instance of StructuredSyslogMessage.
|
||||||
*/
|
*/
|
||||||
public static StructuredSyslogMessage fromString(
|
public static StructuredSyslogMessage fromString(
|
||||||
final String syslogMessageStr) {
|
final String syslogMessageStr) {
|
||||||
final StructuredSyslogMessage syslogMessage = new StructuredSyslogMessage();
|
final StructuredSyslogMessage syslogMessage = new StructuredSyslogMessage();
|
||||||
syslogMessage.deserialize(syslogMessageStr);
|
syslogMessage.deserialize(syslogMessageStr);
|
||||||
return syslogMessage;
|
return syslogMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deserialize(final String stringMessage) {
|
private void deserialize(final String stringMessage) {
|
||||||
// Check correct format
|
// Check correct format
|
||||||
if (stringMessage.indexOf('[') <= 0)
|
if (stringMessage.indexOf('[') <= 0)
|
||||||
throw new IllegalArgumentException("Invalid Syslog string format: "
|
throw new IllegalArgumentException("Invalid Syslog string format: "
|
||||||
+ stringMessage);
|
+ stringMessage);
|
||||||
|
|
||||||
// Divide the string in 2 sections
|
// Divide the string in 2 sections
|
||||||
final String syslogHeader = stringMessage.substring(0, stringMessage
|
final String syslogHeader = stringMessage.substring(0, stringMessage
|
||||||
.indexOf('['));
|
.indexOf('['));
|
||||||
String structuredDataString = stringMessage.substring(stringMessage
|
String structuredDataString = stringMessage.substring(stringMessage
|
||||||
.indexOf('['), stringMessage.lastIndexOf(']') + 1);
|
.indexOf('['), stringMessage.lastIndexOf(']') + 1);
|
||||||
|
|
||||||
if ((stringMessage.lastIndexOf(']') + 2) <= stringMessage.length())
|
if ((stringMessage.lastIndexOf(']') + 2) <= stringMessage.length())
|
||||||
this.message = stringMessage.substring(stringMessage.lastIndexOf(']') + 2);
|
this.message = stringMessage.substring(stringMessage.lastIndexOf(']') + 2);
|
||||||
|
|
||||||
else {
|
else {
|
||||||
this.message = "";
|
this.message = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split into tokens
|
// Split into tokens
|
||||||
final String[] tokens = syslogHeader.split(" ");
|
final String[] tokens = syslogHeader.split(" ");
|
||||||
|
|
||||||
// Check number of tokens must be 1 -- rest of the header should already
|
// Check number of tokens must be 1 -- rest of the header should already
|
||||||
// be stripped
|
// be stripped
|
||||||
if (tokens.length != 1) {
|
if (tokens.length != 1) {
|
||||||
throw new IllegalArgumentException("Invalid Syslog string format: "
|
throw new IllegalArgumentException("Invalid Syslog string format: "
|
||||||
+ stringMessage);
|
+ stringMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messageId = SyslogConstants.STRUCTURED_DATA_NILVALUE.equals(tokens[0]) ? null
|
this.messageId = SyslogConstants.STRUCTURED_DATA_NILVALUE.equals(tokens[0]) ? null
|
||||||
: tokens[0];
|
: tokens[0];
|
||||||
|
|
||||||
this.structuredData = new HashMap();
|
this.structuredData = new HashMap();
|
||||||
if (!SyslogConstants.STRUCTURED_DATA_EMPTY_VALUE.equals(structuredDataString)) {
|
if (!SyslogConstants.STRUCTURED_DATA_EMPTY_VALUE.equals(structuredDataString)) {
|
||||||
while (!"".equals(structuredDataString)) {
|
while (!"".equals(structuredDataString)) {
|
||||||
if (!structuredDataString.startsWith("[")
|
if (!structuredDataString.startsWith("[")
|
||||||
|| structuredDataString.indexOf(']') == -1) {
|
|| structuredDataString.indexOf(']') == -1) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Invalid structured data format in Syslog message: "
|
"Invalid structured data format in Syslog message: "
|
||||||
+ stringMessage);
|
+ stringMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String structuredDataIteration = structuredDataString
|
final String structuredDataIteration = structuredDataString
|
||||||
.substring(1, structuredDataString.indexOf(']'));
|
.substring(1, structuredDataString.indexOf(']'));
|
||||||
|
|
||||||
final Map iterMap = new HashMap();
|
final Map iterMap = new HashMap();
|
||||||
|
|
||||||
final String[] params = structuredDataIteration.split(" ");
|
final String[] params = structuredDataIteration.split(" ");
|
||||||
|
|
||||||
for (int i = 1; i < params.length; i++) {
|
for (int i = 1; i < params.length; i++) {
|
||||||
final String[] paramIter = params[i].split("=");
|
final String[] paramIter = params[i].split("=");
|
||||||
if (paramIter.length != 2) {
|
if (paramIter.length != 2) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Invalid structured data format in Syslog message: "
|
"Invalid structured data format in Syslog message: "
|
||||||
+ stringMessage);
|
+ stringMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!paramIter[1].startsWith("\"")
|
if (!paramIter[1].startsWith("\"")
|
||||||
|| !paramIter[1].endsWith("\"")) {
|
|| !paramIter[1].endsWith("\"")) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Invalid structured data format in Syslog message: "
|
"Invalid structured data format in Syslog message: "
|
||||||
+ stringMessage);
|
+ stringMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
iterMap.put(paramIter[0], paramIter[1].substring(1,
|
iterMap.put(paramIter[0], paramIter[1].substring(1,
|
||||||
paramIter[1].length() - 1));
|
paramIter[1].length() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.structuredData.put(params[0], iterMap);
|
this.structuredData.put(params[0], iterMap);
|
||||||
|
|
||||||
if (structuredDataString.indexOf(']') != structuredDataString
|
if (structuredDataString.indexOf(']') != structuredDataString
|
||||||
.lastIndexOf(']')) {
|
.lastIndexOf(']')) {
|
||||||
structuredDataString = structuredDataString
|
structuredDataString = structuredDataString
|
||||||
.substring(structuredDataString.indexOf(']') + 1);
|
.substring(structuredDataString.indexOf(']') + 1);
|
||||||
} else {
|
} else {
|
||||||
structuredDataString = "";
|
structuredDataString = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the MSGID field of the structured message format, as described
|
* Returns the MSGID field of the structured message format, as described
|
||||||
* in:
|
* in:
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p>
|
||||||
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return Returns the MSG ID field.
|
* @return Returns the MSG ID field.
|
||||||
*/
|
*/
|
||||||
public String getMessageId() {
|
public String getMessageId() {
|
||||||
return this.messageId;
|
return this.messageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the structured data map. The Map is a String -> (Map of String ->
|
* Returns the structured data map. The Map is a String -> (Map of String ->
|
||||||
* String), which encompasses the STRUCTURED-DATA field, as described in:
|
* String), which encompasses the STRUCTURED-DATA field, as described in:
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p>
|
||||||
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return Returns a Map object containing structured data.
|
* @return Returns a Map object containing structured data.
|
||||||
*/
|
*/
|
||||||
public Map getStructuredData() {
|
public Map getStructuredData() {
|
||||||
return this.structuredData;
|
return this.structuredData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the MSG field of the structured message format, as described in:
|
* Returns the MSG field of the structured message format, as described in:
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p>
|
||||||
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return Returns the MSG field.
|
* @return Returns the MSG field.
|
||||||
*/
|
*/
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return this.message;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @seeorg.productivity.java.syslog4j.impl.message.AbstractSyslogMessage#
|
* @seeorg.productivity.java.syslog4j.impl.message.AbstractSyslogMessage#
|
||||||
* createMessage()
|
* createMessage()
|
||||||
*/
|
*/
|
||||||
public String createMessage() {
|
public String createMessage() {
|
||||||
return serialize();
|
return serialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String serialize() {
|
private String serialize() {
|
||||||
if (!StructuredSyslogMessage.checkIsPrintable(getMessageId()))
|
if (!StructuredSyslogMessage.checkIsPrintable(getMessageId()))
|
||||||
throw new IllegalArgumentException("Invalid message id: "
|
throw new IllegalArgumentException("Invalid message id: "
|
||||||
+ getMessageId());
|
+ getMessageId());
|
||||||
|
|
||||||
final StringBuffer sb = new StringBuffer();
|
final StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
sb.append(StructuredSyslogMessage.nilProtect(getMessageId()));
|
sb.append(StructuredSyslogMessage.nilProtect(getMessageId()));
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
|
|
||||||
if (getStructuredData() == null || getStructuredData().size() == 0) {
|
if (getStructuredData() == null || getStructuredData().size() == 0) {
|
||||||
// This is not desired, but rsyslogd does not store version 1 syslog
|
// This is not desired, but rsyslogd does not store version 1 syslog
|
||||||
// message correctly if
|
// message correctly if
|
||||||
// there is no
|
// there is no
|
||||||
// structured data present
|
// structured data present
|
||||||
sb.append(SyslogConstants.STRUCTURED_DATA_EMPTY_VALUE);
|
sb.append(SyslogConstants.STRUCTURED_DATA_EMPTY_VALUE);
|
||||||
} else {
|
} else {
|
||||||
Set sdEntrySet = getStructuredData().entrySet();
|
Set sdEntrySet = getStructuredData().entrySet();
|
||||||
for (Iterator it = sdEntrySet.iterator(); it.hasNext();) {
|
for (Iterator it = sdEntrySet.iterator(); it.hasNext(); ) {
|
||||||
final Map.Entry sdElement = (Map.Entry) it.next();
|
final Map.Entry sdElement = (Map.Entry) it.next();
|
||||||
final String sdId = (String) sdElement.getKey();
|
final String sdId = (String) sdElement.getKey();
|
||||||
|
|
||||||
if (sdId == null || sdId.length() == 0
|
if (sdId == null || sdId.length() == 0
|
||||||
|| !StructuredSyslogMessage.checkIsPrintable(sdId)) {
|
|| !StructuredSyslogMessage.checkIsPrintable(sdId)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Illegal structured data id: " + sdId);
|
"Illegal structured data id: " + sdId);
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append('[').append(sdId);
|
sb.append('[').append(sdId);
|
||||||
|
|
||||||
final Map sdParams = (Map) sdElement.getValue();
|
final Map sdParams = (Map) sdElement.getValue();
|
||||||
|
|
||||||
if (sdParams != null) {
|
if (sdParams != null) {
|
||||||
Set entrySet = sdParams.entrySet();
|
Set entrySet = sdParams.entrySet();
|
||||||
for (Iterator it2 = entrySet.iterator(); it2.hasNext();) {
|
for (Iterator it2 = entrySet.iterator(); it2.hasNext(); ) {
|
||||||
Map.Entry entry = (Map.Entry) it2.next();
|
Map.Entry entry = (Map.Entry) it2.next();
|
||||||
final String paramName = (String) entry.getKey();
|
final String paramName = (String) entry.getKey();
|
||||||
final String paramValue = (String) entry.getValue();
|
final String paramValue = (String) entry.getValue();
|
||||||
|
|
||||||
if (paramName == null
|
if (paramName == null
|
||||||
|| paramName.length() == 0
|
|| paramName.length() == 0
|
||||||
|| !StructuredSyslogMessage
|
|| !StructuredSyslogMessage
|
||||||
.checkIsPrintable(paramName))
|
.checkIsPrintable(paramName))
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Illegal structured data parameter name: "
|
"Illegal structured data parameter name: "
|
||||||
+ paramName);
|
+ paramName);
|
||||||
|
|
||||||
if (paramValue == null)
|
if (paramValue == null)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Null structured data parameter value for parameter name: "
|
"Null structured data parameter value for parameter name: "
|
||||||
+ paramName);
|
+ paramName);
|
||||||
|
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(paramName);
|
sb.append(paramName);
|
||||||
sb.append('=').append('"');
|
sb.append('=').append('"');
|
||||||
StructuredSyslogMessage.sdEscape(sb, paramValue);
|
StructuredSyslogMessage.sdEscape(sb, paramValue);
|
||||||
sb.append('"');
|
sb.append('"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(']');
|
sb.append(']');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getMessage() != null && getMessage().length() != 0) {
|
if (getMessage() != null && getMessage().length() != 0) {
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
sb.append(StructuredSyslogMessage.nilProtect(getMessage()));
|
sb.append(StructuredSyslogMessage.nilProtect(getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sdEscape(final StringBuffer sb, final String value) {
|
public static void sdEscape(final StringBuffer sb, final String value) {
|
||||||
for (int i = 0; i < value.length(); i++) {
|
for (int i = 0; i < value.length(); i++) {
|
||||||
final char c = value.charAt(i);
|
final char c = value.charAt(i);
|
||||||
|
|
||||||
if (c == '"' || c == '\\' || c == ']') {
|
if (c == '"' || c == '\\' || c == ']') {
|
||||||
sb.append('\\');
|
sb.append('\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkIsPrintable(final String value) {
|
public static boolean checkIsPrintable(final String value) {
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (int i = 0; i < value.length(); i++) {
|
for (int i = 0; i < value.length(); i++) {
|
||||||
final char c = value.charAt(i);
|
final char c = value.charAt(i);
|
||||||
|
|
||||||
if (c < 33 || c > 126)
|
if (c < 33 || c > 126)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String nilProtect(final String value) {
|
public static String nilProtect(final String value) {
|
||||||
if (value == null || value.trim().length() == 0) {
|
if (value == null || value.trim().length() == 0) {
|
||||||
return SyslogConstants.STRUCTURED_DATA_NILVALUE;
|
return SyslogConstants.STRUCTURED_DATA_NILVALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
||||||
result = prime * result
|
result = prime * result
|
||||||
+ ((messageId == null) ? 0 : messageId.hashCode());
|
+ ((messageId == null) ? 0 : messageId.hashCode());
|
||||||
result = prime * result
|
result = prime * result
|
||||||
+ ((structuredData == null) ? 0 : structuredData.hashCode());
|
+ ((structuredData == null) ? 0 : structuredData.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (obj == null) return false;
|
if (obj == null) return false;
|
||||||
if (getClass() != obj.getClass()) return false;
|
if (getClass() != obj.getClass()) return false;
|
||||||
|
|
||||||
StructuredSyslogMessage other = (StructuredSyslogMessage) obj;
|
StructuredSyslogMessage other = (StructuredSyslogMessage) obj;
|
||||||
|
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
if (other.message != null) return false;
|
if (other.message != null) return false;
|
||||||
|
|
||||||
} else if (!message.equals(other.message)) return false;
|
} else if (!message.equals(other.message)) return false;
|
||||||
|
|
||||||
if (messageId == null) {
|
if (messageId == null) {
|
||||||
if (other.messageId != null) return false;
|
if (other.messageId != null) return false;
|
||||||
|
|
||||||
} else if (!messageId.equals(other.messageId)) return false;
|
} else if (!messageId.equals(other.messageId)) return false;
|
||||||
|
|
||||||
if (structuredData == null) {
|
if (structuredData == null) {
|
||||||
if (other.structuredData != null) return false;
|
if (other.structuredData != null) return false;
|
||||||
|
|
||||||
} else if (!structuredData.equals(other.structuredData)) return false;
|
} else if (!structuredData.equals(other.structuredData)) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return serialize();
|
return serialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,16 @@ package org.graylog2.syslog4j.impl.message.structured;
|
|||||||
import org.graylog2.syslog4j.SyslogMessageIF;
|
import org.graylog2.syslog4j.SyslogMessageIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StructuredSyslogMessageIF is a "marker" interface to identify structured
|
* StructuredSyslogMessageIF is a "marker" interface to identify structured
|
||||||
* SyslogMessageIF implementations.
|
* SyslogMessageIF implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: StructuredSyslogMessageIF.java,v 1.1 2009/07/22 15:54:23 cvs Exp $
|
* @version $Id: StructuredSyslogMessageIF.java,v 1.1 2009/07/22 15:54:23 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface StructuredSyslogMessageIF extends SyslogMessageIF {
|
public interface StructuredSyslogMessageIF extends SyslogMessageIF {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
@ -9,166 +9,166 @@ import org.graylog2.syslog4j.SyslogMessageProcessorIF;
|
|||||||
import org.graylog2.syslog4j.SyslogRuntimeException;
|
import org.graylog2.syslog4j.SyslogRuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MultipleSyslog is an aggregator Syslog implementation for allowing a single
|
* MultipleSyslog is an aggregator Syslog implementation for allowing a single
|
||||||
* Syslog call to send to multiple Syslog implementations.
|
* Syslog call to send to multiple Syslog implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: MultipleSyslog.java,v 1.10 2010/02/11 05:00:55 cvs Exp $
|
* @version $Id: MultipleSyslog.java,v 1.10 2010/02/11 05:00:55 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class MultipleSyslog implements SyslogIF {
|
public class MultipleSyslog implements SyslogIF {
|
||||||
private static final long serialVersionUID = 587308197526365108L;
|
private static final long serialVersionUID = 587308197526365108L;
|
||||||
|
|
||||||
protected String syslogProtocol = null;
|
protected String syslogProtocol = null;
|
||||||
protected MultipleSyslogConfig multipleSyslogConfig = null;
|
protected MultipleSyslogConfig multipleSyslogConfig = null;
|
||||||
|
|
||||||
public void initialize(String protocol, SyslogConfigIF config) throws SyslogRuntimeException {
|
public void initialize(String protocol, SyslogConfigIF config) throws SyslogRuntimeException {
|
||||||
this.syslogProtocol = protocol;
|
this.syslogProtocol = protocol;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.multipleSyslogConfig = (MultipleSyslogConfig) config;
|
this.multipleSyslogConfig = (MultipleSyslogConfig) config;
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("config must be of type MultipleSyslogConfig");
|
throw new SyslogRuntimeException("config must be of type MultipleSyslogConfig");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyslogConfigIF getConfig() {
|
public SyslogConfigIF getConfig() {
|
||||||
return this.multipleSyslogConfig;
|
return this.multipleSyslogConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(String message) {
|
public void debug(String message) {
|
||||||
log(SyslogConstants.LEVEL_DEBUG,message);
|
log(SyslogConstants.LEVEL_DEBUG, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(SyslogMessageIF message) {
|
public void debug(SyslogMessageIF message) {
|
||||||
log(SyslogConstants.LEVEL_DEBUG,message);
|
log(SyslogConstants.LEVEL_DEBUG, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void critical(String message) {
|
public void critical(String message) {
|
||||||
log(SyslogConstants.LEVEL_CRITICAL,message);
|
log(SyslogConstants.LEVEL_CRITICAL, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void critical(SyslogMessageIF message) {
|
public void critical(SyslogMessageIF message) {
|
||||||
log(SyslogConstants.LEVEL_CRITICAL,message);
|
log(SyslogConstants.LEVEL_CRITICAL, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void error(String message) {
|
public void error(String message) {
|
||||||
log(SyslogConstants.LEVEL_ERROR,message);
|
log(SyslogConstants.LEVEL_ERROR, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void error(SyslogMessageIF message) {
|
public void error(SyslogMessageIF message) {
|
||||||
log(SyslogConstants.LEVEL_ERROR,message);
|
log(SyslogConstants.LEVEL_ERROR, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void alert(String message) {
|
public void alert(String message) {
|
||||||
log(SyslogConstants.LEVEL_ALERT,message);
|
log(SyslogConstants.LEVEL_ALERT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void alert(SyslogMessageIF message) {
|
public void alert(SyslogMessageIF message) {
|
||||||
log(SyslogConstants.LEVEL_ALERT,message);
|
log(SyslogConstants.LEVEL_ALERT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notice(String message) {
|
public void notice(String message) {
|
||||||
log(SyslogConstants.LEVEL_NOTICE,message);
|
log(SyslogConstants.LEVEL_NOTICE, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notice(SyslogMessageIF message) {
|
public void notice(SyslogMessageIF message) {
|
||||||
log(SyslogConstants.LEVEL_NOTICE,message);
|
log(SyslogConstants.LEVEL_NOTICE, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void emergency(String message) {
|
public void emergency(String message) {
|
||||||
log(SyslogConstants.LEVEL_EMERGENCY,message);
|
log(SyslogConstants.LEVEL_EMERGENCY, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void emergency(SyslogMessageIF message) {
|
public void emergency(SyslogMessageIF message) {
|
||||||
log(SyslogConstants.LEVEL_EMERGENCY,message);
|
log(SyslogConstants.LEVEL_EMERGENCY, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void info(String message) {
|
public void info(String message) {
|
||||||
log(SyslogConstants.LEVEL_INFO,message);
|
log(SyslogConstants.LEVEL_INFO, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void info(SyslogMessageIF message) {
|
public void info(SyslogMessageIF message) {
|
||||||
log(SyslogConstants.LEVEL_INFO,message);
|
log(SyslogConstants.LEVEL_INFO, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warn(String message) {
|
public void warn(String message) {
|
||||||
log(SyslogConstants.LEVEL_WARN,message);
|
log(SyslogConstants.LEVEL_WARN, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warn(SyslogMessageIF message) {
|
public void warn(SyslogMessageIF message) {
|
||||||
log(SyslogConstants.LEVEL_WARN,message);
|
log(SyslogConstants.LEVEL_WARN, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(int level, String message) {
|
public void log(int level, String message) {
|
||||||
for(int i=0; i<this.multipleSyslogConfig.getProtocols().size(); i++) {
|
for (int i = 0; i < this.multipleSyslogConfig.getProtocols().size(); i++) {
|
||||||
String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i);
|
String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i);
|
||||||
|
|
||||||
SyslogIF syslog = Syslog.getInstance(protocol);
|
SyslogIF syslog = Syslog.getInstance(protocol);
|
||||||
|
|
||||||
syslog.log(level,message);
|
syslog.log(level, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(int level, SyslogMessageIF message) {
|
public void log(int level, SyslogMessageIF message) {
|
||||||
for(int i=0; i<this.multipleSyslogConfig.getProtocols().size(); i++) {
|
for (int i = 0; i < this.multipleSyslogConfig.getProtocols().size(); i++) {
|
||||||
String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i);
|
String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i);
|
||||||
|
|
||||||
SyslogIF syslog = Syslog.getInstance(protocol);
|
SyslogIF syslog = Syslog.getInstance(protocol);
|
||||||
|
|
||||||
syslog.log(level,message);
|
syslog.log(level, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws SyslogRuntimeException {
|
public void flush() throws SyslogRuntimeException {
|
||||||
for(int i=0; i<this.multipleSyslogConfig.getProtocols().size(); i++) {
|
for (int i = 0; i < this.multipleSyslogConfig.getProtocols().size(); i++) {
|
||||||
String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i);
|
String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i);
|
||||||
|
|
||||||
SyslogIF syslog = Syslog.getInstance(protocol);
|
SyslogIF syslog = Syslog.getInstance(protocol);
|
||||||
|
|
||||||
syslog.flush();
|
syslog.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() throws SyslogRuntimeException {
|
public void shutdown() throws SyslogRuntimeException {
|
||||||
for(int i=0; i<this.multipleSyslogConfig.getProtocols().size(); i++) {
|
for (int i = 0; i < this.multipleSyslogConfig.getProtocols().size(); i++) {
|
||||||
String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i);
|
String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i);
|
||||||
|
|
||||||
SyslogIF syslog = Syslog.getInstance(protocol);
|
SyslogIF syslog = Syslog.getInstance(protocol);
|
||||||
|
|
||||||
syslog.shutdown();
|
syslog.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void backLog(int level, String message, Throwable reasonThrowable) {
|
public void backLog(int level, String message, Throwable reasonThrowable) {
|
||||||
// MultipleSyslog is an aggregator; backLog state will be handled by individual Syslog protocols
|
// MultipleSyslog is an aggregator; backLog state will be handled by individual Syslog protocols
|
||||||
}
|
}
|
||||||
|
|
||||||
public void backLog(int level, String message, String reason) {
|
public void backLog(int level, String message, String reason) {
|
||||||
// MultipleSyslog is an aggregator; backLog state will be handled by individual Syslog protocols
|
// MultipleSyslog is an aggregator; backLog state will be handled by individual Syslog protocols
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessageProcessor(SyslogMessageProcessorIF messageProcessor) {
|
public void setMessageProcessor(SyslogMessageProcessorIF messageProcessor) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyslogMessageProcessorIF getMessageProcessor() {
|
public SyslogMessageProcessorIF getMessageProcessor() {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStructuredMessageProcessor(SyslogMessageProcessorIF messageProcessor) {
|
public void setStructuredMessageProcessor(SyslogMessageProcessorIF messageProcessor) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyslogMessageProcessorIF getStructuredMessageProcessor() {
|
public SyslogMessageProcessorIF getStructuredMessageProcessor() {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProtocol() {
|
public String getProtocol() {
|
||||||
return this.syslogProtocol;
|
return this.syslogProtocol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,232 +10,232 @@ import org.graylog2.syslog4j.SyslogMessageModifierIF;
|
|||||||
import org.graylog2.syslog4j.SyslogRuntimeException;
|
import org.graylog2.syslog4j.SyslogRuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MultipleSyslogConfig is a configuration Object for allowing a single
|
* MultipleSyslogConfig is a configuration Object for allowing a single
|
||||||
* Syslog call to send to multiple Syslog implementations.
|
* Syslog call to send to multiple Syslog implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: MultipleSyslogConfig.java,v 1.8 2010/11/28 04:15:18 cvs Exp $
|
* @version $Id: MultipleSyslogConfig.java,v 1.8 2010/11/28 04:15:18 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class MultipleSyslogConfig implements SyslogConfigIF {
|
public class MultipleSyslogConfig implements SyslogConfigIF {
|
||||||
private static final long serialVersionUID = 753704522364959612L;
|
private static final long serialVersionUID = 753704522364959612L;
|
||||||
|
|
||||||
protected List syslogProtocols = null;
|
protected List syslogProtocols = null;
|
||||||
|
|
||||||
public MultipleSyslogConfig() {
|
public MultipleSyslogConfig() {
|
||||||
this.syslogProtocols = new ArrayList();
|
this.syslogProtocols = new ArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipleSyslogConfig(List protocols) {
|
public MultipleSyslogConfig(List protocols) {
|
||||||
if (protocols != null) {
|
if (protocols != null) {
|
||||||
this.syslogProtocols = protocols;
|
this.syslogProtocols = protocols;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.syslogProtocols = new ArrayList();
|
this.syslogProtocols = new ArrayList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultipleSyslogConfig(String[] protocols) {
|
public MultipleSyslogConfig(String[] protocols) {
|
||||||
if (protocols != null) {
|
if (protocols != null) {
|
||||||
this.syslogProtocols = new ArrayList(protocols.length);
|
this.syslogProtocols = new ArrayList(protocols.length);
|
||||||
|
|
||||||
for(int i=0; i<protocols.length; i++) {
|
for (int i = 0; i < protocols.length; i++) {
|
||||||
this.syslogProtocols.add(protocols[i]);
|
this.syslogProtocols.add(protocols[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.syslogProtocols = new ArrayList();
|
this.syslogProtocols = new ArrayList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getProtocols() {
|
public List getProtocols() {
|
||||||
return this.syslogProtocols;
|
return this.syslogProtocols;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addProtocol(String protocol) {
|
public void addProtocol(String protocol) {
|
||||||
this.syslogProtocols.add(protocol);
|
this.syslogProtocols.add(protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertProtocol(int index, String protocol) {
|
public void insertProtocol(int index, String protocol) {
|
||||||
this.syslogProtocols.add(index,protocol);
|
this.syslogProtocols.add(index, protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeProtocol(String protocol) {
|
public void removeProtocol(String protocol) {
|
||||||
this.syslogProtocols.remove(protocol);
|
this.syslogProtocols.remove(protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllProtocols() {
|
public void removeAllProtocols() {
|
||||||
this.syslogProtocols.clear();
|
this.syslogProtocols.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBackLogHandler(SyslogBackLogHandlerIF backLogHandler) {
|
public void addBackLogHandler(SyslogBackLogHandlerIF backLogHandler) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMessageModifier(SyslogMessageModifierIF messageModifier) {
|
public void addMessageModifier(SyslogMessageModifierIF messageModifier) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogClass() {
|
public Class getSyslogClass() {
|
||||||
return MultipleSyslog.class;
|
return MultipleSyslog.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCharSet() {
|
public String getCharSet() {
|
||||||
return SyslogConstants.CHAR_SET_DEFAULT;
|
return SyslogConstants.CHAR_SET_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFacility() {
|
public int getFacility() {
|
||||||
return SyslogConstants.SYSLOG_FACILITY_DEFAULT;
|
return SyslogConstants.SYSLOG_FACILITY_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return SyslogConstants.SYSLOG_HOST_DEFAULT;
|
return SyslogConstants.SYSLOG_HOST_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdent() {
|
public String getIdent() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocalName() {
|
public String getLocalName() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return SyslogConstants.SYSLOG_PORT_DEFAULT;
|
return SyslogConstants.SYSLOG_PORT_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxShutdownWait() {
|
public int getMaxShutdownWait() {
|
||||||
return SyslogConstants.MAX_SHUTDOWN_WAIT_DEFAULT;
|
return SyslogConstants.MAX_SHUTDOWN_WAIT_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxShutdownWait(int maxShutdownWait) {
|
public void setMaxShutdownWait(int maxShutdownWait) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertBackLogHandler(int index, SyslogBackLogHandlerIF backLogHandler) {
|
public void insertBackLogHandler(int index, SyslogBackLogHandlerIF backLogHandler) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertMessageModifier(int index, SyslogMessageModifierIF messageModifier) {
|
public void insertMessageModifier(int index, SyslogMessageModifierIF messageModifier) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCacheHostAddress() {
|
public boolean isCacheHostAddress() {
|
||||||
return SyslogConstants.CACHE_HOST_ADDRESS_DEFAULT;
|
return SyslogConstants.CACHE_HOST_ADDRESS_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIncludeIdentInMessageModifier() {
|
public boolean isIncludeIdentInMessageModifier() {
|
||||||
return SyslogConstants.INCLUDE_IDENT_IN_MESSAGE_MODIFIER_DEFAULT;
|
return SyslogConstants.INCLUDE_IDENT_IN_MESSAGE_MODIFIER_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSendLocalName() {
|
public boolean isSendLocalName() {
|
||||||
return SyslogConstants.SEND_LOCAL_NAME_DEFAULT;
|
return SyslogConstants.SEND_LOCAL_NAME_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSendLocalTimestamp() {
|
public boolean isSendLocalTimestamp() {
|
||||||
return SyslogConstants.SEND_LOCAL_TIMESTAMP_DEFAULT;
|
return SyslogConstants.SEND_LOCAL_TIMESTAMP_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isThrowExceptionOnInitialize() {
|
public boolean isThrowExceptionOnInitialize() {
|
||||||
return SyslogConstants.THROW_EXCEPTION_ON_INITIALIZE_DEFAULT;
|
return SyslogConstants.THROW_EXCEPTION_ON_INITIALIZE_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isThrowExceptionOnWrite() {
|
public boolean isThrowExceptionOnWrite() {
|
||||||
return SyslogConstants.THROW_EXCEPTION_ON_WRITE_DEFAULT;
|
return SyslogConstants.THROW_EXCEPTION_ON_WRITE_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllBackLogHandlers() {
|
public void removeAllBackLogHandlers() {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllMessageModifiers() {
|
public void removeAllMessageModifiers() {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeBackLogHandler(SyslogBackLogHandlerIF backLogHandler) {
|
public void removeBackLogHandler(SyslogBackLogHandlerIF backLogHandler) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMessageModifier(SyslogMessageModifierIF messageModifier) {
|
public void removeMessageModifier(SyslogMessageModifierIF messageModifier) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCacheHostAddress(boolean cacheHostAddress) {
|
public void setCacheHostAddress(boolean cacheHostAddress) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCharSet(String charSet) {
|
public void setCharSet(String charSet) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacility(int facility) {
|
public void setFacility(int facility) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacility(String facilityName) {
|
public void setFacility(String facilityName) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) throws SyslogRuntimeException {
|
public void setHost(String host) throws SyslogRuntimeException {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdent(String ident) {
|
public void setIdent(String ident) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocalName(String localName) {
|
public void setLocalName(String localName) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIncludeIdentInMessageModifier(boolean throwExceptionOnInitialize) {
|
public void setIncludeIdentInMessageModifier(boolean throwExceptionOnInitialize) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(int port) throws SyslogRuntimeException {
|
public void setPort(int port) throws SyslogRuntimeException {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSendLocalName(boolean sendLocalName) {
|
public void setSendLocalName(boolean sendLocalName) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSendLocalTimestamp(boolean sendLocalTimestamp) {
|
public void setSendLocalTimestamp(boolean sendLocalTimestamp) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThrowExceptionOnInitialize(boolean throwExceptionOnInitialize) {
|
public void setThrowExceptionOnInitialize(boolean throwExceptionOnInitialize) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThrowExceptionOnWrite(boolean throwExceptionOnWrite) {
|
public void setThrowExceptionOnWrite(boolean throwExceptionOnWrite) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxMessageLength() {
|
public int getMaxMessageLength() {
|
||||||
return SyslogConstants.MAX_MESSAGE_LENGTH_DEFAULT;
|
return SyslogConstants.MAX_MESSAGE_LENGTH_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxMessageLength(int maxMessageLength) {
|
public void setMaxMessageLength(int maxMessageLength) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTruncateMessage() {
|
public boolean isTruncateMessage() {
|
||||||
return SyslogConstants.TRUNCATE_MESSAGE_DEFAULT;
|
return SyslogConstants.TRUNCATE_MESSAGE_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTruncateMessage(boolean truncateMessage) {
|
public void setTruncateMessage(boolean truncateMessage) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseStructuredData() {
|
public boolean isUseStructuredData() {
|
||||||
return SyslogConstants.USE_STRUCTURED_DATA_DEFAULT;
|
return SyslogConstants.USE_STRUCTURED_DATA_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseStructuredData(boolean useStructuredData) {
|
public void setUseStructuredData(boolean useStructuredData) {
|
||||||
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
throw new SyslogRuntimeException("MultipleSyslog is an aggregator; please set the individual protocols");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,55 +7,55 @@ import org.graylog2.syslog4j.impl.AbstractSyslog;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractNetSyslog is an abstract extension of AbstractSyslog
|
* AbstractNetSyslog is an abstract extension of AbstractSyslog
|
||||||
* that provides support for network-based syslog clients.
|
* that provides support for network-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractNetSyslog.java,v 1.7 2009/01/24 22:00:18 cvs Exp $
|
* @version $Id: AbstractNetSyslog.java,v 1.7 2009/01/24 22:00:18 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractNetSyslog extends AbstractSyslog {
|
public abstract class AbstractNetSyslog extends AbstractSyslog {
|
||||||
private static final long serialVersionUID = -3250858945515853967L;
|
private static final long serialVersionUID = -3250858945515853967L;
|
||||||
|
|
||||||
protected static final Object cachedHostAddressSyncObject = new Object();
|
protected static final Object cachedHostAddressSyncObject = new Object();
|
||||||
|
|
||||||
protected InetAddress cachedHostAddress = null;
|
protected InetAddress cachedHostAddress = null;
|
||||||
|
|
||||||
protected AbstractNetSyslogConfigIF netSyslogConfig = null;
|
protected AbstractNetSyslogConfigIF netSyslogConfig = null;
|
||||||
|
|
||||||
protected void initialize() throws SyslogRuntimeException {
|
protected void initialize() throws SyslogRuntimeException {
|
||||||
try {
|
try {
|
||||||
this.netSyslogConfig = (AbstractNetSyslogConfigIF) this.syslogConfig;
|
this.netSyslogConfig = (AbstractNetSyslogConfigIF) this.syslogConfig;
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("config must implement interface AbstractNetSyslogConfigIF");
|
throw new SyslogRuntimeException("config must implement interface AbstractNetSyslogConfigIF");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns an object of InetAddress of the local host, using caching if so directed.
|
* @return Returns an object of InetAddress of the local host, using caching if so directed.
|
||||||
*/
|
*/
|
||||||
public InetAddress getHostAddress() {
|
public InetAddress getHostAddress() {
|
||||||
InetAddress hostAddress = null;
|
InetAddress hostAddress = null;
|
||||||
|
|
||||||
if (this.netSyslogConfig.isCacheHostAddress()) {
|
if (this.netSyslogConfig.isCacheHostAddress()) {
|
||||||
if (this.cachedHostAddress == null) {
|
if (this.cachedHostAddress == null) {
|
||||||
synchronized(cachedHostAddressSyncObject) {
|
synchronized (cachedHostAddressSyncObject) {
|
||||||
if (this.cachedHostAddress == null) {
|
if (this.cachedHostAddress == null) {
|
||||||
this.cachedHostAddress = SyslogUtility.getInetAddress(this.syslogConfig.getHost());
|
this.cachedHostAddress = SyslogUtility.getInetAddress(this.syslogConfig.getHost());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hostAddress = this.cachedHostAddress;
|
hostAddress = this.cachedHostAddress;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
hostAddress = SyslogUtility.getInetAddress(this.syslogConfig.getHost());
|
hostAddress = SyslogUtility.getInetAddress(this.syslogConfig.getHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
return hostAddress;
|
return hostAddress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,83 +3,83 @@ package org.graylog2.syslog4j.impl.net;
|
|||||||
import org.graylog2.syslog4j.impl.AbstractSyslogConfig;
|
import org.graylog2.syslog4j.impl.AbstractSyslogConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractNetSyslogConfig is an abstract extension of AbstractSyslogConfig
|
* AbstractNetSyslogConfig is an abstract extension of AbstractSyslogConfig
|
||||||
* that provides configuration support for network-based syslog clients.
|
* that provides configuration support for network-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractNetSyslogConfig.java,v 1.12 2010/10/25 03:50:25 cvs Exp $
|
* @version $Id: AbstractNetSyslogConfig.java,v 1.12 2010/10/25 03:50:25 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractNetSyslogConfig extends AbstractSyslogConfig implements AbstractNetSyslogConfigIF {
|
public abstract class AbstractNetSyslogConfig extends AbstractSyslogConfig implements AbstractNetSyslogConfigIF {
|
||||||
private static final long serialVersionUID = 7240133962159244924L;
|
private static final long serialVersionUID = 7240133962159244924L;
|
||||||
|
|
||||||
protected String host = SYSLOG_HOST_DEFAULT;
|
protected String host = SYSLOG_HOST_DEFAULT;
|
||||||
protected int port = SYSLOG_PORT_DEFAULT;
|
protected int port = SYSLOG_PORT_DEFAULT;
|
||||||
|
|
||||||
protected boolean cacheHostAddress = CACHE_HOST_ADDRESS_DEFAULT;
|
protected boolean cacheHostAddress = CACHE_HOST_ADDRESS_DEFAULT;
|
||||||
|
|
||||||
protected int maxQueueSize = MAX_QUEUE_SIZE_DEFAULT;
|
protected int maxQueueSize = MAX_QUEUE_SIZE_DEFAULT;
|
||||||
|
|
||||||
public AbstractNetSyslogConfig() {
|
public AbstractNetSyslogConfig() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractNetSyslogConfig(int facility) {
|
public AbstractNetSyslogConfig(int facility) {
|
||||||
this.facility = facility;
|
this.facility = facility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractNetSyslogConfig(int facility, String host) {
|
public AbstractNetSyslogConfig(int facility, String host) {
|
||||||
this.facility = facility;
|
this.facility = facility;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractNetSyslogConfig(String host) {
|
public AbstractNetSyslogConfig(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractNetSyslogConfig(int facility, String host, int port) {
|
public AbstractNetSyslogConfig(int facility, String host, int port) {
|
||||||
this.facility = facility;
|
this.facility = facility;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractNetSyslogConfig(String host, int port) {
|
public AbstractNetSyslogConfig(String host, int port) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCacheHostAddress() {
|
public boolean isCacheHostAddress() {
|
||||||
return this.cacheHostAddress;
|
return this.cacheHostAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCacheHostAddress(boolean cacheHostAddress) {
|
public void setCacheHostAddress(boolean cacheHostAddress) {
|
||||||
this.cacheHostAddress = cacheHostAddress;
|
this.cacheHostAddress = cacheHostAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return this.host;
|
return this.host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) {
|
public void setHost(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return this.port;
|
return this.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(int port) {
|
public void setPort(int port) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxQueueSize() {
|
public int getMaxQueueSize() {
|
||||||
return maxQueueSize;
|
return maxQueueSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxQueueSize(int maxQueueSize) {
|
public void setMaxQueueSize(int maxQueueSize) {
|
||||||
this.maxQueueSize = maxQueueSize;
|
this.maxQueueSize = maxQueueSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,18 @@ package org.graylog2.syslog4j.impl.net;
|
|||||||
import org.graylog2.syslog4j.impl.AbstractSyslogConfigIF;
|
import org.graylog2.syslog4j.impl.AbstractSyslogConfigIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractNetSyslogConfigIF is a configuration interface supporting network-based
|
* AbstractNetSyslogConfigIF is a configuration interface supporting network-based
|
||||||
* Syslog implementations.
|
* Syslog implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractNetSyslogConfigIF.java,v 1.4 2009/06/06 19:11:02 cvs Exp $
|
* @version $Id: AbstractNetSyslogConfigIF.java,v 1.4 2009/06/06 19:11:02 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface AbstractNetSyslogConfigIF extends AbstractSyslogConfigIF {
|
public interface AbstractNetSyslogConfigIF extends AbstractSyslogConfigIF {
|
||||||
public boolean isCacheHostAddress();
|
public boolean isCacheHostAddress();
|
||||||
public void setCacheHostAddress(boolean cacheHostAddress);
|
|
||||||
|
public void setCacheHostAddress(boolean cacheHostAddress);
|
||||||
}
|
}
|
||||||
|
@ -5,87 +5,87 @@ import org.graylog2.syslog4j.impl.AbstractSyslogWriter;
|
|||||||
import org.graylog2.syslog4j.impl.net.AbstractNetSyslog;
|
import org.graylog2.syslog4j.impl.net.AbstractNetSyslog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCPNetSyslog is an extension of AbstractSyslog that provides support for
|
* TCPNetSyslog is an extension of AbstractSyslog that provides support for
|
||||||
* TCP/IP-based syslog clients.
|
* TCP/IP-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: TCPNetSyslog.java,v 1.21 2010/11/28 04:43:31 cvs Exp $
|
* @version $Id: TCPNetSyslog.java,v 1.21 2010/11/28 04:43:31 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class TCPNetSyslog extends AbstractNetSyslog {
|
public class TCPNetSyslog extends AbstractNetSyslog {
|
||||||
private static final long serialVersionUID = -2157528355215068721L;
|
private static final long serialVersionUID = -2157528355215068721L;
|
||||||
|
|
||||||
protected TCPNetSyslogWriter writer = null;
|
protected TCPNetSyslogWriter writer = null;
|
||||||
|
|
||||||
protected TCPNetSyslogConfigIF tcpNetSyslogConfig = null;
|
protected TCPNetSyslogConfigIF tcpNetSyslogConfig = null;
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.tcpNetSyslogConfig = (TCPNetSyslogConfigIF) this.syslogConfig;
|
this.tcpNetSyslogConfig = (TCPNetSyslogConfigIF) this.syslogConfig;
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("config must implement interface TCPNetSyslogConfigIF");
|
throw new SyslogRuntimeException("config must implement interface TCPNetSyslogConfigIF");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSyslogWriter getWriter() {
|
public AbstractSyslogWriter getWriter() {
|
||||||
return getWriter(true);
|
return getWriter(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized AbstractSyslogWriter getWriter(boolean create) {
|
public synchronized AbstractSyslogWriter getWriter(boolean create) {
|
||||||
if (this.writer != null || !create) {
|
if (this.writer != null || !create) {
|
||||||
return this.writer;
|
return this.writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.writer = (TCPNetSyslogWriter) createWriter();
|
this.writer = (TCPNetSyslogWriter) createWriter();
|
||||||
|
|
||||||
if (this.tcpNetSyslogConfig.isThreaded()) {
|
if (this.tcpNetSyslogConfig.isThreaded()) {
|
||||||
createWriterThread(this.writer);
|
createWriterThread(this.writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.writer;
|
return this.writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void write(int level, byte[] message) throws SyslogRuntimeException {
|
protected void write(int level, byte[] message) throws SyslogRuntimeException {
|
||||||
AbstractSyslogWriter syslogWriter = getWriter();
|
AbstractSyslogWriter syslogWriter = getWriter();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (syslogWriter.hasThread()) {
|
if (syslogWriter.hasThread()) {
|
||||||
syslogWriter.queue(level,message);
|
syslogWriter.queue(level, message);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
synchronized(syslogWriter) {
|
synchronized (syslogWriter) {
|
||||||
syslogWriter.write(message);
|
syslogWriter.write(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
returnWriter(syslogWriter);
|
returnWriter(syslogWriter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws SyslogRuntimeException {
|
public void flush() throws SyslogRuntimeException {
|
||||||
AbstractSyslogWriter syslogWriter = getWriter(false);
|
AbstractSyslogWriter syslogWriter = getWriter(false);
|
||||||
|
|
||||||
if (syslogWriter != null) {
|
if (syslogWriter != null) {
|
||||||
syslogWriter.flush();
|
syslogWriter.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() throws SyslogRuntimeException {
|
public void shutdown() throws SyslogRuntimeException {
|
||||||
AbstractSyslogWriter syslogWriter = getWriter(false);
|
AbstractSyslogWriter syslogWriter = getWriter(false);
|
||||||
|
|
||||||
if (syslogWriter != null) {
|
if (syslogWriter != null) {
|
||||||
syslogWriter.shutdown();
|
syslogWriter.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,152 +5,152 @@ import org.graylog2.syslog4j.impl.net.AbstractNetSyslogConfig;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCPNetSyslogConfig is an extension of AbstractNetSyslogConfig that provides
|
* TCPNetSyslogConfig is an extension of AbstractNetSyslogConfig that provides
|
||||||
* configuration support for TCP/IP-based syslog clients.
|
* configuration support for TCP/IP-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: TCPNetSyslogConfig.java,v 1.18 2010/10/29 03:14:12 cvs Exp $
|
* @version $Id: TCPNetSyslogConfig.java,v 1.18 2010/10/29 03:14:12 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class TCPNetSyslogConfig extends AbstractNetSyslogConfig implements TCPNetSyslogConfigIF {
|
public class TCPNetSyslogConfig extends AbstractNetSyslogConfig implements TCPNetSyslogConfigIF {
|
||||||
private static final long serialVersionUID = 9023152050686365460L;
|
private static final long serialVersionUID = 9023152050686365460L;
|
||||||
|
|
||||||
public static byte[] SYSTEM_DELIMITER_SEQUENCE = null;
|
public static byte[] SYSTEM_DELIMITER_SEQUENCE = null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String delimiterSequence = System.getProperty("line.separator");
|
String delimiterSequence = System.getProperty("line.separator");
|
||||||
|
|
||||||
SYSTEM_DELIMITER_SEQUENCE = delimiterSequence.getBytes();
|
SYSTEM_DELIMITER_SEQUENCE = delimiterSequence.getBytes();
|
||||||
|
|
||||||
if (SYSTEM_DELIMITER_SEQUENCE == null || SYSTEM_DELIMITER_SEQUENCE.length < 1) {
|
if (SYSTEM_DELIMITER_SEQUENCE == null || SYSTEM_DELIMITER_SEQUENCE.length < 1) {
|
||||||
SYSTEM_DELIMITER_SEQUENCE = SyslogConstants.TCP_DELIMITER_SEQUENCE_DEFAULT;
|
SYSTEM_DELIMITER_SEQUENCE = SyslogConstants.TCP_DELIMITER_SEQUENCE_DEFAULT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] delimiterSequence = SYSTEM_DELIMITER_SEQUENCE;
|
protected byte[] delimiterSequence = SYSTEM_DELIMITER_SEQUENCE;
|
||||||
|
|
||||||
protected boolean persistentConnection = TCP_PERSISTENT_CONNECTION_DEFAULT;
|
protected boolean persistentConnection = TCP_PERSISTENT_CONNECTION_DEFAULT;
|
||||||
|
|
||||||
protected boolean soLinger = TCP_SO_LINGER_DEFAULT;
|
protected boolean soLinger = TCP_SO_LINGER_DEFAULT;
|
||||||
protected int soLingerSeconds = TCP_SO_LINGER_SECONDS_DEFAULT;
|
protected int soLingerSeconds = TCP_SO_LINGER_SECONDS_DEFAULT;
|
||||||
|
|
||||||
protected boolean keepAlive = TCP_KEEP_ALIVE_DEFAULT;
|
protected boolean keepAlive = TCP_KEEP_ALIVE_DEFAULT;
|
||||||
|
|
||||||
protected boolean reuseAddress = TCP_REUSE_ADDRESS_DEFAULT;
|
protected boolean reuseAddress = TCP_REUSE_ADDRESS_DEFAULT;
|
||||||
|
|
||||||
protected boolean setBufferSize = TCP_SET_BUFFER_SIZE_DEFAULT;
|
protected boolean setBufferSize = TCP_SET_BUFFER_SIZE_DEFAULT;
|
||||||
|
|
||||||
protected int freshConnectionInterval = TCP_FRESH_CONNECTION_INTERVAL_DEFAULT;
|
protected int freshConnectionInterval = TCP_FRESH_CONNECTION_INTERVAL_DEFAULT;
|
||||||
|
|
||||||
public TCPNetSyslogConfig() {
|
public TCPNetSyslogConfig() {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initialize() {
|
protected void initialize() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogConfig(int facility, String host, int port) {
|
public TCPNetSyslogConfig(int facility, String host, int port) {
|
||||||
super(facility, host, port);
|
super(facility, host, port);
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogConfig(int facility, String host) {
|
public TCPNetSyslogConfig(int facility, String host) {
|
||||||
super(facility, host);
|
super(facility, host);
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogConfig(int facility) {
|
public TCPNetSyslogConfig(int facility) {
|
||||||
super(facility);
|
super(facility);
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogConfig(String host, int port) {
|
public TCPNetSyslogConfig(String host, int port) {
|
||||||
super(host, port);
|
super(host, port);
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogConfig(String host) {
|
public TCPNetSyslogConfig(String host) {
|
||||||
super(host);
|
super(host);
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogClass() {
|
public Class getSyslogClass() {
|
||||||
return TCPNetSyslog.class;
|
return TCPNetSyslog.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getDelimiterSequence() {
|
public byte[] getDelimiterSequence() {
|
||||||
return this.delimiterSequence;
|
return this.delimiterSequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDelimiterSequence(byte[] delimiterSequence) {
|
public void setDelimiterSequence(byte[] delimiterSequence) {
|
||||||
this.delimiterSequence = delimiterSequence;
|
this.delimiterSequence = delimiterSequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDelimiterSequence(String delimiterSequence) {
|
public void setDelimiterSequence(String delimiterSequence) {
|
||||||
this.delimiterSequence = SyslogUtility.getBytes(this,delimiterSequence);
|
this.delimiterSequence = SyslogUtility.getBytes(this, delimiterSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPersistentConnection() {
|
public boolean isPersistentConnection() {
|
||||||
return this.persistentConnection;
|
return this.persistentConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPersistentConnection(boolean persistentConnection) {
|
public void setPersistentConnection(boolean persistentConnection) {
|
||||||
this.persistentConnection = persistentConnection;
|
this.persistentConnection = persistentConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSoLinger() {
|
public boolean isSoLinger() {
|
||||||
return this.soLinger;
|
return this.soLinger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSoLinger(boolean soLinger) {
|
public void setSoLinger(boolean soLinger) {
|
||||||
this.soLinger = soLinger;
|
this.soLinger = soLinger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSoLingerSeconds() {
|
public int getSoLingerSeconds() {
|
||||||
return this.soLingerSeconds;
|
return this.soLingerSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSoLingerSeconds(int soLingerSeconds) {
|
public void setSoLingerSeconds(int soLingerSeconds) {
|
||||||
this.soLingerSeconds = soLingerSeconds;
|
this.soLingerSeconds = soLingerSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isKeepAlive() {
|
public boolean isKeepAlive() {
|
||||||
return this.keepAlive;
|
return this.keepAlive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeepAlive(boolean keepAlive) {
|
public void setKeepAlive(boolean keepAlive) {
|
||||||
this.keepAlive = keepAlive;
|
this.keepAlive = keepAlive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReuseAddress() {
|
public boolean isReuseAddress() {
|
||||||
return this.reuseAddress;
|
return this.reuseAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReuseAddress(boolean reuseAddress) {
|
public void setReuseAddress(boolean reuseAddress) {
|
||||||
this.reuseAddress = reuseAddress;
|
this.reuseAddress = reuseAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSetBufferSize() {
|
public boolean isSetBufferSize() {
|
||||||
return this.setBufferSize;
|
return this.setBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSetBufferSize(boolean setBufferSize) {
|
public void setSetBufferSize(boolean setBufferSize) {
|
||||||
this.setBufferSize = setBufferSize;
|
this.setBufferSize = setBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFreshConnectionInterval() {
|
public int getFreshConnectionInterval() {
|
||||||
return freshConnectionInterval;
|
return freshConnectionInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFreshConnectionInterval(int freshConnectionInterval) {
|
public void setFreshConnectionInterval(int freshConnectionInterval) {
|
||||||
this.freshConnectionInterval = freshConnectionInterval;
|
this.freshConnectionInterval = freshConnectionInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogWriterClass() {
|
public Class getSyslogWriterClass() {
|
||||||
return TCPNetSyslogWriter.class;
|
return TCPNetSyslogWriter.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,38 +3,46 @@ package org.graylog2.syslog4j.impl.net.tcp;
|
|||||||
import org.graylog2.syslog4j.impl.net.AbstractNetSyslogConfigIF;
|
import org.graylog2.syslog4j.impl.net.AbstractNetSyslogConfigIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCPNetSyslogConfigIF is a configuration interface supporting TCP/IP-based
|
* TCPNetSyslogConfigIF is a configuration interface supporting TCP/IP-based
|
||||||
* Syslog implementations.
|
* Syslog implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: TCPNetSyslogConfigIF.java,v 1.6 2010/10/29 03:14:12 cvs Exp $
|
* @version $Id: TCPNetSyslogConfigIF.java,v 1.6 2010/10/29 03:14:12 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface TCPNetSyslogConfigIF extends AbstractNetSyslogConfigIF {
|
public interface TCPNetSyslogConfigIF extends AbstractNetSyslogConfigIF {
|
||||||
public byte[] getDelimiterSequence();
|
public byte[] getDelimiterSequence();
|
||||||
public void setDelimiterSequence(byte[] delimiterSequence);
|
|
||||||
|
|
||||||
public boolean isPersistentConnection();
|
public void setDelimiterSequence(byte[] delimiterSequence);
|
||||||
public void setPersistentConnection(boolean persistentConnection);
|
|
||||||
|
|
||||||
public boolean isSoLinger();
|
public boolean isPersistentConnection();
|
||||||
public void setSoLinger(boolean soLinger);
|
|
||||||
|
|
||||||
public int getSoLingerSeconds();
|
public void setPersistentConnection(boolean persistentConnection);
|
||||||
public void setSoLingerSeconds(int soLingerSeconds);
|
|
||||||
|
|
||||||
public boolean isKeepAlive();
|
public boolean isSoLinger();
|
||||||
public void setKeepAlive(boolean keepAlive);
|
|
||||||
|
|
||||||
public boolean isReuseAddress();
|
public void setSoLinger(boolean soLinger);
|
||||||
public void setReuseAddress(boolean reuseAddress);
|
|
||||||
|
|
||||||
public boolean isSetBufferSize();
|
public int getSoLingerSeconds();
|
||||||
public void setSetBufferSize(boolean setBufferSize);
|
|
||||||
|
|
||||||
public int getFreshConnectionInterval();
|
public void setSoLingerSeconds(int soLingerSeconds);
|
||||||
public void setFreshConnectionInterval(int interval);
|
|
||||||
|
public boolean isKeepAlive();
|
||||||
|
|
||||||
|
public void setKeepAlive(boolean keepAlive);
|
||||||
|
|
||||||
|
public boolean isReuseAddress();
|
||||||
|
|
||||||
|
public void setReuseAddress(boolean reuseAddress);
|
||||||
|
|
||||||
|
public boolean isSetBufferSize();
|
||||||
|
|
||||||
|
public void setSetBufferSize(boolean setBufferSize);
|
||||||
|
|
||||||
|
public int getFreshConnectionInterval();
|
||||||
|
|
||||||
|
public void setFreshConnectionInterval(int interval);
|
||||||
}
|
}
|
||||||
|
@ -14,213 +14,213 @@ import org.graylog2.syslog4j.impl.AbstractSyslogWriter;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCPNetSyslogWriter is an implementation of Runnable that supports sending
|
* TCPNetSyslogWriter is an implementation of Runnable that supports sending
|
||||||
* TCP-based messages within a separate Thread.
|
* TCP-based messages within a separate Thread.
|
||||||
*
|
* <p/>
|
||||||
* <p>When used in "threaded" mode (see TCPNetSyslogConfig for the option),
|
* <p>When used in "threaded" mode (see TCPNetSyslogConfig for the option),
|
||||||
* a queuing mechanism is used (via LinkedList).</p>
|
* a queuing mechanism is used (via LinkedList).</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: TCPNetSyslogWriter.java,v 1.20 2010/11/28 01:38:08 cvs Exp $
|
* @version $Id: TCPNetSyslogWriter.java,v 1.20 2010/11/28 01:38:08 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class TCPNetSyslogWriter extends AbstractSyslogWriter {
|
public class TCPNetSyslogWriter extends AbstractSyslogWriter {
|
||||||
private static final long serialVersionUID = -6388813866108482855L;
|
private static final long serialVersionUID = -6388813866108482855L;
|
||||||
|
|
||||||
protected TCPNetSyslog tcpNetSyslog = null;
|
protected TCPNetSyslog tcpNetSyslog = null;
|
||||||
|
|
||||||
protected Socket socket = null;
|
protected Socket socket = null;
|
||||||
|
|
||||||
protected TCPNetSyslogConfigIF tcpNetSyslogConfig = null;
|
protected TCPNetSyslogConfigIF tcpNetSyslogConfig = null;
|
||||||
|
|
||||||
protected long lastSocketCreationTimeMs = 0;
|
protected long lastSocketCreationTimeMs = 0;
|
||||||
|
|
||||||
public TCPNetSyslogWriter() {
|
public TCPNetSyslogWriter() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(AbstractSyslog abstractSyslog) {
|
public void initialize(AbstractSyslog abstractSyslog) {
|
||||||
super.initialize(abstractSyslog);
|
super.initialize(abstractSyslog);
|
||||||
|
|
||||||
this.tcpNetSyslog = (TCPNetSyslog) abstractSyslog;
|
this.tcpNetSyslog = (TCPNetSyslog) abstractSyslog;
|
||||||
|
|
||||||
this.tcpNetSyslogConfig = (TCPNetSyslogConfigIF) this.tcpNetSyslog.getConfig();
|
this.tcpNetSyslogConfig = (TCPNetSyslogConfigIF) this.tcpNetSyslog.getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SocketFactory obtainSocketFactory() {
|
protected SocketFactory obtainSocketFactory() {
|
||||||
return SocketFactory.getDefault();
|
return SocketFactory.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Socket createSocket(InetAddress hostAddress, int port, boolean keepalive) throws IOException {
|
protected Socket createSocket(InetAddress hostAddress, int port, boolean keepalive) throws IOException {
|
||||||
SocketFactory socketFactory = obtainSocketFactory();
|
SocketFactory socketFactory = obtainSocketFactory();
|
||||||
|
|
||||||
Socket newSocket = socketFactory.createSocket(hostAddress,port);
|
Socket newSocket = socketFactory.createSocket(hostAddress, port);
|
||||||
|
|
||||||
if (this.tcpNetSyslogConfig.isSoLinger()) {
|
if (this.tcpNetSyslogConfig.isSoLinger()) {
|
||||||
newSocket.setSoLinger(true,this.tcpNetSyslogConfig.getSoLingerSeconds());
|
newSocket.setSoLinger(true, this.tcpNetSyslogConfig.getSoLingerSeconds());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tcpNetSyslogConfig.isKeepAlive()) {
|
if (this.tcpNetSyslogConfig.isKeepAlive()) {
|
||||||
newSocket.setKeepAlive(keepalive);
|
newSocket.setKeepAlive(keepalive);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tcpNetSyslogConfig.isReuseAddress()) {
|
if (this.tcpNetSyslogConfig.isReuseAddress()) {
|
||||||
newSocket.setReuseAddress(true);
|
newSocket.setReuseAddress(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newSocket;
|
return newSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Socket getSocket() throws SyslogRuntimeException {
|
protected Socket getSocket() throws SyslogRuntimeException {
|
||||||
if (this.socket != null && this.socket.isConnected()) {
|
if (this.socket != null && this.socket.isConnected()) {
|
||||||
int freshConnectionInterval = this.tcpNetSyslogConfig.getFreshConnectionInterval();
|
int freshConnectionInterval = this.tcpNetSyslogConfig.getFreshConnectionInterval();
|
||||||
|
|
||||||
if (freshConnectionInterval > 0) {
|
if (freshConnectionInterval > 0) {
|
||||||
long currentTimeMs = System.currentTimeMillis();
|
long currentTimeMs = System.currentTimeMillis();
|
||||||
|
|
||||||
if ((currentTimeMs - lastSocketCreationTimeMs) >= freshConnectionInterval) {
|
if ((currentTimeMs - lastSocketCreationTimeMs) >= freshConnectionInterval) {
|
||||||
closeSocket(this.socket);
|
closeSocket(this.socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return this.socket;
|
return this.socket;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.socket == null) {
|
if (this.socket == null) {
|
||||||
lastSocketCreationTimeMs = 0;
|
lastSocketCreationTimeMs = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InetAddress hostAddress = this.tcpNetSyslog.getHostAddress();
|
InetAddress hostAddress = this.tcpNetSyslog.getHostAddress();
|
||||||
|
|
||||||
this.socket = createSocket(hostAddress,this.syslog.getConfig().getPort(),this.tcpNetSyslogConfig.isPersistentConnection());
|
this.socket = createSocket(hostAddress, this.syslog.getConfig().getPort(), this.tcpNetSyslogConfig.isPersistentConnection());
|
||||||
lastSocketCreationTimeMs = System.currentTimeMillis();
|
lastSocketCreationTimeMs = System.currentTimeMillis();
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new SyslogRuntimeException(ioe);
|
throw new SyslogRuntimeException(ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.socket;
|
return this.socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void closeSocket(Socket socketToClose) {
|
protected void closeSocket(Socket socketToClose) {
|
||||||
if (socketToClose == null) {
|
if (socketToClose == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
socketToClose.close();
|
socketToClose.close();
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
if (!"Socket is closed".equalsIgnoreCase(ioe.getMessage())) {
|
if (!"Socket is closed".equalsIgnoreCase(ioe.getMessage())) {
|
||||||
throw new SyslogRuntimeException(ioe);
|
throw new SyslogRuntimeException(ioe);
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (socketToClose == this.socket) {
|
if (socketToClose == this.socket) {
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
currentSocket = getSocket();
|
currentSocket = getSocket();
|
||||||
|
|
||||||
if (currentSocket == null) {
|
if (currentSocket == null) {
|
||||||
throw new SyslogRuntimeException("No socket available");
|
throw new SyslogRuntimeException("No socket available");
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputStream os = currentSocket.getOutputStream();
|
OutputStream os = currentSocket.getOutputStream();
|
||||||
|
|
||||||
if (this.tcpNetSyslogConfig.isSetBufferSize()) {
|
if (this.tcpNetSyslogConfig.isSetBufferSize()) {
|
||||||
currentSocket.setSendBufferSize(message.length);
|
currentSocket.setSendBufferSize(message.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
os.write(message);
|
os.write(message);
|
||||||
|
|
||||||
byte[] delimiterSequence = this.tcpNetSyslogConfig.getDelimiterSequence();
|
byte[] delimiterSequence = this.tcpNetSyslogConfig.getDelimiterSequence();
|
||||||
if (delimiterSequence != null && delimiterSequence.length > 0) {
|
if (delimiterSequence != null && delimiterSequence.length > 0) {
|
||||||
os.write(delimiterSequence);
|
os.write(delimiterSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.syslog.setBackLogStatus(false);
|
this.syslog.setBackLogStatus(false);
|
||||||
|
|
||||||
attempts = -1;
|
attempts = -1;
|
||||||
|
|
||||||
if (!this.tcpNetSyslogConfig.isPersistentConnection()) {
|
if (!this.tcpNetSyslogConfig.isPersistentConnection()) {
|
||||||
closeSocket(currentSocket);
|
closeSocket(currentSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
attempts++;
|
attempts++;
|
||||||
closeSocket(currentSocket);
|
closeSocket(currentSocket);
|
||||||
|
|
||||||
if (attempts >= (this.tcpNetSyslogConfig.getWriteRetries() + 1)) {
|
if (attempts >= (this.tcpNetSyslogConfig.getWriteRetries() + 1)) {
|
||||||
throw new SyslogRuntimeException(ioe);
|
throw new SyslogRuntimeException(ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void flush() throws SyslogRuntimeException {
|
public synchronized void flush() throws SyslogRuntimeException {
|
||||||
if (this.socket == null) {
|
if (this.socket == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.syslogConfig.isThreaded()) {
|
if (this.syslogConfig.isThreaded()) {
|
||||||
this.shutdown();
|
this.shutdown();
|
||||||
this.syslog.createWriterThread(this);
|
this.syslog.createWriterThread(this);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
closeSocket(this.socket);
|
closeSocket(this.socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void shutdown() throws SyslogRuntimeException {
|
public synchronized void shutdown() throws SyslogRuntimeException {
|
||||||
this.shutdown = true;
|
this.shutdown = true;
|
||||||
|
|
||||||
if (this.syslogConfig.isThreaded()) {
|
if (this.syslogConfig.isThreaded()) {
|
||||||
long timeStart = System.currentTimeMillis();
|
long timeStart = System.currentTimeMillis();
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
|
||||||
while(!done) {
|
while (!done) {
|
||||||
if (this.socket == null || this.socket.isClosed()) {
|
if (this.socket == null || this.socket.isClosed()) {
|
||||||
done = true;
|
done = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
if (now > (timeStart + this.tcpNetSyslogConfig.getMaxShutdownWait())) {
|
if (now > (timeStart + this.tcpNetSyslogConfig.getMaxShutdownWait())) {
|
||||||
closeSocket(this.socket);
|
closeSocket(this.socket);
|
||||||
this.thread.interrupt();
|
this.thread.interrupt();
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
SyslogUtility.sleep(SyslogConstants.SHUTDOWN_INTERVAL);
|
SyslogUtility.sleep(SyslogConstants.SHUTDOWN_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (this.socket == null || this.socket.isClosed()) {
|
if (this.socket == null || this.socket.isClosed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeSocket(this.socket);
|
closeSocket(this.socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void runCompleted() {
|
protected void runCompleted() {
|
||||||
closeSocket(this.socket);
|
closeSocket(this.socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,70 +7,70 @@ import org.graylog2.syslog4j.impl.pool.AbstractSyslogPoolFactory;
|
|||||||
import org.graylog2.syslog4j.impl.pool.generic.GenericSyslogPoolFactory;
|
import org.graylog2.syslog4j.impl.pool.generic.GenericSyslogPoolFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PooledTCPNetSyslog is an extension of TCPNetSyslog which provides support
|
* PooledTCPNetSyslog is an extension of TCPNetSyslog which provides support
|
||||||
* for Apache Commons Pool.
|
* for Apache Commons Pool.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: PooledTCPNetSyslog.java,v 1.5 2008/12/10 04:30:15 cvs Exp $
|
* @version $Id: PooledTCPNetSyslog.java,v 1.5 2008/12/10 04:30:15 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class PooledTCPNetSyslog extends TCPNetSyslog {
|
public class PooledTCPNetSyslog extends TCPNetSyslog {
|
||||||
private static final long serialVersionUID = 4279960451141784200L;
|
private static final long serialVersionUID = 4279960451141784200L;
|
||||||
|
|
||||||
protected AbstractSyslogPoolFactory poolFactory = null;
|
protected AbstractSyslogPoolFactory poolFactory = null;
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
|
|
||||||
this.poolFactory = createSyslogPoolFactory();
|
this.poolFactory = createSyslogPoolFactory();
|
||||||
|
|
||||||
this.poolFactory.initialize(this);
|
this.poolFactory.initialize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractSyslogPoolFactory createSyslogPoolFactory() {
|
protected AbstractSyslogPoolFactory createSyslogPoolFactory() {
|
||||||
AbstractSyslogPoolFactory syslogPoolFactory = new GenericSyslogPoolFactory();
|
AbstractSyslogPoolFactory syslogPoolFactory = new GenericSyslogPoolFactory();
|
||||||
|
|
||||||
return syslogPoolFactory;
|
return syslogPoolFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSyslogWriter getWriter() {
|
public AbstractSyslogWriter getWriter() {
|
||||||
try {
|
try {
|
||||||
AbstractSyslogWriter syslogWriter = this.poolFactory.borrowSyslogWriter();
|
AbstractSyslogWriter syslogWriter = this.poolFactory.borrowSyslogWriter();
|
||||||
|
|
||||||
return syslogWriter;
|
return syslogWriter;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SyslogRuntimeException(e);
|
throw new SyslogRuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
||||||
try {
|
try {
|
||||||
this.poolFactory.returnSyslogWriter(syslogWriter);
|
this.poolFactory.returnSyslogWriter(syslogWriter);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SyslogRuntimeException(e);
|
throw new SyslogRuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws SyslogRuntimeException {
|
public void flush() throws SyslogRuntimeException {
|
||||||
try {
|
try {
|
||||||
this.poolFactory.clear();
|
this.poolFactory.clear();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() throws SyslogRuntimeException {
|
public void shutdown() throws SyslogRuntimeException {
|
||||||
try {
|
try {
|
||||||
this.poolFactory.close();
|
this.poolFactory.close();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,168 +5,168 @@ import org.graylog2.syslog4j.SyslogPoolConfigIF;
|
|||||||
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogConfig;
|
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NetSyslogPoolFactory is an implementation of SyslogPoolConfigIF
|
* NetSyslogPoolFactory is an implementation of SyslogPoolConfigIF
|
||||||
* which provides configuration support for the Apache Commons Pool.
|
* which provides configuration support for the Apache Commons Pool.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: PooledTCPNetSyslogConfig.java,v 1.3 2008/11/26 15:01:47 cvs Exp $
|
* @version $Id: PooledTCPNetSyslogConfig.java,v 1.3 2008/11/26 15:01:47 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class PooledTCPNetSyslogConfig extends TCPNetSyslogConfig implements SyslogPoolConfigIF {
|
public class PooledTCPNetSyslogConfig extends TCPNetSyslogConfig implements SyslogPoolConfigIF {
|
||||||
private static final long serialVersionUID = 2283355983363422888L;
|
private static final long serialVersionUID = 2283355983363422888L;
|
||||||
|
|
||||||
protected int maxActive = SYSLOG_POOL_CONFIG_MAX_ACTIVE_DEFAULT;
|
protected int maxActive = SYSLOG_POOL_CONFIG_MAX_ACTIVE_DEFAULT;
|
||||||
protected int maxIdle = SYSLOG_POOL_CONFIG_MAX_IDLE_DEFAULT;
|
protected int maxIdle = SYSLOG_POOL_CONFIG_MAX_IDLE_DEFAULT;
|
||||||
protected long maxWait = SYSLOG_POOL_CONFIG_MAX_WAIT_DEFAULT;
|
protected long maxWait = SYSLOG_POOL_CONFIG_MAX_WAIT_DEFAULT;
|
||||||
protected long minEvictableIdleTimeMillis = SYSLOG_POOL_CONFIG_MIN_EVICTABLE_IDLE_TIME_MILLIS_DEFAULT;
|
protected long minEvictableIdleTimeMillis = SYSLOG_POOL_CONFIG_MIN_EVICTABLE_IDLE_TIME_MILLIS_DEFAULT;
|
||||||
protected int minIdle = SYSLOG_POOL_CONFIG_MIN_IDLE_DEFAULT;
|
protected int minIdle = SYSLOG_POOL_CONFIG_MIN_IDLE_DEFAULT;
|
||||||
protected int numTestsPerEvictionRun = SYSLOG_POOL_CONFIG_NUM_TESTS_PER_EVICTION_RUN_DEFAULT;
|
protected int numTestsPerEvictionRun = SYSLOG_POOL_CONFIG_NUM_TESTS_PER_EVICTION_RUN_DEFAULT;
|
||||||
protected long softMinEvictableIdleTimeMillis = SYSLOG_POOL_CONFIG_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS_DEFAULT;
|
protected long softMinEvictableIdleTimeMillis = SYSLOG_POOL_CONFIG_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS_DEFAULT;
|
||||||
protected long timeBetweenEvictionRunsMillis = SYSLOG_POOL_CONFIG_TIME_BETWEEN_EVICTION_RUNS_MILLIS_DEFAULT;
|
protected long timeBetweenEvictionRunsMillis = SYSLOG_POOL_CONFIG_TIME_BETWEEN_EVICTION_RUNS_MILLIS_DEFAULT;
|
||||||
protected byte whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
|
protected byte whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
|
||||||
protected boolean testOnBorrow = SYSLOG_POOL_CONFIG_TEST_ON_BORROW_DEFAULT;
|
protected boolean testOnBorrow = SYSLOG_POOL_CONFIG_TEST_ON_BORROW_DEFAULT;
|
||||||
protected boolean testOnReturn = SYSLOG_POOL_CONFIG_TEST_ON_RETURN_DEFAULT;
|
protected boolean testOnReturn = SYSLOG_POOL_CONFIG_TEST_ON_RETURN_DEFAULT;
|
||||||
protected boolean testWhileIdle = SYSLOG_POOL_CONFIG_TEST_WHILE_IDLE_DEFAULT;
|
protected boolean testWhileIdle = SYSLOG_POOL_CONFIG_TEST_WHILE_IDLE_DEFAULT;
|
||||||
|
|
||||||
public PooledTCPNetSyslogConfig() {
|
public PooledTCPNetSyslogConfig() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledTCPNetSyslogConfig(int facility, String host, int port) {
|
public PooledTCPNetSyslogConfig(int facility, String host, int port) {
|
||||||
super(facility, host, port);
|
super(facility, host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledTCPNetSyslogConfig(int facility, String host) {
|
public PooledTCPNetSyslogConfig(int facility, String host) {
|
||||||
super(facility, host);
|
super(facility, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledTCPNetSyslogConfig(int facility) {
|
public PooledTCPNetSyslogConfig(int facility) {
|
||||||
super(facility);
|
super(facility);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledTCPNetSyslogConfig(String host, int port) {
|
public PooledTCPNetSyslogConfig(String host, int port) {
|
||||||
super(host, port);
|
super(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledTCPNetSyslogConfig(String host) {
|
public PooledTCPNetSyslogConfig(String host) {
|
||||||
super(host);
|
super(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void configureThreadedValues(int value) {
|
protected void configureThreadedValues(int value) {
|
||||||
if (isThreaded()) {
|
if (isThreaded()) {
|
||||||
this.minIdle = value;
|
this.minIdle = value;
|
||||||
this.maxIdle = value;
|
this.maxIdle = value;
|
||||||
this.maxActive = value;
|
this.maxActive = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxActive() {
|
public int getMaxActive() {
|
||||||
return this.maxActive;
|
return this.maxActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxActive(int maxActive) {
|
public void setMaxActive(int maxActive) {
|
||||||
configureThreadedValues(maxActive);
|
configureThreadedValues(maxActive);
|
||||||
|
|
||||||
this.maxActive = maxActive;
|
this.maxActive = maxActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxIdle() {
|
public int getMaxIdle() {
|
||||||
return this.maxIdle;
|
return this.maxIdle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxIdle(int maxIdle) {
|
public void setMaxIdle(int maxIdle) {
|
||||||
configureThreadedValues(maxIdle);
|
configureThreadedValues(maxIdle);
|
||||||
|
|
||||||
this.maxIdle = maxIdle;
|
this.maxIdle = maxIdle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxWait() {
|
public long getMaxWait() {
|
||||||
return this.maxWait;
|
return this.maxWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxWait(long maxWait) {
|
public void setMaxWait(long maxWait) {
|
||||||
this.maxWait = maxWait;
|
this.maxWait = maxWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMinEvictableIdleTimeMillis() {
|
public long getMinEvictableIdleTimeMillis() {
|
||||||
return this.minEvictableIdleTimeMillis;
|
return this.minEvictableIdleTimeMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
|
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
|
||||||
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
|
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinIdle() {
|
public int getMinIdle() {
|
||||||
return this.minIdle;
|
return this.minIdle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMinIdle(int minIdle) {
|
public void setMinIdle(int minIdle) {
|
||||||
configureThreadedValues(minIdle);
|
configureThreadedValues(minIdle);
|
||||||
|
|
||||||
this.minIdle = minIdle;
|
this.minIdle = minIdle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumTestsPerEvictionRun() {
|
public int getNumTestsPerEvictionRun() {
|
||||||
return this.numTestsPerEvictionRun;
|
return this.numTestsPerEvictionRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
|
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
|
||||||
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
|
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getSoftMinEvictableIdleTimeMillis() {
|
public long getSoftMinEvictableIdleTimeMillis() {
|
||||||
return this.softMinEvictableIdleTimeMillis;
|
return this.softMinEvictableIdleTimeMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSoftMinEvictableIdleTimeMillis(
|
public void setSoftMinEvictableIdleTimeMillis(
|
||||||
long softMinEvictableIdleTimeMillis) {
|
long softMinEvictableIdleTimeMillis) {
|
||||||
this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
|
this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimeBetweenEvictionRunsMillis() {
|
public long getTimeBetweenEvictionRunsMillis() {
|
||||||
return this.timeBetweenEvictionRunsMillis;
|
return this.timeBetweenEvictionRunsMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
|
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
|
||||||
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
|
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getWhenExhaustedAction() {
|
public byte getWhenExhaustedAction() {
|
||||||
return this.whenExhaustedAction;
|
return this.whenExhaustedAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWhenExhaustedAction(byte whenExhaustedAction) {
|
public void setWhenExhaustedAction(byte whenExhaustedAction) {
|
||||||
this.whenExhaustedAction = whenExhaustedAction;
|
this.whenExhaustedAction = whenExhaustedAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTestOnBorrow() {
|
public boolean isTestOnBorrow() {
|
||||||
return this.testOnBorrow;
|
return this.testOnBorrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTestOnBorrow(boolean testOnBorrow) {
|
public void setTestOnBorrow(boolean testOnBorrow) {
|
||||||
this.testOnBorrow = testOnBorrow;
|
this.testOnBorrow = testOnBorrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTestOnReturn() {
|
public boolean isTestOnReturn() {
|
||||||
return this.testOnReturn;
|
return this.testOnReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTestOnReturn(boolean testOnReturn) {
|
public void setTestOnReturn(boolean testOnReturn) {
|
||||||
this.testOnReturn = testOnReturn;
|
this.testOnReturn = testOnReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTestWhileIdle() {
|
public boolean isTestWhileIdle() {
|
||||||
return this.testWhileIdle;
|
return this.testWhileIdle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTestWhileIdle(boolean testWhileIdle) {
|
public void setTestWhileIdle(boolean testWhileIdle) {
|
||||||
this.testWhileIdle = testWhileIdle;
|
this.testWhileIdle = testWhileIdle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogClass() {
|
public Class getSyslogClass() {
|
||||||
return PooledTCPNetSyslog.class;
|
return PooledTCPNetSyslog.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,46 +4,46 @@ import org.graylog2.syslog4j.SyslogRuntimeException;
|
|||||||
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslog;
|
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSLTCPNetSyslog is an extension of AbstractSyslog that provides support for
|
* SSLTCPNetSyslog is an extension of AbstractSyslog that provides support for
|
||||||
* TCP/IP-based (over SSL/TLS) syslog clients.
|
* TCP/IP-based (over SSL/TLS) syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SSLTCPNetSyslog.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: SSLTCPNetSyslog.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SSLTCPNetSyslog extends TCPNetSyslog {
|
public class SSLTCPNetSyslog extends TCPNetSyslog {
|
||||||
private static final long serialVersionUID = 2766654802524487317L;
|
private static final long serialVersionUID = 2766654802524487317L;
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
|
|
||||||
SSLTCPNetSyslogConfigIF sslTcpNetSyslogConfig = (SSLTCPNetSyslogConfigIF) this.tcpNetSyslogConfig;
|
SSLTCPNetSyslogConfigIF sslTcpNetSyslogConfig = (SSLTCPNetSyslogConfigIF) this.tcpNetSyslogConfig;
|
||||||
|
|
||||||
String keyStore = sslTcpNetSyslogConfig.getKeyStore();
|
String keyStore = sslTcpNetSyslogConfig.getKeyStore();
|
||||||
|
|
||||||
if (keyStore != null && !"".equals(keyStore.trim())) {
|
if (keyStore != null && !"".equals(keyStore.trim())) {
|
||||||
System.setProperty("javax.net.ssl.keyStore",keyStore);
|
System.setProperty("javax.net.ssl.keyStore", keyStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
String keyStorePassword = sslTcpNetSyslogConfig.getKeyStorePassword();
|
String keyStorePassword = sslTcpNetSyslogConfig.getKeyStorePassword();
|
||||||
|
|
||||||
if (keyStorePassword != null && !"".equals(keyStorePassword.trim())) {
|
if (keyStorePassword != null && !"".equals(keyStorePassword.trim())) {
|
||||||
System.setProperty("javax.net.ssl.keyStorePassword",keyStorePassword);
|
System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
String trustStore = sslTcpNetSyslogConfig.getTrustStore();
|
String trustStore = sslTcpNetSyslogConfig.getTrustStore();
|
||||||
|
|
||||||
if (trustStore != null && !"".equals(trustStore.trim())) {
|
if (trustStore != null && !"".equals(trustStore.trim())) {
|
||||||
System.setProperty("javax.net.ssl.trustStore",trustStore);
|
System.setProperty("javax.net.ssl.trustStore", trustStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
String trustStorePassword = sslTcpNetSyslogConfig.getTrustStorePassword();
|
String trustStorePassword = sslTcpNetSyslogConfig.getTrustStorePassword();
|
||||||
|
|
||||||
if (trustStorePassword != null && !"".equals(trustStorePassword.trim())) {
|
if (trustStorePassword != null && !"".equals(trustStorePassword.trim())) {
|
||||||
System.setProperty("javax.net.ssl.trustStorePassword",trustStorePassword);
|
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,86 +3,86 @@ package org.graylog2.syslog4j.impl.net.tcp.ssl;
|
|||||||
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogConfig;
|
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSLTCPNetSyslogConfig is an extension of TCPNetSyslogConfig that provides
|
* SSLTCPNetSyslogConfig is an extension of TCPNetSyslogConfig that provides
|
||||||
* configuration support for TCP/IP-based (over SSL/TLS) syslog clients.
|
* configuration support for TCP/IP-based (over SSL/TLS) syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SSLTCPNetSyslogConfig.java,v 1.2 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: SSLTCPNetSyslogConfig.java,v 1.2 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SSLTCPNetSyslogConfig extends TCPNetSyslogConfig implements SSLTCPNetSyslogConfigIF {
|
public class SSLTCPNetSyslogConfig extends TCPNetSyslogConfig implements SSLTCPNetSyslogConfigIF {
|
||||||
private static final long serialVersionUID = 5569086213824510834L;
|
private static final long serialVersionUID = 5569086213824510834L;
|
||||||
|
|
||||||
protected String keyStore = null;
|
protected String keyStore = null;
|
||||||
protected String keyStorePassword = null;
|
protected String keyStorePassword = null;
|
||||||
|
|
||||||
protected String trustStore = null;
|
protected String trustStore = null;
|
||||||
protected String trustStorePassword = null;
|
protected String trustStorePassword = null;
|
||||||
|
|
||||||
public SSLTCPNetSyslogConfig() {
|
public SSLTCPNetSyslogConfig() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSLTCPNetSyslogConfig(int facility, String host, int port) {
|
public SSLTCPNetSyslogConfig(int facility, String host, int port) {
|
||||||
super(facility, host, port);
|
super(facility, host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSLTCPNetSyslogConfig(int facility, String host) {
|
public SSLTCPNetSyslogConfig(int facility, String host) {
|
||||||
super(facility, host);
|
super(facility, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSLTCPNetSyslogConfig(int facility) {
|
public SSLTCPNetSyslogConfig(int facility) {
|
||||||
super(facility);
|
super(facility);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSLTCPNetSyslogConfig(String host, int port) {
|
public SSLTCPNetSyslogConfig(String host, int port) {
|
||||||
super(host, port);
|
super(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSLTCPNetSyslogConfig(String host) {
|
public SSLTCPNetSyslogConfig(String host) {
|
||||||
super(host);
|
super(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyStore() {
|
public String getKeyStore() {
|
||||||
return this.keyStore;
|
return this.keyStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyStore(String keyStore) {
|
public void setKeyStore(String keyStore) {
|
||||||
this.keyStore = keyStore;
|
this.keyStore = keyStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyStorePassword() {
|
public String getKeyStorePassword() {
|
||||||
return this.keyStorePassword;
|
return this.keyStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyStorePassword(String keyStorePassword) {
|
public void setKeyStorePassword(String keyStorePassword) {
|
||||||
this.keyStorePassword = keyStorePassword;
|
this.keyStorePassword = keyStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTrustStore() {
|
public String getTrustStore() {
|
||||||
return this.trustStore;
|
return this.trustStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTrustStore(String trustStore) {
|
public void setTrustStore(String trustStore) {
|
||||||
this.trustStore = trustStore;
|
this.trustStore = trustStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTrustStorePassword() {
|
public String getTrustStorePassword() {
|
||||||
return this.trustStorePassword;
|
return this.trustStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTrustStorePassword(String trustStorePassword) {
|
public void setTrustStorePassword(String trustStorePassword) {
|
||||||
this.trustStorePassword = trustStorePassword;
|
this.trustStorePassword = trustStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogClass() {
|
public Class getSyslogClass() {
|
||||||
return SSLTCPNetSyslog.class;
|
return SSLTCPNetSyslog.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogWriterClass() {
|
public Class getSyslogWriterClass() {
|
||||||
return SSLTCPNetSyslogWriter.class;
|
return SSLTCPNetSyslogWriter.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,26 +3,30 @@ package org.graylog2.syslog4j.impl.net.tcp.ssl;
|
|||||||
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogConfigIF;
|
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogConfigIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSLTCPNetSyslogConfigIF is a configuration interface supporting TCP/IP-based
|
* SSLTCPNetSyslogConfigIF is a configuration interface supporting TCP/IP-based
|
||||||
* (over SSL/TLS) Syslog implementations.
|
* (over SSL/TLS) Syslog implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SSLTCPNetSyslogConfigIF.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: SSLTCPNetSyslogConfigIF.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SSLTCPNetSyslogConfigIF extends TCPNetSyslogConfigIF {
|
public interface SSLTCPNetSyslogConfigIF extends TCPNetSyslogConfigIF {
|
||||||
public String getKeyStore();
|
public String getKeyStore();
|
||||||
public void setKeyStore(String keyStore);
|
|
||||||
|
|
||||||
public String getKeyStorePassword();
|
public void setKeyStore(String keyStore);
|
||||||
public void setKeyStorePassword(String keyStorePassword);
|
|
||||||
|
|
||||||
public String getTrustStore();
|
public String getKeyStorePassword();
|
||||||
public void setTrustStore(String trustStore);
|
|
||||||
|
|
||||||
public String getTrustStorePassword();
|
public void setKeyStorePassword(String keyStorePassword);
|
||||||
public void setTrustStorePassword(String trustStorePassword);
|
|
||||||
|
public String getTrustStore();
|
||||||
|
|
||||||
|
public void setTrustStore(String trustStore);
|
||||||
|
|
||||||
|
public String getTrustStorePassword();
|
||||||
|
|
||||||
|
public void setTrustStorePassword(String trustStorePassword);
|
||||||
}
|
}
|
||||||
|
@ -6,23 +6,23 @@ import javax.net.ssl.SSLSocketFactory;
|
|||||||
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogWriter;
|
import org.graylog2.syslog4j.impl.net.tcp.TCPNetSyslogWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSLTCPNetSyslogWriter is an implementation of Runnable that supports sending
|
* SSLTCPNetSyslogWriter is an implementation of Runnable that supports sending
|
||||||
* TCP/IP-based (over SSL/TLS) messages within a separate Thread.
|
* TCP/IP-based (over SSL/TLS) messages within a separate Thread.
|
||||||
*
|
* <p/>
|
||||||
* <p>When used in "threaded" mode (see TCPNetSyslogConfig for the option),
|
* <p>When used in "threaded" mode (see TCPNetSyslogConfig for the option),
|
||||||
* a queuing mechanism is used (via LinkedList).</p>
|
* a queuing mechanism is used (via LinkedList).</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SSLTCPNetSyslogWriter.java,v 1.4 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: SSLTCPNetSyslogWriter.java,v 1.4 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SSLTCPNetSyslogWriter extends TCPNetSyslogWriter {
|
public class SSLTCPNetSyslogWriter extends TCPNetSyslogWriter {
|
||||||
private static final long serialVersionUID = 8944446235285662244L;
|
private static final long serialVersionUID = 8944446235285662244L;
|
||||||
|
|
||||||
protected SocketFactory obtainSocketFactory() {
|
protected SocketFactory obtainSocketFactory() {
|
||||||
return SSLSocketFactory.getDefault();
|
return SSLSocketFactory.getDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,86 +6,86 @@ import org.graylog2.syslog4j.impl.net.tcp.ssl.SSLTCPNetSyslogConfigIF;
|
|||||||
import org.graylog2.syslog4j.impl.net.tcp.ssl.SSLTCPNetSyslogWriter;
|
import org.graylog2.syslog4j.impl.net.tcp.ssl.SSLTCPNetSyslogWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PooledSSLTCPNetSyslogConfig is an extension of PooledTCPNetSyslogConfig
|
* PooledSSLTCPNetSyslogConfig is an extension of PooledTCPNetSyslogConfig
|
||||||
* which provides configuration support for the Apache Commons Pool.
|
* which provides configuration support for the Apache Commons Pool.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: PooledSSLTCPNetSyslogConfig.java,v 1.2 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: PooledSSLTCPNetSyslogConfig.java,v 1.2 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class PooledSSLTCPNetSyslogConfig extends PooledTCPNetSyslogConfig implements SSLTCPNetSyslogConfigIF {
|
public class PooledSSLTCPNetSyslogConfig extends PooledTCPNetSyslogConfig implements SSLTCPNetSyslogConfigIF {
|
||||||
private static final long serialVersionUID = 2092268298395023976L;
|
private static final long serialVersionUID = 2092268298395023976L;
|
||||||
|
|
||||||
protected String keyStore = null;
|
protected String keyStore = null;
|
||||||
protected String keyStorePassword = null;
|
protected String keyStorePassword = null;
|
||||||
|
|
||||||
protected String trustStore = null;
|
protected String trustStore = null;
|
||||||
protected String trustStorePassword = null;
|
protected String trustStorePassword = null;
|
||||||
|
|
||||||
public PooledSSLTCPNetSyslogConfig() {
|
public PooledSSLTCPNetSyslogConfig() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledSSLTCPNetSyslogConfig(int facility, String host, int port) {
|
public PooledSSLTCPNetSyslogConfig(int facility, String host, int port) {
|
||||||
super(facility, host, port);
|
super(facility, host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledSSLTCPNetSyslogConfig(int facility, String host) {
|
public PooledSSLTCPNetSyslogConfig(int facility, String host) {
|
||||||
super(facility, host);
|
super(facility, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledSSLTCPNetSyslogConfig(int facility) {
|
public PooledSSLTCPNetSyslogConfig(int facility) {
|
||||||
super(facility);
|
super(facility);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledSSLTCPNetSyslogConfig(String host, int port) {
|
public PooledSSLTCPNetSyslogConfig(String host, int port) {
|
||||||
super(host, port);
|
super(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PooledSSLTCPNetSyslogConfig(String host) {
|
public PooledSSLTCPNetSyslogConfig(String host) {
|
||||||
super(host);
|
super(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyStore() {
|
public String getKeyStore() {
|
||||||
return this.keyStore;
|
return this.keyStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyStore(String keyStore) {
|
public void setKeyStore(String keyStore) {
|
||||||
this.keyStore = keyStore;
|
this.keyStore = keyStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyStorePassword() {
|
public String getKeyStorePassword() {
|
||||||
return this.keyStorePassword;
|
return this.keyStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyStorePassword(String keyStorePassword) {
|
public void setKeyStorePassword(String keyStorePassword) {
|
||||||
this.keyStorePassword = keyStorePassword;
|
this.keyStorePassword = keyStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTrustStore() {
|
public String getTrustStore() {
|
||||||
return this.trustStore;
|
return this.trustStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTrustStore(String trustStore) {
|
public void setTrustStore(String trustStore) {
|
||||||
this.trustStore = trustStore;
|
this.trustStore = trustStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTrustStorePassword() {
|
public String getTrustStorePassword() {
|
||||||
return this.trustStorePassword;
|
return this.trustStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTrustStorePassword(String trustStorePassword) {
|
public void setTrustStorePassword(String trustStorePassword) {
|
||||||
this.trustStorePassword = trustStorePassword;
|
this.trustStorePassword = trustStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogClass() {
|
public Class getSyslogClass() {
|
||||||
return SSLTCPNetSyslog.class;
|
return SSLTCPNetSyslog.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogWriterClass() {
|
public Class getSyslogWriterClass() {
|
||||||
return SSLTCPNetSyslogWriter.class;
|
return SSLTCPNetSyslogWriter.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,94 +11,94 @@ import org.graylog2.syslog4j.impl.AbstractSyslogWriter;
|
|||||||
import org.graylog2.syslog4j.impl.net.AbstractNetSyslog;
|
import org.graylog2.syslog4j.impl.net.AbstractNetSyslog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UDPNetSyslog is an extension of AbstractSyslog that provides support for
|
* UDPNetSyslog is an extension of AbstractSyslog that provides support for
|
||||||
* UDP/IP-based syslog clients.
|
* UDP/IP-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: UDPNetSyslog.java,v 1.18 2010/10/27 06:18:10 cvs Exp $
|
* @version $Id: UDPNetSyslog.java,v 1.18 2010/10/27 06:18:10 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class UDPNetSyslog extends AbstractNetSyslog {
|
public class UDPNetSyslog extends AbstractNetSyslog {
|
||||||
private static final long serialVersionUID = 5259485504549037999L;
|
private static final long serialVersionUID = 5259485504549037999L;
|
||||||
|
|
||||||
protected DatagramSocket socket = null;
|
protected DatagramSocket socket = null;
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
|
|
||||||
createDatagramSocket(true);
|
createDatagramSocket(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void createDatagramSocket(boolean initialize) {
|
protected synchronized void createDatagramSocket(boolean initialize) {
|
||||||
try {
|
try {
|
||||||
this.socket = new DatagramSocket();
|
this.socket = new DatagramSocket();
|
||||||
|
|
||||||
} catch (SocketException se) {
|
} catch (SocketException se) {
|
||||||
if (initialize) {
|
if (initialize) {
|
||||||
if (this.syslogConfig.isThrowExceptionOnInitialize()) {
|
if (this.syslogConfig.isThrowExceptionOnInitialize()) {
|
||||||
throw new SyslogRuntimeException(se);
|
throw new SyslogRuntimeException(se);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new SyslogRuntimeException(se);
|
throw new SyslogRuntimeException(se);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.socket == null) {
|
if (this.socket == null) {
|
||||||
throw new SyslogRuntimeException("Cannot seem to get a Datagram socket");
|
throw new SyslogRuntimeException("Cannot seem to get a Datagram socket");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void write(int level, byte[] message) throws SyslogRuntimeException {
|
protected void write(int level, byte[] message) throws SyslogRuntimeException {
|
||||||
if (this.socket == null) {
|
if (this.socket == null) {
|
||||||
createDatagramSocket(false);
|
createDatagramSocket(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
InetAddress hostAddress = getHostAddress();
|
InetAddress hostAddress = getHostAddress();
|
||||||
|
|
||||||
DatagramPacket packet = new DatagramPacket(
|
DatagramPacket packet = new DatagramPacket(
|
||||||
message,
|
message,
|
||||||
message.length,
|
message.length,
|
||||||
hostAddress,
|
hostAddress,
|
||||||
this.syslogConfig.getPort()
|
this.syslogConfig.getPort()
|
||||||
);
|
);
|
||||||
|
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
|
|
||||||
while(attempts != -1 && attempts < (this.netSyslogConfig.getWriteRetries() + 1)) {
|
while (attempts != -1 && attempts < (this.netSyslogConfig.getWriteRetries() + 1)) {
|
||||||
try {
|
try {
|
||||||
this.socket.send(packet);
|
this.socket.send(packet);
|
||||||
attempts = -1;
|
attempts = -1;
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
if (attempts == (this.netSyslogConfig.getWriteRetries() + 1)) {
|
if (attempts == (this.netSyslogConfig.getWriteRetries() + 1)) {
|
||||||
throw new SyslogRuntimeException(ioe);
|
throw new SyslogRuntimeException(ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws SyslogRuntimeException {
|
public void flush() throws SyslogRuntimeException {
|
||||||
shutdown();
|
shutdown();
|
||||||
|
|
||||||
createDatagramSocket(true);
|
createDatagramSocket(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() throws SyslogRuntimeException {
|
public void shutdown() throws SyslogRuntimeException {
|
||||||
if (this.socket != null) {
|
if (this.socket != null) {
|
||||||
this.socket.close();
|
this.socket.close();
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSyslogWriter getWriter() {
|
public AbstractSyslogWriter getWriter() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,44 +3,44 @@ package org.graylog2.syslog4j.impl.net.udp;
|
|||||||
import org.graylog2.syslog4j.impl.net.AbstractNetSyslogConfig;
|
import org.graylog2.syslog4j.impl.net.AbstractNetSyslogConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UDPNetSyslogConfig is an extension of AbstractNetSyslogConfig that provides
|
* UDPNetSyslogConfig is an extension of AbstractNetSyslogConfig that provides
|
||||||
* configuration support for UDP/IP-based syslog clients.
|
* configuration support for UDP/IP-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: UDPNetSyslogConfig.java,v 1.6 2008/11/14 04:32:00 cvs Exp $
|
* @version $Id: UDPNetSyslogConfig.java,v 1.6 2008/11/14 04:32:00 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class UDPNetSyslogConfig extends AbstractNetSyslogConfig {
|
public class UDPNetSyslogConfig extends AbstractNetSyslogConfig {
|
||||||
private static final long serialVersionUID = 4465067182562754345L;
|
private static final long serialVersionUID = 4465067182562754345L;
|
||||||
|
|
||||||
public UDPNetSyslogConfig() {
|
public UDPNetSyslogConfig() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UDPNetSyslogConfig(int facility, String host, int port) {
|
public UDPNetSyslogConfig(int facility, String host, int port) {
|
||||||
super(facility,host,port);
|
super(facility, host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UDPNetSyslogConfig(int facility, String host) {
|
public UDPNetSyslogConfig(int facility, String host) {
|
||||||
super(facility,host);
|
super(facility, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UDPNetSyslogConfig(int facility) {
|
public UDPNetSyslogConfig(int facility) {
|
||||||
super(facility);
|
super(facility);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UDPNetSyslogConfig(String host, int port) {
|
public UDPNetSyslogConfig(String host, int port) {
|
||||||
super(host,port);
|
super(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UDPNetSyslogConfig(String host) {
|
public UDPNetSyslogConfig(String host) {
|
||||||
super(host);
|
super(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogClass() {
|
public Class getSyslogClass() {
|
||||||
return UDPNetSyslog.class;
|
return UDPNetSyslog.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,77 +8,77 @@ import org.graylog2.syslog4j.impl.AbstractSyslogConfigIF;
|
|||||||
import org.graylog2.syslog4j.impl.AbstractSyslogWriter;
|
import org.graylog2.syslog4j.impl.AbstractSyslogWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslogPoolFactory is an abstract implementation of the Apache Commons Pool
|
* AbstractSyslogPoolFactory is an abstract implementation of the Apache Commons Pool
|
||||||
* BasePoolableObjectFactory.
|
* BasePoolableObjectFactory.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogPoolFactory.java,v 1.5 2008/12/10 04:15:11 cvs Exp $
|
* @version $Id: AbstractSyslogPoolFactory.java,v 1.5 2008/12/10 04:15:11 cvs Exp $
|
||||||
* @see org.graylog2.syslog4j.impl.pool.generic.GenericSyslogPoolFactory
|
* @see org.graylog2.syslog4j.impl.pool.generic.GenericSyslogPoolFactory
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslogPoolFactory extends BasePoolableObjectFactory {
|
public abstract class AbstractSyslogPoolFactory extends BasePoolableObjectFactory {
|
||||||
private static final long serialVersionUID = -7441569603980981508L;
|
private static final long serialVersionUID = -7441569603980981508L;
|
||||||
|
|
||||||
protected AbstractSyslog syslog = null;
|
protected AbstractSyslog syslog = null;
|
||||||
protected AbstractSyslogConfigIF syslogConfig = null;
|
protected AbstractSyslogConfigIF syslogConfig = null;
|
||||||
|
|
||||||
protected ObjectPool pool = null;
|
protected ObjectPool pool = null;
|
||||||
|
|
||||||
public AbstractSyslogPoolFactory() {
|
public AbstractSyslogPoolFactory() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(AbstractSyslog abstractSyslog) throws SyslogRuntimeException {
|
public void initialize(AbstractSyslog abstractSyslog) throws SyslogRuntimeException {
|
||||||
this.syslog = abstractSyslog;
|
this.syslog = abstractSyslog;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.syslogConfig = (AbstractSyslogConfigIF) this.syslog.getConfig();
|
this.syslogConfig = (AbstractSyslogConfigIF) this.syslog.getConfig();
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("config must implement AbstractSyslogConfigIF");
|
throw new SyslogRuntimeException("config must implement AbstractSyslogConfigIF");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pool = createPool();
|
this.pool = createPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object makeObject() throws Exception {
|
public Object makeObject() throws Exception {
|
||||||
AbstractSyslogWriter syslogWriter = this.syslog.createWriter();
|
AbstractSyslogWriter syslogWriter = this.syslog.createWriter();
|
||||||
|
|
||||||
if (this.syslogConfig.isThreaded()) {
|
if (this.syslogConfig.isThreaded()) {
|
||||||
this.syslog.createWriterThread(syslogWriter);
|
this.syslog.createWriterThread(syslogWriter);
|
||||||
}
|
}
|
||||||
|
|
||||||
return syslogWriter;
|
return syslogWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroyObject(Object obj) throws Exception {
|
public void destroyObject(Object obj) throws Exception {
|
||||||
AbstractSyslogWriter writer = (AbstractSyslogWriter) obj;
|
AbstractSyslogWriter writer = (AbstractSyslogWriter) obj;
|
||||||
|
|
||||||
writer.shutdown();
|
writer.shutdown();
|
||||||
|
|
||||||
super.destroyObject(writer);
|
super.destroyObject(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract ObjectPool createPool() throws SyslogRuntimeException;
|
public abstract ObjectPool createPool() throws SyslogRuntimeException;
|
||||||
|
|
||||||
public AbstractSyslogWriter borrowSyslogWriter() throws Exception {
|
public AbstractSyslogWriter borrowSyslogWriter() throws Exception {
|
||||||
AbstractSyslogWriter syslogWriter = (AbstractSyslogWriter) this.pool.borrowObject();
|
AbstractSyslogWriter syslogWriter = (AbstractSyslogWriter) this.pool.borrowObject();
|
||||||
|
|
||||||
return syslogWriter;
|
return syslogWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnSyslogWriter(AbstractSyslogWriter syslogWriter) throws Exception {
|
public void returnSyslogWriter(AbstractSyslogWriter syslogWriter) throws Exception {
|
||||||
this.pool.returnObject(syslogWriter);
|
this.pool.returnObject(syslogWriter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() throws Exception {
|
public void clear() throws Exception {
|
||||||
this.pool.clear();
|
this.pool.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws Exception {
|
public void close() throws Exception {
|
||||||
this.pool.close();
|
this.pool.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,46 +7,46 @@ import org.graylog2.syslog4j.SyslogRuntimeException;
|
|||||||
import org.graylog2.syslog4j.impl.pool.AbstractSyslogPoolFactory;
|
import org.graylog2.syslog4j.impl.pool.AbstractSyslogPoolFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GenericSyslogPoolFactory is an implementation of the Apache Commons Pool
|
* GenericSyslogPoolFactory is an implementation of the Apache Commons Pool
|
||||||
* BasePoolableObjectFactory using a GenericObjectPool.
|
* BasePoolableObjectFactory using a GenericObjectPool.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: GenericSyslogPoolFactory.java,v 1.5 2008/12/10 04:15:10 cvs Exp $
|
* @version $Id: GenericSyslogPoolFactory.java,v 1.5 2008/12/10 04:15:10 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class GenericSyslogPoolFactory extends AbstractSyslogPoolFactory {
|
public class GenericSyslogPoolFactory extends AbstractSyslogPoolFactory {
|
||||||
protected void configureGenericObjectPool(GenericObjectPool genericObjectPool) throws SyslogRuntimeException {
|
protected void configureGenericObjectPool(GenericObjectPool genericObjectPool) throws SyslogRuntimeException {
|
||||||
SyslogPoolConfigIF poolConfig = null;
|
SyslogPoolConfigIF poolConfig = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
poolConfig = (SyslogPoolConfigIF) this.syslog.getConfig();
|
poolConfig = (SyslogPoolConfigIF) this.syslog.getConfig();
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("config must implement interface SyslogPoolConfigIF");
|
throw new SyslogRuntimeException("config must implement interface SyslogPoolConfigIF");
|
||||||
}
|
}
|
||||||
|
|
||||||
genericObjectPool.setMaxActive(poolConfig.getMaxActive());
|
genericObjectPool.setMaxActive(poolConfig.getMaxActive());
|
||||||
genericObjectPool.setMaxIdle(poolConfig.getMaxIdle());
|
genericObjectPool.setMaxIdle(poolConfig.getMaxIdle());
|
||||||
genericObjectPool.setMaxWait(poolConfig.getMaxWait());
|
genericObjectPool.setMaxWait(poolConfig.getMaxWait());
|
||||||
genericObjectPool.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis());
|
genericObjectPool.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis());
|
||||||
genericObjectPool.setMinIdle(poolConfig.getMinIdle());
|
genericObjectPool.setMinIdle(poolConfig.getMinIdle());
|
||||||
genericObjectPool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun());
|
genericObjectPool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun());
|
||||||
genericObjectPool.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis());
|
genericObjectPool.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis());
|
||||||
genericObjectPool.setTestOnBorrow(poolConfig.isTestOnBorrow());
|
genericObjectPool.setTestOnBorrow(poolConfig.isTestOnBorrow());
|
||||||
genericObjectPool.setTestOnReturn(poolConfig.isTestOnReturn());
|
genericObjectPool.setTestOnReturn(poolConfig.isTestOnReturn());
|
||||||
genericObjectPool.setTestWhileIdle(poolConfig.isTestWhileIdle());
|
genericObjectPool.setTestWhileIdle(poolConfig.isTestWhileIdle());
|
||||||
genericObjectPool.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis());
|
genericObjectPool.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis());
|
||||||
genericObjectPool.setWhenExhaustedAction(poolConfig.getWhenExhaustedAction());
|
genericObjectPool.setWhenExhaustedAction(poolConfig.getWhenExhaustedAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectPool createPool() throws SyslogRuntimeException {
|
public ObjectPool createPool() throws SyslogRuntimeException {
|
||||||
GenericObjectPool genericPool = new GenericObjectPool(this);
|
GenericObjectPool genericPool = new GenericObjectPool(this);
|
||||||
|
|
||||||
configureGenericObjectPool(genericPool);
|
configureGenericObjectPool(genericPool);
|
||||||
|
|
||||||
return genericPool;
|
return genericPool;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,115 +11,117 @@ import com.sun.jna.Memory;
|
|||||||
import com.sun.jna.Native;
|
import com.sun.jna.Native;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UnixSyslog is an extension of AbstractSyslog that provides support for
|
* UnixSyslog is an extension of AbstractSyslog that provides support for
|
||||||
* Unix-based syslog clients.
|
* Unix-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>This class requires the JNA (Java Native Access) library to directly
|
* <p>This class requires the JNA (Java Native Access) library to directly
|
||||||
* access the native C libraries utilized on Unix platforms.</p>
|
* access the native C libraries utilized on Unix platforms.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: UnixSyslog.java,v 1.27 2010/10/25 04:21:19 cvs Exp $
|
* @version $Id: UnixSyslog.java,v 1.27 2010/10/25 04:21:19 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class UnixSyslog extends AbstractSyslog {
|
public class UnixSyslog extends AbstractSyslog {
|
||||||
private static final long serialVersionUID = 4973353204252276740L;
|
private static final long serialVersionUID = 4973353204252276740L;
|
||||||
|
|
||||||
protected UnixSyslogConfig unixSyslogConfig = null;
|
protected UnixSyslogConfig unixSyslogConfig = null;
|
||||||
|
|
||||||
protected interface CLibrary extends Library {
|
protected interface CLibrary extends Library {
|
||||||
public void openlog(final Memory ident, int option, int facility);
|
public void openlog(final Memory ident, int option, int facility);
|
||||||
|
|
||||||
public void syslog(int priority, final String format, final String message);
|
public void syslog(int priority, final String format, final String message);
|
||||||
|
|
||||||
public void closelog();
|
public void closelog();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static int currentFacility = -1;
|
protected static int currentFacility = -1;
|
||||||
protected static boolean openlogCalled = false;
|
protected static boolean openlogCalled = false;
|
||||||
|
|
||||||
protected static CLibrary libraryInstance = null;
|
protected static CLibrary libraryInstance = null;
|
||||||
|
|
||||||
protected static synchronized void loadLibrary(UnixSyslogConfig config) throws SyslogRuntimeException {
|
protected static synchronized void loadLibrary(UnixSyslogConfig config) throws SyslogRuntimeException {
|
||||||
if (!OSDetectUtility.isUnix()) {
|
if (!OSDetectUtility.isUnix()) {
|
||||||
throw new SyslogRuntimeException("UnixSyslog not supported on non-Unix platforms");
|
throw new SyslogRuntimeException("UnixSyslog not supported on non-Unix platforms");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (libraryInstance == null) {
|
if (libraryInstance == null) {
|
||||||
libraryInstance = (CLibrary) Native.loadLibrary(config.getLibrary(),CLibrary.class);
|
libraryInstance = (CLibrary) Native.loadLibrary(config.getLibrary(), CLibrary.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
try {
|
try {
|
||||||
this.unixSyslogConfig = (UnixSyslogConfig) this.syslogConfig;
|
this.unixSyslogConfig = (UnixSyslogConfig) this.syslogConfig;
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("config must be of type UnixSyslogConfig");
|
throw new SyslogRuntimeException("config must be of type UnixSyslogConfig");
|
||||||
}
|
}
|
||||||
|
|
||||||
loadLibrary(this.unixSyslogConfig);
|
loadLibrary(this.unixSyslogConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void write(int level, String message, UnixSyslogConfig config) throws SyslogRuntimeException {
|
protected static void write(int level, String message, UnixSyslogConfig config) throws SyslogRuntimeException {
|
||||||
synchronized(libraryInstance) {
|
synchronized (libraryInstance) {
|
||||||
if (currentFacility != config.getFacility()) {
|
if (currentFacility != config.getFacility()) {
|
||||||
if (openlogCalled) {
|
if (openlogCalled) {
|
||||||
libraryInstance.closelog();
|
libraryInstance.closelog();
|
||||||
openlogCalled = false;
|
openlogCalled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFacility = config.getFacility();
|
currentFacility = config.getFacility();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!openlogCalled) {
|
if (!openlogCalled) {
|
||||||
String ident = config.getIdent();
|
String ident = config.getIdent();
|
||||||
|
|
||||||
if (ident != null && "".equals(ident.trim())) {
|
if (ident != null && "".equals(ident.trim())) {
|
||||||
ident = null;
|
ident = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Memory identBuffer = null;
|
Memory identBuffer = null;
|
||||||
|
|
||||||
if (ident != null) {
|
if (ident != null) {
|
||||||
identBuffer = new Memory(128);
|
identBuffer = new Memory(128);
|
||||||
identBuffer.setString(0, ident, false);
|
identBuffer.setString(0, ident, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
libraryInstance.openlog(identBuffer,config.getOption(),currentFacility);
|
libraryInstance.openlog(identBuffer, config.getOption(), currentFacility);
|
||||||
openlogCalled = true;
|
openlogCalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int priority = currentFacility | level;
|
int priority = currentFacility | level;
|
||||||
|
|
||||||
libraryInstance.syslog(priority,"%s",message);
|
libraryInstance.syslog(priority, "%s", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void write(int level, byte[] message) throws SyslogRuntimeException {
|
protected void write(int level, byte[] message) throws SyslogRuntimeException {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(SyslogMessageProcessorIF messageProcessor, int level, String message) {
|
public void log(SyslogMessageProcessorIF messageProcessor, int level, String message) {
|
||||||
write(level,message,this.unixSyslogConfig);
|
write(level, message, this.unixSyslogConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws SyslogRuntimeException {
|
public void flush() throws SyslogRuntimeException {
|
||||||
synchronized(libraryInstance) {
|
synchronized (libraryInstance) {
|
||||||
libraryInstance.closelog();
|
libraryInstance.closelog();
|
||||||
openlogCalled = false;
|
openlogCalled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() throws SyslogRuntimeException {
|
public void shutdown() throws SyslogRuntimeException {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSyslogWriter getWriter() {
|
public AbstractSyslogWriter getWriter() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,68 +4,68 @@ import org.graylog2.syslog4j.SyslogRuntimeException;
|
|||||||
import org.graylog2.syslog4j.impl.AbstractSyslogConfig;
|
import org.graylog2.syslog4j.impl.AbstractSyslogConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UnixSyslogConfig is an extension of AbstractNetSyslogConfig that provides
|
* UnixSyslogConfig is an extension of AbstractNetSyslogConfig that provides
|
||||||
* configuration support for Unix-based syslog clients.
|
* configuration support for Unix-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: UnixSyslogConfig.java,v 1.13 2010/10/25 03:50:25 cvs Exp $
|
* @version $Id: UnixSyslogConfig.java,v 1.13 2010/10/25 03:50:25 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class UnixSyslogConfig extends AbstractSyslogConfig {
|
public class UnixSyslogConfig extends AbstractSyslogConfig {
|
||||||
private static final long serialVersionUID = -4805767812011660656L;
|
private static final long serialVersionUID = -4805767812011660656L;
|
||||||
|
|
||||||
protected String library = SYSLOG_LIBRARY_DEFAULT;
|
protected String library = SYSLOG_LIBRARY_DEFAULT;
|
||||||
protected int option = OPTION_NONE;
|
protected int option = OPTION_NONE;
|
||||||
|
|
||||||
public UnixSyslogConfig() {
|
public UnixSyslogConfig() {
|
||||||
// Unix-based syslog does not need localName sent
|
// Unix-based syslog does not need localName sent
|
||||||
this.setSendLocalName(false);
|
this.setSendLocalName(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogClass() {
|
public Class getSyslogClass() {
|
||||||
return UnixSyslog.class;
|
return UnixSyslog.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) throws SyslogRuntimeException {
|
public void setHost(String host) throws SyslogRuntimeException {
|
||||||
throw new SyslogRuntimeException("Host not appropriate for class \"" + this.getClass().getName() + "\"");
|
throw new SyslogRuntimeException("Host not appropriate for class \"" + this.getClass().getName() + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(int port) throws SyslogRuntimeException {
|
public void setPort(int port) throws SyslogRuntimeException {
|
||||||
throw new SyslogRuntimeException("Port not appropriate for class \"" + this.getClass().getName() + "\"");
|
throw new SyslogRuntimeException("Port not appropriate for class \"" + this.getClass().getName() + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLibrary() {
|
public String getLibrary() {
|
||||||
return this.library;
|
return this.library;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLibrary(String library) {
|
public void setLibrary(String library) {
|
||||||
this.library = library;
|
this.library = library;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOption() {
|
public int getOption() {
|
||||||
return this.option;
|
return this.option;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOption(int option) {
|
public void setOption(int option) {
|
||||||
this.option = option;
|
this.option = option;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxQueueSize() {
|
public int getMaxQueueSize() {
|
||||||
throw new SyslogRuntimeException("UnixSyslog protocol does not uses a queueing mechanism");
|
throw new SyslogRuntimeException("UnixSyslog protocol does not uses a queueing mechanism");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxQueueSize(int maxQueueSize) {
|
public void setMaxQueueSize(int maxQueueSize) {
|
||||||
throw new SyslogRuntimeException("UnixSyslog protocol does not uses a queueing mechanism");
|
throw new SyslogRuntimeException("UnixSyslog protocol does not uses a queueing mechanism");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,132 +12,136 @@ import com.sun.jna.Native;
|
|||||||
import com.sun.jna.Structure;
|
import com.sun.jna.Structure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UnixSocketSyslog is an extension of AbstractSyslog that provides support for
|
* UnixSocketSyslog is an extension of AbstractSyslog that provides support for
|
||||||
* Unix socket-based syslog clients.
|
* Unix socket-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>This class requires the JNA (Java Native Access) library to directly
|
* <p>This class requires the JNA (Java Native Access) library to directly
|
||||||
* access the native C libraries utilized on Unix platforms.</p>
|
* access the native C libraries utilized on Unix platforms.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: UnixSocketSyslog.java,v 1.13 2010/11/16 00:52:01 cvs Exp $
|
* @version $Id: UnixSocketSyslog.java,v 1.13 2010/11/16 00:52:01 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class UnixSocketSyslog extends AbstractSyslog {
|
public class UnixSocketSyslog extends AbstractSyslog {
|
||||||
private static final long serialVersionUID = 39878807911936785L;
|
private static final long serialVersionUID = 39878807911936785L;
|
||||||
|
|
||||||
protected static class SockAddr extends Structure {
|
protected static class SockAddr extends Structure {
|
||||||
public final static int SUN_PATH_SIZE = 108;
|
public final static int SUN_PATH_SIZE = 108;
|
||||||
public final static byte[] ZERO_BYTE = new byte[] { 0 };
|
public final static byte[] ZERO_BYTE = new byte[]{0};
|
||||||
|
|
||||||
public short sun_family = 1;
|
public short sun_family = 1;
|
||||||
public byte[] sun_path = new byte[SUN_PATH_SIZE];
|
public byte[] sun_path = new byte[SUN_PATH_SIZE];
|
||||||
|
|
||||||
public void setSunPath(String sunPath) {
|
public void setSunPath(String sunPath) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected interface CLibrary extends Library {
|
protected interface CLibrary extends Library {
|
||||||
public int socket(int domain, int type, int protocol);
|
public int socket(int domain, int type, int protocol);
|
||||||
|
|
||||||
public int connect(int sockfd, SockAddr sockaddr, int addrlen);
|
public int connect(int sockfd, SockAddr sockaddr, int addrlen);
|
||||||
|
|
||||||
public int write(int fd, ByteBuffer buffer, int count);
|
public int write(int fd, ByteBuffer buffer, int count);
|
||||||
|
|
||||||
public int close(int fd);
|
public int close(int fd);
|
||||||
|
|
||||||
public String strerror(int errno);
|
public String strerror(int errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean libraryLoaded = false;
|
protected boolean libraryLoaded = false;
|
||||||
protected CLibrary libraryInstance = null;
|
protected CLibrary libraryInstance = null;
|
||||||
|
|
||||||
protected UnixSocketSyslogConfig unixSocketSyslogConfig = null;
|
protected UnixSocketSyslogConfig unixSocketSyslogConfig = null;
|
||||||
protected int fd = -1;
|
protected int fd = -1;
|
||||||
|
|
||||||
protected synchronized void loadLibrary() {
|
protected synchronized void loadLibrary() {
|
||||||
if (!OSDetectUtility.isUnix()) {
|
if (!OSDetectUtility.isUnix()) {
|
||||||
throw new SyslogRuntimeException("UnixSyslog not supported on non-Unix platforms");
|
throw new SyslogRuntimeException("UnixSyslog not supported on non-Unix platforms");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.libraryLoaded) {
|
if (!this.libraryLoaded) {
|
||||||
this.libraryInstance = (CLibrary) Native.loadLibrary(this.unixSocketSyslogConfig.getLibrary(),CLibrary.class);
|
this.libraryInstance = (CLibrary) Native.loadLibrary(this.unixSocketSyslogConfig.getLibrary(), CLibrary.class);
|
||||||
this.libraryLoaded = true;
|
this.libraryLoaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
try {
|
try {
|
||||||
this.unixSocketSyslogConfig = (UnixSocketSyslogConfig) this.syslogConfig;
|
this.unixSocketSyslogConfig = (UnixSocketSyslogConfig) this.syslogConfig;
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("config must be of type UnixSocketSyslogConfig");
|
throw new SyslogRuntimeException("config must be of type UnixSocketSyslogConfig");
|
||||||
}
|
}
|
||||||
|
|
||||||
loadLibrary();
|
loadLibrary();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void connect() {
|
protected synchronized void connect() {
|
||||||
if (this.fd != -1) {
|
if (this.fd != -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fd = this.libraryInstance.socket(this.unixSocketSyslogConfig.getFamily(),this.unixSocketSyslogConfig.getType(),this.unixSocketSyslogConfig.getProtocol());
|
this.fd = this.libraryInstance.socket(this.unixSocketSyslogConfig.getFamily(), this.unixSocketSyslogConfig.getType(), this.unixSocketSyslogConfig.getProtocol());
|
||||||
|
|
||||||
if (this.fd == -1) {
|
if (this.fd == -1) {
|
||||||
this.fd = -1;
|
this.fd = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SockAddr sockAddr = new SockAddr();
|
SockAddr sockAddr = new SockAddr();
|
||||||
|
|
||||||
sockAddr.sun_family = this.unixSocketSyslogConfig.getFamily();
|
sockAddr.sun_family = this.unixSocketSyslogConfig.getFamily();
|
||||||
sockAddr.setSunPath(this.unixSocketSyslogConfig.getPath());
|
sockAddr.setSunPath(this.unixSocketSyslogConfig.getPath());
|
||||||
|
|
||||||
int c = this.libraryInstance.connect(this.fd, sockAddr, sockAddr.size());
|
int c = this.libraryInstance.connect(this.fd, sockAddr, sockAddr.size());
|
||||||
|
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
this.fd = -1;
|
this.fd = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void write(int level, byte[] message) throws SyslogRuntimeException {
|
protected void write(int level, byte[] message) throws SyslogRuntimeException {
|
||||||
if (this.fd == -1) {
|
if (this.fd == -1) {
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.fd == -1) {
|
if (this.fd == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer byteBuffer = ByteBuffer.wrap(message);
|
ByteBuffer byteBuffer = ByteBuffer.wrap(message);
|
||||||
|
|
||||||
this.libraryInstance.write(this.fd,byteBuffer,message.length);
|
this.libraryInstance.write(this.fd, byteBuffer, message.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws SyslogRuntimeException {
|
public void flush() throws SyslogRuntimeException {
|
||||||
shutdown();
|
shutdown();
|
||||||
|
|
||||||
this.fd = this.libraryInstance.socket(this.unixSocketSyslogConfig.getFamily(),this.unixSocketSyslogConfig.getType(),this.unixSocketSyslogConfig.getProtocol());
|
this.fd = this.libraryInstance.socket(this.unixSocketSyslogConfig.getFamily(), this.unixSocketSyslogConfig.getType(), this.unixSocketSyslogConfig.getProtocol());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() throws SyslogRuntimeException {
|
public void shutdown() throws SyslogRuntimeException {
|
||||||
if (this.fd == -1) {
|
if (this.fd == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.libraryInstance.close(this.fd);
|
this.libraryInstance.close(this.fd);
|
||||||
|
|
||||||
this.fd = -1;
|
this.fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSyslogWriter getWriter() {
|
public AbstractSyslogWriter getWriter() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
public void returnWriter(AbstractSyslogWriter syslogWriter) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,138 +4,138 @@ import org.graylog2.syslog4j.SyslogRuntimeException;
|
|||||||
import org.graylog2.syslog4j.impl.AbstractSyslogConfig;
|
import org.graylog2.syslog4j.impl.AbstractSyslogConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UnixSocketSyslogConfig is an extension of AbstractNetSyslogConfig that provides
|
* UnixSocketSyslogConfig is an extension of AbstractNetSyslogConfig that provides
|
||||||
* configuration support for Unix socket-based syslog clients.
|
* configuration support for Unix socket-based syslog clients.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: UnixSocketSyslogConfig.java,v 1.8 2010/11/12 03:43:12 cvs Exp $
|
* @version $Id: UnixSocketSyslogConfig.java,v 1.8 2010/11/12 03:43:12 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class UnixSocketSyslogConfig extends AbstractSyslogConfig {
|
public class UnixSocketSyslogConfig extends AbstractSyslogConfig {
|
||||||
private static final long serialVersionUID = -3145794243736015707L;
|
private static final long serialVersionUID = -3145794243736015707L;
|
||||||
|
|
||||||
protected int type = SYSLOG_SOCKET_TYPE_DEFAULT;
|
protected int type = SYSLOG_SOCKET_TYPE_DEFAULT;
|
||||||
protected short family = SYSLOG_SOCKET_FAMILY_DEFAULT;
|
protected short family = SYSLOG_SOCKET_FAMILY_DEFAULT;
|
||||||
protected int protocol = SYSLOG_SOCKET_PROTOCOL_DEFAULT;
|
protected int protocol = SYSLOG_SOCKET_PROTOCOL_DEFAULT;
|
||||||
protected String library = SYSLOG_SOCKET_LIBRARY_DEFAULT;
|
protected String library = SYSLOG_SOCKET_LIBRARY_DEFAULT;
|
||||||
protected String path = SYSLOG_SOCKET_PATH_DEFAULT;
|
protected String path = SYSLOG_SOCKET_PATH_DEFAULT;
|
||||||
|
|
||||||
public UnixSocketSyslogConfig() {
|
public UnixSocketSyslogConfig() {
|
||||||
// Unix-based socket does not need localName sent
|
// Unix-based socket does not need localName sent
|
||||||
this.setSendLocalName(false);
|
this.setSendLocalName(false);
|
||||||
this.setIdent("java");
|
this.setIdent("java");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogClass() {
|
public Class getSyslogClass() {
|
||||||
return UnixSocketSyslog.class;
|
return UnixSocketSyslog.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnixSocketSyslogConfig(int facility) {
|
public UnixSocketSyslogConfig(int facility) {
|
||||||
this.facility = facility;
|
this.facility = facility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnixSocketSyslogConfig(int facility, String path) {
|
public UnixSocketSyslogConfig(int facility, String path) {
|
||||||
this.facility = facility;
|
this.facility = facility;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnixSocketSyslogConfig(String path) {
|
public UnixSocketSyslogConfig(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) throws SyslogRuntimeException {
|
public void setHost(String host) throws SyslogRuntimeException {
|
||||||
throw new SyslogRuntimeException("Host not appropriate for class \"" + this.getClass().getName() + "\"");
|
throw new SyslogRuntimeException("Host not appropriate for class \"" + this.getClass().getName() + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(int port) throws SyslogRuntimeException {
|
public void setPort(int port) throws SyslogRuntimeException {
|
||||||
throw new SyslogRuntimeException("Port not appropriate for class \"" + this.getClass().getName() + "\"");
|
throw new SyslogRuntimeException("Port not appropriate for class \"" + this.getClass().getName() + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLibrary() {
|
public String getLibrary() {
|
||||||
return this.library;
|
return this.library;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLibrary(String library) {
|
public void setLibrary(String library) {
|
||||||
this.library = library;
|
this.library = library;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return this.path;
|
return this.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPath(String path) {
|
public void setPath(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(int type) {
|
public void setType(int type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
throw new SyslogRuntimeException("Type cannot be null for class \"" + this.getClass().getName() + "\"");
|
throw new SyslogRuntimeException("Type cannot be null for class \"" + this.getClass().getName() + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("SOCK_STREAM".equalsIgnoreCase(type.trim())) {
|
if ("SOCK_STREAM".equalsIgnoreCase(type.trim())) {
|
||||||
this.type = SOCK_STREAM;
|
this.type = SOCK_STREAM;
|
||||||
|
|
||||||
} else if ("SOCK_DGRAM".equalsIgnoreCase(type.trim())) {
|
} else if ("SOCK_DGRAM".equalsIgnoreCase(type.trim())) {
|
||||||
this.type = SOCK_DGRAM;
|
this.type = SOCK_DGRAM;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new SyslogRuntimeException("Type must be \"SOCK_STREAM\" or \"SOCK_DGRAM\" for class \"" + this.getClass().getName() + "\"");
|
throw new SyslogRuntimeException("Type must be \"SOCK_STREAM\" or \"SOCK_DGRAM\" for class \"" + this.getClass().getName() + "\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getFamily() {
|
public short getFamily() {
|
||||||
return this.family;
|
return this.family;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFamily(short family) {
|
public void setFamily(short family) {
|
||||||
this.family = family;
|
this.family = family;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFamily(String family) {
|
public void setFamily(String family) {
|
||||||
if (family == null) {
|
if (family == null) {
|
||||||
throw new SyslogRuntimeException("Family cannot be null for class \"" + this.getClass().getName() + "\"");
|
throw new SyslogRuntimeException("Family cannot be null for class \"" + this.getClass().getName() + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("AF_UNIX".equalsIgnoreCase(family.trim())) {
|
if ("AF_UNIX".equalsIgnoreCase(family.trim())) {
|
||||||
this.family = AF_UNIX;
|
this.family = AF_UNIX;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new SyslogRuntimeException("Family must be \"AF_UNIX\" for class \"" + this.getClass().getName() + "\"");
|
throw new SyslogRuntimeException("Family must be \"AF_UNIX\" for class \"" + this.getClass().getName() + "\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getProtocol() {
|
public int getProtocol() {
|
||||||
return this.protocol;
|
return this.protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProtocol(int protocol) {
|
public void setProtocol(int protocol) {
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxQueueSize() {
|
public int getMaxQueueSize() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxQueueSize(int maxQueueSize) {
|
public void setMaxQueueSize(int maxQueueSize) {
|
||||||
throw new SyslogRuntimeException("UnixSyslog protocol does not uses a queueing mechanism");
|
throw new SyslogRuntimeException("UnixSyslog protocol does not uses a queueing mechanism");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import org.graylog2.syslog4j.util.SyslogUtility;
|
|||||||
/**
|
/**
|
||||||
* This class provides a Singleton-based interface for Syslog4j
|
* This class provides a Singleton-based interface for Syslog4j
|
||||||
* server implementations.
|
* server implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
@ -24,216 +24,216 @@ import org.graylog2.syslog4j.util.SyslogUtility;
|
|||||||
* @version $Id: SyslogServer.java,v 1.14 2011/01/23 20:49:12 cvs Exp $
|
* @version $Id: SyslogServer.java,v 1.14 2011/01/23 20:49:12 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SyslogServer implements SyslogConstants {
|
public class SyslogServer implements SyslogConstants {
|
||||||
private static final long serialVersionUID = -2260889360828258602L;
|
private static final long serialVersionUID = -2260889360828258602L;
|
||||||
|
|
||||||
private static boolean SUPPRESS_RUNTIME_EXCEPTIONS = false;
|
private static boolean SUPPRESS_RUNTIME_EXCEPTIONS = false;
|
||||||
|
|
||||||
protected static final Map instances = new Hashtable();
|
protected static final Map instances = new Hashtable();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SyslogServer() {
|
private SyslogServer() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the current version identifier for Syslog4j.
|
* @return Returns the current version identifier for Syslog4j.
|
||||||
*/
|
*/
|
||||||
public static final String getVersion() {
|
public static final String getVersion() {
|
||||||
return Syslog4jVersion.VERSION;
|
return Syslog4jVersion.VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param suppress - true to suppress throwing SyslogRuntimeException in many methods of this class, false to throw exceptions (default)
|
* @param suppress - true to suppress throwing SyslogRuntimeException in many methods of this class, false to throw exceptions (default)
|
||||||
*/
|
*/
|
||||||
public static void setSuppressRuntimeExceptions(boolean suppress) {
|
public static void setSuppressRuntimeExceptions(boolean suppress) {
|
||||||
SUPPRESS_RUNTIME_EXCEPTIONS = suppress;
|
SUPPRESS_RUNTIME_EXCEPTIONS = suppress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns whether or not to suppress throwing SyslogRuntimeException in many methods of this class
|
* @return Returns whether or not to suppress throwing SyslogRuntimeException in many methods of this class
|
||||||
*/
|
*/
|
||||||
public static boolean getSuppressRuntimeExceptions() {
|
public static boolean getSuppressRuntimeExceptions() {
|
||||||
return SUPPRESS_RUNTIME_EXCEPTIONS;
|
return SUPPRESS_RUNTIME_EXCEPTIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws SyslogRuntimeException unless it has been suppressed via setSuppressRuntimeException(boolean).
|
* Throws SyslogRuntimeException unless it has been suppressed via setSuppressRuntimeException(boolean).
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
* @throws SyslogRuntimeException
|
* @throws SyslogRuntimeException
|
||||||
*/
|
*/
|
||||||
private static void throwRuntimeException(String message) throws SyslogRuntimeException {
|
private static void throwRuntimeException(String message) throws SyslogRuntimeException {
|
||||||
if (SUPPRESS_RUNTIME_EXCEPTIONS) {
|
if (SUPPRESS_RUNTIME_EXCEPTIONS) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new SyslogRuntimeException(message.toString());
|
throw new SyslogRuntimeException(message.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final SyslogServerIF getInstance(String protocol) throws SyslogRuntimeException {
|
public static final SyslogServerIF getInstance(String protocol) throws SyslogRuntimeException {
|
||||||
String syslogProtocol = protocol.toLowerCase();
|
String syslogProtocol = protocol.toLowerCase();
|
||||||
|
|
||||||
if (instances.containsKey(syslogProtocol)) {
|
if (instances.containsKey(syslogProtocol)) {
|
||||||
return (SyslogServerIF) instances.get(syslogProtocol);
|
return (SyslogServerIF) instances.get(syslogProtocol);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throwRuntimeException("SyslogServer instance \"" + syslogProtocol + "\" not defined; use \"tcp\" or \"udp\" or call SyslogServer.createInstance(protocol,config) first");
|
throwRuntimeException("SyslogServer instance \"" + syslogProtocol + "\" not defined; use \"tcp\" or \"udp\" or call SyslogServer.createInstance(protocol,config) first");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final SyslogServerIF getThreadedInstance(String protocol) throws SyslogRuntimeException {
|
public static final SyslogServerIF getThreadedInstance(String protocol) throws SyslogRuntimeException {
|
||||||
SyslogServerIF server = getInstance(protocol);
|
SyslogServerIF server = getInstance(protocol);
|
||||||
|
|
||||||
if (server.getThread() == null) {
|
if (server.getThread() == null) {
|
||||||
Thread thread = new Thread(server);
|
Thread thread = new Thread(server);
|
||||||
thread.setName("SyslogServer: " + protocol);
|
thread.setName("SyslogServer: " + protocol);
|
||||||
thread.setDaemon(server.getConfig().isUseDaemonThread());
|
thread.setDaemon(server.getConfig().isUseDaemonThread());
|
||||||
if (server.getConfig().getThreadPriority() > -1) {
|
if (server.getConfig().getThreadPriority() > -1) {
|
||||||
thread.setPriority(server.getConfig().getThreadPriority());
|
thread.setPriority(server.getConfig().getThreadPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
server.setThread(thread);
|
server.setThread(thread);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final boolean exists(String protocol) {
|
public static final boolean exists(String protocol) {
|
||||||
if (protocol == null || "".equals(protocol.trim())) {
|
if (protocol == null || "".equals(protocol.trim())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return instances.containsKey(protocol.toLowerCase());
|
return instances.containsKey(protocol.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final SyslogServerIF createInstance(String protocol, SyslogServerConfigIF config) throws SyslogRuntimeException {
|
public static final SyslogServerIF createInstance(String protocol, SyslogServerConfigIF config) throws SyslogRuntimeException {
|
||||||
if (protocol == null || "".equals(protocol.trim())) {
|
if (protocol == null || "".equals(protocol.trim())) {
|
||||||
throwRuntimeException("Instance protocol cannot be null or empty");
|
throwRuntimeException("Instance protocol cannot be null or empty");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
throwRuntimeException("SyslogServerConfig cannot be null");
|
throwRuntimeException("SyslogServerConfig cannot be null");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String syslogProtocol = protocol.toLowerCase();
|
String syslogProtocol = protocol.toLowerCase();
|
||||||
|
|
||||||
SyslogServerIF syslogServer = null;
|
SyslogServerIF syslogServer = null;
|
||||||
|
|
||||||
synchronized(instances) {
|
synchronized (instances) {
|
||||||
if (instances.containsKey(syslogProtocol)) {
|
if (instances.containsKey(syslogProtocol)) {
|
||||||
throwRuntimeException("SyslogServer instance \"" + syslogProtocol + "\" already defined.");
|
throwRuntimeException("SyslogServer instance \"" + syslogProtocol + "\" already defined.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class syslogClass = config.getSyslogServerClass();
|
Class syslogClass = config.getSyslogServerClass();
|
||||||
|
|
||||||
syslogServer = (SyslogServerIF) syslogClass.newInstance();
|
syslogServer = (SyslogServerIF) syslogClass.newInstance();
|
||||||
|
|
||||||
} catch (ClassCastException cse) {
|
} catch (ClassCastException cse) {
|
||||||
throw new SyslogRuntimeException(cse);
|
throw new SyslogRuntimeException(cse);
|
||||||
|
|
||||||
} catch (IllegalAccessException iae) {
|
} catch (IllegalAccessException iae) {
|
||||||
throw new SyslogRuntimeException(iae);
|
throw new SyslogRuntimeException(iae);
|
||||||
|
|
||||||
} catch (InstantiationException ie) {
|
} catch (InstantiationException ie) {
|
||||||
throw new SyslogRuntimeException(ie);
|
throw new SyslogRuntimeException(ie);
|
||||||
}
|
}
|
||||||
|
|
||||||
syslogServer.initialize(syslogProtocol,config);
|
syslogServer.initialize(syslogProtocol, config);
|
||||||
|
|
||||||
instances.put(syslogProtocol,syslogServer);
|
instances.put(syslogProtocol, syslogServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return syslogServer;
|
return syslogServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final SyslogServerIF createThreadedInstance(String protocol, SyslogServerConfigIF config) throws SyslogRuntimeException {
|
public static final SyslogServerIF createThreadedInstance(String protocol, SyslogServerConfigIF config) throws SyslogRuntimeException {
|
||||||
createInstance(protocol,config);
|
createInstance(protocol, config);
|
||||||
|
|
||||||
SyslogServerIF server = getThreadedInstance(protocol);
|
SyslogServerIF server = getThreadedInstance(protocol);
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static final void destroyInstance(String protocol) {
|
public synchronized static final void destroyInstance(String protocol) {
|
||||||
if (protocol == null || "".equals(protocol.trim())) {
|
if (protocol == null || "".equals(protocol.trim())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _protocol = protocol.toLowerCase();
|
String _protocol = protocol.toLowerCase();
|
||||||
|
|
||||||
if (instances.containsKey(_protocol)) {
|
if (instances.containsKey(_protocol)) {
|
||||||
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
||||||
|
|
||||||
SyslogServerIF syslogServer = (SyslogServerIF) instances.get(_protocol);
|
SyslogServerIF syslogServer = (SyslogServerIF) instances.get(_protocol);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
syslogServer.shutdown();
|
syslogServer.shutdown();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
instances.remove(_protocol);
|
instances.remove(_protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throwRuntimeException("Cannot destroy server protocol \"" + protocol + "\" instance; call shutdown instead");
|
throwRuntimeException("Cannot destroy server protocol \"" + protocol + "\" instance; call shutdown instead");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static final void destroyInstance(SyslogServerIF syslogServer) {
|
public synchronized static final void destroyInstance(SyslogServerIF syslogServer) {
|
||||||
if (syslogServer == null) {
|
if (syslogServer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String protocol = syslogServer.getProtocol().toLowerCase();
|
String protocol = syslogServer.getProtocol().toLowerCase();
|
||||||
|
|
||||||
if (instances.containsKey(protocol)) {
|
if (instances.containsKey(protocol)) {
|
||||||
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
syslogServer.shutdown();
|
syslogServer.shutdown();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
instances.remove(protocol);
|
instances.remove(protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throwRuntimeException("Cannot destroy server protocol \"" + protocol + "\" instance; call shutdown instead");
|
throwRuntimeException("Cannot destroy server protocol \"" + protocol + "\" instance; call shutdown instead");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static void initialize() {
|
public synchronized static void initialize() {
|
||||||
createInstance(UDP,new UDPNetSyslogServerConfig());
|
createInstance(UDP, new UDPNetSyslogServerConfig());
|
||||||
createInstance(TCP,new TCPNetSyslogServerConfig());
|
createInstance(TCP, new TCPNetSyslogServerConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static final void shutdown() throws SyslogRuntimeException {
|
public synchronized static final void shutdown() throws SyslogRuntimeException {
|
||||||
Set protocols = instances.keySet();
|
Set protocols = instances.keySet();
|
||||||
|
|
||||||
Iterator i = protocols.iterator();
|
Iterator i = protocols.iterator();
|
||||||
|
|
||||||
while(i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
String protocol = (String) i.next();
|
String protocol = (String) i.next();
|
||||||
|
|
||||||
SyslogServerIF syslogServer = (SyslogServerIF) instances.get(protocol);
|
SyslogServerIF syslogServer = (SyslogServerIF) instances.get(protocol);
|
||||||
|
|
||||||
syslogServer.shutdown();
|
syslogServer.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
instances.clear();
|
instances.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
SyslogServerMain.main(args);
|
SyslogServerMain.main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,44 +7,54 @@ import org.graylog2.syslog4j.SyslogConstants;
|
|||||||
import org.graylog2.syslog4j.SyslogRuntimeException;
|
import org.graylog2.syslog4j.SyslogRuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogServerConfigIF provides a common, extensible configuration interface for all
|
* SyslogServerConfigIF provides a common, extensible configuration interface for all
|
||||||
* implementations of SyslogServerIF.
|
* implementations of SyslogServerIF.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogServerConfigIF.java,v 1.12 2011/01/11 05:11:13 cvs Exp $
|
* @version $Id: SyslogServerConfigIF.java,v 1.12 2011/01/11 05:11:13 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogServerConfigIF extends SyslogConstants, SyslogCharSetIF {
|
public interface SyslogServerConfigIF extends SyslogConstants, SyslogCharSetIF {
|
||||||
public Class getSyslogServerClass();
|
public Class getSyslogServerClass();
|
||||||
|
|
||||||
public String getHost();
|
public String getHost();
|
||||||
public void setHost(String host) throws SyslogRuntimeException;
|
|
||||||
|
|
||||||
public int getPort();
|
public void setHost(String host) throws SyslogRuntimeException;
|
||||||
public void setPort(int port) throws SyslogRuntimeException;
|
|
||||||
|
|
||||||
public boolean isUseDaemonThread();
|
public int getPort();
|
||||||
public void setUseDaemonThread(boolean useDaemonThread);
|
|
||||||
|
|
||||||
public int getThreadPriority();
|
public void setPort(int port) throws SyslogRuntimeException;
|
||||||
public void setThreadPriority(int threadPriority);
|
|
||||||
|
|
||||||
public List getEventHandlers();
|
public boolean isUseDaemonThread();
|
||||||
|
|
||||||
public long getShutdownWait();
|
public void setUseDaemonThread(boolean useDaemonThread);
|
||||||
public void setShutdownWait(long shutdownWait);
|
|
||||||
|
|
||||||
public void addEventHandler(SyslogServerEventHandlerIF eventHandler);
|
public int getThreadPriority();
|
||||||
public void insertEventHandler(int pos, SyslogServerEventHandlerIF eventHandler);
|
|
||||||
public void removeEventHandler(SyslogServerEventHandlerIF eventHandler);
|
|
||||||
public void removeAllEventHandlers();
|
|
||||||
|
|
||||||
public boolean isUseStructuredData();
|
public void setThreadPriority(int threadPriority);
|
||||||
public void setUseStructuredData(boolean useStructuredData);
|
|
||||||
|
|
||||||
public Object getDateTimeFormatter();
|
public List getEventHandlers();
|
||||||
public void setDateTimeFormatter(Object dateTimeFormatter);
|
|
||||||
|
public long getShutdownWait();
|
||||||
|
|
||||||
|
public void setShutdownWait(long shutdownWait);
|
||||||
|
|
||||||
|
public void addEventHandler(SyslogServerEventHandlerIF eventHandler);
|
||||||
|
|
||||||
|
public void insertEventHandler(int pos, SyslogServerEventHandlerIF eventHandler);
|
||||||
|
|
||||||
|
public void removeEventHandler(SyslogServerEventHandlerIF eventHandler);
|
||||||
|
|
||||||
|
public void removeAllEventHandlers();
|
||||||
|
|
||||||
|
public boolean isUseStructuredData();
|
||||||
|
|
||||||
|
public void setUseStructuredData(boolean useStructuredData);
|
||||||
|
|
||||||
|
public Object getDateTimeFormatter();
|
||||||
|
|
||||||
|
public void setDateTimeFormatter(Object dateTimeFormatter);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package org.graylog2.syslog4j.server;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public abstract interface SyslogServerEventHandlerIF extends Serializable {
|
public abstract interface SyslogServerEventHandlerIF extends Serializable {
|
||||||
public void initialize(SyslogServerIF syslogServer);
|
public void initialize(SyslogServerIF syslogServer);
|
||||||
public void destroy(SyslogServerIF syslogServer);
|
|
||||||
|
public void destroy(SyslogServerIF syslogServer);
|
||||||
}
|
}
|
||||||
|
@ -5,37 +5,43 @@ import java.util.Date;
|
|||||||
import org.graylog2.syslog4j.SyslogCharSetIF;
|
import org.graylog2.syslog4j.SyslogCharSetIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogServerEventIF provides an extensible interface for Syslog4j
|
* SyslogServerEventIF provides an extensible interface for Syslog4j
|
||||||
* server events.
|
* server events.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogServerEventIF.java,v 1.4 2010/11/28 01:38:08 cvs Exp $
|
* @version $Id: SyslogServerEventIF.java,v 1.4 2010/11/28 01:38:08 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogServerEventIF extends SyslogCharSetIF {
|
public interface SyslogServerEventIF extends SyslogCharSetIF {
|
||||||
/**
|
/**
|
||||||
* Note: getRaw() may use System.arraycopy(..) each time it is called; best to call it once and store the result.
|
* Note: getRaw() may use System.arraycopy(..) each time it is called; best to call it once and store the result.
|
||||||
*
|
*
|
||||||
* @return Returns the raw data received from the client.
|
* @return Returns the raw data received from the client.
|
||||||
*/
|
*/
|
||||||
public byte[] getRaw();
|
public byte[] getRaw();
|
||||||
|
|
||||||
public int getFacility();
|
public int getFacility();
|
||||||
public void setFacility(int facility);
|
|
||||||
|
|
||||||
public Date getDate();
|
public void setFacility(int facility);
|
||||||
public void setDate(Date date);
|
|
||||||
|
|
||||||
public int getLevel();
|
public Date getDate();
|
||||||
public void setLevel(int level);
|
|
||||||
|
|
||||||
public String getHost();
|
public void setDate(Date date);
|
||||||
public void setHost(String host);
|
|
||||||
public boolean isHostStrippedFromMessage();
|
|
||||||
|
|
||||||
public String getMessage();
|
public int getLevel();
|
||||||
public void setMessage(String message);
|
|
||||||
|
public void setLevel(int level);
|
||||||
|
|
||||||
|
public String getHost();
|
||||||
|
|
||||||
|
public void setHost(String host);
|
||||||
|
|
||||||
|
public boolean isHostStrippedFromMessage();
|
||||||
|
|
||||||
|
public String getMessage();
|
||||||
|
|
||||||
|
public void setMessage(String message);
|
||||||
}
|
}
|
||||||
|
@ -3,25 +3,27 @@ package org.graylog2.syslog4j.server;
|
|||||||
import org.graylog2.syslog4j.SyslogRuntimeException;
|
import org.graylog2.syslog4j.SyslogRuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogServerIF provides a common interface for all Syslog4j server implementations.
|
* SyslogServerIF provides a common interface for all Syslog4j server implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogServerIF.java,v 1.5 2008/11/07 15:15:41 cvs Exp $
|
* @version $Id: SyslogServerIF.java,v 1.5 2008/11/07 15:15:41 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogServerIF extends Runnable {
|
public interface SyslogServerIF extends Runnable {
|
||||||
public void initialize(String protocol, SyslogServerConfigIF config) throws SyslogRuntimeException;
|
public void initialize(String protocol, SyslogServerConfigIF config) throws SyslogRuntimeException;
|
||||||
|
|
||||||
public String getProtocol();
|
public String getProtocol();
|
||||||
public SyslogServerConfigIF getConfig();
|
|
||||||
|
|
||||||
public void run();
|
public SyslogServerConfigIF getConfig();
|
||||||
|
|
||||||
public Thread getThread();
|
public void run();
|
||||||
public void setThread(Thread thread);
|
|
||||||
|
|
||||||
public void shutdown();
|
public Thread getThread();
|
||||||
|
|
||||||
|
public void setThread(Thread thread);
|
||||||
|
|
||||||
|
public void shutdown();
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import org.graylog2.syslog4j.util.SyslogUtility;
|
|||||||
/**
|
/**
|
||||||
* This class provides a command-line interface for Syslog4j
|
* This class provides a command-line interface for Syslog4j
|
||||||
* server implementations.
|
* server implementations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
@ -17,149 +17,191 @@ import org.graylog2.syslog4j.util.SyslogUtility;
|
|||||||
* @version $Id: SyslogServerMain.java,v 1.3 2010/11/28 01:38:08 cvs Exp $
|
* @version $Id: SyslogServerMain.java,v 1.3 2010/11/28 01:38:08 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SyslogServerMain {
|
public class SyslogServerMain {
|
||||||
public static boolean CALL_SYSTEM_EXIT_ON_FAILURE = true;
|
public static boolean CALL_SYSTEM_EXIT_ON_FAILURE = true;
|
||||||
|
|
||||||
public static class Options {
|
public static class Options {
|
||||||
public String protocol = null;
|
public String protocol = null;
|
||||||
public String fileName = null;
|
public String fileName = null;
|
||||||
public boolean append = false;
|
public boolean append = false;
|
||||||
public boolean quiet = false;
|
public boolean quiet = false;
|
||||||
|
|
||||||
public String host = null;
|
public String host = null;
|
||||||
public String port = null;
|
public String port = null;
|
||||||
public String timeout = null;
|
public String timeout = null;
|
||||||
|
|
||||||
public String usage = null;
|
public String usage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void usage(String problem) {
|
public static void usage(String problem) {
|
||||||
if (problem != null) {
|
if (problem != null) {
|
||||||
System.out.println("Error: " + problem);
|
System.out.println("Error: " + problem);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Usage:");
|
System.out.println("Usage:");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("SyslogServer [-h <host>] [-p <port>] [-o <file>] [-a] [-q] <protocol>");
|
System.out.println("SyslogServer [-h <host>] [-p <port>] [-o <file>] [-a] [-q] <protocol>");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("-h <host> host or IP to bind");
|
System.out.println("-h <host> host or IP to bind");
|
||||||
System.out.println("-p <port> port to bind");
|
System.out.println("-p <port> port to bind");
|
||||||
System.out.println("-t <timeout> socket timeout (in milliseconds)");
|
System.out.println("-t <timeout> socket timeout (in milliseconds)");
|
||||||
System.out.println("-o <file> file to write entries (overwrites by default)");
|
System.out.println("-o <file> file to write entries (overwrites by default)");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("-a append to file (instead of overwrite)");
|
System.out.println("-a append to file (instead of overwrite)");
|
||||||
System.out.println("-q do not write anything to standard out");
|
System.out.println("-q do not write anything to standard out");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("protocol Syslog4j protocol implementation (tcp, udp, ...)");
|
System.out.println("protocol Syslog4j protocol implementation (tcp, udp, ...)");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Options parseOptions(String[] args) {
|
public static Options parseOptions(String[] args) {
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i < args.length) {
|
while (i < args.length) {
|
||||||
String arg = args[i++];
|
String arg = args[i++];
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
|
|
||||||
if ("-h".equals(arg)) { if (i == args.length) { options.usage = "Must specify host with -h"; return options; } match = true; options.host = args[i++]; }
|
if ("-h".equals(arg)) {
|
||||||
if ("-p".equals(arg)) { if (i == args.length) { options.usage = "Must specify port with -p"; return options; } match = true; options.port = args[i++]; }
|
if (i == args.length) {
|
||||||
if ("-t".equals(arg)) { if (i == args.length) { options.usage = "Must specify value (in milliseconds)"; return options; } match = true; options.timeout = args[i++]; }
|
options.usage = "Must specify host with -h";
|
||||||
if ("-o".equals(arg)) { if (i == args.length) { options.usage = "Must specify file with -o"; return options; } match = true; options.fileName = args[i++]; }
|
return options;
|
||||||
|
}
|
||||||
|
match = true;
|
||||||
|
options.host = args[i++];
|
||||||
|
}
|
||||||
|
if ("-p".equals(arg)) {
|
||||||
|
if (i == args.length) {
|
||||||
|
options.usage = "Must specify port with -p";
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
match = true;
|
||||||
|
options.port = args[i++];
|
||||||
|
}
|
||||||
|
if ("-t".equals(arg)) {
|
||||||
|
if (i == args.length) {
|
||||||
|
options.usage = "Must specify value (in milliseconds)";
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
match = true;
|
||||||
|
options.timeout = args[i++];
|
||||||
|
}
|
||||||
|
if ("-o".equals(arg)) {
|
||||||
|
if (i == args.length) {
|
||||||
|
options.usage = "Must specify file with -o";
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
match = true;
|
||||||
|
options.fileName = args[i++];
|
||||||
|
}
|
||||||
|
|
||||||
if ("-a".equals(arg)) { match = true; options.append = true; }
|
if ("-a".equals(arg)) {
|
||||||
if ("-q".equals(arg)) { match = true; options.quiet = true; }
|
match = true;
|
||||||
|
options.append = true;
|
||||||
|
}
|
||||||
|
if ("-q".equals(arg)) {
|
||||||
|
match = true;
|
||||||
|
options.quiet = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
if (options.protocol != null) {
|
if (options.protocol != null) {
|
||||||
options.usage = "Only one protocol definition allowed";
|
options.usage = "Only one protocol definition allowed";
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
options.protocol = arg;
|
options.protocol = arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.protocol == null) {
|
if (options.protocol == null) {
|
||||||
options.usage = "Must specify protocol";
|
options.usage = "Must specify protocol";
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.fileName == null && options.append) {
|
if (options.fileName == null && options.append) {
|
||||||
options.usage = "Cannot specify -a without specifying -f <file>";
|
options.usage = "Cannot specify -a without specifying -f <file>";
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Options options = parseOptions(args);
|
Options options = parseOptions(args);
|
||||||
|
|
||||||
if (options.usage != null) {
|
if (options.usage != null) {
|
||||||
usage(options.usage);
|
usage(options.usage);
|
||||||
if (CALL_SYSTEM_EXIT_ON_FAILURE) { System.exit(1); } else { return; }
|
if (CALL_SYSTEM_EXIT_ON_FAILURE) {
|
||||||
}
|
System.exit(1);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println("SyslogServer " + SyslogServer.getVersion());
|
System.out.println("SyslogServer " + SyslogServer.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SyslogServer.exists(options.protocol)) {
|
if (!SyslogServer.exists(options.protocol)) {
|
||||||
usage("Protocol \"" + options.protocol + "\" not supported");
|
usage("Protocol \"" + options.protocol + "\" not supported");
|
||||||
if (CALL_SYSTEM_EXIT_ON_FAILURE) { System.exit(1); } else { return; }
|
if (CALL_SYSTEM_EXIT_ON_FAILURE) {
|
||||||
}
|
System.exit(1);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SyslogServerIF syslogServer = SyslogServer.getInstance(options.protocol);
|
SyslogServerIF syslogServer = SyslogServer.getInstance(options.protocol);
|
||||||
|
|
||||||
SyslogServerConfigIF syslogServerConfig = syslogServer.getConfig();
|
SyslogServerConfigIF syslogServerConfig = syslogServer.getConfig();
|
||||||
|
|
||||||
if (options.host != null) {
|
if (options.host != null) {
|
||||||
syslogServerConfig.setHost(options.host);
|
syslogServerConfig.setHost(options.host);
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println("Listening on host: " + options.host);
|
System.out.println("Listening on host: " + options.host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.port != null) {
|
if (options.port != null) {
|
||||||
syslogServerConfig.setPort(Integer.parseInt(options.port));
|
syslogServerConfig.setPort(Integer.parseInt(options.port));
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println("Listening on port: " + options.port);
|
System.out.println("Listening on port: " + options.port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.timeout != null) {
|
if (options.timeout != null) {
|
||||||
if (syslogServerConfig instanceof TCPNetSyslogServerConfigIF) {
|
if (syslogServerConfig instanceof TCPNetSyslogServerConfigIF) {
|
||||||
((TCPNetSyslogServerConfigIF) syslogServerConfig).setTimeout(Integer.parseInt(options.timeout));
|
((TCPNetSyslogServerConfigIF) syslogServerConfig).setTimeout(Integer.parseInt(options.timeout));
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println("Timeout: " + options.timeout);
|
System.out.println("Timeout: " + options.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Timeout not supported for protocol \"" + options.protocol + "\" (ignored)");
|
System.err.println("Timeout not supported for protocol \"" + options.protocol + "\" (ignored)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.fileName != null) {
|
if (options.fileName != null) {
|
||||||
SyslogServerEventHandlerIF eventHandler = new FileSyslogServerEventHandler(options.fileName,options.append);
|
SyslogServerEventHandlerIF eventHandler = new FileSyslogServerEventHandler(options.fileName, options.append);
|
||||||
syslogServerConfig.addEventHandler(eventHandler);
|
syslogServerConfig.addEventHandler(eventHandler);
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println((options.append ? "Appending" : "Writing") + " to file: " + options.fileName);
|
System.out.println((options.append ? "Appending" : "Writing") + " to file: " + options.fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
SyslogServerEventHandlerIF eventHandler = SystemOutSyslogServerEventHandler.create();
|
SyslogServerEventHandlerIF eventHandler = SystemOutSyslogServerEventHandler.create();
|
||||||
syslogServerConfig.addEventHandler(eventHandler);
|
syslogServerConfig.addEventHandler(eventHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.quiet) {
|
if (!options.quiet) {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
SyslogServer.getThreadedInstance(options.protocol);
|
SyslogServer.getThreadedInstance(options.protocol);
|
||||||
|
|
||||||
while(true) {
|
while (true) {
|
||||||
SyslogUtility.sleep(1000);
|
SyslogUtility.sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,11 @@ package org.graylog2.syslog4j.server;
|
|||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
public interface SyslogServerSessionEventHandlerIF extends SyslogServerEventHandlerIF {
|
public interface SyslogServerSessionEventHandlerIF extends SyslogServerEventHandlerIF {
|
||||||
public Object sessionOpened(SyslogServerIF syslogServer, SocketAddress socketAddress);
|
public Object sessionOpened(SyslogServerIF syslogServer, SocketAddress socketAddress);
|
||||||
public void event(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, SyslogServerEventIF event);
|
|
||||||
public void exception(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, Exception exception);
|
public void event(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, SyslogServerEventIF event);
|
||||||
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout);
|
|
||||||
|
public void exception(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, Exception exception);
|
||||||
|
|
||||||
|
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout);
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,18 @@ import java.net.SocketAddress;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogServerEventHandlerIF provides an extensible interface for Syslog4j
|
* SyslogServerEventHandlerIF provides an extensible interface for Syslog4j
|
||||||
* server event handlers.
|
* server event handlers.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogServerSessionlessEventHandlerIF.java,v 1.1 2010/11/12 02:56:44 cvs Exp $
|
* @version $Id: SyslogServerSessionlessEventHandlerIF.java,v 1.1 2010/11/12 02:56:44 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SyslogServerSessionlessEventHandlerIF extends SyslogServerEventHandlerIF {
|
public interface SyslogServerSessionlessEventHandlerIF extends SyslogServerEventHandlerIF {
|
||||||
public void event(SyslogServerIF syslogServer, SocketAddress socketAddress, SyslogServerEventIF event);
|
public void event(SyslogServerIF syslogServer, SocketAddress socketAddress, SyslogServerEventIF event);
|
||||||
public void exception(SyslogServerIF syslogServer, SocketAddress socketAddress, Exception exception);
|
|
||||||
|
public void exception(SyslogServerIF syslogServer, SocketAddress socketAddress, Exception exception);
|
||||||
}
|
}
|
||||||
|
@ -22,318 +22,318 @@ import org.graylog2.syslog4j.server.impl.event.structured.StructuredSyslogServer
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslogServer provides a base abstract implementation of the SyslogServerIF.
|
* AbstractSyslogServer provides a base abstract implementation of the SyslogServerIF.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogServer.java,v 1.12 2011/01/11 05:11:13 cvs Exp $
|
* @version $Id: AbstractSyslogServer.java,v 1.12 2011/01/11 05:11:13 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslogServer implements SyslogServerIF {
|
public abstract class AbstractSyslogServer implements SyslogServerIF {
|
||||||
public static class Sessions extends HashMap {
|
public static class Sessions extends HashMap {
|
||||||
private static final long serialVersionUID = -4438949276263772580L;
|
private static final long serialVersionUID = -4438949276263772580L;
|
||||||
|
|
||||||
public static final Object syncObject = new Object();
|
public static final Object syncObject = new Object();
|
||||||
|
|
||||||
public void addSocket(Socket socket) {
|
public void addSocket(Socket socket) {
|
||||||
synchronized(syncObject) {
|
synchronized (syncObject) {
|
||||||
put(socket,new HashMap());
|
put(socket, new HashMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator getSockets() {
|
public Iterator getSockets() {
|
||||||
if (size() > 0) {
|
if (size() > 0) {
|
||||||
return keySet().iterator();
|
return keySet().iterator();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSession(Socket socket, SyslogServerEventHandlerIF eventHandler, Object session) {
|
public void addSession(Socket socket, SyslogServerEventHandlerIF eventHandler, Object session) {
|
||||||
synchronized(syncObject) {
|
synchronized (syncObject) {
|
||||||
Map handlerMap = getHandlerMap(socket);
|
Map handlerMap = getHandlerMap(socket);
|
||||||
|
|
||||||
if (handlerMap == null) {
|
if (handlerMap == null) {
|
||||||
handlerMap = new HashMap();
|
handlerMap = new HashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
handlerMap.put(eventHandler,session);
|
handlerMap.put(eventHandler, session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSocket(Socket socket) {
|
public void removeSocket(Socket socket) {
|
||||||
synchronized(syncObject) {
|
synchronized (syncObject) {
|
||||||
Map handlerMap = getHandlerMap(socket);
|
Map handlerMap = getHandlerMap(socket);
|
||||||
|
|
||||||
if (handlerMap != null) {
|
if (handlerMap != null) {
|
||||||
handlerMap.clear();
|
handlerMap.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map getHandlerMap(Socket socket) {
|
protected Map getHandlerMap(Socket socket) {
|
||||||
Map handlerMap = null;
|
Map handlerMap = null;
|
||||||
|
|
||||||
if (containsKey(socket)) {
|
if (containsKey(socket)) {
|
||||||
handlerMap = (Map) get(socket);
|
handlerMap = (Map) get(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
return handlerMap;
|
return handlerMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getSession(Socket socket, SyslogServerEventHandlerIF eventHandler) {
|
public Object getSession(Socket socket, SyslogServerEventHandlerIF eventHandler) {
|
||||||
synchronized(syncObject) {
|
synchronized (syncObject) {
|
||||||
Map handlerMap = getHandlerMap(socket);
|
Map handlerMap = getHandlerMap(socket);
|
||||||
|
|
||||||
Object session = handlerMap.get(eventHandler);
|
Object session = handlerMap.get(eventHandler);
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String syslogProtocol = null;
|
protected String syslogProtocol = null;
|
||||||
protected AbstractSyslogServerConfig syslogServerConfig = null;
|
protected AbstractSyslogServerConfig syslogServerConfig = null;
|
||||||
protected Thread thread = null;
|
protected Thread thread = null;
|
||||||
|
|
||||||
protected boolean shutdown = false;
|
protected boolean shutdown = false;
|
||||||
|
|
||||||
public void initialize(String protocol, SyslogServerConfigIF config) throws SyslogRuntimeException {
|
public void initialize(String protocol, SyslogServerConfigIF config) throws SyslogRuntimeException {
|
||||||
this.syslogProtocol = protocol;
|
this.syslogProtocol = protocol;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.syslogServerConfig = (AbstractSyslogServerConfig) config;
|
this.syslogServerConfig = (AbstractSyslogServerConfig) config;
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException(cce);
|
throw new SyslogRuntimeException(cce);
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProtocol() {
|
public String getProtocol() {
|
||||||
return this.syslogProtocol;
|
return this.syslogProtocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyslogServerConfigIF getConfig() {
|
public SyslogServerConfigIF getConfig() {
|
||||||
return this.syslogServerConfig;
|
return this.syslogServerConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void initialize() throws SyslogRuntimeException;
|
protected abstract void initialize() throws SyslogRuntimeException;
|
||||||
|
|
||||||
public void shutdown() throws SyslogRuntimeException {
|
public void shutdown() throws SyslogRuntimeException {
|
||||||
this.shutdown = true;
|
this.shutdown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Thread getThread() {
|
public Thread getThread() {
|
||||||
return this.thread;
|
return this.thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThread(Thread thread) {
|
public void setThread(Thread thread) {
|
||||||
this.thread = thread;
|
this.thread = thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isStructuredMessage(SyslogCharSetIF syslogCharSet, byte[] receiveData) {
|
protected static boolean isStructuredMessage(SyslogCharSetIF syslogCharSet, byte[] receiveData) {
|
||||||
String receiveDataString = SyslogUtility.newString(syslogCharSet, receiveData);
|
String receiveDataString = SyslogUtility.newString(syslogCharSet, receiveData);
|
||||||
|
|
||||||
boolean isStructuredMessage = isStructuredMessage(syslogCharSet,receiveDataString);
|
boolean isStructuredMessage = isStructuredMessage(syslogCharSet, receiveDataString);
|
||||||
|
|
||||||
return isStructuredMessage;
|
return isStructuredMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isStructuredMessage(SyslogCharSetIF syslogCharSet, String receiveData) {
|
protected static boolean isStructuredMessage(SyslogCharSetIF syslogCharSet, String receiveData) {
|
||||||
int idx = receiveData.indexOf('>');
|
int idx = receiveData.indexOf('>');
|
||||||
|
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
// If there's a numerical VERSION field after the <priority>, return true.
|
// If there's a numerical VERSION field after the <priority>, return true.
|
||||||
if (receiveData.length() > idx + 1 && Character.isDigit(receiveData.charAt(idx + 1))) {
|
if (receiveData.length() > idx + 1 && Character.isDigit(receiveData.charAt(idx + 1))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static SyslogServerEventIF createEvent(SyslogServerConfigIF serverConfig, byte[] lineBytes, int lineBytesLength, InetAddress inetAddr) {
|
protected static SyslogServerEventIF createEvent(SyslogServerConfigIF serverConfig, byte[] lineBytes, int lineBytesLength, InetAddress inetAddr) {
|
||||||
SyslogServerEventIF event = null;
|
SyslogServerEventIF event = null;
|
||||||
|
|
||||||
if (serverConfig.isUseStructuredData() && AbstractSyslogServer.isStructuredMessage(serverConfig,lineBytes)) {
|
if (serverConfig.isUseStructuredData() && AbstractSyslogServer.isStructuredMessage(serverConfig, lineBytes)) {
|
||||||
event = new StructuredSyslogServerEvent(lineBytes,lineBytesLength,inetAddr);
|
event = new StructuredSyslogServerEvent(lineBytes, lineBytesLength, inetAddr);
|
||||||
|
|
||||||
if (serverConfig.getDateTimeFormatter() != null) {
|
if (serverConfig.getDateTimeFormatter() != null) {
|
||||||
((StructuredSyslogServerEvent) event).setDateTimeFormatter(serverConfig.getDateTimeFormatter());
|
((StructuredSyslogServerEvent) event).setDateTimeFormatter(serverConfig.getDateTimeFormatter());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
event = new SyslogServerEvent(lineBytes,lineBytesLength,inetAddr);
|
event = new SyslogServerEvent(lineBytes, lineBytesLength, inetAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static SyslogServerEventIF createEvent(SyslogServerConfigIF serverConfig, String line, InetAddress inetAddr) {
|
protected static SyslogServerEventIF createEvent(SyslogServerConfigIF serverConfig, String line, InetAddress inetAddr) {
|
||||||
SyslogServerEventIF event = null;
|
SyslogServerEventIF event = null;
|
||||||
|
|
||||||
if (serverConfig.isUseStructuredData() && AbstractSyslogServer.isStructuredMessage(serverConfig,line)) {
|
if (serverConfig.isUseStructuredData() && AbstractSyslogServer.isStructuredMessage(serverConfig, line)) {
|
||||||
event = new StructuredSyslogServerEvent(line,inetAddr);
|
event = new StructuredSyslogServerEvent(line, inetAddr);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
event = new SyslogServerEvent(line,inetAddr);
|
event = new SyslogServerEvent(line, inetAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleInitialize(SyslogServerIF syslogServer) {
|
public static void handleInitialize(SyslogServerIF syslogServer) {
|
||||||
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
||||||
|
|
||||||
for(int i=0; i<eventHandlers.size(); i++) {
|
for (int i = 0; i < eventHandlers.size(); i++) {
|
||||||
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
eventHandler.initialize(syslogServer);
|
eventHandler.initialize(syslogServer);
|
||||||
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleDestroy(SyslogServerIF syslogServer) {
|
public static void handleDestroy(SyslogServerIF syslogServer) {
|
||||||
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
||||||
|
|
||||||
for(int i=0; i<eventHandlers.size(); i++) {
|
for (int i = 0; i < eventHandlers.size(); i++) {
|
||||||
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
eventHandler.destroy(syslogServer);
|
eventHandler.destroy(syslogServer);
|
||||||
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleSessionOpen(Sessions sessions, SyslogServerIF syslogServer, Socket socket) {
|
public static void handleSessionOpen(Sessions sessions, SyslogServerIF syslogServer, Socket socket) {
|
||||||
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
||||||
|
|
||||||
for(int i=0; i<eventHandlers.size(); i++) {
|
for (int i = 0; i < eventHandlers.size(); i++) {
|
||||||
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
||||||
|
|
||||||
if (eventHandler instanceof SyslogServerSessionEventHandlerIF) {
|
if (eventHandler instanceof SyslogServerSessionEventHandlerIF) {
|
||||||
try {
|
try {
|
||||||
Object session = ((SyslogServerSessionEventHandlerIF) eventHandler).sessionOpened(syslogServer,socket.getRemoteSocketAddress());
|
Object session = ((SyslogServerSessionEventHandlerIF) eventHandler).sessionOpened(syslogServer, socket.getRemoteSocketAddress());
|
||||||
|
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
sessions.addSession(socket,eventHandler,session);
|
sessions.addSession(socket, eventHandler, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
try {
|
try {
|
||||||
((SyslogServerSessionEventHandlerIF) eventHandler).exception(null,syslogServer,socket.getRemoteSocketAddress(),exception);
|
((SyslogServerSessionEventHandlerIF) eventHandler).exception(null, syslogServer, socket.getRemoteSocketAddress(), exception);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleSessionClosed(Sessions sessions, SyslogServerIF syslogServer, Socket socket, boolean timeout) {
|
public static void handleSessionClosed(Sessions sessions, SyslogServerIF syslogServer, Socket socket, boolean timeout) {
|
||||||
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
||||||
|
|
||||||
for(int i=0; i<eventHandlers.size(); i++) {
|
for (int i = 0; i < eventHandlers.size(); i++) {
|
||||||
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
||||||
|
|
||||||
if (eventHandler instanceof SyslogServerSessionEventHandlerIF) {
|
if (eventHandler instanceof SyslogServerSessionEventHandlerIF) {
|
||||||
Object session = sessions.getSession(socket,eventHandler);
|
Object session = sessions.getSession(socket, eventHandler);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
((SyslogServerSessionEventHandlerIF) eventHandler).sessionClosed(session,syslogServer,socket.getRemoteSocketAddress(),timeout);
|
((SyslogServerSessionEventHandlerIF) eventHandler).sessionClosed(session, syslogServer, socket.getRemoteSocketAddress(), timeout);
|
||||||
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
try {
|
try {
|
||||||
((SyslogServerSessionEventHandlerIF) eventHandler).exception(session,syslogServer,socket.getRemoteSocketAddress(),exception);
|
((SyslogServerSessionEventHandlerIF) eventHandler).exception(session, syslogServer, socket.getRemoteSocketAddress(), exception);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleEvent(Sessions sessions, SyslogServerIF syslogServer, DatagramPacket packet, SyslogServerEventIF event) {
|
public static void handleEvent(Sessions sessions, SyslogServerIF syslogServer, DatagramPacket packet, SyslogServerEventIF event) {
|
||||||
handleEvent(sessions,syslogServer,null,packet.getSocketAddress(),event);
|
handleEvent(sessions, syslogServer, null, packet.getSocketAddress(), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleEvent(Sessions sessions, SyslogServerIF syslogServer, Socket socket, SyslogServerEventIF event) {
|
public static void handleEvent(Sessions sessions, SyslogServerIF syslogServer, Socket socket, SyslogServerEventIF event) {
|
||||||
handleEvent(sessions,syslogServer,socket,socket.getRemoteSocketAddress(),event);
|
handleEvent(sessions, syslogServer, socket, socket.getRemoteSocketAddress(), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void handleEvent(Sessions sessions, SyslogServerIF syslogServer, Socket socket, SocketAddress socketAddress, SyslogServerEventIF event) {
|
protected static void handleEvent(Sessions sessions, SyslogServerIF syslogServer, Socket socket, SocketAddress socketAddress, SyslogServerEventIF event) {
|
||||||
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
||||||
|
|
||||||
for(int i=0; i<eventHandlers.size(); i++) {
|
for (int i = 0; i < eventHandlers.size(); i++) {
|
||||||
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
||||||
|
|
||||||
Object session = (sessions != null && socket != null) ? sessions.getSession(socket,eventHandler) : null;
|
Object session = (sessions != null && socket != null) ? sessions.getSession(socket, eventHandler) : null;
|
||||||
|
|
||||||
if (eventHandler instanceof SyslogServerSessionEventHandlerIF) {
|
if (eventHandler instanceof SyslogServerSessionEventHandlerIF) {
|
||||||
try {
|
try {
|
||||||
((SyslogServerSessionEventHandlerIF) eventHandler).event(session,syslogServer,socketAddress,event);
|
((SyslogServerSessionEventHandlerIF) eventHandler).event(session, syslogServer, socketAddress, event);
|
||||||
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
try {
|
try {
|
||||||
((SyslogServerSessionEventHandlerIF) eventHandler).exception(session,syslogServer,socketAddress,exception);
|
((SyslogServerSessionEventHandlerIF) eventHandler).exception(session, syslogServer, socketAddress, exception);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (eventHandler instanceof SyslogServerSessionlessEventHandlerIF) {
|
} else if (eventHandler instanceof SyslogServerSessionlessEventHandlerIF) {
|
||||||
try {
|
try {
|
||||||
((SyslogServerSessionlessEventHandlerIF) eventHandler).event(syslogServer,socketAddress,event);
|
((SyslogServerSessionlessEventHandlerIF) eventHandler).event(syslogServer, socketAddress, event);
|
||||||
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
try {
|
try {
|
||||||
((SyslogServerSessionlessEventHandlerIF) eventHandler).exception(syslogServer,socketAddress,exception);
|
((SyslogServerSessionlessEventHandlerIF) eventHandler).exception(syslogServer, socketAddress, exception);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleException(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, Exception exception) {
|
public static void handleException(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, Exception exception) {
|
||||||
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
List eventHandlers = syslogServer.getConfig().getEventHandlers();
|
||||||
|
|
||||||
for(int i=0; i<eventHandlers.size(); i++) {
|
for (int i = 0; i < eventHandlers.size(); i++) {
|
||||||
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
SyslogServerEventHandlerIF eventHandler = (SyslogServerEventHandlerIF) eventHandlers.get(i);
|
||||||
|
|
||||||
if (eventHandler instanceof SyslogServerSessionEventHandlerIF) {
|
if (eventHandler instanceof SyslogServerSessionEventHandlerIF) {
|
||||||
try {
|
try {
|
||||||
((SyslogServerSessionEventHandlerIF) eventHandler).exception(session,syslogServer,socketAddress,exception);
|
((SyslogServerSessionEventHandlerIF) eventHandler).exception(session, syslogServer, socketAddress, exception);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (eventHandler instanceof SyslogServerSessionlessEventHandlerIF) {
|
} else if (eventHandler instanceof SyslogServerSessionlessEventHandlerIF) {
|
||||||
try {
|
try {
|
||||||
((SyslogServerSessionlessEventHandlerIF) eventHandler).exception(syslogServer,socketAddress,exception);
|
((SyslogServerSessionlessEventHandlerIF) eventHandler).exception(syslogServer, socketAddress, exception);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,99 +8,99 @@ import org.graylog2.syslog4j.server.SyslogServerConfigIF;
|
|||||||
import org.graylog2.syslog4j.server.SyslogServerEventHandlerIF;
|
import org.graylog2.syslog4j.server.SyslogServerEventHandlerIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractSyslogServerConfig provides a base abstract implementation of the SyslogServerConfigIF
|
* AbstractSyslogServerConfig provides a base abstract implementation of the SyslogServerConfigIF
|
||||||
* configuration interface.
|
* configuration interface.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractSyslogServerConfig.java,v 1.9 2011/01/11 05:11:13 cvs Exp $
|
* @version $Id: AbstractSyslogServerConfig.java,v 1.9 2011/01/11 05:11:13 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSyslogServerConfig implements SyslogServerConfigIF {
|
public abstract class AbstractSyslogServerConfig implements SyslogServerConfigIF {
|
||||||
private static final long serialVersionUID = 870248648801259856L;
|
private static final long serialVersionUID = 870248648801259856L;
|
||||||
|
|
||||||
public abstract Class getSyslogServerClass();
|
public abstract Class getSyslogServerClass();
|
||||||
|
|
||||||
protected String charSet = CHAR_SET_DEFAULT;
|
protected String charSet = CHAR_SET_DEFAULT;
|
||||||
|
|
||||||
protected long shutdownWait = SyslogConstants.SERVER_SHUTDOWN_WAIT_DEFAULT;
|
protected long shutdownWait = SyslogConstants.SERVER_SHUTDOWN_WAIT_DEFAULT;
|
||||||
|
|
||||||
protected List eventHandlers = new ArrayList();
|
protected List eventHandlers = new ArrayList();
|
||||||
|
|
||||||
protected boolean useStructuredData = USE_STRUCTURED_DATA_DEFAULT;
|
protected boolean useStructuredData = USE_STRUCTURED_DATA_DEFAULT;
|
||||||
|
|
||||||
protected Object dateTimeFormatter = null;
|
protected Object dateTimeFormatter = null;
|
||||||
|
|
||||||
protected boolean useDaemonThread = USE_DAEMON_THREAD_DEFAULT;
|
protected boolean useDaemonThread = USE_DAEMON_THREAD_DEFAULT;
|
||||||
protected int threadPriority = THREAD_PRIORITY_DEFAULT;
|
protected int threadPriority = THREAD_PRIORITY_DEFAULT;
|
||||||
|
|
||||||
public String getCharSet() {
|
public String getCharSet() {
|
||||||
return this.charSet;
|
return this.charSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCharSet(String charSet) {
|
public void setCharSet(String charSet) {
|
||||||
this.charSet = charSet;
|
this.charSet = charSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getShutdownWait() {
|
public long getShutdownWait() {
|
||||||
return this.shutdownWait;
|
return this.shutdownWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShutdownWait(long shutdownWait) {
|
public void setShutdownWait(long shutdownWait) {
|
||||||
this.shutdownWait = shutdownWait;
|
this.shutdownWait = shutdownWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getEventHandlers() {
|
public List getEventHandlers() {
|
||||||
return this.eventHandlers;
|
return this.eventHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEventHandler(SyslogServerEventHandlerIF eventHandler) {
|
public void addEventHandler(SyslogServerEventHandlerIF eventHandler) {
|
||||||
this.eventHandlers.add(eventHandler);
|
this.eventHandlers.add(eventHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertEventHandler(int pos, SyslogServerEventHandlerIF eventHandler) {
|
public void insertEventHandler(int pos, SyslogServerEventHandlerIF eventHandler) {
|
||||||
this.eventHandlers.add(pos, eventHandler);
|
this.eventHandlers.add(pos, eventHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeEventHandler(SyslogServerEventHandlerIF eventHandler) {
|
public void removeEventHandler(SyslogServerEventHandlerIF eventHandler) {
|
||||||
this.eventHandlers.remove(eventHandler);
|
this.eventHandlers.remove(eventHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllEventHandlers() {
|
public void removeAllEventHandlers() {
|
||||||
this.eventHandlers.clear();
|
this.eventHandlers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseStructuredData() {
|
public boolean isUseStructuredData() {
|
||||||
return useStructuredData;
|
return useStructuredData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseStructuredData(boolean useStructuredData) {
|
public void setUseStructuredData(boolean useStructuredData) {
|
||||||
this.useStructuredData = useStructuredData;
|
this.useStructuredData = useStructuredData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseDaemonThread() {
|
public boolean isUseDaemonThread() {
|
||||||
return useDaemonThread;
|
return useDaemonThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getDateTimeFormatter() {
|
public Object getDateTimeFormatter() {
|
||||||
return dateTimeFormatter;
|
return dateTimeFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDateTimeFormatter(Object dateTimeFormatter) {
|
public void setDateTimeFormatter(Object dateTimeFormatter) {
|
||||||
this.dateTimeFormatter = dateTimeFormatter;
|
this.dateTimeFormatter = dateTimeFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseDaemonThread(boolean useDaemonThread) {
|
public void setUseDaemonThread(boolean useDaemonThread) {
|
||||||
this.useDaemonThread = useDaemonThread;
|
this.useDaemonThread = useDaemonThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getThreadPriority() {
|
public int getThreadPriority() {
|
||||||
return threadPriority;
|
return threadPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThreadPriority(int threadPriority) {
|
public void setThreadPriority(int threadPriority) {
|
||||||
this.threadPriority = threadPriority;
|
this.threadPriority = threadPriority;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,202 +12,203 @@ import org.graylog2.syslog4j.server.SyslogServerEventIF;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SyslogServerEvent provides an implementation of the SyslogServerEventIF interface.
|
* SyslogServerEvent provides an implementation of the SyslogServerEventIF interface.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SyslogServerEvent.java,v 1.9 2011/01/11 06:21:15 cvs Exp $
|
* @version $Id: SyslogServerEvent.java,v 1.9 2011/01/11 06:21:15 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SyslogServerEvent implements SyslogServerEventIF {
|
public class SyslogServerEvent implements SyslogServerEventIF {
|
||||||
private static final long serialVersionUID = 6136043067089899962L;
|
private static final long serialVersionUID = 6136043067089899962L;
|
||||||
|
|
||||||
public static final String DATE_FORMAT = "MMM dd HH:mm:ss yyyy";
|
public static final String DATE_FORMAT = "MMM dd HH:mm:ss yyyy";
|
||||||
public static final String DATE_FORMAT_S = "MMM d HH:mm:ss yyyy";
|
public static final String DATE_FORMAT_S = "MMM d HH:mm:ss yyyy";
|
||||||
|
|
||||||
protected String charSet = SyslogConstants.CHAR_SET_DEFAULT;
|
protected String charSet = SyslogConstants.CHAR_SET_DEFAULT;
|
||||||
protected String rawString = null;
|
protected String rawString = null;
|
||||||
protected byte[] rawBytes = null;
|
protected byte[] rawBytes = null;
|
||||||
protected int rawLength = -1;
|
protected int rawLength = -1;
|
||||||
protected Date date = null;
|
protected Date date = null;
|
||||||
protected int level = -1;
|
protected int level = -1;
|
||||||
protected int facility = -1;
|
protected int facility = -1;
|
||||||
protected String host = null;
|
protected String host = null;
|
||||||
protected boolean isHostStrippedFromMessage = false;
|
protected boolean isHostStrippedFromMessage = false;
|
||||||
protected String message = null;
|
protected String message = null;
|
||||||
protected InetAddress inetAddress = null;
|
protected InetAddress inetAddress = null;
|
||||||
|
|
||||||
protected SyslogServerEvent() { }
|
protected SyslogServerEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
public SyslogServerEvent(final String message, InetAddress inetAddress) {
|
public SyslogServerEvent(final String message, InetAddress inetAddress) {
|
||||||
initialize(message,inetAddress);
|
initialize(message, inetAddress);
|
||||||
|
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyslogServerEvent(final byte[] message, int length, InetAddress inetAddress) {
|
public SyslogServerEvent(final byte[] message, int length, InetAddress inetAddress) {
|
||||||
initialize(message,length,inetAddress);
|
initialize(message, length, inetAddress);
|
||||||
|
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initialize(final String message, InetAddress inetAddress) {
|
protected void initialize(final String message, InetAddress inetAddress) {
|
||||||
this.rawString = message;
|
this.rawString = message;
|
||||||
this.rawLength = message.length();
|
this.rawLength = message.length();
|
||||||
this.inetAddress = inetAddress;
|
this.inetAddress = inetAddress;
|
||||||
|
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initialize(final byte[] message, int length, InetAddress inetAddress) {
|
protected void initialize(final byte[] message, int length, InetAddress inetAddress) {
|
||||||
this.rawBytes = message;
|
this.rawBytes = message;
|
||||||
this.rawLength = length;
|
this.rawLength = length;
|
||||||
this.inetAddress = inetAddress;
|
this.inetAddress = inetAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseHost() {
|
protected void parseHost() {
|
||||||
int i = this.message.indexOf(' ');
|
int i = this.message.indexOf(' ');
|
||||||
|
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
this.host = this.message.substring(0,i).trim();
|
this.host = this.message.substring(0, i).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseDate() {
|
protected void parseDate() {
|
||||||
int datelength = 16;
|
int datelength = 16;
|
||||||
String dateFormatS = DATE_FORMAT;
|
String dateFormatS = DATE_FORMAT;
|
||||||
|
|
||||||
if (this.message.length() > datelength) {
|
if (this.message.length() > datelength) {
|
||||||
|
|
||||||
// http://jira.graylog2.org/browse/SERVER-287
|
// http://jira.graylog2.org/browse/SERVER-287
|
||||||
if (this.message.charAt(5) == ' ') {
|
if (this.message.charAt(5) == ' ') {
|
||||||
datelength = 15;
|
datelength = 15;
|
||||||
dateFormatS = DATE_FORMAT_S;
|
dateFormatS = DATE_FORMAT_S;
|
||||||
}
|
}
|
||||||
|
|
||||||
String year = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
|
String year = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
|
||||||
|
|
||||||
String originalDate = this.message.substring(0,datelength-1) + " " + year;
|
String originalDate = this.message.substring(0, datelength - 1) + " " + year;
|
||||||
DateFormat dateFormat = new SimpleDateFormat(dateFormatS);
|
DateFormat dateFormat = new SimpleDateFormat(dateFormatS);
|
||||||
try {
|
try {
|
||||||
this.date = dateFormat.parse(originalDate);
|
this.date = dateFormat.parse(originalDate);
|
||||||
|
|
||||||
this.message = this.message.substring(datelength);
|
this.message = this.message.substring(datelength);
|
||||||
|
|
||||||
} catch (ParseException pe) {
|
} catch (ParseException pe) {
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parseHost();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void parsePriority() {
|
||||||
|
if (this.message.charAt(0) == '<') {
|
||||||
|
int i = this.message.indexOf(">");
|
||||||
|
|
||||||
|
if (i <= 4 && i > -1) {
|
||||||
|
String priorityStr = this.message.substring(1, i);
|
||||||
|
|
||||||
|
int priority = 0;
|
||||||
|
try {
|
||||||
|
priority = Integer.parseInt(priorityStr);
|
||||||
|
this.facility = priority >> 3;
|
||||||
|
this.level = priority - (this.facility << 3);
|
||||||
|
|
||||||
|
this.message = this.message.substring(i + 1);
|
||||||
|
|
||||||
|
parseDate();
|
||||||
|
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
parseHost();
|
parseHost();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void parsePriority() {
|
protected void parse() {
|
||||||
if (this.message.charAt(0) == '<') {
|
if (this.message == null) {
|
||||||
int i = this.message.indexOf(">");
|
this.message = SyslogUtility.newString(this, this.rawBytes, this.rawLength);
|
||||||
|
}
|
||||||
|
|
||||||
if (i <= 4 && i > -1) {
|
parsePriority();
|
||||||
String priorityStr = this.message.substring(1,i);
|
}
|
||||||
|
|
||||||
int priority = 0;
|
public int getFacility() {
|
||||||
try {
|
return this.facility;
|
||||||
priority = Integer.parseInt(priorityStr);
|
}
|
||||||
this.facility = priority >> 3;
|
|
||||||
this.level = priority - (this.facility << 3);
|
|
||||||
|
|
||||||
this.message = this.message.substring(i+1);
|
public void setFacility(int facility) {
|
||||||
|
this.facility = facility;
|
||||||
|
}
|
||||||
|
|
||||||
parseDate();
|
public byte[] getRaw() {
|
||||||
|
if (this.rawString != null) {
|
||||||
|
byte[] rawStringBytes = SyslogUtility.getBytes(this, this.rawString);
|
||||||
|
|
||||||
} catch (NumberFormatException nfe) {
|
return rawStringBytes;
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
parseHost();
|
} else if (this.rawBytes.length == this.rawLength) {
|
||||||
}
|
return this.rawBytes;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void parse() {
|
} else {
|
||||||
if (this.message == null) {
|
byte[] newRawBytes = new byte[this.rawLength];
|
||||||
this.message = SyslogUtility.newString(this,this.rawBytes,this.rawLength);
|
System.arraycopy(this.rawBytes, 0, newRawBytes, 0, this.rawLength);
|
||||||
}
|
|
||||||
|
|
||||||
parsePriority();
|
return newRawBytes;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getFacility() {
|
public int getRawLength() {
|
||||||
return this.facility;
|
return this.rawLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacility(int facility) {
|
public Date getDate() {
|
||||||
this.facility = facility;
|
return this.date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getRaw() {
|
public void setDate(Date date) {
|
||||||
if (this.rawString != null) {
|
this.date = date;
|
||||||
byte[] rawStringBytes = SyslogUtility.getBytes(this,this.rawString);
|
}
|
||||||
|
|
||||||
return rawStringBytes;
|
public int getLevel() {
|
||||||
|
return this.level;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (this.rawBytes.length == this.rawLength) {
|
public void setLevel(int level) {
|
||||||
return this.rawBytes;
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
public String getHost() {
|
||||||
byte[] newRawBytes = new byte[this.rawLength];
|
return this.host;
|
||||||
System.arraycopy(this.rawBytes,0,newRawBytes,0,this.rawLength);
|
}
|
||||||
|
|
||||||
return newRawBytes;
|
public void setHost(String host) {
|
||||||
}
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRawLength() {
|
public boolean isHostStrippedFromMessage() {
|
||||||
return this.rawLength;
|
return isHostStrippedFromMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDate() {
|
public String getMessage() {
|
||||||
return this.date;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDate(Date date) {
|
public void setMessage(String message) {
|
||||||
this.date = date;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLevel() {
|
public String getCharSet() {
|
||||||
return this.level;
|
return this.charSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLevel(int level) {
|
public void setCharSet(String charSet) {
|
||||||
this.level = level;
|
this.charSet = charSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
|
||||||
return this.host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHost(String host) {
|
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHostStrippedFromMessage() {
|
|
||||||
return isHostStrippedFromMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessage(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCharSet() {
|
|
||||||
return this.charSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCharSet(String charSet) {
|
|
||||||
this.charSet = charSet;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,23 +7,23 @@ import java.io.OutputStream;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
public class FileSyslogServerEventHandler extends PrintStreamSyslogServerEventHandler {
|
public class FileSyslogServerEventHandler extends PrintStreamSyslogServerEventHandler {
|
||||||
private static final long serialVersionUID = -755824686809731430L;
|
private static final long serialVersionUID = -755824686809731430L;
|
||||||
|
|
||||||
protected static PrintStream createPrintStream(String fileName, boolean append) throws IOException {
|
protected static PrintStream createPrintStream(String fileName, boolean append) throws IOException {
|
||||||
File file = new File(fileName);
|
File file = new File(fileName);
|
||||||
|
|
||||||
OutputStream os = new FileOutputStream(file,append);
|
OutputStream os = new FileOutputStream(file, append);
|
||||||
|
|
||||||
PrintStream printStream = new PrintStream(os);
|
PrintStream printStream = new PrintStream(os);
|
||||||
|
|
||||||
return printStream;
|
return printStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileSyslogServerEventHandler(String fileName) throws IOException {
|
public FileSyslogServerEventHandler(String fileName) throws IOException {
|
||||||
super(createPrintStream(fileName,true));
|
super(createPrintStream(fileName, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileSyslogServerEventHandler(String fileName, boolean append) throws IOException {
|
public FileSyslogServerEventHandler(String fileName, boolean append) throws IOException {
|
||||||
super(createPrintStream(fileName,append));
|
super(createPrintStream(fileName, append));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,50 +10,50 @@ import org.graylog2.syslog4j.server.SyslogServerSessionEventHandlerIF;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SystemOutSyslogServerEventHandler provides a simple example implementation
|
* SystemOutSyslogServerEventHandler provides a simple example implementation
|
||||||
* of the SyslogServerEventHandlerIF which writes the events to System.out.
|
* of the SyslogServerEventHandlerIF which writes the events to System.out.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: PrintStreamSyslogServerEventHandler.java,v 1.7 2010/11/28 22:07:57 cvs Exp $
|
* @version $Id: PrintStreamSyslogServerEventHandler.java,v 1.7 2010/11/28 22:07:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class PrintStreamSyslogServerEventHandler implements SyslogServerSessionEventHandlerIF {
|
public class PrintStreamSyslogServerEventHandler implements SyslogServerSessionEventHandlerIF {
|
||||||
private static final long serialVersionUID = 6036415838696050746L;
|
private static final long serialVersionUID = 6036415838696050746L;
|
||||||
|
|
||||||
protected PrintStream stream = null;
|
protected PrintStream stream = null;
|
||||||
|
|
||||||
public PrintStreamSyslogServerEventHandler(PrintStream stream) {
|
public PrintStreamSyslogServerEventHandler(PrintStream stream) {
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(SyslogServerIF syslogServer) {
|
public void initialize(SyslogServerIF syslogServer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object sessionOpened(SyslogServerIF syslogServer, SocketAddress socketAddress) {
|
public Object sessionOpened(SyslogServerIF syslogServer, SocketAddress socketAddress) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void event(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, SyslogServerEventIF event) {
|
public void event(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, SyslogServerEventIF event) {
|
||||||
String date = (event.getDate() == null ? new Date() : event.getDate()).toString();
|
String date = (event.getDate() == null ? new Date() : event.getDate()).toString();
|
||||||
String facility = SyslogUtility.getFacilityString(event.getFacility());
|
String facility = SyslogUtility.getFacilityString(event.getFacility());
|
||||||
String level = SyslogUtility.getLevelString(event.getLevel());
|
String level = SyslogUtility.getLevelString(event.getLevel());
|
||||||
|
|
||||||
this.stream.println("{" + facility + "} " + date + " " + level + " " + event.getMessage());
|
this.stream.println("{" + facility + "} " + date + " " + level + " " + event.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exception(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, Exception exception) {
|
public void exception(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, Exception exception) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout) {
|
public void sessionClosed(Object session, SyslogServerIF syslogServer, SocketAddress socketAddress, boolean timeout) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(SyslogServerIF syslogServer) {
|
public void destroy(SyslogServerIF syslogServer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,13 @@ package org.graylog2.syslog4j.server.impl.event.printstream;
|
|||||||
import org.graylog2.syslog4j.server.SyslogServerSessionEventHandlerIF;
|
import org.graylog2.syslog4j.server.SyslogServerSessionEventHandlerIF;
|
||||||
|
|
||||||
public class SystemErrSyslogServerEventHandler extends PrintStreamSyslogServerEventHandler {
|
public class SystemErrSyslogServerEventHandler extends PrintStreamSyslogServerEventHandler {
|
||||||
private static final long serialVersionUID = -3496862887351690575L;
|
private static final long serialVersionUID = -3496862887351690575L;
|
||||||
|
|
||||||
public static SyslogServerSessionEventHandlerIF create() {
|
public static SyslogServerSessionEventHandlerIF create() {
|
||||||
return new SystemErrSyslogServerEventHandler();
|
return new SystemErrSyslogServerEventHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SystemErrSyslogServerEventHandler() {
|
public SystemErrSyslogServerEventHandler() {
|
||||||
super(System.err);
|
super(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,13 @@ package org.graylog2.syslog4j.server.impl.event.printstream;
|
|||||||
import org.graylog2.syslog4j.server.SyslogServerSessionEventHandlerIF;
|
import org.graylog2.syslog4j.server.SyslogServerSessionEventHandlerIF;
|
||||||
|
|
||||||
public class SystemOutSyslogServerEventHandler extends PrintStreamSyslogServerEventHandler {
|
public class SystemOutSyslogServerEventHandler extends PrintStreamSyslogServerEventHandler {
|
||||||
private static final long serialVersionUID = 1690551409588182601L;
|
private static final long serialVersionUID = 1690551409588182601L;
|
||||||
|
|
||||||
public static SyslogServerSessionEventHandlerIF create() {
|
public static SyslogServerSessionEventHandlerIF create() {
|
||||||
return new SystemOutSyslogServerEventHandler();
|
return new SystemOutSyslogServerEventHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SystemOutSyslogServerEventHandler() {
|
public SystemOutSyslogServerEventHandler() {
|
||||||
super(System.out);
|
super(System.out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ import org.graylog2.syslog4j.server.impl.event.SyslogServerEvent;
|
|||||||
* SyslogServerStructuredEvent provides an implementation of the
|
* SyslogServerStructuredEvent provides an implementation of the
|
||||||
* SyslogServerEventIF interface that supports receiving of structured syslog
|
* SyslogServerEventIF interface that supports receiving of structured syslog
|
||||||
* messages, as defined in:
|
* messages, as defined in:
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p>
|
||||||
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
* http://tools.ietf.org/html/draft-ietf-syslog-protocol-23#section-6
|
||||||
* </p>
|
* </p>
|
||||||
*
|
* <p/>
|
||||||
* <p>
|
* <p>
|
||||||
* Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy of the
|
* Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy of the
|
||||||
* LGPL license is available in the META-INF folder in all distributions of
|
* LGPL license is available in the META-INF folder in all distributions of
|
||||||
@ -28,124 +28,124 @@ import org.graylog2.syslog4j.server.impl.event.SyslogServerEvent;
|
|||||||
* @version $Id: StructuredSyslogServerEvent.java,v 1.6 2011/01/11 05:11:13 cvs Exp $
|
* @version $Id: StructuredSyslogServerEvent.java,v 1.6 2011/01/11 05:11:13 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class StructuredSyslogServerEvent extends SyslogServerEvent {
|
public class StructuredSyslogServerEvent extends SyslogServerEvent {
|
||||||
private static final long serialVersionUID = 1676499796406044315L;
|
private static final long serialVersionUID = 1676499796406044315L;
|
||||||
|
|
||||||
protected String applicationName = SyslogConstants.STRUCTURED_DATA_APP_NAME_DEFAULT_VALUE;
|
protected String applicationName = SyslogConstants.STRUCTURED_DATA_APP_NAME_DEFAULT_VALUE;
|
||||||
protected String processId = null;
|
protected String processId = null;
|
||||||
protected DateTime dateTime = null;
|
protected DateTime dateTime = null;
|
||||||
protected DateTimeFormatter dateTimeFormatter = null;
|
protected DateTimeFormatter dateTimeFormatter = null;
|
||||||
|
|
||||||
public StructuredSyslogServerEvent(final byte[] message, int length, InetAddress inetAddress) {
|
public StructuredSyslogServerEvent(final byte[] message, int length, InetAddress inetAddress) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
initialize(message,length,inetAddress);
|
initialize(message, length, inetAddress);
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructuredSyslogServerEvent(final String message, InetAddress inetAddress) {
|
public StructuredSyslogServerEvent(final String message, InetAddress inetAddress) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
initialize(message,inetAddress);
|
initialize(message, inetAddress);
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTimeFormatter getDateTimeFormatter() {
|
public DateTimeFormatter getDateTimeFormatter() {
|
||||||
if (dateTimeFormatter == null) {
|
if (dateTimeFormatter == null) {
|
||||||
this.dateTimeFormatter = ISODateTimeFormat.dateTime();
|
this.dateTimeFormatter = ISODateTimeFormat.dateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
return dateTimeFormatter;
|
return dateTimeFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDateTimeFormatter(Object dateTimeFormatter) {
|
public void setDateTimeFormatter(Object dateTimeFormatter) {
|
||||||
this.dateTimeFormatter = (DateTimeFormatter) dateTimeFormatter;
|
this.dateTimeFormatter = (DateTimeFormatter) dateTimeFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseApplicationName() {
|
protected void parseApplicationName() {
|
||||||
int i = this.message.indexOf(' ');
|
int i = this.message.indexOf(' ');
|
||||||
|
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
this.applicationName = this.message.substring(0, i).trim();
|
this.applicationName = this.message.substring(0, i).trim();
|
||||||
this.message = this.message.substring(i + 1);
|
this.message = this.message.substring(i + 1);
|
||||||
parseProcessId();
|
parseProcessId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SyslogConstants.STRUCTURED_DATA_NILVALUE.equals(this.applicationName)) {
|
if (SyslogConstants.STRUCTURED_DATA_NILVALUE.equals(this.applicationName)) {
|
||||||
this.applicationName = null;
|
this.applicationName = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseProcessId() {
|
protected void parseProcessId() {
|
||||||
int i = this.message.indexOf(' ');
|
int i = this.message.indexOf(' ');
|
||||||
|
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
this.processId = this.message.substring(0, i).trim();
|
this.processId = this.message.substring(0, i).trim();
|
||||||
this.message = this.message.substring(i + 1);
|
this.message = this.message.substring(i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SyslogConstants.STRUCTURED_DATA_NILVALUE.equals(this.processId)) {
|
if (SyslogConstants.STRUCTURED_DATA_NILVALUE.equals(this.processId)) {
|
||||||
this.processId = null;
|
this.processId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseDate() {
|
protected void parseDate() {
|
||||||
// skip VERSION field
|
// skip VERSION field
|
||||||
int i = this.message.indexOf(' ');
|
int i = this.message.indexOf(' ');
|
||||||
this.message = this.message.substring(i + 1);
|
this.message = this.message.substring(i + 1);
|
||||||
|
|
||||||
// parse the date
|
// parse the date
|
||||||
i = this.message.indexOf(' ');
|
i = this.message.indexOf(' ');
|
||||||
|
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
String dateString = this.message.substring(0, i).trim();
|
String dateString = this.message.substring(0, i).trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DateTimeFormatter formatter = getDateTimeFormatter();
|
DateTimeFormatter formatter = getDateTimeFormatter();
|
||||||
|
|
||||||
this.dateTime = formatter.parseDateTime(dateString);
|
this.dateTime = formatter.parseDateTime(dateString);
|
||||||
this.date = this.dateTime.toDate();
|
this.date = this.dateTime.toDate();
|
||||||
|
|
||||||
this.message = this.message.substring(dateString.length() + 1);
|
this.message = this.message.substring(dateString.length() + 1);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Not structured date format, try super one
|
// Not structured date format, try super one
|
||||||
super.parseDate();
|
super.parseDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseHost() {
|
protected void parseHost() {
|
||||||
int i = this.message.indexOf(' ');
|
int i = this.message.indexOf(' ');
|
||||||
|
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
this.host = this.message.substring(0,i).trim();
|
this.host = this.message.substring(0, i).trim();
|
||||||
this.message = this.message.substring(i+1);
|
this.message = this.message.substring(i + 1);
|
||||||
|
|
||||||
parseApplicationName();
|
parseApplicationName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getApplicationName() {
|
public String getApplicationName() {
|
||||||
return this.applicationName;
|
return this.applicationName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProcessId() {
|
public String getProcessId() {
|
||||||
return this.processId;
|
return this.processId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime getDateTime() {
|
public DateTime getDateTime() {
|
||||||
return this.dateTime;
|
return this.dateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructuredSyslogMessage getStructuredMessage() {
|
public StructuredSyslogMessage getStructuredMessage() {
|
||||||
try {
|
try {
|
||||||
return StructuredSyslogMessage.fromString(getMessage());
|
return StructuredSyslogMessage.fromString(getMessage());
|
||||||
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// throw new SyslogRuntimeException(
|
// throw new SyslogRuntimeException(
|
||||||
// "Message received is not a valid structured message: "
|
// "Message received is not a valid structured message: "
|
||||||
// + getMessage(), e);
|
// + getMessage(), e);
|
||||||
return new StructuredSyslogMessage(null,null,getMessage());
|
return new StructuredSyslogMessage(null, null, getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,35 +3,35 @@ package org.graylog2.syslog4j.server.impl.net;
|
|||||||
import org.graylog2.syslog4j.server.impl.AbstractSyslogServerConfig;
|
import org.graylog2.syslog4j.server.impl.AbstractSyslogServerConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractNetSyslogServerConfig provides a base abstract implementation of the AbstractSyslogServerConfig
|
* AbstractNetSyslogServerConfig provides a base abstract implementation of the AbstractSyslogServerConfig
|
||||||
* configuration interface.
|
* configuration interface.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: AbstractNetSyslogServerConfig.java,v 1.4 2008/11/07 15:15:41 cvs Exp $
|
* @version $Id: AbstractNetSyslogServerConfig.java,v 1.4 2008/11/07 15:15:41 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractNetSyslogServerConfig extends AbstractSyslogServerConfig {
|
public abstract class AbstractNetSyslogServerConfig extends AbstractSyslogServerConfig {
|
||||||
private static final long serialVersionUID = -3363374941938350263L;
|
private static final long serialVersionUID = -3363374941938350263L;
|
||||||
|
|
||||||
protected String host = null;
|
protected String host = null;
|
||||||
protected int port = SYSLOG_PORT_DEFAULT;
|
protected int port = SYSLOG_PORT_DEFAULT;
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return this.host;
|
return this.host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) {
|
public void setHost(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return this.port;
|
return this.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(int port) {
|
public void setPort(int port) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,233 +20,233 @@ import org.graylog2.syslog4j.server.impl.AbstractSyslogServer;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCPNetSyslogServer provides a simple threaded TCP/IP server implementation.
|
* TCPNetSyslogServer provides a simple threaded TCP/IP server implementation.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: TCPNetSyslogServer.java,v 1.23 2010/11/28 22:07:57 cvs Exp $
|
* @version $Id: TCPNetSyslogServer.java,v 1.23 2010/11/28 22:07:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class TCPNetSyslogServer extends AbstractSyslogServer {
|
public class TCPNetSyslogServer extends AbstractSyslogServer {
|
||||||
public static class TCPNetSyslogSocketHandler implements Runnable {
|
public static class TCPNetSyslogSocketHandler implements Runnable {
|
||||||
protected SyslogServerIF server = null;
|
protected SyslogServerIF server = null;
|
||||||
protected Socket socket = null;
|
protected Socket socket = null;
|
||||||
protected Sessions sessions = null;
|
protected Sessions sessions = null;
|
||||||
|
|
||||||
public TCPNetSyslogSocketHandler(Sessions sessions, SyslogServerIF server, Socket socket) {
|
public TCPNetSyslogSocketHandler(Sessions sessions, SyslogServerIF server, Socket socket) {
|
||||||
this.sessions = sessions;
|
this.sessions = sessions;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
|
|
||||||
synchronized(this.sessions) {
|
synchronized (this.sessions) {
|
||||||
this.sessions.addSocket(socket);
|
this.sessions.addSocket(socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean timeout = false;
|
boolean timeout = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
|
BufferedReader br = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
|
||||||
|
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
|
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
AbstractSyslogServer.handleSessionOpen(this.sessions,this.server,this.socket);
|
AbstractSyslogServer.handleSessionOpen(this.sessions, this.server, this.socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (line != null && line.length() != 0) {
|
while (line != null && line.length() != 0) {
|
||||||
SyslogServerEventIF event = createEvent(this.server.getConfig(),line,this.socket.getInetAddress());
|
SyslogServerEventIF event = createEvent(this.server.getConfig(), line, this.socket.getInetAddress());
|
||||||
|
|
||||||
AbstractSyslogServer.handleEvent(this.sessions,this.server,this.socket,event);
|
AbstractSyslogServer.handleEvent(this.sessions, this.server, this.socket, event);
|
||||||
|
|
||||||
line = br.readLine();
|
line = br.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SocketTimeoutException ste) {
|
} catch (SocketTimeoutException ste) {
|
||||||
timeout = true;
|
timeout = true;
|
||||||
|
|
||||||
} catch (SocketException se) {
|
} catch (SocketException se) {
|
||||||
AbstractSyslogServer.handleException(this.sessions,this.server,this.socket.getRemoteSocketAddress(),se);
|
AbstractSyslogServer.handleException(this.sessions, this.server, this.socket.getRemoteSocketAddress(), se);
|
||||||
|
|
||||||
if ("Socket closed".equals(se.getMessage())) {
|
if ("Socket closed".equals(se.getMessage())) {
|
||||||
//
|
//
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
AbstractSyslogServer.handleException(this.sessions,this.server,this.socket.getRemoteSocketAddress(),ioe);
|
AbstractSyslogServer.handleException(this.sessions, this.server, this.socket.getRemoteSocketAddress(), ioe);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AbstractSyslogServer.handleSessionClosed(this.sessions,this.server,this.socket,timeout);
|
AbstractSyslogServer.handleSessionClosed(this.sessions, this.server, this.socket, timeout);
|
||||||
|
|
||||||
this.sessions.removeSocket(this.socket);
|
this.sessions.removeSocket(this.socket);
|
||||||
|
|
||||||
this.socket.close();
|
this.socket.close();
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
AbstractSyslogServer.handleException(this.sessions,this.server,this.socket.getRemoteSocketAddress(),ioe);
|
AbstractSyslogServer.handleException(this.sessions, this.server, this.socket.getRemoteSocketAddress(), ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ServerSocket serverSocket = null;
|
protected ServerSocket serverSocket = null;
|
||||||
|
|
||||||
protected final Sessions sessions = new Sessions();
|
protected final Sessions sessions = new Sessions();
|
||||||
|
|
||||||
protected TCPNetSyslogServerConfigIF tcpNetSyslogServerConfig = null;
|
protected TCPNetSyslogServerConfigIF tcpNetSyslogServerConfig = null;
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
this.tcpNetSyslogServerConfig = null;
|
this.tcpNetSyslogServerConfig = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.tcpNetSyslogServerConfig = (TCPNetSyslogServerConfigIF) this.syslogServerConfig;
|
this.tcpNetSyslogServerConfig = (TCPNetSyslogServerConfigIF) this.syslogServerConfig;
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
throw new SyslogRuntimeException("config must be of type TCPNetSyslogServerConfig");
|
throw new SyslogRuntimeException("config must be of type TCPNetSyslogServerConfig");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.syslogServerConfig == null) {
|
if (this.syslogServerConfig == null) {
|
||||||
throw new SyslogRuntimeException("config cannot be null");
|
throw new SyslogRuntimeException("config cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tcpNetSyslogServerConfig.getBacklog() < 1) {
|
if (this.tcpNetSyslogServerConfig.getBacklog() < 1) {
|
||||||
this.tcpNetSyslogServerConfig.setBacklog(SyslogConstants.SERVER_SOCKET_BACKLOG_DEFAULT);
|
this.tcpNetSyslogServerConfig.setBacklog(SyslogConstants.SERVER_SOCKET_BACKLOG_DEFAULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sessions getSessions() {
|
public Sessions getSessions() {
|
||||||
return this.sessions;
|
return this.sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void shutdown() {
|
public synchronized void shutdown() {
|
||||||
super.shutdown();
|
super.shutdown();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.serverSocket != null) {
|
if (this.serverSocket != null) {
|
||||||
if (this.syslogServerConfig.getShutdownWait() > 0) {
|
if (this.syslogServerConfig.getShutdownWait() > 0) {
|
||||||
SyslogUtility.sleep(this.syslogServerConfig.getShutdownWait());
|
SyslogUtility.sleep(this.syslogServerConfig.getShutdownWait());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.serverSocket.close();
|
this.serverSocket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized(this.sessions) {
|
synchronized (this.sessions) {
|
||||||
Iterator i = this.sessions.getSockets();
|
Iterator i = this.sessions.getSockets();
|
||||||
|
|
||||||
if (i != null) {
|
if (i != null) {
|
||||||
while(i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
Socket s = (Socket) i.next();
|
Socket s = (Socket) i.next();
|
||||||
|
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.thread != null) {
|
if (this.thread != null) {
|
||||||
this.thread.interrupt();
|
this.thread.interrupt();
|
||||||
this.thread = null;
|
this.thread = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ServerSocketFactory getServerSocketFactory() throws IOException {
|
protected ServerSocketFactory getServerSocketFactory() throws IOException {
|
||||||
ServerSocketFactory serverSocketFactory = ServerSocketFactory.getDefault();
|
ServerSocketFactory serverSocketFactory = ServerSocketFactory.getDefault();
|
||||||
|
|
||||||
return serverSocketFactory;
|
return serverSocketFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ServerSocket createServerSocket() throws IOException {
|
protected ServerSocket createServerSocket() throws IOException {
|
||||||
ServerSocket newServerSocket = null;
|
ServerSocket newServerSocket = null;
|
||||||
|
|
||||||
ServerSocketFactory factory = getServerSocketFactory();
|
ServerSocketFactory factory = getServerSocketFactory();
|
||||||
|
|
||||||
if (this.syslogServerConfig.getHost() != null) {
|
if (this.syslogServerConfig.getHost() != null) {
|
||||||
InetAddress inetAddress = InetAddress.getByName(this.syslogServerConfig.getHost());
|
InetAddress inetAddress = InetAddress.getByName(this.syslogServerConfig.getHost());
|
||||||
|
|
||||||
newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort(),this.tcpNetSyslogServerConfig.getBacklog(),inetAddress);
|
newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort(), this.tcpNetSyslogServerConfig.getBacklog(), inetAddress);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (this.tcpNetSyslogServerConfig.getBacklog() < 1) {
|
if (this.tcpNetSyslogServerConfig.getBacklog() < 1) {
|
||||||
newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort());
|
newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort(),this.tcpNetSyslogServerConfig.getBacklog());
|
newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort(), this.tcpNetSyslogServerConfig.getBacklog());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newServerSocket;
|
return newServerSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
this.serverSocket = createServerSocket();
|
this.serverSocket = createServerSocket();
|
||||||
this.shutdown = false;
|
this.shutdown = false;
|
||||||
|
|
||||||
} catch (SocketException se) {
|
} catch (SocketException se) {
|
||||||
throw new SyslogRuntimeException(se);
|
throw new SyslogRuntimeException(se);
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new SyslogRuntimeException(ioe);
|
throw new SyslogRuntimeException(ioe);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleInitialize(this);
|
handleInitialize(this);
|
||||||
|
|
||||||
while(!this.shutdown) {
|
while (!this.shutdown) {
|
||||||
try {
|
try {
|
||||||
Socket socket = this.serverSocket.accept();
|
Socket socket = this.serverSocket.accept();
|
||||||
|
|
||||||
if (this.tcpNetSyslogServerConfig.getTimeout() > 0) {
|
if (this.tcpNetSyslogServerConfig.getTimeout() > 0) {
|
||||||
socket.setSoTimeout(this.tcpNetSyslogServerConfig.getTimeout());
|
socket.setSoTimeout(this.tcpNetSyslogServerConfig.getTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tcpNetSyslogServerConfig.getMaxActiveSockets() > 0 && this.sessions.size() >= this.tcpNetSyslogServerConfig.getMaxActiveSockets()) {
|
if (this.tcpNetSyslogServerConfig.getMaxActiveSockets() > 0 && this.sessions.size() >= this.tcpNetSyslogServerConfig.getMaxActiveSockets()) {
|
||||||
if (this.tcpNetSyslogServerConfig.getMaxActiveSocketsBehavior() == TCPNetSyslogServerConfigIF.MAX_ACTIVE_SOCKETS_BEHAVIOR_REJECT) {
|
if (this.tcpNetSyslogServerConfig.getMaxActiveSocketsBehavior() == TCPNetSyslogServerConfigIF.MAX_ACTIVE_SOCKETS_BEHAVIOR_REJECT) {
|
||||||
try {
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
socket = null;
|
socket = null;
|
||||||
|
|
||||||
} else if (this.tcpNetSyslogServerConfig.getMaxActiveSocketsBehavior() == TCPNetSyslogServerConfigIF.MAX_ACTIVE_SOCKETS_BEHAVIOR_BLOCK) {
|
} else if (this.tcpNetSyslogServerConfig.getMaxActiveSocketsBehavior() == TCPNetSyslogServerConfigIF.MAX_ACTIVE_SOCKETS_BEHAVIOR_BLOCK) {
|
||||||
while (!this.shutdown && this.sessions.size() >= this.tcpNetSyslogServerConfig.getMaxActiveSockets() && socket.isConnected() && !socket.isClosed()) {
|
while (!this.shutdown && this.sessions.size() >= this.tcpNetSyslogServerConfig.getMaxActiveSockets() && socket.isConnected() && !socket.isClosed()) {
|
||||||
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket != null) {
|
if (socket != null) {
|
||||||
TCPNetSyslogSocketHandler handler = new TCPNetSyslogSocketHandler(this.sessions,this,socket);
|
TCPNetSyslogSocketHandler handler = new TCPNetSyslogSocketHandler(this.sessions, this, socket);
|
||||||
|
|
||||||
Thread t = new Thread(handler);
|
Thread t = new Thread(handler);
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SocketException se) {
|
} catch (SocketException se) {
|
||||||
if ("Socket closed".equals(se.getMessage())) {
|
if ("Socket closed".equals(se.getMessage())) {
|
||||||
this.shutdown = true;
|
this.shutdown = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDestroy(this);
|
handleDestroy(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,84 +3,84 @@ package org.graylog2.syslog4j.server.impl.net.tcp;
|
|||||||
import org.graylog2.syslog4j.server.impl.net.AbstractNetSyslogServerConfig;
|
import org.graylog2.syslog4j.server.impl.net.AbstractNetSyslogServerConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCPNetSyslogServerConfig provides configuration for TCPNetSyslogServer.
|
* TCPNetSyslogServerConfig provides configuration for TCPNetSyslogServer.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: TCPNetSyslogServerConfig.java,v 1.8 2010/11/28 01:38:08 cvs Exp $
|
* @version $Id: TCPNetSyslogServerConfig.java,v 1.8 2010/11/28 01:38:08 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class TCPNetSyslogServerConfig extends AbstractNetSyslogServerConfig implements TCPNetSyslogServerConfigIF {
|
public class TCPNetSyslogServerConfig extends AbstractNetSyslogServerConfig implements TCPNetSyslogServerConfigIF {
|
||||||
private static final long serialVersionUID = -1546696301177599370L;
|
private static final long serialVersionUID = -1546696301177599370L;
|
||||||
|
|
||||||
protected int timeout = 0;
|
protected int timeout = 0;
|
||||||
protected int backlog = 0;
|
protected int backlog = 0;
|
||||||
protected int maxActiveSockets = TCP_MAX_ACTIVE_SOCKETS_DEFAULT;
|
protected int maxActiveSockets = TCP_MAX_ACTIVE_SOCKETS_DEFAULT;
|
||||||
protected byte maxActiveSocketsBehavior = TCP_MAX_ACTIVE_SOCKETS_BEHAVIOR_DEFAULT;
|
protected byte maxActiveSocketsBehavior = TCP_MAX_ACTIVE_SOCKETS_BEHAVIOR_DEFAULT;
|
||||||
|
|
||||||
public TCPNetSyslogServerConfig() {
|
public TCPNetSyslogServerConfig() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogServerConfig(int port) {
|
public TCPNetSyslogServerConfig(int port) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogServerConfig(int port, int backlog) {
|
public TCPNetSyslogServerConfig(int port, int backlog) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.backlog = backlog;
|
this.backlog = backlog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogServerConfig(String host) {
|
public TCPNetSyslogServerConfig(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogServerConfig(String host, int port) {
|
public TCPNetSyslogServerConfig(String host, int port) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TCPNetSyslogServerConfig(String host, int port, int backlog) {
|
public TCPNetSyslogServerConfig(String host, int port, int backlog) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.backlog = backlog;
|
this.backlog = backlog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogServerClass() {
|
public Class getSyslogServerClass() {
|
||||||
return TCPNetSyslogServer.class;
|
return TCPNetSyslogServer.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTimeout() {
|
public int getTimeout() {
|
||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeout(int timeout) {
|
public void setTimeout(int timeout) {
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBacklog() {
|
public int getBacklog() {
|
||||||
return this.backlog;
|
return this.backlog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBacklog(int backlog) {
|
public void setBacklog(int backlog) {
|
||||||
this.backlog = backlog;
|
this.backlog = backlog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxActiveSockets() {
|
public int getMaxActiveSockets() {
|
||||||
return maxActiveSockets;
|
return maxActiveSockets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxActiveSockets(int maxActiveSockets) {
|
public void setMaxActiveSockets(int maxActiveSockets) {
|
||||||
this.maxActiveSockets = maxActiveSockets;
|
this.maxActiveSockets = maxActiveSockets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getMaxActiveSocketsBehavior() {
|
public byte getMaxActiveSocketsBehavior() {
|
||||||
return maxActiveSocketsBehavior;
|
return maxActiveSocketsBehavior;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxActiveSocketsBehavior(byte maxActiveSocketsBehavior) {
|
public void setMaxActiveSocketsBehavior(byte maxActiveSocketsBehavior) {
|
||||||
this.maxActiveSocketsBehavior = maxActiveSocketsBehavior;
|
this.maxActiveSocketsBehavior = maxActiveSocketsBehavior;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,28 +3,32 @@ package org.graylog2.syslog4j.server.impl.net.tcp;
|
|||||||
import org.graylog2.syslog4j.server.SyslogServerConfigIF;
|
import org.graylog2.syslog4j.server.SyslogServerConfigIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCPNetSyslogServerConfigIF provides configuration for TCPNetSyslogServer.
|
* TCPNetSyslogServerConfigIF provides configuration for TCPNetSyslogServer.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: TCPNetSyslogServerConfigIF.java,v 1.3 2010/11/28 01:38:08 cvs Exp $
|
* @version $Id: TCPNetSyslogServerConfigIF.java,v 1.3 2010/11/28 01:38:08 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface TCPNetSyslogServerConfigIF extends SyslogServerConfigIF {
|
public interface TCPNetSyslogServerConfigIF extends SyslogServerConfigIF {
|
||||||
public final static byte MAX_ACTIVE_SOCKETS_BEHAVIOR_BLOCK = 0;
|
public final static byte MAX_ACTIVE_SOCKETS_BEHAVIOR_BLOCK = 0;
|
||||||
public final static byte MAX_ACTIVE_SOCKETS_BEHAVIOR_REJECT = 1;
|
public final static byte MAX_ACTIVE_SOCKETS_BEHAVIOR_REJECT = 1;
|
||||||
|
|
||||||
public int getTimeout();
|
public int getTimeout();
|
||||||
public void setTimeout(int timeout);
|
|
||||||
|
|
||||||
public int getBacklog();
|
public void setTimeout(int timeout);
|
||||||
public void setBacklog(int backlog);
|
|
||||||
|
|
||||||
public int getMaxActiveSockets();
|
public int getBacklog();
|
||||||
public void setMaxActiveSockets(int maxActiveSockets);
|
|
||||||
|
|
||||||
public byte getMaxActiveSocketsBehavior();
|
public void setBacklog(int backlog);
|
||||||
public void setMaxActiveSocketsBehavior(byte maxActiveSocketsBehavior);
|
|
||||||
|
public int getMaxActiveSockets();
|
||||||
|
|
||||||
|
public void setMaxActiveSockets(int maxActiveSockets);
|
||||||
|
|
||||||
|
public byte getMaxActiveSocketsBehavior();
|
||||||
|
|
||||||
|
public void setMaxActiveSocketsBehavior(byte maxActiveSocketsBehavior);
|
||||||
}
|
}
|
||||||
|
@ -9,50 +9,50 @@ import org.graylog2.syslog4j.SyslogRuntimeException;
|
|||||||
import org.graylog2.syslog4j.server.impl.net.tcp.TCPNetSyslogServer;
|
import org.graylog2.syslog4j.server.impl.net.tcp.TCPNetSyslogServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSLTCPNetSyslogServer provides a simple threaded TCP/IP server implementation
|
* SSLTCPNetSyslogServer provides a simple threaded TCP/IP server implementation
|
||||||
* which uses SSL/TLS.
|
* which uses SSL/TLS.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SSLTCPNetSyslogServer.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: SSLTCPNetSyslogServer.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SSLTCPNetSyslogServer extends TCPNetSyslogServer {
|
public class SSLTCPNetSyslogServer extends TCPNetSyslogServer {
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
|
|
||||||
SSLTCPNetSyslogServerConfigIF sslTcpNetSyslogServerConfig = (SSLTCPNetSyslogServerConfigIF) this.tcpNetSyslogServerConfig;
|
SSLTCPNetSyslogServerConfigIF sslTcpNetSyslogServerConfig = (SSLTCPNetSyslogServerConfigIF) this.tcpNetSyslogServerConfig;
|
||||||
|
|
||||||
String keyStore = sslTcpNetSyslogServerConfig.getKeyStore();
|
String keyStore = sslTcpNetSyslogServerConfig.getKeyStore();
|
||||||
|
|
||||||
if (keyStore != null && !"".equals(keyStore.trim())) {
|
if (keyStore != null && !"".equals(keyStore.trim())) {
|
||||||
System.setProperty("javax.net.ssl.keyStore",keyStore);
|
System.setProperty("javax.net.ssl.keyStore", keyStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
String keyStorePassword = sslTcpNetSyslogServerConfig.getKeyStorePassword();
|
String keyStorePassword = sslTcpNetSyslogServerConfig.getKeyStorePassword();
|
||||||
|
|
||||||
if (keyStorePassword != null && !"".equals(keyStorePassword.trim())) {
|
if (keyStorePassword != null && !"".equals(keyStorePassword.trim())) {
|
||||||
System.setProperty("javax.net.ssl.keyStorePassword",keyStorePassword);
|
System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
String trustStore = sslTcpNetSyslogServerConfig.getTrustStore();
|
String trustStore = sslTcpNetSyslogServerConfig.getTrustStore();
|
||||||
|
|
||||||
if (trustStore != null && !"".equals(trustStore.trim())) {
|
if (trustStore != null && !"".equals(trustStore.trim())) {
|
||||||
System.setProperty("javax.net.ssl.trustStore",trustStore);
|
System.setProperty("javax.net.ssl.trustStore", trustStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
String trustStorePassword = sslTcpNetSyslogServerConfig.getTrustStorePassword();
|
String trustStorePassword = sslTcpNetSyslogServerConfig.getTrustStorePassword();
|
||||||
|
|
||||||
if (trustStorePassword != null && !"".equals(trustStorePassword.trim())) {
|
if (trustStorePassword != null && !"".equals(trustStorePassword.trim())) {
|
||||||
System.setProperty("javax.net.ssl.trustStorePassword",trustStorePassword);
|
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ServerSocketFactory getServerSocketFactory() throws IOException {
|
protected ServerSocketFactory getServerSocketFactory() throws IOException {
|
||||||
ServerSocketFactory serverSocketFactory = SSLServerSocketFactory.getDefault();
|
ServerSocketFactory serverSocketFactory = SSLServerSocketFactory.getDefault();
|
||||||
|
|
||||||
return serverSocketFactory;
|
return serverSocketFactory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,57 +3,57 @@ package org.graylog2.syslog4j.server.impl.net.tcp.ssl;
|
|||||||
import org.graylog2.syslog4j.server.impl.net.tcp.TCPNetSyslogServerConfig;
|
import org.graylog2.syslog4j.server.impl.net.tcp.TCPNetSyslogServerConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSLTCPNetSyslogServerConfig provides configuration for SSLTCPNetSyslogServer.
|
* SSLTCPNetSyslogServerConfig provides configuration for SSLTCPNetSyslogServer.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SSLTCPNetSyslogServerConfig.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: SSLTCPNetSyslogServerConfig.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class SSLTCPNetSyslogServerConfig extends TCPNetSyslogServerConfig implements SSLTCPNetSyslogServerConfigIF {
|
public class SSLTCPNetSyslogServerConfig extends TCPNetSyslogServerConfig implements SSLTCPNetSyslogServerConfigIF {
|
||||||
private static final long serialVersionUID = -840102682868286462L;
|
private static final long serialVersionUID = -840102682868286462L;
|
||||||
|
|
||||||
protected String keyStore = null;
|
protected String keyStore = null;
|
||||||
protected String keyStorePassword = null;
|
protected String keyStorePassword = null;
|
||||||
|
|
||||||
protected String trustStore = null;
|
protected String trustStore = null;
|
||||||
protected String trustStorePassword = null;
|
protected String trustStorePassword = null;
|
||||||
|
|
||||||
public String getKeyStore() {
|
public String getKeyStore() {
|
||||||
return this.keyStore;
|
return this.keyStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyStore(String keyStore) {
|
public void setKeyStore(String keyStore) {
|
||||||
this.keyStore = keyStore;
|
this.keyStore = keyStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyStorePassword() {
|
public String getKeyStorePassword() {
|
||||||
return this.keyStorePassword;
|
return this.keyStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyStorePassword(String keyStorePassword) {
|
public void setKeyStorePassword(String keyStorePassword) {
|
||||||
this.keyStorePassword = keyStorePassword;
|
this.keyStorePassword = keyStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTrustStore() {
|
public String getTrustStore() {
|
||||||
return this.trustStore;
|
return this.trustStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTrustStore(String trustStore) {
|
public void setTrustStore(String trustStore) {
|
||||||
this.trustStore = trustStore;
|
this.trustStore = trustStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTrustStorePassword() {
|
public String getTrustStorePassword() {
|
||||||
return this.trustStorePassword;
|
return this.trustStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTrustStorePassword(String trustStorePassword) {
|
public void setTrustStorePassword(String trustStorePassword) {
|
||||||
this.trustStorePassword = trustStorePassword;
|
this.trustStorePassword = trustStorePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogServerClass() {
|
public Class getSyslogServerClass() {
|
||||||
return SSLTCPNetSyslogServer.class;
|
return SSLTCPNetSyslogServer.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,25 +3,29 @@ package org.graylog2.syslog4j.server.impl.net.tcp.ssl;
|
|||||||
import org.graylog2.syslog4j.server.impl.net.tcp.TCPNetSyslogServerConfigIF;
|
import org.graylog2.syslog4j.server.impl.net.tcp.TCPNetSyslogServerConfigIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSLTCPNetSyslogServerConfigIF provides configuration for SSLTCPNetSyslogServer.
|
* SSLTCPNetSyslogServerConfigIF provides configuration for SSLTCPNetSyslogServer.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: SSLTCPNetSyslogServerConfigIF.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
* @version $Id: SSLTCPNetSyslogServerConfigIF.java,v 1.1 2009/03/29 17:38:58 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public interface SSLTCPNetSyslogServerConfigIF extends TCPNetSyslogServerConfigIF {
|
public interface SSLTCPNetSyslogServerConfigIF extends TCPNetSyslogServerConfigIF {
|
||||||
public String getKeyStore();
|
public String getKeyStore();
|
||||||
public void setKeyStore(String keyStore);
|
|
||||||
|
|
||||||
public String getKeyStorePassword();
|
public void setKeyStore(String keyStore);
|
||||||
public void setKeyStorePassword(String keyStorePassword);
|
|
||||||
|
|
||||||
public String getTrustStore();
|
public String getKeyStorePassword();
|
||||||
public void setTrustStore(String trustStore);
|
|
||||||
|
|
||||||
public String getTrustStorePassword();
|
public void setKeyStorePassword(String keyStorePassword);
|
||||||
public void setTrustStorePassword(String trustStorePassword);
|
|
||||||
|
public String getTrustStore();
|
||||||
|
|
||||||
|
public void setTrustStore(String trustStore);
|
||||||
|
|
||||||
|
public String getTrustStorePassword();
|
||||||
|
|
||||||
|
public void setTrustStorePassword(String trustStorePassword);
|
||||||
}
|
}
|
||||||
|
@ -14,89 +14,89 @@ import org.graylog2.syslog4j.server.impl.AbstractSyslogServer;
|
|||||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UDPNetSyslogServer provides a simple non-threaded UDP/IP server implementation.
|
* UDPNetSyslogServer provides a simple non-threaded UDP/IP server implementation.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: UDPNetSyslogServer.java,v 1.16 2010/11/12 03:43:15 cvs Exp $
|
* @version $Id: UDPNetSyslogServer.java,v 1.16 2010/11/12 03:43:15 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class UDPNetSyslogServer extends AbstractSyslogServer {
|
public class UDPNetSyslogServer extends AbstractSyslogServer {
|
||||||
protected DatagramSocket ds = null;
|
protected DatagramSocket ds = null;
|
||||||
|
|
||||||
public void initialize() throws SyslogRuntimeException {
|
public void initialize() throws SyslogRuntimeException {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
super.shutdown();
|
super.shutdown();
|
||||||
|
|
||||||
if (this.syslogServerConfig.getShutdownWait() > 0) {
|
if (this.syslogServerConfig.getShutdownWait() > 0) {
|
||||||
SyslogUtility.sleep(this.syslogServerConfig.getShutdownWait());
|
SyslogUtility.sleep(this.syslogServerConfig.getShutdownWait());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.ds != null && !this.ds.isClosed()) {
|
if (this.ds != null && !this.ds.isClosed()) {
|
||||||
this.ds.close();
|
this.ds.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DatagramSocket createDatagramSocket() throws SocketException, UnknownHostException {
|
protected DatagramSocket createDatagramSocket() throws SocketException, UnknownHostException {
|
||||||
DatagramSocket datagramSocket = null;
|
DatagramSocket datagramSocket = null;
|
||||||
|
|
||||||
if (this.syslogServerConfig.getHost() != null) {
|
if (this.syslogServerConfig.getHost() != null) {
|
||||||
InetAddress inetAddress = InetAddress.getByName(this.syslogServerConfig.getHost());
|
InetAddress inetAddress = InetAddress.getByName(this.syslogServerConfig.getHost());
|
||||||
|
|
||||||
datagramSocket = new DatagramSocket(this.syslogServerConfig.getPort(),inetAddress);
|
datagramSocket = new DatagramSocket(this.syslogServerConfig.getPort(), inetAddress);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
datagramSocket = new DatagramSocket(this.syslogServerConfig.getPort());
|
datagramSocket = new DatagramSocket(this.syslogServerConfig.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
return datagramSocket;
|
return datagramSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
this.ds = createDatagramSocket();
|
this.ds = createDatagramSocket();
|
||||||
this.shutdown = false;
|
this.shutdown = false;
|
||||||
|
|
||||||
} catch (SocketException se) {
|
} catch (SocketException se) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} catch (UnknownHostException uhe) {
|
} catch (UnknownHostException uhe) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] receiveData = new byte[SyslogConstants.SYSLOG_BUFFER_SIZE];
|
byte[] receiveData = new byte[SyslogConstants.SYSLOG_BUFFER_SIZE];
|
||||||
|
|
||||||
handleInitialize(this);
|
handleInitialize(this);
|
||||||
|
|
||||||
while(!this.shutdown) {
|
while (!this.shutdown) {
|
||||||
DatagramPacket dp = null;
|
DatagramPacket dp = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dp = new DatagramPacket(receiveData,receiveData.length);
|
dp = new DatagramPacket(receiveData, receiveData.length);
|
||||||
|
|
||||||
this.ds.receive(dp);
|
this.ds.receive(dp);
|
||||||
|
|
||||||
SyslogServerEventIF event = createEvent(this.getConfig(),receiveData,dp.getLength(),dp.getAddress());
|
SyslogServerEventIF event = createEvent(this.getConfig(), receiveData, dp.getLength(), dp.getAddress());
|
||||||
|
|
||||||
handleEvent(null,this,dp,event);
|
handleEvent(null, this, dp, event);
|
||||||
|
|
||||||
} catch (SocketException se) {
|
} catch (SocketException se) {
|
||||||
int i = se.getMessage() == null ? -1 : se.getMessage().toLowerCase().indexOf("socket closed");
|
int i = se.getMessage() == null ? -1 : se.getMessage().toLowerCase().indexOf("socket closed");
|
||||||
|
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
handleException(null,this,dp.getSocketAddress(),se);
|
handleException(null, this, dp.getSocketAddress(), se);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
handleException(null,this,dp.getSocketAddress(),ioe);
|
handleException(null, this, dp.getSocketAddress(), ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDestroy(this);
|
handleDestroy(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,36 +3,36 @@ package org.graylog2.syslog4j.server.impl.net.udp;
|
|||||||
import org.graylog2.syslog4j.server.impl.net.AbstractNetSyslogServerConfig;
|
import org.graylog2.syslog4j.server.impl.net.AbstractNetSyslogServerConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UDPNetSyslogServerConfig provides configuration for UDPNetSyslogServer.
|
* UDPNetSyslogServerConfig provides configuration for UDPNetSyslogServer.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: UDPNetSyslogServerConfig.java,v 1.6 2010/10/28 05:10:57 cvs Exp $
|
* @version $Id: UDPNetSyslogServerConfig.java,v 1.6 2010/10/28 05:10:57 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public class UDPNetSyslogServerConfig extends AbstractNetSyslogServerConfig {
|
public class UDPNetSyslogServerConfig extends AbstractNetSyslogServerConfig {
|
||||||
private static final long serialVersionUID = -2005919161187055486L;
|
private static final long serialVersionUID = -2005919161187055486L;
|
||||||
|
|
||||||
public UDPNetSyslogServerConfig() {
|
public UDPNetSyslogServerConfig() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public UDPNetSyslogServerConfig(int port) {
|
public UDPNetSyslogServerConfig(int port) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UDPNetSyslogServerConfig(String host) {
|
public UDPNetSyslogServerConfig(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UDPNetSyslogServerConfig(String host, int port) {
|
public UDPNetSyslogServerConfig(String host, int port) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSyslogServerClass() {
|
public Class getSyslogServerClass() {
|
||||||
return UDPNetSyslogServer.class;
|
return UDPNetSyslogServer.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,77 +1,77 @@
|
|||||||
package org.graylog2.syslog4j.util;
|
package org.graylog2.syslog4j.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OSDetectUtility provides operating system detection used to determine
|
* OSDetectUtility provides operating system detection used to determine
|
||||||
* whether Syslog4j is running on a Unix platform.
|
* whether Syslog4j is running on a Unix platform.
|
||||||
*
|
* <p/>
|
||||||
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
* <p>Syslog4j is licensed under the Lesser GNU Public License v2.1. A copy
|
||||||
* of the LGPL license is available in the META-INF folder in all
|
* of the LGPL license is available in the META-INF folder in all
|
||||||
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
* distributions of Syslog4j and in the base directory of the "doc" ZIP.</p>
|
||||||
*
|
*
|
||||||
* @author <syslog4j@productivity.org>
|
* @author <syslog4j@productivity.org>
|
||||||
* @version $Id: OSDetectUtility.java,v 1.4 2008/11/14 04:31:59 cvs Exp $
|
* @version $Id: OSDetectUtility.java,v 1.4 2008/11/14 04:31:59 cvs Exp $
|
||||||
*/
|
*/
|
||||||
public final class OSDetectUtility {
|
public final class OSDetectUtility {
|
||||||
private final static String[] UNIX_PLATFORMS = {
|
private final static String[] UNIX_PLATFORMS = {
|
||||||
"Linux",
|
"Linux",
|
||||||
"Mac OS",
|
"Mac OS",
|
||||||
"Solaris",
|
"Solaris",
|
||||||
"SunOS",
|
"SunOS",
|
||||||
"MPE/iX",
|
"MPE/iX",
|
||||||
"HP-UX",
|
"HP-UX",
|
||||||
"AIX",
|
"AIX",
|
||||||
"OS/390",
|
"OS/390",
|
||||||
"FreeBSD",
|
"FreeBSD",
|
||||||
"Irix",
|
"Irix",
|
||||||
"Digital Unix",
|
"Digital Unix",
|
||||||
"FreeBSD",
|
"FreeBSD",
|
||||||
"OSF1",
|
"OSF1",
|
||||||
"OpenVMS"
|
"OpenVMS"
|
||||||
};
|
};
|
||||||
|
|
||||||
private final static String[] WINDOWS_PLATFORMS = {
|
private final static String[] WINDOWS_PLATFORMS = {
|
||||||
"Windows",
|
"Windows",
|
||||||
"OS/2"
|
"OS/2"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static boolean UNIX = false;
|
private static boolean UNIX = false;
|
||||||
private static boolean WINDOWS = false;
|
private static boolean WINDOWS = false;
|
||||||
|
|
||||||
private OSDetectUtility() {
|
private OSDetectUtility() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isMatch(String[] platforms) {
|
private static boolean isMatch(String[] platforms) {
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
|
|
||||||
String osName = System.getProperty("os.name");
|
String osName = System.getProperty("os.name");
|
||||||
|
|
||||||
if (osName != null && !"".equals(osName.trim())) {
|
if (osName != null && !"".equals(osName.trim())) {
|
||||||
osName = osName.toLowerCase();
|
osName = osName.toLowerCase();
|
||||||
|
|
||||||
for(int i=0; i<platforms.length; i++) {
|
for (int i = 0; i < platforms.length; i++) {
|
||||||
String platform = platforms[i].toLowerCase();
|
String platform = platforms[i].toLowerCase();
|
||||||
|
|
||||||
if (osName.indexOf(platform) > -1) {
|
if (osName.indexOf(platform) > -1) {
|
||||||
match = true;
|
match = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
UNIX = isMatch(UNIX_PLATFORMS);
|
UNIX = isMatch(UNIX_PLATFORMS);
|
||||||
WINDOWS = isMatch(WINDOWS_PLATFORMS);
|
WINDOWS = isMatch(WINDOWS_PLATFORMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUnix() {
|
public static boolean isUnix() {
|
||||||
return UNIX;
|
return UNIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWindows() {
|
public static boolean isWindows() {
|
||||||
return WINDOWS;
|
return WINDOWS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user