|
50 | 50 |
|
51 | 51 | import junit.framework.TestCase;
|
52 | 52 | import org.graylog2.syslog4j.impl.message.structured.StructuredSyslogMessage;
|
| 53 | +import org.graylog2.syslog4j.server.impl.event.SyslogServerEvent; |
53 | 54 | import org.graylog2.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent;
|
54 | 55 | import org.junit.Assert;
|
55 | 56 |
|
56 | 57 | import java.net.InetAddress;
|
| 58 | +import java.util.ArrayList; |
57 | 59 | import java.util.HashMap;
|
| 60 | +import java.util.List; |
58 | 61 | import java.util.Map;
|
59 | 62 |
|
60 | 63 | public class StructuredSyslogMessageTest extends TestCase
|
@@ -279,4 +282,31 @@ public void testMessageWithoutIdOrStructuredData()
|
279 | 282 | assertNull(message.getMessageId());
|
280 | 283 | assertNull(message.getStructuredData());
|
281 | 284 | }
|
| 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 | + } |
282 | 312 | }
|
0 commit comments