Merged development into master

This commit is contained in:
Mark Nellemann 2021-01-05 15:08:07 +01:00
commit 0e73aa8321
8 changed files with 36 additions and 20 deletions

View file

@ -2,11 +2,11 @@
Basic syslog server written in Java. All received messages are written to *stdout*. Basic syslog server written in Java. All received messages are written to *stdout*.
The syslog server is able to listen on UDP and/or TCP and parses syslog messages in either RFC5424 or RFC3164 (BSD) format. The default syslog port (514) requires you to run syslogd as root / administrator. If you do not with to do so, you can choose a port number (with the -p flag) above 1024. The syslog server is able to listen on UDP and/or TCP and parses syslog messages in either RFC5424 or RFC3164 (BSD) format. The default syslog port (514) requires you to run syslogd as root / administrator. If you do not wish to do so, you can choose a port number (with the -p flag) above 1024.
## Usage Instructions ## Usage Instructions
- Install the syslogd package (*.deb* or *.rpm*) from [downloads](https://bitbucket.org/mnellemann/syslogd/downloads/) or compile from source. - Install the syslogd package (*.deb* or *.rpm*) from [downloads](https://bitbucket.org/mnellemann/syslogd/downloads/) or build from source.
- Run *bin/syslogd*, use the *-h* option for help :) - Run *bin/syslogd*, use the *-h* option for help :)
```` ````

View file

@ -12,18 +12,17 @@ repositories {
} }
dependencies { dependencies {
compile 'info.picocli:picocli:4.5.2' annotationProcessor 'info.picocli:picocli-codegen:4.6.0'
annotationProcessor 'info.picocli:picocli-codegen:4.5.2' implementation 'info.picocli:picocli:4.6.0'
implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'org.slf4j:slf4j-api:1.7.+' runtimeOnly 'org.slf4j:slf4j-simple:1.7.30'
runtimeOnly 'ch.qos.logback:logback-classic:1.+'
testImplementation('org.spockframework:spock-core:2.0-M4-groovy-3.0') testImplementation('org.spockframework:spock-core:2.0-M4-groovy-3.0')
testImplementation("org.slf4j:slf4j-simple:1.7.+") testImplementation("org.slf4j:slf4j-simple:1.7.+")
} }
application { application {
mainClassName = 'biz.nellemann.syslogd.SyslogServer' mainClassName = 'biz.nellemann.syslogd.Application'
} }
test { test {
@ -75,3 +74,6 @@ jar {
) )
} }
} }
sourceCompatibility = 1.8
targetCompatibility = 1.8

View file

@ -1,3 +1,3 @@
id = syslogd id = syslogd
group = biz.nellemann.syslogd group = biz.nellemann.syslogd
version = 1.0.5 version = 1.0.7

View file

@ -27,9 +27,9 @@ import java.util.concurrent.Callable;
mixinStandardHelpOptions = true, mixinStandardHelpOptions = true,
description = "Basic syslog server.", description = "Basic syslog server.",
versionProvider = biz.nellemann.syslogd.VersionProvider.class) versionProvider = biz.nellemann.syslogd.VersionProvider.class)
public class SyslogServer implements Callable<Integer>, LogListener { public class Application implements Callable<Integer>, LogListener {
private final static Logger log = LoggerFactory.getLogger(SyslogServer.class); private final static Logger log = LoggerFactory.getLogger(Application.class);
@CommandLine.Option(names = {"-p", "--port"}, description = "Listening port [default: 514].") @CommandLine.Option(names = {"-p", "--port"}, description = "Listening port [default: 514].")
private int port = 514; private int port = 514;
@ -48,7 +48,7 @@ public class SyslogServer implements Callable<Integer>, LogListener {
public static void main(String... args) { public static void main(String... args) {
int exitCode = new CommandLine(new SyslogServer()).execute(args); int exitCode = new CommandLine(new Application()).execute(args);
System.exit(exitCode); System.exit(exitCode);
} }

View file

@ -21,7 +21,6 @@ import java.io.InputStreamReader;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
public class TcpServer { public class TcpServer {
@ -100,9 +99,8 @@ public class TcpServer {
private synchronized void sendEvent(String message) { private synchronized void sendEvent(String message) {
LogEvent event = new LogEvent( this, message ); LogEvent event = new LogEvent( this, message );
Iterator<LogListener> listeners = eventListeners.iterator(); for (LogListener eventListener : eventListeners) {
while( listeners.hasNext() ) { eventListener.onLogEvent(event);
listeners.next().onLogEvent( event );
} }
} }

View file

@ -20,7 +20,6 @@ import java.net.DatagramPacket;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
public class UdpServer extends Thread { public class UdpServer extends Thread {
@ -57,9 +56,8 @@ public class UdpServer extends Thread {
private synchronized void sendEvent(String message) { private synchronized void sendEvent(String message) {
LogEvent event = new LogEvent( this, message); LogEvent event = new LogEvent( this, message);
Iterator<LogListener> listeners = eventListeners.iterator(); for (LogListener eventListener : eventListeners) {
while( listeners.hasNext() ) { eventListener.onLogEvent(event);
listeners.next().onLogEvent( event );
} }
} }

View file

@ -0,0 +1,4 @@
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.showShortLogName=true
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS
org.slf4j.simpleLogger.levelInBrackets=true

View file

@ -32,6 +32,20 @@ class SyslogParserTest extends Specification {
msg.application == "padmin" msg.application == "padmin"
} }
void "test another rfc3164 aix/vios message"() {
setup:
def input = "<13>Dec 18 10:09:22 Message forwarded from p924vio1: root: [errnotify] seq: 24266 - AA8AB241 1218100920 T O OPERATOR OPERATOR NOTIFICATION"
when:
SyslogMessage msg = SyslogParser.parseRfc3164(input)
then:
msg.message == "[errnotify] seq: 24266 - AA8AB241 1218100920 T O OPERATOR OPERATOR NOTIFICATION"
msg.hostname == "p924vio1"
msg.application == "root"
}
void "test rfc3164 normal message"() { void "test rfc3164 normal message"() {
setup: setup: