@Test public void testRecordParsingInvalid() { String val = "2 123456789101 eni-g123abcd 100.100.10.2 50.90.30.21 43895 443 6 13 1836 1469126675 1469126733 RE OK"; try { VPCFlowLogParser.parseToRecord(val); fail("Should throw an exception and not pass"); } catch (InterceptException e) { } }
public static void parseToRecord(Map<String, Object> map, String line) throws InterceptException { Matcher matcher = FLOW_RECORD_PATTERN.matcher(line); if (matcher.matches()) { try { map.put(VERSION, Short.parseShort(matcher.group(1))); map.put(ACCOUNT_ID, matcher.group(2)); map.put(INTERFACE_ID, matcher.group(3)); if (matcher.group(14).charAt(0) == STATUS_CODE_ZERO) { map.put(SRCADDR, matcher.group(4)); map.put(DSTADDR, matcher.group(5)); map.put(SRCPORT, Integer.parseInt(matcher.group(6))); map.put(DSTPORT, Integer.parseInt(matcher.group(7))); map.put(PROTOCOL, matcher.group(8).charAt(0)); map.put(PACKETS, Integer.parseInt(matcher.group(9))); map.put(BYTES, Integer.parseInt(matcher.group(10))); } map.put(START, Integer.parseInt(matcher.group(11))); map.put(END, Integer.parseInt(matcher.group(12))); map.put(ACCEPTED, matcher.group(13).equals(ACCEPT)); map.put(LOG_STATUS, (byte) matcher.group(14).charAt(0)); } catch (Exception e) { throw new InterceptException(e); } } else { throw new InterceptException("Line doesn't match flow record:" + line); } }
VPCFlowLogParser { public static void parseToRecord(Map<String, Object> map, String line) throws InterceptException { Matcher matcher = FLOW_RECORD_PATTERN.matcher(line); if (matcher.matches()) { try { map.put(VERSION, Short.parseShort(matcher.group(1))); map.put(ACCOUNT_ID, matcher.group(2)); map.put(INTERFACE_ID, matcher.group(3)); if (matcher.group(14).charAt(0) == STATUS_CODE_ZERO) { map.put(SRCADDR, matcher.group(4)); map.put(DSTADDR, matcher.group(5)); map.put(SRCPORT, Integer.parseInt(matcher.group(6))); map.put(DSTPORT, Integer.parseInt(matcher.group(7))); map.put(PROTOCOL, matcher.group(8).charAt(0)); map.put(PACKETS, Integer.parseInt(matcher.group(9))); map.put(BYTES, Integer.parseInt(matcher.group(10))); } map.put(START, Integer.parseInt(matcher.group(11))); map.put(END, Integer.parseInt(matcher.group(12))); map.put(ACCEPTED, matcher.group(13).equals(ACCEPT)); map.put(LOG_STATUS, (byte) matcher.group(14).charAt(0)); } catch (Exception e) { throw new InterceptException(e); } } else { throw new InterceptException("Line doesn't match flow record:" + line); } } }
VPCFlowLogParser { public static void parseToRecord(Map<String, Object> map, String line) throws InterceptException { Matcher matcher = FLOW_RECORD_PATTERN.matcher(line); if (matcher.matches()) { try { map.put(VERSION, Short.parseShort(matcher.group(1))); map.put(ACCOUNT_ID, matcher.group(2)); map.put(INTERFACE_ID, matcher.group(3)); if (matcher.group(14).charAt(0) == STATUS_CODE_ZERO) { map.put(SRCADDR, matcher.group(4)); map.put(DSTADDR, matcher.group(5)); map.put(SRCPORT, Integer.parseInt(matcher.group(6))); map.put(DSTPORT, Integer.parseInt(matcher.group(7))); map.put(PROTOCOL, matcher.group(8).charAt(0)); map.put(PACKETS, Integer.parseInt(matcher.group(9))); map.put(BYTES, Integer.parseInt(matcher.group(10))); } map.put(START, Integer.parseInt(matcher.group(11))); map.put(END, Integer.parseInt(matcher.group(12))); map.put(ACCEPTED, matcher.group(13).equals(ACCEPT)); map.put(LOG_STATUS, (byte) matcher.group(14).charAt(0)); } catch (Exception e) { throw new InterceptException(e); } } else { throw new InterceptException("Line doesn't match flow record:" + line); } } VPCFlowLogParser(); }
VPCFlowLogParser { public static void parseToRecord(Map<String, Object> map, String line) throws InterceptException { Matcher matcher = FLOW_RECORD_PATTERN.matcher(line); if (matcher.matches()) { try { map.put(VERSION, Short.parseShort(matcher.group(1))); map.put(ACCOUNT_ID, matcher.group(2)); map.put(INTERFACE_ID, matcher.group(3)); if (matcher.group(14).charAt(0) == STATUS_CODE_ZERO) { map.put(SRCADDR, matcher.group(4)); map.put(DSTADDR, matcher.group(5)); map.put(SRCPORT, Integer.parseInt(matcher.group(6))); map.put(DSTPORT, Integer.parseInt(matcher.group(7))); map.put(PROTOCOL, matcher.group(8).charAt(0)); map.put(PACKETS, Integer.parseInt(matcher.group(9))); map.put(BYTES, Integer.parseInt(matcher.group(10))); } map.put(START, Integer.parseInt(matcher.group(11))); map.put(END, Integer.parseInt(matcher.group(12))); map.put(ACCEPTED, matcher.group(13).equals(ACCEPT)); map.put(LOG_STATUS, (byte) matcher.group(14).charAt(0)); } catch (Exception e) { throw new InterceptException(e); } } else { throw new InterceptException("Line doesn't match flow record:" + line); } } VPCFlowLogParser(); List<Map<String, Object>> parseFlowLogMap(String json); static void parseToRecord(Map<String, Object> map, String line); List<Event> parseFlowLogJson(EventFactory factory, String json); static void parseToRecord(Event event, String line); static VPCFlowLogRecord parseToRecord(String line); }
VPCFlowLogParser { public static void parseToRecord(Map<String, Object> map, String line) throws InterceptException { Matcher matcher = FLOW_RECORD_PATTERN.matcher(line); if (matcher.matches()) { try { map.put(VERSION, Short.parseShort(matcher.group(1))); map.put(ACCOUNT_ID, matcher.group(2)); map.put(INTERFACE_ID, matcher.group(3)); if (matcher.group(14).charAt(0) == STATUS_CODE_ZERO) { map.put(SRCADDR, matcher.group(4)); map.put(DSTADDR, matcher.group(5)); map.put(SRCPORT, Integer.parseInt(matcher.group(6))); map.put(DSTPORT, Integer.parseInt(matcher.group(7))); map.put(PROTOCOL, matcher.group(8).charAt(0)); map.put(PACKETS, Integer.parseInt(matcher.group(9))); map.put(BYTES, Integer.parseInt(matcher.group(10))); } map.put(START, Integer.parseInt(matcher.group(11))); map.put(END, Integer.parseInt(matcher.group(12))); map.put(ACCEPTED, matcher.group(13).equals(ACCEPT)); map.put(LOG_STATUS, (byte) matcher.group(14).charAt(0)); } catch (Exception e) { throw new InterceptException(e); } } else { throw new InterceptException("Line doesn't match flow record:" + line); } } VPCFlowLogParser(); List<Map<String, Object>> parseFlowLogMap(String json); static void parseToRecord(Map<String, Object> map, String line); List<Event> parseFlowLogJson(EventFactory factory, String json); static void parseToRecord(Event event, String line); static VPCFlowLogRecord parseToRecord(String line);  }