From f9982a79474c1838f37fc0ff88437980b228d7a1 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sun, 1 Mar 2020 16:49:52 -0800 Subject: [PATCH] fixes for from and comment fields --- jc/parsers/who.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jc/parsers/who.py b/jc/parsers/who.py index 1a779c26..38baa229 100644 --- a/jc/parsers/who.py +++ b/jc/parsers/who.py @@ -149,6 +149,11 @@ def parse(data, raw=False, quiet=False): output_line['time'] = ' '.join([linedata.pop(0), linedata.pop(0)]) + # if just one more field, then it's the remote IP + if len(linedata) == 1: + output_line['from'] = linedata[0].replace('(', '').replace(')', '') + continue + # extended info: idle if len(linedata) > 0: output_line['idle'] = linedata.pop(0) @@ -157,8 +162,12 @@ def parse(data, raw=False, quiet=False): if len(linedata) > 0: output_line['pid'] = linedata.pop(0) - # extended info: comment - if len(linedata) > 0: + # extended info is from + if len(linedata) > 0 and linedata[0].startswith('('): + output_line['from'] = linedata[0].replace('(', '').replace(')', '') + + # else, extended info is comment + elif len(linedata) > 0: output_line['comment'] = ' '.join(linedata) raw_output.append(output_line)