Skip to content

Commit ce9572d

Browse files
committed
clean up
1 parent 7af0c07 commit ce9572d

File tree

3 files changed

+28
-38
lines changed

3 files changed

+28
-38
lines changed

src/main/java/org/graylog2/syslog4j/server/impl/event/CiscoSyslogServerEvent.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import org.joda.time.DateTimeZone;
44

55
import java.net.InetAddress;
6-
import java.time.ZoneId;
7-
import java.time.ZoneOffset;
86
import java.time.ZonedDateTime;
97
import java.time.format.DateTimeFormatter;
108
import java.time.format.DateTimeParseException;
119
import java.util.Calendar;
1210
import java.util.Date;
1311
import java.util.Locale;
14-
import java.util.Objects;
1512

1613
/**
1714
* CiscoSyslogServerEvent provides an implementation of the

src/test/java/org/graylog2/syslog4j/server/impl/event/CiscoSyslogServerEventTest.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
import java.net.InetAddress;
77
import java.net.InetSocketAddress;
88
import java.time.ZoneId;
9-
import java.time.ZoneOffset;
109
import java.time.ZonedDateTime;
11-
import java.time.format.DateTimeFormatter;
1210
import java.util.Date;
13-
import java.util.Locale;
1411

1512
import static java.time.ZoneOffset.UTC;
1613
import static org.assertj.core.api.Assertions.assertThat;
@@ -24,15 +21,15 @@ public class CiscoSyslogServerEventTest {
2421
private static final ZoneId CET = ZoneId.of("CET");
2522
private static final int YEAR = ZonedDateTime.now().getYear();
2623

27-
private CiscoSyslogServerEvent buildEvent(String message) {
28-
return new CiscoSyslogServerEvent(message, INET_ADDR);
24+
private CiscoSyslogServerEvent buildEvent(String message, DateTimeZone defaultZone) {
25+
return new CiscoSyslogServerEvent(message, INET_ADDR, defaultZone);
2926
}
3027

3128
@Test
3229
public void testCisco1() throws Exception {
3330
final String message = "<166>Mar 06 2016 12:53:10 DEVICENAME : %ASA-6-302013: Built inbound TCP connection 723494125 for FRONTEND:IP/11288 (IP/11288) to BACKEND:IP/27180 (IP/27180)";
3431

35-
final CiscoSyslogServerEvent event = buildEvent(message);
32+
final CiscoSyslogServerEvent event = buildEvent(message, null);
3633

3734
assertThat(toZonedDateTime(event.getDate(), UTC)).isEqualTo(ZonedDateTime.of(2016, 3, 6, 12, 53, 10, 0, UTC));
3835
assertThat(event.getFacility()).isEqualTo(20);
@@ -46,7 +43,7 @@ public void testCisco1() throws Exception {
4643
public void testCisco2() throws Exception {
4744
final String message = "<186>1541800: Feb 27 06:08:59.485: %HARDWARE-2-FAN_ERROR: Fan Failure";
4845

49-
final CiscoSyslogServerEvent event = buildEvent(message);
46+
final CiscoSyslogServerEvent event = buildEvent(message, null);
5047

5148
assertThat(toZonedDateTime(event.getDate(), UTC)).isEqualTo(ZonedDateTime.of(YEAR, 2, 27, 6, 8, 59, 485_000_000, UTC));
5249
assertThat(event.getFacility()).isEqualTo(23);
@@ -60,7 +57,7 @@ public void testCisco2() throws Exception {
6057
public void testCisco3() throws Exception {
6158
final String message = "<187>148094: Feb 27 06:07:29.716: %LINK-3-UPDOWN: Interface GigabitEthernet1/0/15, changed state to down";
6259

63-
final CiscoSyslogServerEvent event = buildEvent(message);
60+
final CiscoSyslogServerEvent event = buildEvent(message, null);
6461

6562
assertThat(toZonedDateTime(event.getDate(), UTC)).isEqualTo(ZonedDateTime.of(YEAR, 2, 27, 6, 7, 29, 716_000_000, UTC));
6663
assertThat(event.getFacility()).isEqualTo(23);
@@ -74,7 +71,7 @@ public void testCisco3() throws Exception {
7471
public void testCisco4() throws Exception {
7572
final String message = "<190>530470: *Sep 28 17:13:35.098: %SEC-6-IPACCESSLOGP: list MGMT_IN denied udp IP(49964) -> IP(161), 11 packets";
7673

77-
final CiscoSyslogServerEvent event = buildEvent(message);
74+
final CiscoSyslogServerEvent event = buildEvent(message, null);
7875

7976
assertThat(toZonedDateTime(event.getDate(), UTC)).isEqualTo(ZonedDateTime.of(YEAR, 9, 28, 17, 13, 35, 98_000_000, UTC));
8077
assertThat(event.getFacility()).isEqualTo(23);
@@ -88,7 +85,7 @@ public void testCisco4() throws Exception {
8885
public void testCisco5() throws Exception {
8986
final String message = "<190>: 2016 Mar 06 09:22:34 CET: %AUTHPRIV-6-SYSTEM_MSG: START: rsync pid=4311 from=::ffff:IP - xinetd[6219]";
9087

91-
final CiscoSyslogServerEvent event = buildEvent(message);
88+
final CiscoSyslogServerEvent event = buildEvent(message, null);
9289

9390
assertThat(toZonedDateTime(event.getDate(), CET)).isEqualTo(ZonedDateTime.of(2016, 3, 6, 9, 22, 34, 0, CET));
9491
assertThat(event.getFacility()).isEqualTo(23);
@@ -102,7 +99,7 @@ public void testCisco5() throws Exception {
10299
public void testCisco6() throws Exception {
103100
final String message = "<134>: 2016 Mar 6 12:53:10 UTC: %POLICY_ENGINE-6-POLICY_LOOKUP_EVENT: policy=POLICYNAME rule=RULENAME action=Permit direction=egress src.net.ip-address=IP src.net.port=38321 dst.net.ip-address=IP dst.net.port=5666 net.protocol=6 net.ethertype=800 net.service=\"protocol 6 port 5666\"";
104101

105-
final CiscoSyslogServerEvent event = buildEvent(message);
102+
final CiscoSyslogServerEvent event = buildEvent(message, null);
106103

107104
assertThat(toZonedDateTime(event.getDate(), UTC)).isEqualTo(ZonedDateTime.of(2016, 3, 6, 12, 53, 10, 0, UTC));
108105
assertThat(event.getFacility()).isEqualTo(16);
@@ -116,7 +113,7 @@ public void testCisco6() throws Exception {
116113
public void testCisco7() throws Exception {
117114
final String message = "<166>%ASA-6-302015: Built inbound UDP connection 23631055 for inside:192.168.19.91/44764 (192.168.19.91/44764) to identity:192.168.249.33/161 (192.168.249.33/161)";
118115

119-
final CiscoSyslogServerEvent event = buildEvent(message);
116+
final CiscoSyslogServerEvent event = buildEvent(message, null);
120117

121118
assertThat(event.getDate())
122119
.isInThePast()
@@ -131,15 +128,15 @@ public void testCisco7() throws Exception {
131128
@Test
132129
public void testDefaultTimeZoneUtcIfNotConfigured() throws Exception {
133130
final String message = "<190>: 2016 Mar 06 09:22:34: %AUTHPRIV-6-SYSTEM_MSG: START: rsync pid=4311 from=::ffff:IP - xinetd[6219]";
134-
final CiscoSyslogServerEvent event = buildEvent(message);
131+
final CiscoSyslogServerEvent event = buildEvent(message, null);
135132

136133
assertThat(toZonedDateTime(event.getDate(), UTC)).isEqualTo(ZonedDateTime.of(2016, 3, 6, 9, 22, 34, 0, UTC));
137134
}
138135

139136
@Test
140137
public void testDefaultTimeZoneConfigured() throws Exception {
141138
final String message = "<190>: 2016 Mar 06 09:22:34: %AUTHPRIV-6-SYSTEM_MSG: START: rsync pid=4311 from=::ffff:IP - xinetd[6219]";
142-
final CiscoSyslogServerEvent event = new CiscoSyslogServerEvent(message, INET_ADDR, MST);
139+
final CiscoSyslogServerEvent event = buildEvent(message, MST);
143140

144141
assertThat(toZonedDateTime(event.getDate(), MST_ZONE_ID)).isEqualTo(ZonedDateTime.of(2016, 3, 6, 9, 22, 34, 0, MST_ZONE_ID));
145142
}
@@ -148,12 +145,12 @@ public void testDefaultTimeZoneConfigured() throws Exception {
148145
public void testDefaultTimeZoneIgnoredSinceZoneDetected() throws Exception {
149146
final String message = "<190>: 2016 Mar 06 09:22:34 CET: %AUTHPRIV-6-SYSTEM_MSG: START: rsync pid=4311 from=::ffff:IP - xinetd[6219]";
150147
DateTimeZone mst = DateTimeZone.forID("MST");
151-
final CiscoSyslogServerEvent event = new CiscoSyslogServerEvent(message, INET_ADDR, mst);
148+
final CiscoSyslogServerEvent event = buildEvent(message, mst);
152149

153150
assertThat(toZonedDateTime(event.getDate(), CET)).isEqualTo(ZonedDateTime.of(2016, 3, 6, 9, 22, 34, 0, CET));
154151
}
155152

156153
private ZonedDateTime toZonedDateTime(Date date, ZoneId zoneId) {
157154
return ZonedDateTime.ofInstant(date.toInstant(), zoneId);
158155
}
159-
}
156+
}

src/test/java/org/graylog2/syslog4j/server/impl/event/structured/StructuredSyslogServerEventTest.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,26 @@
66

77
import java.net.InetAddress;
88
import java.net.InetSocketAddress;
9-
import java.time.ZoneId;
10-
import java.time.ZoneOffset;
11-
import java.time.ZonedDateTime;
129
import java.util.HashMap;
1310
import java.util.Map;
1411

1512
import static org.junit.Assert.assertEquals;
1613

1714

1815
public class StructuredSyslogServerEventTest {
19-
public static final DateTimeZone MST = DateTimeZone.forID("MST");
16+
private static final DateTimeZone MST = DateTimeZone.forID("MST");
2017
private final InetAddress INET_ADDR = new InetSocketAddress(514).getAddress();
2118

22-
private StructuredSyslogServerEvent buildEvent(String message) {
23-
return new StructuredSyslogServerEvent(message, INET_ADDR);
19+
private StructuredSyslogServerEvent buildEvent(String message, DateTimeZone defaultZone) {
20+
return new StructuredSyslogServerEvent(message, INET_ADDR, defaultZone);
2421
}
2522

2623
@Test
2724
public void testStructured1() throws Exception {
2825
// Message from: https://tools.ietf.org/html/rfc5424#section-6.5
2926
final String message = "<165>1 2012-12-25T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"] BOMAn application event log entry";
3027

31-
final StructuredSyslogServerEvent event = buildEvent(message);
28+
final StructuredSyslogServerEvent event = buildEvent(message, null);
3229

3330
Map<String, Map<String, String>> structuredData = new HashMap<String, Map<String, String>>() {
3431
{
@@ -60,7 +57,7 @@ public void testStructured2() throws Exception {
6057
// Message from: https://github.com/Graylog2/graylog2-server/issues/845
6158
final String message = "<190>1 2015-01-06T20:56:33.287Z app-1 app - - [mdc@18060 ip=\"::ffff:132.213.51.30\" logger=\"{c.corp.Handler}\" session=\"4ot7\" user=\"[email protected]\" user-agent=\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/7.1.2 Safari/537.85.11\"] User page 13 requested";
6259

63-
final StructuredSyslogServerEvent event = buildEvent(message);
60+
final StructuredSyslogServerEvent event = buildEvent(message, null);
6461

6562
Map<String, Map<String, String>> structuredData = new HashMap<String, Map<String, String>>() {
6663
{
@@ -94,7 +91,7 @@ public void testStructured3() throws Exception {
9491
// Message from: https://github.com/Graylog2/graylog2-server/issues/845
9592
final String message = "<128>1 2015-01-11T16:35:21.335797+01:00 s000000.example.com - - - - tralala";
9693

97-
final StructuredSyslogServerEvent event = buildEvent(message);
94+
final StructuredSyslogServerEvent event = buildEvent(message, null);
9895

9996
assertEquals(null, event.getApplicationName());
10097
assertEquals(new DateTime("2015-01-11T15:35:21.335797Z"), event.getDateTime());
@@ -114,7 +111,7 @@ public void testStructuredWithOnlyStructuredData() throws Exception {
114111
// Message from: https://tools.ietf.org/html/rfc5424#section-6.5
115112
final String message = "<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"][examplePriority@32473 class=\"high\"]";
116113

117-
final StructuredSyslogServerEvent event = buildEvent(message);
114+
final StructuredSyslogServerEvent event = buildEvent(message, null);
118115

119116
Map<String, Map<String, String>> structuredData = new HashMap<String, Map<String, String>>() {
120117
{
@@ -153,7 +150,7 @@ public void testStructuredWithoutStructuredData() throws Exception {
153150
// Message from: https://tools.ietf.org/html/rfc5424#section-6.5
154151
final String message = "<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - %% It's time to make the do-nuts.";
155152

156-
final StructuredSyslogServerEvent event = buildEvent(message);
153+
final StructuredSyslogServerEvent event = buildEvent(message, null);
157154

158155
assertEquals("myproc", event.getApplicationName());
159156
assertEquals(new DateTime("2003-08-24T05:14:15.000003-07:00"), event.getDateTime());
@@ -174,7 +171,7 @@ public void testStructuredSyslogNg1() throws Exception {
174171
// Manually added ".000" to timestamp!
175172
final String message = "<45>1 2014-10-21T10:21:09.000+00:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'";
176173

177-
final StructuredSyslogServerEvent event = buildEvent(message);
174+
final StructuredSyslogServerEvent event = buildEvent(message, null);
178175

179176
Map<String, Map<String, String>> structuredData = new HashMap<String, Map<String, String>>() {
180177
{
@@ -204,7 +201,7 @@ public void testStructuredSyslogNgNoMillisecTimestamp() throws Exception {
204201
// Message from: syslog-ng-core 3.5.3-1 package in Ubuntu 14.04 (default config)
205202
final String message = "<45>1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'";
206203

207-
final StructuredSyslogServerEvent event = buildEvent(message);
204+
final StructuredSyslogServerEvent event = buildEvent(message, null);
208205

209206
Map<String, Map<String, String>> structuredData = new HashMap<String, Map<String, String>>() {
210207
{
@@ -235,17 +232,16 @@ public void testDefaultTimeZoneNotSet() throws Exception {
235232
final String messageWithoutZone = "<45>1 2014-10-21T10:21:09 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'";
236233
final String messageWithZone = "<45>1 2014-10-21T10:21:09-07:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'";
237234

238-
assertEquals(new DateTime("2014-10-21T10:21:09.000"), buildEvent(messageWithoutZone).getDateTime());
239-
assertEquals(new DateTime("2014-10-21T10:21:09.000-07:00"), buildEvent(messageWithZone).getDateTime());
235+
assertEquals(new DateTime("2014-10-21T10:21:09.000"), buildEvent(messageWithoutZone, null).getDateTime());
236+
assertEquals(new DateTime("2014-10-21T10:21:09.000-07:00"), buildEvent(messageWithZone, null).getDateTime());
240237
}
241238

242239
@Test
243240
public void testDefaultTimeZoneSet() throws Exception {
244-
// Message from: https://github.com/Graylog2/graylog2-server/issues/845
245241
final String messageWithoutZone = "<45>1 2014-10-21T10:21:09 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'";
246242
final String messageWithZone = "<45>1 2014-10-21T10:21:09+01:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'";
247-
ZonedDateTime of = ZonedDateTime.of(2014, 10, 21, 10, 21, 9, 0, MST.toTimeZone().toZoneId());
248-
assertEquals(new DateTime("2014-10-21T10:21:09.000-07:00", MST), new StructuredSyslogServerEvent(messageWithoutZone, INET_ADDR, MST).getDateTime());
249-
assertEquals(new DateTime("2014-10-21T10:21:09.000+01:00"), new StructuredSyslogServerEvent(messageWithZone, INET_ADDR, MST).getDateTime());
243+
244+
assertEquals(new DateTime("2014-10-21T10:21:09.000-07:00", MST), buildEvent(messageWithoutZone, MST).getDateTime());
245+
assertEquals(new DateTime("2014-10-21T10:21:09.000+01:00"), buildEvent(messageWithZone, MST).getDateTime());
250246
}
251247
}

0 commit comments

Comments
 (0)