From cb80c415d8a20b03f0d6a8f2fc38e8c8250a04da Mon Sep 17 00:00:00 2001
From: Toni Uhlig <matzeton@googlemail.com>
Date: Sat, 5 Feb 2022 15:09:21 +0100
Subject: Improved py-flow-info to provide more optional information about
 received timestamps.

 * py-flow-dashboard: Added color mapping for PieCharts/Graph that make more sense
 * nDPId: Renamed `flow_type' to a more precisely `flow_state'
 * nDPId: Changed the default setting to process only as much packets as libnDPI does

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
---
 examples/py-flow-dashboard/flow-dash.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

(limited to 'examples/py-flow-dashboard/flow-dash.py')

diff --git a/examples/py-flow-dashboard/flow-dash.py b/examples/py-flow-dashboard/flow-dash.py
index 2e3ea3dcf..947f5b48c 100755
--- a/examples/py-flow-dashboard/flow-dash.py
+++ b/examples/py-flow-dashboard/flow-dash.py
@@ -81,6 +81,8 @@ def nDPIsrvd_worker_onJsonLineRecvd(json_dict, instance, current_flow, global_us
         shared_flow_dict[flow_id]['is_risky']        = False
         shared_flow_dict[flow_id]['total-l4-bytes']  = 0
 
+        shared_flow_dict[flow_id]['json'] = mgr.dict()
+
         shared_flow_dict['total-flows']   += 1
         shared_flow_dict['current-flows'] += 1
 
@@ -93,11 +95,15 @@ def nDPIsrvd_worker_onJsonLineRecvd(json_dict, instance, current_flow, global_us
             shared_flow_dict['current-midstream-flows'] += 1
         shared_flow_dict[flow_id]['is_midstream'] = True
 
-    if 'ndpi' in json_dict and 'flow_risk' in json_dict['ndpi']:
-        if shared_flow_dict[flow_id]['is_risky'] is False:
-            shared_flow_dict['total-risky-flows']   += 1
-            shared_flow_dict['current-risky-flows'] += 1
-        shared_flow_dict[flow_id]['is_risky'] = True
+    if 'ndpi' in json_dict:
+        # XXX: Will make use of that JSON string in Plotly. Soon..
+        shared_flow_dict[flow_id]['json']['ndpi'] = json_dict['ndpi']
+
+        if 'flow_risk' in json_dict['ndpi']:
+            if shared_flow_dict[flow_id]['is_risky'] is False:
+                shared_flow_dict['total-risky-flows']   += 1
+                shared_flow_dict['current-risky-flows'] += 1
+            shared_flow_dict[flow_id]['is_risky'] = True
 
     if 'flow_event_name' not in json_dict:
         return True
-- 
cgit v1.2.3