@Test(expected = RedisSerializerException.class) public void nullLogstashEventTest() throws RedisSerializerException { LogstashSerializer serializer = new LogstashSerializer(); serializer.convertToLogstashEvent(null); }
public LogstashEvent convertToLogstashEvent(Event event) throws RedisSerializerException { if (event == null) { throw new RedisSerializerException("Event cannot be null"); } LogstashEvent logstashEvent = new LogstashEvent(); final Map<String, String> headers = event.getHeaders(); logstashEvent.setMessage(new String(event.getBody())); for (Entry<String, String> entry : headers.entrySet()) { logstashEvent.putField(entry.getKey(), entry.getValue()); } String timestamp = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP))) { timestamp = headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP); } else if (StringUtils.isNotBlank(headers.get(TIMESTAMP))) { timestamp = headers.get(TIMESTAMP); } if (timestamp != null) { long timestampMs = Long.parseLong(timestamp); logstashEvent.setTimestamp(new Date(timestampMs)); } String source = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE))) { source = headers.get(LogstashConstant.ATTRIBUTE_SOURCE); } else if (StringUtils.isNotBlank(headers.get(SOURCE))) { source = headers.get(SOURCE); } if (source != null) { logstashEvent.setSource(source); } String host = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST))) { host = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST); } else if (StringUtils.isNotBlank(headers.get(HOST))) { host = headers.get(HOST); } if (host != null) { logstashEvent.setSourceHost(host); } String sourcePath = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH))) { sourcePath = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH); } else if (StringUtils.isNotBlank(headers.get(SRC_PATH))) { sourcePath = headers.get(SRC_PATH); } if (sourcePath != null) { logstashEvent.setSourcePath(sourcePath); } String type = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TYPE))) { type = headers.get(LogstashConstant.ATTRIBUTE_TYPE); } else if (StringUtils.isNotBlank(headers.get(TYPE))) { type = headers.get(TYPE); } if (type != null) { logstashEvent.setType(type); } String tags = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TAGS))) { tags = headers.get(LogstashConstant.ATTRIBUTE_TAGS); } else if (StringUtils.isNotBlank(headers.get(TAGS))) { tags = headers.get(TAGS); } if (StringUtils.isNotBlank(tags)) { String[] allTags = tags.split(tagsSeparator); List<String> tagsList = new ArrayList<String>(); for(String tag: allTags) { if(StringUtils.isNotBlank(tag)) { tagsList.add(tag); } } logstashEvent.setTags(tagsList); } return logstashEvent; }
LogstashSerializer implements Serializer { public LogstashEvent convertToLogstashEvent(Event event) throws RedisSerializerException { if (event == null) { throw new RedisSerializerException("Event cannot be null"); } LogstashEvent logstashEvent = new LogstashEvent(); final Map<String, String> headers = event.getHeaders(); logstashEvent.setMessage(new String(event.getBody())); for (Entry<String, String> entry : headers.entrySet()) { logstashEvent.putField(entry.getKey(), entry.getValue()); } String timestamp = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP))) { timestamp = headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP); } else if (StringUtils.isNotBlank(headers.get(TIMESTAMP))) { timestamp = headers.get(TIMESTAMP); } if (timestamp != null) { long timestampMs = Long.parseLong(timestamp); logstashEvent.setTimestamp(new Date(timestampMs)); } String source = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE))) { source = headers.get(LogstashConstant.ATTRIBUTE_SOURCE); } else if (StringUtils.isNotBlank(headers.get(SOURCE))) { source = headers.get(SOURCE); } if (source != null) { logstashEvent.setSource(source); } String host = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST))) { host = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST); } else if (StringUtils.isNotBlank(headers.get(HOST))) { host = headers.get(HOST); } if (host != null) { logstashEvent.setSourceHost(host); } String sourcePath = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH))) { sourcePath = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH); } else if (StringUtils.isNotBlank(headers.get(SRC_PATH))) { sourcePath = headers.get(SRC_PATH); } if (sourcePath != null) { logstashEvent.setSourcePath(sourcePath); } String type = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TYPE))) { type = headers.get(LogstashConstant.ATTRIBUTE_TYPE); } else if (StringUtils.isNotBlank(headers.get(TYPE))) { type = headers.get(TYPE); } if (type != null) { logstashEvent.setType(type); } String tags = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TAGS))) { tags = headers.get(LogstashConstant.ATTRIBUTE_TAGS); } else if (StringUtils.isNotBlank(headers.get(TAGS))) { tags = headers.get(TAGS); } if (StringUtils.isNotBlank(tags)) { String[] allTags = tags.split(tagsSeparator); List<String> tagsList = new ArrayList<String>(); for(String tag: allTags) { if(StringUtils.isNotBlank(tag)) { tagsList.add(tag); } } logstashEvent.setTags(tagsList); } return logstashEvent; } }
LogstashSerializer implements Serializer { public LogstashEvent convertToLogstashEvent(Event event) throws RedisSerializerException { if (event == null) { throw new RedisSerializerException("Event cannot be null"); } LogstashEvent logstashEvent = new LogstashEvent(); final Map<String, String> headers = event.getHeaders(); logstashEvent.setMessage(new String(event.getBody())); for (Entry<String, String> entry : headers.entrySet()) { logstashEvent.putField(entry.getKey(), entry.getValue()); } String timestamp = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP))) { timestamp = headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP); } else if (StringUtils.isNotBlank(headers.get(TIMESTAMP))) { timestamp = headers.get(TIMESTAMP); } if (timestamp != null) { long timestampMs = Long.parseLong(timestamp); logstashEvent.setTimestamp(new Date(timestampMs)); } String source = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE))) { source = headers.get(LogstashConstant.ATTRIBUTE_SOURCE); } else if (StringUtils.isNotBlank(headers.get(SOURCE))) { source = headers.get(SOURCE); } if (source != null) { logstashEvent.setSource(source); } String host = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST))) { host = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST); } else if (StringUtils.isNotBlank(headers.get(HOST))) { host = headers.get(HOST); } if (host != null) { logstashEvent.setSourceHost(host); } String sourcePath = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH))) { sourcePath = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH); } else if (StringUtils.isNotBlank(headers.get(SRC_PATH))) { sourcePath = headers.get(SRC_PATH); } if (sourcePath != null) { logstashEvent.setSourcePath(sourcePath); } String type = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TYPE))) { type = headers.get(LogstashConstant.ATTRIBUTE_TYPE); } else if (StringUtils.isNotBlank(headers.get(TYPE))) { type = headers.get(TYPE); } if (type != null) { logstashEvent.setType(type); } String tags = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TAGS))) { tags = headers.get(LogstashConstant.ATTRIBUTE_TAGS); } else if (StringUtils.isNotBlank(headers.get(TAGS))) { tags = headers.get(TAGS); } if (StringUtils.isNotBlank(tags)) { String[] allTags = tags.split(tagsSeparator); List<String> tagsList = new ArrayList<String>(); for(String tag: allTags) { if(StringUtils.isNotBlank(tag)) { tagsList.add(tag); } } logstashEvent.setTags(tagsList); } return logstashEvent; }  }
LogstashSerializer implements Serializer { public LogstashEvent convertToLogstashEvent(Event event) throws RedisSerializerException { if (event == null) { throw new RedisSerializerException("Event cannot be null"); } LogstashEvent logstashEvent = new LogstashEvent(); final Map<String, String> headers = event.getHeaders(); logstashEvent.setMessage(new String(event.getBody())); for (Entry<String, String> entry : headers.entrySet()) { logstashEvent.putField(entry.getKey(), entry.getValue()); } String timestamp = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP))) { timestamp = headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP); } else if (StringUtils.isNotBlank(headers.get(TIMESTAMP))) { timestamp = headers.get(TIMESTAMP); } if (timestamp != null) { long timestampMs = Long.parseLong(timestamp); logstashEvent.setTimestamp(new Date(timestampMs)); } String source = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE))) { source = headers.get(LogstashConstant.ATTRIBUTE_SOURCE); } else if (StringUtils.isNotBlank(headers.get(SOURCE))) { source = headers.get(SOURCE); } if (source != null) { logstashEvent.setSource(source); } String host = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST))) { host = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST); } else if (StringUtils.isNotBlank(headers.get(HOST))) { host = headers.get(HOST); } if (host != null) { logstashEvent.setSourceHost(host); } String sourcePath = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH))) { sourcePath = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH); } else if (StringUtils.isNotBlank(headers.get(SRC_PATH))) { sourcePath = headers.get(SRC_PATH); } if (sourcePath != null) { logstashEvent.setSourcePath(sourcePath); } String type = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TYPE))) { type = headers.get(LogstashConstant.ATTRIBUTE_TYPE); } else if (StringUtils.isNotBlank(headers.get(TYPE))) { type = headers.get(TYPE); } if (type != null) { logstashEvent.setType(type); } String tags = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TAGS))) { tags = headers.get(LogstashConstant.ATTRIBUTE_TAGS); } else if (StringUtils.isNotBlank(headers.get(TAGS))) { tags = headers.get(TAGS); } if (StringUtils.isNotBlank(tags)) { String[] allTags = tags.split(tagsSeparator); List<String> tagsList = new ArrayList<String>(); for(String tag: allTags) { if(StringUtils.isNotBlank(tag)) { tagsList.add(tag); } } logstashEvent.setTags(tagsList); } return logstashEvent; }  void configure(Context context); void configure(ComponentConfiguration conf); LogstashEvent convertToLogstashEvent(Event event); byte[] serialize(Event event); }
LogstashSerializer implements Serializer { public LogstashEvent convertToLogstashEvent(Event event) throws RedisSerializerException { if (event == null) { throw new RedisSerializerException("Event cannot be null"); } LogstashEvent logstashEvent = new LogstashEvent(); final Map<String, String> headers = event.getHeaders(); logstashEvent.setMessage(new String(event.getBody())); for (Entry<String, String> entry : headers.entrySet()) { logstashEvent.putField(entry.getKey(), entry.getValue()); } String timestamp = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP))) { timestamp = headers.get(LogstashConstant.ATTRIBUTE_AT_TIMESTAMP); } else if (StringUtils.isNotBlank(headers.get(TIMESTAMP))) { timestamp = headers.get(TIMESTAMP); } if (timestamp != null) { long timestampMs = Long.parseLong(timestamp); logstashEvent.setTimestamp(new Date(timestampMs)); } String source = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE))) { source = headers.get(LogstashConstant.ATTRIBUTE_SOURCE); } else if (StringUtils.isNotBlank(headers.get(SOURCE))) { source = headers.get(SOURCE); } if (source != null) { logstashEvent.setSource(source); } String host = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST))) { host = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_HOST); } else if (StringUtils.isNotBlank(headers.get(HOST))) { host = headers.get(HOST); } if (host != null) { logstashEvent.setSourceHost(host); } String sourcePath = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH))) { sourcePath = headers.get(LogstashConstant.ATTRIBUTE_SOURCE_PATH); } else if (StringUtils.isNotBlank(headers.get(SRC_PATH))) { sourcePath = headers.get(SRC_PATH); } if (sourcePath != null) { logstashEvent.setSourcePath(sourcePath); } String type = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TYPE))) { type = headers.get(LogstashConstant.ATTRIBUTE_TYPE); } else if (StringUtils.isNotBlank(headers.get(TYPE))) { type = headers.get(TYPE); } if (type != null) { logstashEvent.setType(type); } String tags = null; if (StringUtils.isNotBlank(headers.get(LogstashConstant.ATTRIBUTE_TAGS))) { tags = headers.get(LogstashConstant.ATTRIBUTE_TAGS); } else if (StringUtils.isNotBlank(headers.get(TAGS))) { tags = headers.get(TAGS); } if (StringUtils.isNotBlank(tags)) { String[] allTags = tags.split(tagsSeparator); List<String> tagsList = new ArrayList<String>(); for(String tag: allTags) { if(StringUtils.isNotBlank(tag)) { tagsList.add(tag); } } logstashEvent.setTags(tagsList); } return logstashEvent; }  void configure(Context context); void configure(ComponentConfiguration conf); LogstashEvent convertToLogstashEvent(Event event); byte[] serialize(Event event); static final String CONFIGURATION_TAGS_SEPARATOR; static final String HOST; static final String SOURCE; static final String SRC_PATH; static final String TIMESTAMP; static final String TYPE; static final String TAGS; static final String DEFAULT_TAGS_SEPARATOR; }