BasicLancopeParser extends BasicParser { @Override public List<JSONObject> parse(byte[] msg) { JSONObject payload = null; List<JSONObject> messages = new ArrayList<>(); try { String raw_message = new String(msg, getReadCharset()); payload = (JSONObject) JSONValue.parse(raw_message); String message = payload.get("message").toString(); String[] parts = message.split(" "); payload.put("ip_src_addr", parts[6]); payload.put("ip_dst_addr", parts[7]); String fixed_date = parts[5].replace('T', ' '); fixed_date = fixed_date.replace('Z', ' ').trim(); SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Date date; date = formatter.parse(fixed_date); long timestamp = date.getTime(); payload.put("timestamp", timestamp); payload.remove("@timestamp"); payload.remove("message"); payload.put("original_string", message); messages.add(payload); return messages; } catch (Exception e) { _LOG.error("Unable to parse message: {}", payload.toJSONString()); return null; } }  @Override void configure(Map<String, Object> parserConfig); @Override void init(); @Override List<JSONObject> parse(byte[] msg);  }
@Test public void testParse() throws ParseException, IOException, ProcessingException { for (String inputString : inputStrings) { JSONObject parsed = parser.parse(inputString.getBytes(StandardCharsets.UTF_8)).get(0); assertNotNull(parsed); JSONParser parser = new JSONParser(); Map<?, ?> json = (Map<?, ?>) parser.parse(parsed.toJSONString()); assertTrue(validateJsonData(getSchemaJsonString(), json.toString())); } }