@Override public Record nextRecord(boolean coerceTypes, boolean dropUnknownFields) throws IOException, MalformedRecordException { String line = reader.readLine(); if (line == null) { // a null return from readLine() signals the end of the stream return null; } if (StringUtils.isBlank(line)) { // while an empty string is an error throw new MalformedRecordException("Encountered a blank message!"); } final MalformedRecordException malformedRecordException; SyslogEvent event = parser.parseEvent(ByteBuffer.wrap(line.getBytes(parser.getCharsetName()))); if (!event.isValid()) { malformedRecordException = new MalformedRecordException( String.format("Failed to parse %s as a Syslog message: it does not conform to any of the RFC" + " formats supported", line)); throw malformedRecordException; } final Map<String, Object> syslogMap = new HashMap<>(8); syslogMap.put(SyslogAttributes.PRIORITY.key(), event.getPriority()); syslogMap.put(SyslogAttributes.SEVERITY.key(), event.getSeverity()); syslogMap.put(SyslogAttributes.FACILITY.key(), event.getFacility()); syslogMap.put(SyslogAttributes.VERSION.key(), event.getVersion()); syslogMap.put(SyslogAttributes.TIMESTAMP.key(), event.getTimeStamp()); syslogMap.put(SyslogAttributes.HOSTNAME.key(), event.getHostName()); syslogMap.put(SyslogAttributes.BODY.key(), event.getMsgBody()); return new MapRecord(schema, syslogMap); }
if (!valid || event == null || !event.isValid()) { FlowFile invalidFlowFile = session.create(); invalidFlowFile = session.putAllAttributes(invalidFlowFile, defaultAttributes); attributes.put(SyslogAttributes.SYSLOG_HOSTNAME.key(), event.getHostName()); attributes.put(SyslogAttributes.SYSLOG_BODY.key(), event.getMsgBody()); attributes.put(SyslogAttributes.SYSLOG_VALID.key(), String.valueOf(event.isValid()));
if (event == null || !event.isValid()) { getLogger().error("Failed to parse {} as a Syslog message: it does not conform to any of the RFC formats supported; routing to failure", new Object[] {flowFile}); session.transfer(flowFile, REL_FAILURE);
if (!valid || event == null || !event.isValid()) { FlowFile invalidFlowFile = session.create(); invalidFlowFile = session.putAllAttributes(invalidFlowFile, defaultAttributes); attributes.put(SyslogAttributes.SYSLOG_HOSTNAME.key(), event.getHostName()); attributes.put(SyslogAttributes.SYSLOG_BODY.key(), event.getMsgBody()); attributes.put(SyslogAttributes.SYSLOG_VALID.key(), String.valueOf(event.isValid()));
if (event == null || !event.isValid()) { getLogger().error("Failed to parse {} as a Syslog message: it does not conform to any of the RFC formats supported; routing to failure", new Object[] {flowFile}); session.transfer(flowFile, REL_FAILURE);