@Test public void testBadEventBadEvent() { String badData1 = "hi guys! <10F> bad bad data\n"; SyslogUtils util = new SyslogUtils(false); ChannelBuffer buff = ChannelBuffers.buffer(100); buff.writeBytes(badData1.getBytes()); String badData2 = "hi guys! <20> bad bad data\n"; buff.writeBytes((badData2).getBytes()); Event e = util.extractEvent(buff); if (e == null) { throw new NullPointerException("Event is null"); } Map<String, String> headers = e.getHeaders(); Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY)); Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY)); Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(), headers.get(SyslogUtils.EVENT_STATUS)); Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim()); Event e2 = util.extractEvent(buff); if (e2 == null) { throw new NullPointerException("Event is null"); } Map<String, String> headers2 = e2.getHeaders(); Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_FACILITY)); Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_SEVERITY)); Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(), headers2.get(SyslogUtils.EVENT_STATUS)); Assert.assertEquals(badData2.trim(), new String(e2.getBody()).trim()); }
public Event extractEvent(ChannelBuffer in) { byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { baos.write(b); m = Mode.PRIO; } else if (b == '\n') { logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: baos.write(b); if (b == '>') { if (prio.length() == 0) { isBadEvent = true; } m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch) || prio.length() > 3) { isBadEvent = true; m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if (baos.size() == this.maxSize && !doneReading) { isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } finally { } return e; }
SyslogUtils { public Event extractEvent(ChannelBuffer in) { byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { baos.write(b); m = Mode.PRIO; } else if (b == '\n') { logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: baos.write(b); if (b == '>') { if (prio.length() == 0) { isBadEvent = true; } m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch) || prio.length() > 3) { isBadEvent = true; m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if (baos.size() == this.maxSize && !doneReading) { isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } finally { } return e; } }
SyslogUtils { public Event extractEvent(ChannelBuffer in) { byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { baos.write(b); m = Mode.PRIO; } else if (b == '\n') { logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: baos.write(b); if (b == '>') { if (prio.length() == 0) { isBadEvent = true; } m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch) || prio.length() > 3) { isBadEvent = true; m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if (baos.size() == this.maxSize && !doneReading) { isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } finally { } return e; } SyslogUtils();  SyslogUtils(boolean isUdp);  SyslogUtils(Integer defaultSize, Set<String> keepFields, boolean isUdp);  SyslogUtils(Integer eventSize, Set<String> keepFields, boolean isUdp, Clock clock); }
SyslogUtils { public Event extractEvent(ChannelBuffer in) { byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { baos.write(b); m = Mode.PRIO; } else if (b == '\n') { logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: baos.write(b); if (b == '>') { if (prio.length() == 0) { isBadEvent = true; } m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch) || prio.length() > 3) { isBadEvent = true; m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if (baos.size() == this.maxSize && !doneReading) { isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } finally { } return e; } SyslogUtils();  SyslogUtils(boolean isUdp);  SyslogUtils(Integer defaultSize, Set<String> keepFields, boolean isUdp);  SyslogUtils(Integer eventSize, Set<String> keepFields, boolean isUdp, Clock clock); static boolean keepAllFields(Set<String> keepFields); static Set<String> chooseFieldsToKeep(String keepFields); static String addFieldsToBody(Set<String> keepFields,
                                       String body,
                                       String priority,
                                       String version,
                                       String timestamp,
                                       String hostname); static String getIP(SocketAddress socketAddress); static String getHostname(SocketAddress socketAddress); void addFormats(Map<String, String> formatProp); Event extractEvent(ChannelBuffer in); Integer getEventSize(); void setEventSize(Integer eventSize); void setKeepFields(Set<String> keepFields); }
SyslogUtils { public Event extractEvent(ChannelBuffer in) { byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { baos.write(b); m = Mode.PRIO; } else if (b == '\n') { logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: baos.write(b); if (b == '>') { if (prio.length() == 0) { isBadEvent = true; } m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch) || prio.length() > 3) { isBadEvent = true; m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if (baos.size() == this.maxSize && !doneReading) { isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } finally { } return e; } SyslogUtils();  SyslogUtils(boolean isUdp);  SyslogUtils(Integer defaultSize, Set<String> keepFields, boolean isUdp);  SyslogUtils(Integer eventSize, Set<String> keepFields, boolean isUdp, Clock clock); static boolean keepAllFields(Set<String> keepFields); static Set<String> chooseFieldsToKeep(String keepFields); static String addFieldsToBody(Set<String> keepFields,
                                       String body,
                                       String priority,
                                       String version,
                                       String timestamp,
                                       String hostname); static String getIP(SocketAddress socketAddress); static String getHostname(SocketAddress socketAddress); void addFormats(Map<String, String> formatProp); Event extractEvent(ChannelBuffer in); Integer getEventSize(); void setEventSize(Integer eventSize); void setKeepFields(Set<String> keepFields); static final String SYSLOG_TIMESTAMP_FORMAT_RFC5424_2; static final String SYSLOG_TIMESTAMP_FORMAT_RFC5424_1; static final String SYSLOG_TIMESTAMP_FORMAT_RFC5424_3; static final String SYSLOG_TIMESTAMP_FORMAT_RFC5424_4; static final String SYSLOG_TIMESTAMP_FORMAT_RFC3164_1; static final String SYSLOG_MSG_RFC5424_0; static final String SYSLOG_MSG_RFC3164_0; static final int SYSLOG_PRIORITY_POS; static final int SYSLOG_VERSION_POS; static final int SYSLOG_TIMESTAMP_POS; static final int SYSLOG_HOSTNAME_POS; static final int SYSLOG_BODY_POS; static final String SYSLOG_FACILITY; static final String SYSLOG_SEVERITY; static final String SYSLOG_PRIORITY; static final String SYSLOG_VERSION; static final String EVENT_STATUS; static final Integer MIN_SIZE; static final Integer DEFAULT_SIZE; static final String KEEP_FIELDS_ALL; }