diff --git a/jc/parsers/last.py b/jc/parsers/last.py index 5f1fc202..69202212 100644 --- a/jc/parsers/last.py +++ b/jc/parsers/last.py @@ -203,7 +203,8 @@ def parse(data, raw=False, quiet=False): if len(linedata) > 14: output_line['duration'] = linedata[14].replace('(', '').replace(')', '') - + + # normal last support else: output_line['login'] = ' '.join(linedata[3:7]) diff --git a/tests/fixtures/ubuntu-20.04/last-F.json b/tests/fixtures/ubuntu-20.04/last-F.json new file mode 100644 index 00000000..c866e968 --- /dev/null +++ b/tests/fixtures/ubuntu-20.04/last-F.json @@ -0,0 +1 @@ +[{"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Tue Jan 5 20:03:51 2021", "logout": "still logged in"}, {"user": "kbrazil", "tty": "pts/0", "hostname": "192.168.71.1", "login": "Tue Jan 5 00:17:29 2021", "logout": "Tue Jan 5 20:03:47 2021", "duration": "19:46"}, {"user": "kbrazil", "tty": "tty1", "hostname": null, "login": "Tue Jan 5 00:08:46 2021", "logout": "gone - no logout"}, {"user": "reboot", "tty": "system boot", "hostname": "5.8.0-34-generic", "login": "Tue Jan 5 00:08:28 2021", "logout": "running"}] diff --git a/tests/test_last.py b/tests/test_last.py index 048d9b06..4aca472d 100644 --- a/tests/test_last.py +++ b/tests/test_last.py @@ -37,6 +37,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/last.out'), 'r', encoding='utf-8') as f: self.freebsd12_last = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/last-F.out'), 'r', encoding='utf-8') as f: + self.ubuntu_20_4_last_F = f.read() + # output with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/last.json'), 'r', encoding='utf-8') as f: self.centos_7_7_last_json = json.loads(f.read()) @@ -65,6 +68,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/last.json'), 'r', encoding='utf-8') as f: self.freebsd12_last_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/last-F.json'), 'r', encoding='utf-8') as f: + self.ubuntu_20_4_last_F_json = json.loads(f.read()) + def test_last_nodata(self): """ Test plain 'last' with no data @@ -113,6 +119,12 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.last.parse(self.ubuntu_18_4_last_w, quiet=True), self.ubuntu_18_4_last_w_json) + def test_last_F_ubuntu_20_4(self): + """ + Test 'last -F' on Ubuntu 20.4 + """ + self.assertEqual(jc.parsers.last.parse(self.ubuntu_20_4_last_F, quiet=True), self.ubuntu_20_4_last_F_json) + def test_last_fedora32(self): """ Test plain 'last' on Fedora32