changeset 985:ed255da90ec3

PcapSessionEventSource - MySql integration
author Devel 2
date Mon, 19 Aug 2019 10:24:58 +0200
parents bbb1dfc08cdb
children 2fc3f6154913
files stress-tester/src/main/java/com/passus/st/source/PcapMySqlListener.java stress-tester/src/main/java/com/passus/st/source/PcapMySqlSessionAnalyzerHook.java stress-tester/src/main/java/com/passus/st/source/PcapPgSqlListener.java stress-tester/src/main/java/com/passus/st/source/PcapPgSqlSessionAnalyzerHook.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java
diffstat 5 files changed, 56 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/source/PcapMySqlListener.java	Mon Aug 19 10:24:58 2019 +0200
@@ -0,0 +1,24 @@
+package com.passus.st.source;
+
+import com.passus.net.mysql.MySqlPacket;
+import com.passus.net.session.SessionContext;
+import com.passus.st.client.EventHandler;
+
+import static com.passus.st.Protocols.MYSQL;
+
+public class PcapMySqlListener extends BaseSessionAnalyzerListener<MySqlPacket> {
+
+    public PcapMySqlListener(String sourceName, EventHandler eventHandler,
+                             boolean collectMetric, PcapSessionEventSourceMetric metric) {
+        super(sourceName, eventHandler, collectMetric, metric, MYSQL);
+    }
+
+    @Override
+    public void onMessageReceived(SessionContext context, MySqlPacket msg, long timestamp) {
+        //Nie przetwarzamy odpowiedzi
+        if (!msg.isRequest()) {
+            firePayloadEvent(msg, null, context, timestamp);
+        }
+    }
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/source/PcapMySqlSessionAnalyzerHook.java	Mon Aug 19 10:24:58 2019 +0200
@@ -0,0 +1,29 @@
+package com.passus.st.source;
+
+import com.passus.net.mysql.MySqlTcpSessionAnalyzer;
+import com.passus.net.session.SessionAnalyzer;
+
+public class PcapMySqlSessionAnalyzerHook extends PcapSessionAnalyzerHook {
+
+    @Override
+    public boolean supports(Class<? extends SessionAnalyzer> clazz) {
+        return MySqlTcpSessionAnalyzer.class.isAssignableFrom(clazz);
+    }
+
+    @Override
+    protected void doAttach(SessionAnalyzer analyzer, PcapSessionAnalyzerHookContext context) {
+        PcapMySqlListener listener = new PcapMySqlListener(context.getSourceName(),
+                context.getEventHandler(),
+                context.isCollectMetric(),
+                context.getMetric());
+        analyzer.setListener(listener);
+        context.getTcpProcessor().addAnalyzer(analyzer);
+    }
+
+    @Override
+    protected void doDetach(SessionAnalyzer analyzer, PcapSessionAnalyzerHookContext context) {
+        analyzer.setListener(null);
+        context.getTcpProcessor().removeAnalyzer(analyzer);
+    }
+
+}
--- a/stress-tester/src/main/java/com/passus/st/source/PcapPgSqlListener.java	Fri Aug 16 14:22:13 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/source/PcapPgSqlListener.java	Mon Aug 19 10:24:58 2019 +0200
@@ -9,7 +9,7 @@
 public class PcapPgSqlListener extends BaseSessionAnalyzerListener<PgSqlMessage> {
 
     public PcapPgSqlListener(String sourceName, EventHandler eventHandler,
-                             boolean collectMetric, PcapSessionEventSourceMetric metric, int maxSessionNum) {
+                             boolean collectMetric, PcapSessionEventSourceMetric metric) {
         super(sourceName, eventHandler, collectMetric, metric, PGSQL);
     }
 
--- a/stress-tester/src/main/java/com/passus/st/source/PcapPgSqlSessionAnalyzerHook.java	Fri Aug 16 14:22:13 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/source/PcapPgSqlSessionAnalyzerHook.java	Mon Aug 19 10:24:58 2019 +0200
@@ -15,10 +15,8 @@
         PcapPgSqlListener listener = new PcapPgSqlListener(context.getSourceName(),
                 context.getEventHandler(),
                 context.isCollectMetric(),
-                context.getMetric(),
-                context.getTcpProcessor().getMaxSessionNumber());
+                context.getMetric());
         analyzer.setListener(listener);
-
         context.getTcpProcessor().addAnalyzer(analyzer);
     }
 
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java	Fri Aug 16 14:22:13 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java	Mon Aug 19 10:24:58 2019 +0200
@@ -84,6 +84,7 @@
         hooks.add(new PcapDnsSessionAnalyzerHook());
         hooks.add(new PcapNetflowSessionAnalyzerHook());
         hooks.add(new PcapPgSqlSessionAnalyzerHook());
+        hooks.add(new PcapMySqlSessionAnalyzerHook());
 
         analyzers.add(new HttpSessionAnalyzer());
     }