aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2023-11-24 10:41:26 +0100
committerToni Uhlig <matzeton@googlemail.com>2023-12-01 06:43:39 +0100
commitd274a06176156b6eb8b1523375f94cbe5ecbbab7 (patch)
tree23dceb5600be76fdb48d01e805e245955f622b45
parenta5dcc1739616f9fe1cda6bd1dea06c30f07dcdcf (diff)
flow-info.py: Do not print any information if a flow is "empty" meaning no L4 payload seen so far.
* added JsonDecodeError to provide more information if builtin JSON decoder fails Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--dependencies/nDPIsrvd.py11
-rwxr-xr-xexamples/py-flow-info/flow-info.py7
2 files changed, 17 insertions, 1 deletions
diff --git a/dependencies/nDPIsrvd.py b/dependencies/nDPIsrvd.py
index 8e14aa47d..841971c3c 100644
--- a/dependencies/nDPIsrvd.py
+++ b/dependencies/nDPIsrvd.py
@@ -295,6 +295,7 @@ class nDPIsrvdException(Exception):
INVALID_LINE_RECEIVED = 4
CALLBACK_RETURNED_FALSE = 5
SOCKET_TIMEOUT = 6
+ JSON_DECODE_ERROR = 7
def __init__(self, etype):
self.etype = etype
@@ -341,6 +342,14 @@ class SocketTimeout(nDPIsrvdException):
def __str__(self):
return 'Socket timeout.'
+class JsonDecodeError(nDPIsrvdException):
+ def __init__(self, json_exception, failed_line):
+ super().__init__(nDPIsrvdException.JSON_DECODE_ERROR)
+ self.json_exception = json_exception
+ self.failed_line = failed_line
+ def __str__(self):
+ return '{}: {}'.format(self.json_exception, self.failed_line)
+
class JsonFilter():
def __init__(self, filter_string):
self.filter_string = filter_string
@@ -456,7 +465,7 @@ class nDPIsrvdSocket:
json_dict = dict()
self.failed_lines += [received_line]
self.lines = self.lines[1:]
- raise(e)
+ raise JsonDecodeError(e, received_line)
instance = self.flow_mgr.getInstance(json_dict)
if instance is None:
diff --git a/examples/py-flow-info/flow-info.py b/examples/py-flow-info/flow-info.py
index f905231e4..99eadb9ac 100755
--- a/examples/py-flow-info/flow-info.py
+++ b/examples/py-flow-info/flow-info.py
@@ -498,6 +498,11 @@ def onJsonLineRecvd(json_dict, instance, current_flow, global_user_data):
if args.print_hostname is True:
line_suffix += '[{}]'.format(json_dict['ndpi']['hostname'])
+ if args.skip_empty is True:
+ if json_dict['flow_src_tot_l4_payload_len'] == 0 or json_dict['flow_dst_tot_l4_payload_len'] == 0:
+ stats.printStatus()
+ return True
+
if args.print_bytes is True:
src_color = ''
dst_color = ''
@@ -566,6 +571,8 @@ if __name__ == '__main__':
help='Print received/transmitted source/dest bytes for every flow.')
argparser.add_argument('--print-packets', action='store_true', default=False,
help='Print received/transmitted source/dest packets for every flow.')
+ argparser.add_argument('--skip-empty', action='store_true', default=False,
+ help='Do not print flows that did not carry any layer7 payload.')
argparser.add_argument('--guessed', action='store_true', default=False, help='Print only guessed flow events.')
argparser.add_argument('--not-detected', action='store_true', default=False, help='Print only undetected flow events.')
argparser.add_argument('--detected', action='store_true', default=False, help='Print only detected flow events.')