Skip to content

Commit a0140a0

Browse files
committed
Add messages from #13 for testing
1 parent b4a32aa commit a0140a0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/test/java/org/graylog2/syslog4j/test/message/structured/StructuredSyslogMessageTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,14 @@
5050

5151
import junit.framework.TestCase;
5252
import org.graylog2.syslog4j.impl.message.structured.StructuredSyslogMessage;
53+
import org.graylog2.syslog4j.server.impl.event.SyslogServerEvent;
5354
import org.graylog2.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent;
5455
import org.junit.Assert;
5556

5657
import java.net.InetAddress;
58+
import java.util.ArrayList;
5759
import java.util.HashMap;
60+
import java.util.List;
5861
import java.util.Map;
5962

6063
public class StructuredSyslogMessageTest extends TestCase
@@ -279,4 +282,31 @@ public void testMessageWithoutIdOrStructuredData()
279282
assertNull(message.getMessageId());
280283
assertNull(message.getStructuredData());
281284
}
285+
286+
287+
public void testMessagesIssue13() throws Exception
288+
{
289+
final List<String> rfc3164Events = new ArrayList<String>();
290+
rfc3164Events.add("<4>Jun 20 11:59:57 xiaoleidouglas kernel: [ 357.266774] [UFW BLOCK] IN=enp9s0 OUT=enp9s0 MAC=01:2e:12:49:87:2b:01:36:1b:38:ad:80:08:50 SRC=289.15.121.109 DST=110.67.112.10 LEN=52 TOS=0x00 PREC=0x00 TTL=47 ID=43803 DF PROTO=TCP SPT=39693 DPT=23");
291+
rfc3164Events.add("<30>Jun 21 00:35:33 xiaoleidouglas dhclient[7445]: bound to 289.15.121.109 -- renewal in 1189 seconds.");
292+
rfc3164Events.add("<29>Jun 21 00:35:33 xiaoleidouglas dbus[775]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'");
293+
rfc3164Events.add("<86>Jun 21 00:35:39 xiaoleidouglas compiz: gkr-pam: unlocked login keyring");
294+
295+
final List<String> rfc5424Events = new ArrayList<String>();
296+
rfc5424Events.add("<4>1 2016-06-21T15:27:15.771223+08:00 xiaoleidouglas kernel - - - [ 3132.531409] [UFW BLOCK] IN=enp9s0 OUT= MAC=01:2e:12:49:87:2b:01:36:1b:38:ad:80:08:50 SRC=219.15.121.109 DST=219.15.121.109 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=0 PROTO=2");
297+
rfc5424Events.add("<30>1 2016-06-21T15:27:27.627057+08:00 xiaoleidouglas dhclient 1641 - - DHCPREQUEST of 219.15.121.109 on wlp3s0 to 219.15.121.109 port 67 (xid=0x327a7f27)");
298+
rfc5424Events.add("<6>1 2016-06-21T15:27:27.672963+08:00 xiaoleidouglas NetworkManager 810 - - <info> [1466494047.6728] address 219.15.121.109");
299+
300+
for (String message : rfc3164Events) {
301+
final SyslogServerEvent event = new SyslogServerEvent(message, InetAddress.getLocalHost());
302+
assertEquals("xiaoleidouglas", event.getHost());
303+
}
304+
305+
for (String message : rfc5424Events) {
306+
final StructuredSyslogServerEvent event = new StructuredSyslogServerEvent(message, InetAddress.getLocalHost());
307+
assertEquals("xiaoleidouglas", event.getHost());
308+
final StructuredSyslogMessage msg = event.getStructuredMessage();
309+
assertNull(msg.getStructuredData());
310+
}
311+
}
282312
}

0 commit comments

Comments
 (0)