diff options
Diffstat (limited to 'examples/py-flow-dashboard/flow-dash.py')
-rwxr-xr-x | examples/py-flow-dashboard/flow-dash.py | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/examples/py-flow-dashboard/flow-dash.py b/examples/py-flow-dashboard/flow-dash.py index e3ac0776d..2e3ea3dcf 100755 --- a/examples/py-flow-dashboard/flow-dash.py +++ b/examples/py-flow-dashboard/flow-dash.py @@ -24,6 +24,11 @@ def nDPIsrvd_worker_onFlowCleanup(instance, current_flow, global_user_data): shared_flow_dict['current-flows'] -= 1 + if flow_id not in shared_flow_dict: + return True + + shared_flow_dict['total-l4-bytes'] += shared_flow_dict[flow_id]['total-l4-bytes'] + if shared_flow_dict[flow_id]['is_detected'] is True: shared_flow_dict['current-detected-flows'] -= 1 @@ -47,7 +52,7 @@ def nDPIsrvd_worker_onJsonLineRecvd(json_dict, instance, current_flow, global_us nsock, shared_flow_dict = global_user_data shared_flow_dict['total-events'] += 1 - shared_flow_dict['total-bytes'] = nsock.received_bytes + shared_flow_dict['total-json-bytes'] = nsock.received_bytes if 'basic_event_name' in json_dict: shared_flow_dict['total-base-events'] += 1 @@ -74,10 +79,14 @@ def nDPIsrvd_worker_onJsonLineRecvd(json_dict, instance, current_flow, global_us shared_flow_dict[flow_id]['is_not_detected'] = False shared_flow_dict[flow_id]['is_midstream'] = False shared_flow_dict[flow_id]['is_risky'] = False + shared_flow_dict[flow_id]['total-l4-bytes'] = 0 shared_flow_dict['total-flows'] += 1 shared_flow_dict['current-flows'] += 1 + if 'flow_tot_l4_payload_len' in json_dict: + shared_flow_dict[flow_id]['total-l4-bytes'] = json_dict['flow_tot_l4_payload_len'] + if 'midstream' in json_dict and json_dict['midstream'] != 0: if shared_flow_dict[flow_id]['is_midstream'] is False: shared_flow_dict['total-midstream-flows'] += 1 @@ -93,6 +102,13 @@ def nDPIsrvd_worker_onJsonLineRecvd(json_dict, instance, current_flow, global_us if 'flow_event_name' not in json_dict: return True + if json_dict['flow_state'] == 'finished' and \ + json_dict['ndpi']['proto'] != 'Unknown' and \ + shared_flow_dict[flow_id]['is_detected'] is False: + shared_flow_dict['total-detected-flows'] += 1 + shared_flow_dict['current-detected-flows'] += 1 + shared_flow_dict[flow_id]['is_detected'] = True + if json_dict['flow_event_name'] == 'new': shared_flow_dict['total-flow-new-events'] += 1 @@ -155,11 +171,20 @@ def nDPIsrvd_worker(address, shared_flow_dict): .format(address[0]+':'+str(address[1]) if type(address) is tuple else address)) - nsock = nDPIsrvdSocket() - nsock.connect(address) - nsock.loop(nDPIsrvd_worker_onJsonLineRecvd, - nDPIsrvd_worker_onFlowCleanup, - (nsock, shared_flow_dict)) + try: + while True: + try: + nsock = nDPIsrvdSocket() + nsock.connect(address) + nsock.loop(nDPIsrvd_worker_onJsonLineRecvd, + nDPIsrvd_worker_onFlowCleanup, + (nsock, shared_flow_dict)) + except nDPIsrvd.SocketConnectionBroken: + sys.stderr.write('Lost connection to {} .. reconnecting\n' + .format(address[0]+':'+str(address[1]) + if type(address) is tuple else address)) + except KeyboardInterrupt: + pass if __name__ == '__main__': @@ -185,7 +210,8 @@ if __name__ == '__main__': shared_flow_dict['total-base-events'] = 0 shared_flow_dict['total-daemon-events'] = 0 - shared_flow_dict['total-bytes'] = 0 + shared_flow_dict['total-json-bytes'] = 0 + shared_flow_dict['total-l4-bytes'] = 0 shared_flow_dict['total-flows'] = 0 shared_flow_dict['total-detected-flows'] = 0 shared_flow_dict['total-risky-flows'] = 0 |