package tcpdumpAnalyzer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.Scanner; public class TcpDumpAnalyzer { public static void main(String[] args) { Scanner scanner = new Scanner(new java.io.BufferedInputStream(System.in), "UTF-8"); long lineNumber = 1; long startTime = 0; long acumulatedBytes = 0; long acumulationLimitPerInterval=10000; int interval = Integer.parseInt(args[0]); while (scanner.hasNextLine()) { String line = scanner.nextLine(); String time = line.substring(0, 8); String hour = line.substring(0, 2); String min = line.substring(3, 5); String sec = line.substring(6, 8); //System.out.println(time + " hour:"+hour+" min:"+min+" sec:"+sec); long totalSeconds = Integer.parseInt(hour) * 60 * 60 + Integer.parseInt(min) * 60 + Integer.parseInt(sec); if (lineNumber == 1) { System.out.println("Time,Bytes"); startTime = totalSeconds; } if (line.contains("length")) { // System.out.println(line.substring(line.indexOf("length")) +"valor:"+ // line.substring(line.indexOf("length")).substring(7)); String lengthString=line.substring(line.indexOf("length")).substring(7); long bytes=0; if(!lengthString.contains(":")) { bytes = Long.parseLong(lengthString); }else { bytes = Long.parseLong(lengthString.substring(0,lengthString.indexOf(":"))); } acumulatedBytes += bytes; if (acumulatedBytes > acumulationLimitPerInterval) { //Your alert code here. For example perform a request to an endpoint using a Java Client //or use a JVM queue to trigger an event on another process //It can be used to trigger a flow of a Mule Application //The following is an example with http request try { URL url = new URL("http://localhost:8081?parameter1=value1¶meter2=value2"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); int status = con.getResponseCode(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } System.out.println("Status: "+status + " response: " + inputLine); in.close(); con.disconnect(); } catch (IOException e) { System.out.println("ERROR sending ALERT request"); } } //System.out.println((totalSeconds - startTime)+" seconds passed so far "+acumulatedBytes+" bytes acumulated"); if ((totalSeconds - startTime) > interval) { System.out.println(time + "," + String.valueOf(acumulatedBytes)); acumulatedBytes = 0; startTime = totalSeconds; } } lineNumber++; } scanner.close(); } }