http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ParseSyslog5424.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ParseSyslog5424.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ParseSyslog5424.java index 1436921..4078402 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ParseSyslog5424.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ParseSyslog5424.java @@ -17,7 +17,6 @@ package org.apache.nifi.processors.standard; -import com.github.palindromicity.syslog.NilPolicy; import org.apache.nifi.annotation.behavior.EventDriven; import org.apache.nifi.annotation.behavior.InputRequirement; import org.apache.nifi.annotation.behavior.InputRequirement.Requirement; @@ -40,15 +39,19 @@ import org.apache.nifi.processor.Relationship; import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.processor.io.InputStreamCallback; import org.apache.nifi.processor.util.StandardValidators; -import org.apache.nifi.processors.standard.syslog.StrictSyslog5424Parser; -import org.apache.nifi.processors.standard.syslog.Syslog5424Event; -import org.apache.nifi.processors.standard.syslog.SyslogAttributes; import org.apache.nifi.stream.io.StreamUtils; +import org.apache.nifi.syslog.keyproviders.SyslogPrefixedKeyProvider; +import org.apache.nifi.syslog.utils.NifiStructuredDataPolicy; +import org.apache.nifi.syslog.utils.NilHandlingPolicy; +import org.apache.nifi.syslog.parsers.StrictSyslog5424Parser; +import org.apache.nifi.syslog.events.Syslog5424Event; +import org.apache.nifi.syslog.attributes.SyslogAttributes; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -82,9 +85,9 @@ import java.util.Set; @SeeAlso({ListenSyslog.class, ParseSyslog.class, PutSyslog.class}) public class ParseSyslog5424 extends AbstractProcessor { - public static final AllowableValue OMIT = new AllowableValue(NilPolicy.OMIT.name(),NilPolicy.OMIT.name(),"The missing field will not have an attribute added."); - public static final AllowableValue NULL = new AllowableValue(NilPolicy.NULL.name(),NilPolicy.NULL.name(),"The missing field will have an empty attribute added."); - public static final AllowableValue DASH = new AllowableValue(NilPolicy.DASH.name(),NilPolicy.DASH.name(),"The missing field will have an attribute added with the value of '-'."); + public static final AllowableValue OMIT = new AllowableValue(NilHandlingPolicy.OMIT.name(),NilHandlingPolicy.OMIT.name(),"The missing field will not have an attribute added."); + public static final AllowableValue NULL = new AllowableValue(NilHandlingPolicy.NULL.name(),NilHandlingPolicy.NULL.name(),"The missing field will have an empty attribute added."); + public static final AllowableValue DASH = new AllowableValue(NilHandlingPolicy.DASH.name(),NilHandlingPolicy.DASH.name(),"The missing field will have an attribute added with the value of '-'."); public static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder() .name("Character Set") @@ -149,7 +152,9 @@ public class ParseSyslog5424 extends AbstractProcessor { public void onScheduled(final ProcessContext context) { final String charsetName = context.getProperty(CHARSET).getValue(); final String nilPolicyString = context.getProperty(NIL_POLICY).getValue(); - parser = new StrictSyslog5424Parser(Charset.forName(charsetName),NilPolicy.valueOf(nilPolicyString)); + parser = new StrictSyslog5424Parser(Charset.forName(charsetName), + NilHandlingPolicy.valueOf(nilPolicyString), + NifiStructuredDataPolicy.FLATTEN,new SyslogPrefixedKeyProvider()); } @Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { @@ -186,11 +191,18 @@ public class ParseSyslog5424 extends AbstractProcessor { session.transfer(flowFile, REL_FAILURE); return; } - Map<String,String> attributeMap = syslogEvent.getFieldMap(); + Map<String,String> attributeMap = convertMap(syslogEvent.getFieldMap()); if (!includeBody) { - attributeMap.remove(SyslogAttributes.BODY.key()); + attributeMap.remove(SyslogAttributes.SYSLOG_BODY.key()); } flowFile = session.putAllAttributes(flowFile, attributeMap); session.transfer(flowFile, REL_SUCCESS); } + + + private static Map<String,String> convertMap(Map<String, Object> map) { + Map<String,String> returnMap = new HashMap<>(); + map.forEach((key,value) -> returnMap.put(key,(String)value)); + return returnMap; + } }
http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSyslog.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSyslog.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSyslog.java index 78a585a..fa38dce 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSyslog.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSyslog.java @@ -39,8 +39,8 @@ import org.apache.nifi.processor.util.put.sender.ChannelSender; import org.apache.nifi.processor.util.put.sender.DatagramChannelSender; import org.apache.nifi.processor.util.put.sender.SSLSocketChannelSender; import org.apache.nifi.processor.util.put.sender.SocketChannelSender; -import org.apache.nifi.processors.standard.syslog.SyslogParser; import org.apache.nifi.ssl.SSLContextService; +import org.apache.nifi.syslog.parsers.SyslogParser; import org.apache.nifi.util.StopWatch; import javax.net.ssl.SSLContext; http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/StrictSyslog5424Parser.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/StrictSyslog5424Parser.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/StrictSyslog5424Parser.java deleted file mode 100644 index 09c51b1..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/StrictSyslog5424Parser.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.syslog; - -import com.github.palindromicity.syslog.KeyProvider; -import com.github.palindromicity.syslog.NilPolicy; -import com.github.palindromicity.syslog.SyslogParserBuilder; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; - -/** - * Parses a Syslog message from a ByteBuffer into a Syslog5424Event instance. - * For 5424 we use simple-syslog-5424 since it parsers out structured data. - */ -public class StrictSyslog5424Parser { - private Charset charset; - private com.github.palindromicity.syslog.SyslogParser parser; - - public StrictSyslog5424Parser() { - this(StandardCharsets.UTF_8, NilPolicy.NULL); - } - - public StrictSyslog5424Parser(final Charset charset, final NilPolicy nilPolicy) { - this.charset = charset; - parser = new SyslogParserBuilder() - .withNilPolicy(nilPolicy) - .withKeyProvider(new NifiKeyProvider()) - .build(); - } - - /** - * Parses a Syslog5424Event from a byte buffer. - * - * @param buffer a byte buffer containing a syslog message - * @return a Syslog5424Event parsed from the byte array - */ - public Syslog5424Event parseEvent(final ByteBuffer buffer) { - return parseEvent(buffer, null); - } - - /** - * Parses a Syslog5424Event from a byte buffer. - * - * @param buffer a byte buffer containing a syslog message - * @param sender the hostname of the syslog server that sent the message - * @return a Syslog5424Event parsed from the byte array - */ - public Syslog5424Event parseEvent(final ByteBuffer buffer, final String sender) { - if (buffer == null) { - return null; - } - if (buffer.position() != 0) { - buffer.flip(); - } - byte bytes[] = new byte[buffer.limit()]; - buffer.get(bytes, 0, buffer.limit()); - return parseEvent(bytes, sender); - } - - /** - * Parses a Syslog5424Event from a byte array. - * - * @param bytes a byte array containing a syslog message - * @param sender the hostname of the syslog server that sent the message - * @return a Syslog5424Event parsed from the byte array - */ - public Syslog5424Event parseEvent(final byte[] bytes, final String sender) { - if (bytes == null || bytes.length == 0) { - return null; - } - - // remove trailing new line before parsing - int length = bytes.length; - if (bytes[length - 1] == '\n') { - length = length - 1; - } - - final String message = new String(bytes, 0, length, charset); - - final Syslog5424Event.Builder builder = new Syslog5424Event.Builder() - .valid(false).fullMessage(message).rawMessage(bytes).sender(sender); - - try { - parser.parseLine(message,(map)-> { - builder.fieldMap(convertMap(map)); - }); - builder.valid(true); - return builder.build(); - } catch (Exception e) { - // this is not a valid 5424 message - builder.valid(false); - } - - // either invalid w/original msg, or fully parsed event - return builder.build(); - } - - public String getCharsetName() { - return charset == null ? StandardCharsets.UTF_8.name() : charset.name(); - } - - private static Map<String,String> convertMap(Map<String, Object> map) { - Map<String,String> returnMap = new HashMap<>(); - map.forEach((key,value) -> returnMap.put(key,(String)value)); - return returnMap; - } - - public static class NifiKeyProvider implements KeyProvider { - private Pattern pattern; - - public NifiKeyProvider(){} - - @Override - public String getMessage() { - return SyslogAttributes.BODY.key(); - } - - @Override - public String getHeaderAppName() { - return Syslog5424Attributes.APP_NAME.key(); - } - - @Override - public String getHeaderHostName() { - return SyslogAttributes.HOSTNAME.key(); - } - - @Override - public String getHeaderPriority() { - return SyslogAttributes.PRIORITY.key(); - } - - @Override - public String getHeaderFacility() { - return SyslogAttributes.FACILITY.key(); - } - - @Override - public String getHeaderSeverity() { - return SyslogAttributes.SEVERITY.key(); - } - - - @Override - public String getHeaderProcessId() { - return Syslog5424Attributes.PROCID.key(); - } - - @Override - public String getHeaderTimeStamp() { - return SyslogAttributes.TIMESTAMP.key(); - } - - @Override - public String getHeaderMessageId() { - return Syslog5424Attributes.MESSAGEID.key(); - } - - @Override - public String getHeaderVersion() { - return SyslogAttributes.VERSION.key(); - } - - @Override - public String getStructuredBase() { - return Syslog5424Attributes.STRUCTURED_BASE.key(); - } - - @Override - public String getStructuredElementIdFormat() { - return Syslog5424Attributes.STRUCTURED_ELEMENT_ID_FMT.key(); - } - - @Override - public String getStructuredElementIdParamNameFormat() { - return Syslog5424Attributes.STRUCTURED_ELEMENT_ID_PNAME_FMT.key(); - } - - @Override - public Pattern getStructuredElementIdParamNamePattern() { - if (pattern == null) { - pattern = Pattern.compile(Syslog5424Attributes.STRUCTURED_ELEMENT_ID_PNAME_PATTERN.key()); - } - return pattern; - } - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/Syslog5424Attributes.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/Syslog5424Attributes.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/Syslog5424Attributes.java deleted file mode 100644 index 284cc84..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/Syslog5424Attributes.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.syslog; - -import org.apache.nifi.flowfile.attributes.FlowFileAttributeKey; - -/** - * FlowFile Attributes for each Syslog message. - */ -public enum Syslog5424Attributes implements FlowFileAttributeKey { - - APP_NAME("syslog.appName"), - PROCID("syslog.procid"), - MESSAGEID("syslog.messageid"), - STRUCTURED_BASE("syslog.structuredData"), - STRUCTURED_ELEMENT_ID_FMT("syslog.structuredData.%s"), - STRUCTURED_ELEMENT_ID_PNAME_FMT("syslog.structuredData.%s.%s"), - STRUCTURED_ELEMENT_ID_PNAME_PATTERN("syslog.structuredData\\.(.*)\\.(.*)$"); - private String key; - - Syslog5424Attributes(String key) { - this.key = key; - } - - @Override - public String key() { - return key; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/Syslog5424Event.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/Syslog5424Event.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/Syslog5424Event.java deleted file mode 100644 index 89910a9..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/Syslog5424Event.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.syslog; - -import java.util.Map; - -/** - * Encapsulates the parsed information for a single Syslog 5424 event. - */ -public class Syslog5424Event { - private final Map<String,String> fieldMap; - private final String fullMessage; - private final byte[] rawMessage; - private final String sender; - private final boolean valid; - - private Syslog5424Event(final Builder builder) { - this.fieldMap = builder.fieldMap; - this.fullMessage = builder.fullMessage; - this.rawMessage = builder.rawMessage; - this.sender = builder.sender; - this.valid = builder.valid; - } - - public Map<String,String> getFieldMap() { - return fieldMap; - } - - public String getFullMessage() { - return fullMessage; - } - - public byte[] getRawMessage() { - return rawMessage; - } - - public String getSender() { - return sender; - } - - public boolean isValid() { - return valid; - } - - public static final class Builder { - private String fullMessage; - private String sender; - private Map<String, String> fieldMap; - private byte[] rawMessage; - private boolean valid; - - public void reset() { - this.fieldMap = null; - this.sender = null; - this.fullMessage = null; - this.valid = false; - } - - public Builder sender(String sender) { - this.sender = sender; - return this; - } - - public Builder fieldMap(Map<String, String> fieldMap) { - this.fieldMap = fieldMap; - return this; - } - - public Builder fullMessage(String fullMessage) { - this.fullMessage = fullMessage; - return this; - } - - public Builder rawMessage(byte[] rawMessage) { - this.rawMessage = rawMessage; - return this; - } - - public Builder valid(boolean valid) { - this.valid = valid; - return this; - } - - public Syslog5424Event build() { - return new Syslog5424Event(this); - } - } - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogAttributes.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogAttributes.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogAttributes.java deleted file mode 100644 index e7a13f1..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogAttributes.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.syslog; - -import org.apache.nifi.flowfile.attributes.FlowFileAttributeKey; - -/** - * FlowFile Attributes for each Syslog message. - */ -public enum SyslogAttributes implements FlowFileAttributeKey { - - PRIORITY("syslog.priority"), - SEVERITY("syslog.severity"), - FACILITY("syslog.facility"), - VERSION("syslog.version"), - TIMESTAMP("syslog.timestamp"), - HOSTNAME("syslog.hostname"), - SENDER("syslog.sender"), - BODY("syslog.body"), - VALID("syslog.valid"), - PROTOCOL("syslog.protocol"), - PORT("syslog.port"); - - private String key; - - SyslogAttributes(String key) { - this.key = key; - } - - @Override - public String key() { - return key; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogEvent.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogEvent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogEvent.java deleted file mode 100644 index 29243cd..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogEvent.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.syslog; - -/** - * Encapsulates the parsed information for a single Syslog event. - */ -public class SyslogEvent { - - private final String priority; - private final String severity; - private final String facility; - private final String version; - private final String timeStamp; - private final String hostName; - private final String sender; - private final String msgBody; - private final String fullMessage; - private final byte[] rawMessage; - private final boolean valid; - - private SyslogEvent(final Builder builder) { - this.priority = builder.priority; - this.severity = builder.severity; - this.facility = builder.facility; - this.version = builder.version; - this.timeStamp = builder.timeStamp; - this.hostName = builder.hostName; - this.sender = builder.sender; - this.msgBody = builder.msgBody; - this.fullMessage = builder.fullMessage; - this.rawMessage = builder.rawMessage; - this.valid = builder.valid; - } - - public String getPriority() { - return priority; - } - - public String getSeverity() { - return severity; - } - - public String getFacility() { - return facility; - } - - public String getVersion() { - return version; - } - - public String getTimeStamp() { - return timeStamp; - } - - public String getHostName() { - return hostName; - } - - public String getSender() { - return sender; - } - - public String getMsgBody() { - return msgBody; - } - - public String getFullMessage() { - return fullMessage; - } - - public byte[] getRawMessage() { - return rawMessage; - } - - public boolean isValid() { - return valid; - } - - public static final class Builder { - private String priority; - private String severity; - private String facility; - private String version; - private String timeStamp; - private String hostName; - private String sender; - private String msgBody; - private String fullMessage; - private byte[] rawMessage; - private boolean valid; - - public void reset() { - this.priority = null; - this.severity = null; - this.facility = null; - this.version = null; - this.timeStamp = null; - this.hostName = null; - this.sender = null; - this.msgBody = null; - this.fullMessage = null; - this.valid = false; - } - - public Builder priority(String priority) { - this.priority = priority; - return this; - } - - public Builder severity(String severity) { - this.severity = severity; - return this; - } - - public Builder facility(String facility) { - this.facility = facility; - return this; - } - - public Builder version(String version) { - this.version = version; - return this; - } - - public Builder timestamp(String timestamp) { - this.timeStamp = timestamp; - return this; - } - - public Builder hostname(String hostName) { - this.hostName = hostName; - return this; - } - - public Builder sender(String sender) { - this.sender = sender; - return this; - } - - public Builder msgBody(String msgBody) { - this.msgBody = msgBody; - return this; - } - - public Builder fullMessage(String fullMessage) { - this.fullMessage = fullMessage; - return this; - } - - public Builder rawMessage(byte[] rawMessage) { - this.rawMessage = rawMessage; - return this; - } - - public Builder valid(boolean valid) { - this.valid = valid; - return this; - } - - public SyslogEvent build() { - return new SyslogEvent(this); - } - } - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogParser.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogParser.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogParser.java deleted file mode 100644 index 8235feb..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/syslog/SyslogParser.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.syslog; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.regex.MatchResult; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Parses a Syslog message from a ByteBuffer into a SyslogEvent instance. - * - * The Syslog regular expressions below were adapted from the Apache Flume project. - */ -public class SyslogParser { - - public static final String SYSLOG_MSG_RFC5424_0 = - "(?:\\<(\\d{1,3})\\>)" + // priority - "(?:(\\d)?\\s?)" + // version - /* yyyy-MM-dd'T'HH:mm:ss.SZ or yyyy-MM-dd'T'HH:mm:ss.S+hh:mm or - (null stamp) */ - "(?:" + - "(\\d{4}[-]\\d{2}[-]\\d{2}[T]\\d{2}[:]\\d{2}[:]\\d{2}" + - "(?:\\.\\d{1,6})?(?:[+-]\\d{2}[:]\\d{2}|Z)?)|-)" + // stamp - "\\s" + // separator - "(?:([\\w][\\w\\d\\.@\\-]*)|-)" + // host name or - (null) - "\\s" + // separator - "(.*)$"; // body - - public static final String SYSLOG_MSG_RFC3164_0 = - "(?:\\<(\\d{1,3})\\>)" + - "(?:(\\d)?\\s?)" + // version - // stamp MMM d HH:mm:ss, single digit date has two spaces - "([A-Z][a-z][a-z]\\s{1,2}\\d{1,2}\\s\\d{2}[:]\\d{2}[:]\\d{2})" + - "\\s" + // separator - "([\\w][\\w\\d(\\.|\\:)@-]*)" + // host - "\\s(.*)$"; // body - - public static final Collection<Pattern> MESSAGE_PATTERNS; - static { - List<Pattern> patterns = new ArrayList<>(); - patterns.add(Pattern.compile(SYSLOG_MSG_RFC5424_0)); - patterns.add(Pattern.compile(SYSLOG_MSG_RFC3164_0)); - MESSAGE_PATTERNS = Collections.unmodifiableList(patterns); - } - - // capture group positions from the above message patterns - public static final int SYSLOG_PRIORITY_POS = 1; - public static final int SYSLOG_VERSION_POS = 2; - public static final int SYSLOG_TIMESTAMP_POS = 3; - public static final int SYSLOG_HOSTNAME_POS = 4; - public static final int SYSLOG_BODY_POS = 5; - - private Charset charset; - - public SyslogParser() { - this(StandardCharsets.UTF_8); - } - - public SyslogParser(final Charset charset) { - this.charset = charset; - } - - /** - * Parses a SyslogEvent from a byte buffer. - * - * @param buffer a byte buffer containing a syslog message - * @return a SyslogEvent parsed from the byte array - */ - public SyslogEvent parseEvent(final ByteBuffer buffer) { - return parseEvent(buffer, null); - } - - /** - * Parses a SyslogEvent from a byte buffer. - * - * @param buffer a byte buffer containing a syslog message - * @param sender the hostname of the syslog server that sent the message - * @return a SyslogEvent parsed from the byte array - */ - public SyslogEvent parseEvent(final ByteBuffer buffer, final String sender) { - if (buffer == null) { - return null; - } - if (buffer.position() != 0) { - buffer.flip(); - } - byte bytes[] = new byte[buffer.limit()]; - buffer.get(bytes, 0, buffer.limit()); - return parseEvent(bytes, sender); - } - - /** - * Parses a SyslogEvent from a byte array. - * - * @param bytes a byte array containing a syslog message - * @param sender the hostname of the syslog server that sent the message - * @return a SyslogEvent parsed from the byte array - */ - public SyslogEvent parseEvent(final byte[] bytes, final String sender) { - if (bytes == null || bytes.length == 0) { - return null; - } - - // remove trailing new line before parsing - int length = bytes.length; - if (bytes[length - 1] == '\n') { - length = length - 1; - } - - final String message = new String(bytes, 0, length, charset); - - final SyslogEvent.Builder builder = new SyslogEvent.Builder() - .valid(false).fullMessage(message).rawMessage(bytes).sender(sender); - - for (Pattern pattern : MESSAGE_PATTERNS) { - final Matcher matcher = pattern.matcher(message); - if (!matcher.matches()) { - continue; - } - - final MatchResult res = matcher.toMatchResult(); - for (int grp = 1; grp <= res.groupCount(); grp++) { - String value = res.group(grp); - if (grp == SYSLOG_TIMESTAMP_POS) { - builder.timestamp(value); - } else if (grp == SYSLOG_HOSTNAME_POS) { - builder.hostname(value); - } else if (grp == SYSLOG_PRIORITY_POS) { - int pri = Integer.parseInt(value); - int sev = pri % 8; - int facility = pri / 8; - builder.priority(value); - builder.severity(String.valueOf(sev)); - builder.facility(String.valueOf(facility)); - } else if (grp == SYSLOG_VERSION_POS) { - builder.version(value); - } else if (grp == SYSLOG_BODY_POS) { - builder.msgBody(value); - } - } - - builder.valid(true); - break; - } - - // either invalid w/original msg, or fully parsed event - return builder.build(); - } - - public String getCharsetName() { - return charset == null ? StandardCharsets.UTF_8.name() : charset.name(); - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ITListenSyslogGroovy.groovy ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ITListenSyslogGroovy.groovy b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ITListenSyslogGroovy.groovy index 3f5d16e..c3378bc 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ITListenSyslogGroovy.groovy +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ITListenSyslogGroovy.groovy @@ -18,7 +18,7 @@ package org.apache.nifi.processors.standard import org.apache.nifi.processor.ProcessContext import org.apache.nifi.processor.ProcessSessionFactory -import org.apache.nifi.processors.standard.syslog.SyslogParser +import org.apache.nifi.syslog.parsers.SyslogParser import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunners import org.bouncycastle.util.encoders.Hex http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ParseSyslogGroovyTest.groovy ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ParseSyslogGroovyTest.groovy b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ParseSyslogGroovyTest.groovy index 208eaee..e34902b 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ParseSyslogGroovyTest.groovy +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/ParseSyslogGroovyTest.groovy @@ -16,7 +16,7 @@ */ package org.apache.nifi.processors.standard -import org.apache.nifi.processors.standard.syslog.SyslogParser +import org.apache.nifi.syslog.parsers.SyslogParser import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunners import org.bouncycastle.util.encoders.Hex http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ITListenSyslog.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ITListenSyslog.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ITListenSyslog.java index a94bb20..52f2c58 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ITListenSyslog.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ITListenSyslog.java @@ -19,9 +19,9 @@ package org.apache.nifi.processors.standard; import org.apache.commons.lang3.StringUtils; import org.apache.nifi.processor.ProcessContext; import org.apache.nifi.processor.ProcessSessionFactory; -import org.apache.nifi.processors.standard.syslog.SyslogAttributes; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; +import org.apache.nifi.syslog.attributes.SyslogAttributes; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; @@ -301,16 +301,16 @@ public class ITListenSyslog { private void checkFlowFile(final MockFlowFile flowFile, final int port, final String protocol) { flowFile.assertContentEquals(VALID_MESSAGE.replace("\n", "")); - Assert.assertEquals(PRI, flowFile.getAttribute(SyslogAttributes.PRIORITY.key())); - Assert.assertEquals(SEV, flowFile.getAttribute(SyslogAttributes.SEVERITY.key())); - Assert.assertEquals(FAC, flowFile.getAttribute(SyslogAttributes.FACILITY.key())); - Assert.assertEquals(TIME, flowFile.getAttribute(SyslogAttributes.TIMESTAMP.key())); - Assert.assertEquals(HOST, flowFile.getAttribute(SyslogAttributes.HOSTNAME.key())); - Assert.assertEquals(BODY, flowFile.getAttribute(SyslogAttributes.BODY.key())); - Assert.assertEquals("true", flowFile.getAttribute(SyslogAttributes.VALID.key())); - Assert.assertEquals(String.valueOf(port), flowFile.getAttribute(SyslogAttributes.PORT.key())); - Assert.assertEquals(protocol, flowFile.getAttribute(SyslogAttributes.PROTOCOL.key())); - Assert.assertTrue(!StringUtils.isBlank(flowFile.getAttribute(SyslogAttributes.SENDER.key()))); + Assert.assertEquals(PRI, flowFile.getAttribute(SyslogAttributes.SYSLOG_PRIORITY.key())); + Assert.assertEquals(SEV, flowFile.getAttribute(SyslogAttributes.SYSLOG_SEVERITY.key())); + Assert.assertEquals(FAC, flowFile.getAttribute(SyslogAttributes.SYSLOG_FACILITY.key())); + Assert.assertEquals(TIME, flowFile.getAttribute(SyslogAttributes.SYSLOG_TIMESTAMP.key())); + Assert.assertEquals(HOST, flowFile.getAttribute(SyslogAttributes.SYSLOG_HOSTNAME.key())); + Assert.assertEquals(BODY, flowFile.getAttribute(SyslogAttributes.SYSLOG_BODY.key())); + Assert.assertEquals("true", flowFile.getAttribute(SyslogAttributes.SYSLOG_VALID.key())); + Assert.assertEquals(String.valueOf(port), flowFile.getAttribute(SyslogAttributes.SYSLOG_PORT.key())); + Assert.assertEquals(protocol, flowFile.getAttribute(SyslogAttributes.SYSLOG_PROTOCOL.key())); + Assert.assertTrue(!StringUtils.isBlank(flowFile.getAttribute(SyslogAttributes.SYSLOG_SENDER.key()))); } /** http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenSyslog.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenSyslog.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenSyslog.java index 70495e1..7fddc1b 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenSyslog.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenSyslog.java @@ -25,11 +25,11 @@ import org.apache.nifi.processor.ProcessSession; import org.apache.nifi.processor.ProcessSessionFactory; import org.apache.nifi.processor.exception.FlowFileAccessException; import org.apache.nifi.processor.exception.ProcessException; -import org.apache.nifi.processors.standard.syslog.SyslogAttributes; -import org.apache.nifi.processors.standard.syslog.SyslogEvent; -import org.apache.nifi.processors.standard.syslog.SyslogParser; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; +import org.apache.nifi.syslog.attributes.SyslogAttributes; +import org.apache.nifi.syslog.events.SyslogEvent; +import org.apache.nifi.syslog.parsers.SyslogParser; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; @@ -98,9 +98,9 @@ public class TestListenSyslog { runner.assertAllFlowFilesTransferred(ListenSyslog.REL_SUCCESS, 1); final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenSyslog.REL_SUCCESS).get(0); - Assert.assertEquals("0", flowFile.getAttribute(SyslogAttributes.PORT.key())); - Assert.assertEquals(ListenSyslog.UDP_VALUE.getValue(), flowFile.getAttribute(SyslogAttributes.PROTOCOL.key())); - Assert.assertTrue(!StringUtils.isBlank(flowFile.getAttribute(SyslogAttributes.SENDER.key()))); + Assert.assertEquals("0", flowFile.getAttribute(SyslogAttributes.SYSLOG_PORT.key())); + Assert.assertEquals(ListenSyslog.UDP_VALUE.getValue(), flowFile.getAttribute(SyslogAttributes.SYSLOG_PROTOCOL.key())); + Assert.assertTrue(!StringUtils.isBlank(flowFile.getAttribute(SyslogAttributes.SYSLOG_SENDER.key()))); final String content = new String(flowFile.toByteArray(), StandardCharsets.UTF_8); final String[] splits = content.split("\\|"); http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog.java index ff6cc90..79d4c09 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog.java @@ -17,7 +17,7 @@ package org.apache.nifi.processors.standard; -import org.apache.nifi.processors.standard.syslog.SyslogAttributes; +import org.apache.nifi.syslog.attributes.SyslogAttributes; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; @@ -46,12 +46,12 @@ public class TestParseSyslog { runner.assertAllFlowFilesTransferred(ParseSyslog.REL_SUCCESS, 1); final MockFlowFile mff = runner.getFlowFilesForRelationship(ParseSyslog.REL_SUCCESS).get(0); - mff.assertAttributeEquals(SyslogAttributes.BODY.key(), BODY); - mff.assertAttributeEquals(SyslogAttributes.FACILITY.key(), FAC); - mff.assertAttributeEquals(SyslogAttributes.HOSTNAME.key(), HOST); - mff.assertAttributeEquals(SyslogAttributes.PRIORITY.key(), PRI); - mff.assertAttributeEquals(SyslogAttributes.SEVERITY.key(), SEV); - mff.assertAttributeEquals(SyslogAttributes.TIMESTAMP.key(), TIME); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_BODY.key(), BODY); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_FACILITY.key(), FAC); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_HOSTNAME.key(), HOST); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_PRIORITY.key(), PRI); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_SEVERITY.key(), SEV); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_TIMESTAMP.key(), TIME); } @Test @@ -62,12 +62,12 @@ public class TestParseSyslog { runner.assertAllFlowFilesTransferred(ParseSyslog.REL_SUCCESS, 1); final MockFlowFile mff = runner.getFlowFilesForRelationship(ParseSyslog.REL_SUCCESS).get(0); - mff.assertAttributeEquals(SyslogAttributes.BODY.key(), BODY); - mff.assertAttributeEquals(SyslogAttributes.FACILITY.key(), FAC); - mff.assertAttributeEquals(SyslogAttributes.HOSTNAME.key(), IPV6SRC); - mff.assertAttributeEquals(SyslogAttributes.PRIORITY.key(), PRI); - mff.assertAttributeEquals(SyslogAttributes.SEVERITY.key(), SEV); - mff.assertAttributeEquals(SyslogAttributes.TIMESTAMP.key(), TIME); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_BODY.key(), BODY); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_FACILITY.key(), FAC); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_HOSTNAME.key(), IPV6SRC); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_PRIORITY.key(), PRI); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_SEVERITY.key(), SEV); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_TIMESTAMP.key(), TIME); } @Test @@ -78,12 +78,12 @@ public class TestParseSyslog { runner.assertAllFlowFilesTransferred(ParseSyslog.REL_SUCCESS, 1); final MockFlowFile mff = runner.getFlowFilesForRelationship(ParseSyslog.REL_SUCCESS).get(0); - mff.assertAttributeEquals(SyslogAttributes.BODY.key(), BODY); - mff.assertAttributeEquals(SyslogAttributes.FACILITY.key(), FAC); - mff.assertAttributeEquals(SyslogAttributes.HOSTNAME.key(), IPV4SRC); - mff.assertAttributeEquals(SyslogAttributes.PRIORITY.key(), PRI); - mff.assertAttributeEquals(SyslogAttributes.SEVERITY.key(), SEV); - mff.assertAttributeEquals(SyslogAttributes.TIMESTAMP.key(), TIME); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_BODY.key(), BODY); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_FACILITY.key(), FAC); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_HOSTNAME.key(), IPV4SRC); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_PRIORITY.key(), PRI); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_SEVERITY.key(), SEV); + mff.assertAttributeEquals(SyslogAttributes.SYSLOG_TIMESTAMP.key(), TIME); } @Test http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java index eb88d6c..86cc102 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java @@ -18,7 +18,7 @@ package org.apache.nifi.processors.standard; import com.github.palindromicity.syslog.NilPolicy; -import org.apache.nifi.processors.standard.syslog.SyslogAttributes; +import org.apache.nifi.syslog.attributes.SyslogAttributes; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; @@ -73,7 +73,7 @@ public class TestParseSyslog5424 { runner.run(); runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS,1); List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS); - Assert.assertNotNull(results.get(0).getAttribute(SyslogAttributes.BODY.key())); + Assert.assertNotNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key())); } @Test @@ -85,7 +85,7 @@ public class TestParseSyslog5424 { runner.run(); runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS,1); List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS); - Assert.assertNotNull(results.get(0).getAttribute(SyslogAttributes.BODY.key())); + Assert.assertNotNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key())); } @Test @@ -97,6 +97,6 @@ public class TestParseSyslog5424 { runner.run(); runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS,1); List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS); - Assert.assertNull(results.get(0).getAttribute(SyslogAttributes.BODY.key())); + Assert.assertNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key())); } } http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/BaseStrictSyslog5424ParserTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/BaseStrictSyslog5424ParserTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/BaseStrictSyslog5424ParserTest.java deleted file mode 100644 index f6217cb..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/BaseStrictSyslog5424ParserTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.util; - -import com.github.palindromicity.syslog.NilPolicy; -import org.apache.commons.lang3.StringUtils; -import org.apache.nifi.processors.standard.syslog.StrictSyslog5424Parser; -import org.apache.nifi.processors.standard.syslog.Syslog5424Attributes; -import org.apache.nifi.processors.standard.syslog.Syslog5424Event; -import org.apache.nifi.processors.standard.syslog.SyslogAttributes; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; - -public abstract class BaseStrictSyslog5424ParserTest { - - private static final Charset CHARSET = Charset.forName("UTF-8"); - private static final String NIL_VALUE = "-"; - private StrictSyslog5424Parser parser; - - protected abstract NilPolicy getPolicy(); - - protected void validateForPolicy(String expected, String actual) { - switch (getPolicy()) { - case DASH: - Assert.assertEquals(actual, NIL_VALUE); - break; - case OMIT: - case NULL: - Assert.assertNull(actual); - - } - } - - @Before - public void setup() { - parser = new StrictSyslog5424Parser(CHARSET, getPolicy()); - } - - @Test - public void testRFC5424WithVersion() { - final String pri = "34"; - final String version = "1"; - final String stamp = "2003-10-11T22:14:15.003Z"; - final String host = "mymachine.example.com"; - final String appName = "su"; - final String procId = "-"; - final String msgId = "ID17"; - final String structuredData = "-"; - final String body = "BOM'su root' failed for lonvick on /dev/pts/8"; - - final String message = "<" + pri + ">" + version + " " + stamp + " " + host + " " - + appName + " " + procId + " " + msgId + " " + "-" + " " + body; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final Syslog5424Event event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertTrue(event.isValid()); - Assert.assertFalse(event.getFieldMap().isEmpty()); - Map<String,String> fieldMap = event.getFieldMap(); - Assert.assertEquals(pri, fieldMap.get(SyslogAttributes.PRIORITY.key())); - Assert.assertEquals("2", fieldMap.get(SyslogAttributes.SEVERITY.key())); - Assert.assertEquals("4", fieldMap.get(SyslogAttributes.FACILITY.key())); - Assert.assertEquals(version, fieldMap.get(SyslogAttributes.VERSION.key())); - Assert.assertEquals(stamp, fieldMap.get(SyslogAttributes.TIMESTAMP.key())); - Assert.assertEquals(host, fieldMap.get(SyslogAttributes.HOSTNAME.key())); - Assert.assertEquals(appName, fieldMap.get(Syslog5424Attributes.APP_NAME.key())); - validateForPolicy(procId, fieldMap.get(Syslog5424Attributes.PROCID.key())); - Assert.assertEquals(msgId, fieldMap.get(Syslog5424Attributes.MESSAGEID.key())); - - Pattern structuredPattern = new StrictSyslog5424Parser.NifiKeyProvider().getStructuredElementIdParamNamePattern(); - fieldMap.forEach((key,value) -> { - if (!StringUtils.isBlank(value)) { - Assert.assertFalse(structuredPattern.matcher(value).matches()); - } - }); - - Assert.assertEquals(body, fieldMap.get(SyslogAttributes.BODY.key())); - Assert.assertEquals(message, event.getFullMessage()); - Assert.assertNull(event.getSender()); - } - - @Test - public void testRFC5424WithoutVersion() { - final String pri = "34"; - final String version = "-"; - final String stamp = "2003-10-11T22:14:15.003Z"; - final String host = "mymachine.example.com"; - final String appName = "su"; - final String procId = "-"; - final String msgId = "ID17"; - final String structuredData = "-"; - final String body = "BOM'su root' failed for lonvick on /dev/pts/8"; - - final String message = "<" + pri + ">" + version + " " + stamp + " " + host + " " - + appName + " " + procId + " " + msgId + " " + "-" + " " + body; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final Syslog5424Event event = parser.parseEvent(buffer); - Assert.assertFalse(event.isValid()); - } - - @Test - public void testTrailingNewLine() { - final String message = "<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - " + - "ID47 - BOM'su root' failed for lonvick on /dev/pts/8\n"; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final Syslog5424Event event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertTrue(event.isValid()); - } - - @Test - public void testVariety() { - final List<String> messages = new ArrayList<>(); - - // supported examples from RFC 5424 - messages.add("<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - " + - "ID47 - BOM'su root' failed for lonvick on /dev/pts/8"); - messages.add("<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc " + - "8710 - - %% It's time to make the do-nuts."); - messages.add("<14>1 2014-06-20T09:14:07+00:00 loggregator" - + " d0602076-b14a-4c55-852a-981e7afeed38 DEA MSG-01" - + " [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"]" - + " [exampleSDID@32480 iut=\"4\" eventSource=\"Other Application\" eventID=\"2022\"] Removing instance"); - - for (final String message : messages) { - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final Syslog5424Event event = parser.parseEvent(buffer); - Assert.assertTrue(event.isValid()); - } - } - - @Test - public void testInvalidPriority() { - final String message = "10 Oct 13 14:14:43 localhost some body of the message"; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final Syslog5424Event event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertFalse(event.isValid()); - Assert.assertEquals(message, event.getFullMessage()); - } - - @Test - public void testParseWithSender() { - final String sender = "127.0.0.1"; - final String message = "<14>1 2014-06-20T09:14:07+00:00 loggregator" - + " d0602076-b14a-4c55-852a-981e7afeed38 DEA MSG-01" - + " [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"]" - + " [exampleSDID@32480 iut=\"4\" eventSource=\"Other Application\" eventID=\"2022\"] Removing instance"; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final Syslog5424Event event = parser.parseEvent(buffer, sender); - Assert.assertNotNull(event); - Assert.assertTrue(event.isValid()); - Assert.assertEquals(sender, event.getSender()); - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserDashPolicyTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserDashPolicyTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserDashPolicyTest.java deleted file mode 100644 index 9b78d4d..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserDashPolicyTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.util; - -import com.github.palindromicity.syslog.NilPolicy; - -public class StrictSyslog5424ParserDashPolicyTest extends BaseStrictSyslog5424ParserTest { - protected NilPolicy getPolicy() { - return NilPolicy.DASH; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserNullPolicyTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserNullPolicyTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserNullPolicyTest.java deleted file mode 100644 index 4a7a3d6..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserNullPolicyTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.util; - -import com.github.palindromicity.syslog.NilPolicy; - -public class StrictSyslog5424ParserNullPolicyTest extends BaseStrictSyslog5424ParserTest { - protected NilPolicy getPolicy() { - return NilPolicy.NULL; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserOmitPolicyTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserOmitPolicyTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserOmitPolicyTest.java deleted file mode 100644 index 0e58f2a..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/StrictSyslog5424ParserOmitPolicyTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.util; - -import com.github.palindromicity.syslog.NilPolicy; - -public class StrictSyslog5424ParserOmitPolicyTest extends BaseStrictSyslog5424ParserTest { - protected NilPolicy getPolicy() { - return NilPolicy.OMIT; - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestSyslogParser.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestSyslogParser.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestSyslogParser.java deleted file mode 100644 index 24fd59e..0000000 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestSyslogParser.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.standard.util; - -import org.apache.nifi.processors.standard.syslog.SyslogEvent; -import org.apache.nifi.processors.standard.syslog.SyslogParser; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -public class TestSyslogParser { - - static final Charset CHARSET = Charset.forName("UTF-8"); - - private SyslogParser parser; - - @Before - public void setup() { - parser = new SyslogParser(CHARSET); - } - - @Test - public void testRFC3164SingleDigitDay() { - final String pri = "10"; - final String stamp = "Oct 1 13:14:04"; - final String host = "my.host.com"; - final String body = "some body message"; - final String message = "<" + pri + ">" + stamp + " " + host + " " + body; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final SyslogEvent event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertEquals(pri, event.getPriority()); - Assert.assertEquals("2", event.getSeverity()); - Assert.assertEquals("1", event.getFacility()); - Assert.assertNull(event.getVersion()); - Assert.assertEquals(stamp, event.getTimeStamp()); - Assert.assertEquals(host, event.getHostName()); - Assert.assertEquals(body, event.getMsgBody()); - Assert.assertEquals(message, event.getFullMessage()); - Assert.assertTrue(event.isValid()); - } - - @Test - public void testRFC3164DoubleDigitDay() { - final String pri = "31"; - final String stamp = "Oct 13 14:14:43"; - final String host = "localhost"; - final String body = "AppleCameraAssistant[470]: DeviceMessageNotificationCallback: kIOPMMessageSystemPowerEventOccurred: 0x00000000"; - final String message = "<" + pri + ">" + stamp + " " + host + " " + body; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final SyslogEvent event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertEquals(pri, event.getPriority()); - Assert.assertEquals("7", event.getSeverity()); - Assert.assertEquals("3", event.getFacility()); - Assert.assertNull(event.getVersion()); - Assert.assertEquals(stamp, event.getTimeStamp()); - Assert.assertEquals(host, event.getHostName()); - Assert.assertEquals(body, event.getMsgBody()); - Assert.assertEquals(message, event.getFullMessage()); - Assert.assertTrue(event.isValid()); - } - - @Test - public void testRFC3164WithVersion() { - final String pri = "31"; - final String version = "1"; - final String stamp = "Oct 13 14:14:43"; - final String host = "localhost"; - final String body = "AppleCameraAssistant[470]: DeviceMessageNotificationCallback: kIOPMMessageSystemPowerEventOccurred: 0x00000000"; - final String message = "<" + pri + ">" + version + " " + stamp + " " + host + " " + body; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final SyslogEvent event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertEquals(pri, event.getPriority()); - Assert.assertEquals("7", event.getSeverity()); - Assert.assertEquals("3", event.getFacility()); - Assert.assertEquals(version, event.getVersion()); - Assert.assertEquals(stamp, event.getTimeStamp()); - Assert.assertEquals(host, event.getHostName()); - Assert.assertEquals(body, event.getMsgBody()); - Assert.assertEquals(message, event.getFullMessage()); - Assert.assertTrue(event.isValid()); - } - - @Test - public void testRFC5424WithVersion() { - final String pri = "34"; - final String version = "1"; - final String stamp = "2003-10-11T22:14:15.003Z"; - final String host = "mymachine.example.com"; - final String body = "su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8"; - - final String message = "<" + pri + ">" + version + " " + stamp + " " + host + " " + body; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final SyslogEvent event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertEquals(pri, event.getPriority()); - Assert.assertEquals("2", event.getSeverity()); - Assert.assertEquals("4", event.getFacility()); - Assert.assertEquals(version, event.getVersion()); - Assert.assertEquals(stamp, event.getTimeStamp()); - Assert.assertEquals(host, event.getHostName()); - Assert.assertEquals(body, event.getMsgBody()); - Assert.assertEquals(message, event.getFullMessage()); - Assert.assertTrue(event.isValid()); - } - - @Test - public void testRFC5424WithoutVersion() { - final String pri = "34"; - final String stamp = "2003-10-11T22:14:15.003Z"; - final String host = "mymachine.example.com"; - final String body = "su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8"; - - final String message = "<" + pri + ">" + stamp + " " + host + " " + body; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final SyslogEvent event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertEquals(pri, event.getPriority()); - Assert.assertEquals("2", event.getSeverity()); - Assert.assertEquals("4", event.getFacility()); - Assert.assertNull(event.getVersion()); - Assert.assertEquals(stamp, event.getTimeStamp()); - Assert.assertEquals(host, event.getHostName()); - Assert.assertEquals(body, event.getMsgBody()); - Assert.assertEquals(message, event.getFullMessage()); - Assert.assertTrue(event.isValid()); - } - - @Test - public void testTrailingNewLine() { - final String message = "<31>Oct 13 15:43:23 localhost.home some message\n"; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final SyslogEvent event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertTrue(event.isValid()); - } - - @Test - public void testVariety() { - final List<String> messages = new ArrayList<>(); - - // supported examples from RFC 3164 - messages.add("<34>Oct 11 22:14:15 mymachine su: 'su root' failed for " + - "lonvick on /dev/pts/8"); - messages.add("<13>Feb 5 17:32:18 10.0.0.99 Use the BFG!"); - messages.add("<165>Aug 24 05:34:00 CST 1987 mymachine myproc[10]: %% " + - "It's time to make the do-nuts. %% Ingredients: Mix=OK, Jelly=OK # " + - "Devices: Mixer=OK, Jelly_Injector=OK, Frier=OK # Transport: " + - "Conveyer1=OK, Conveyer2=OK # %%"); - messages.add("<0>Oct 22 10:52:12 scapegoat 1990 Oct 22 10:52:01 TZ-6 " + - "scapegoat.dmz.example.org 10.1.2.3 sched[0]: That's All Folks!"); - - // supported examples from RFC 5424 - messages.add("<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - " + - "ID47 - BOM'su root' failed for lonvick on /dev/pts/8"); - messages.add("<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc " + - "8710 - - %% It's time to make the do-nuts."); - - // non-standard (but common) messages (RFC3339 dates, no version digit) - messages.add("<13>2003-08-24T05:14:15Z localhost snarf?"); - messages.add("<13>2012-08-16T14:34:03-08:00 127.0.0.1 test shnap!"); - - for (final String message : messages) { - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final SyslogEvent event = parser.parseEvent(buffer); - Assert.assertTrue(event.isValid()); - } - } - - @Test - public void testInvalidPriority() { - final String message = "10 Oct 13 14:14:43 localhost some body of the message"; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final SyslogEvent event = parser.parseEvent(buffer); - Assert.assertNotNull(event); - Assert.assertFalse(event.isValid()); - Assert.assertEquals(message, event.getFullMessage()); - } - - @Test - public void testParseWithSender() { - final String sender = "127.0.0.1"; - final String message = "<31>Oct 13 15:43:23 localhost.home some message\n"; - - final byte[] bytes = message.getBytes(CHARSET); - final ByteBuffer buffer = ByteBuffer.allocate(bytes.length); - buffer.clear(); - buffer.put(bytes); - - final SyslogEvent event = parser.parseEvent(buffer, sender); - Assert.assertNotNull(event); - Assert.assertTrue(event.isValid()); - Assert.assertEquals(sender, event.getSender()); - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-bundle/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/pom.xml index caf1c3c..0a0952b 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/pom.xml +++ b/nifi-nar-bundles/nifi-standard-bundle/pom.xml @@ -380,11 +380,6 @@ <artifactId>avro</artifactId> <version>1.8.1</version> </dependency> - <dependency> - <groupId>com.github.palindromicity</groupId> - <artifactId>simple-syslog-5424</artifactId> - <version>0.0.5</version> - </dependency> </dependencies> </dependencyManagement> </project> http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services-nar/src/main/resources/META-INF/NOTICE ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services-nar/src/main/resources/META-INF/NOTICE b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services-nar/src/main/resources/META-INF/NOTICE index 5807ebb..0678d2c 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services-nar/src/main/resources/META-INF/NOTICE +++ b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services-nar/src/main/resources/META-INF/NOTICE @@ -77,4 +77,12 @@ The following binary components are provided under the Apache Software License v The following NOTICE information applies: Apache Avro Copyright 2009-2017 The Apache Software Foundation + + (ASLv2) simple-syslog-5424 + The following NOTICE information applies: + + simple-syslog-5424 + https://github.com/palindromicity/simple-syslog-5424 + + Copyright 2018 simple-syslog-5424 authors. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/b1022043/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/pom.xml b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/pom.xml index 7e5ddfc..30694b5 100755 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/pom.xml +++ b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/pom.xml @@ -47,6 +47,11 @@ <version>1.8.0-SNAPSHOT</version> </dependency> <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-syslog-utils</artifactId> + <version>1.8.0-SNAPSHOT</version> + </dependency> + <dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <version>2.4.0</version> @@ -145,6 +150,10 @@ <exclude>src/test/resources/json/output/dataTypes.json</exclude> <exclude>src/test/resources/json/elements-for-record-choice.json</exclude> <exclude>src/test/resources/json/record-choice.avsc</exclude> + <exclude>src/test/resources/syslog/syslog5424/log.txt</exclude> + <exclude>src/test/resources/syslog/syslog5424/log_all.txt</exclude> + <exclude>src/test/resources/syslog/syslog5424/log_mix.txt</exclude> + <exclude>src/test/resources/syslog/syslog5424/log_mix_in_error.txt</exclude> <exclude>src/test/resources/xml/people.xml</exclude> <exclude>src/test/resources/xml/people2.xml</exclude> <exclude>src/test/resources/xml/people3.xml</exclude>
