mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-12-18 00:18:28 +02:00
Fix for who output containing process name #663
This commit is contained in:
@@ -1,14 +1,16 @@
|
|||||||
jc changelog
|
jc changelog
|
||||||
|
|
||||||
20250904 v1.25.6
|
20250908 v1.25.6
|
||||||
- Add `net-localgroup` Windows command parser
|
- Add `net-localgroup` Windows command parser
|
||||||
- Add `net-user` Windows command parser
|
- Add `net-user` Windows command parser
|
||||||
- Add `route-print` Windows command parser
|
- Add `route-print` Windows command parser
|
||||||
- Add `x509-crl` file parser to support Certificate Revocation List PEM and DER files
|
- Add `x509-crl` file parser to support Certificate Revocation List PEM and DER files
|
||||||
|
- Add `yay` as a magic command for the `pacman` command parser
|
||||||
- Fix `bluetoothctl` command parser to support output with the `cable_pairing` attribute
|
- Fix `bluetoothctl` command parser to support output with the `cable_pairing` attribute
|
||||||
- Fix `nmcli` command parser to support blank `team.config` JSON value and `team-port.config` JSON value
|
- Fix `nmcli` command parser to support blank `team.config` JSON value and `team-port.config` JSON value
|
||||||
- Fix `top` command parsers to correct memory size field parsing. Several new unit
|
- Fix `top` command parsers to correct memory size field parsing. Several new unit
|
||||||
and byte conversion fields have been added
|
and byte conversion fields have been added
|
||||||
|
- Fix `who` command parser to support the `process` field on Debian13
|
||||||
|
|
||||||
20250503 v1.25.5
|
20250503 v1.25.5
|
||||||
- Add `amixer` command parser
|
- Add `amixer` command parser
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ Schema:
|
|||||||
"user": string,
|
"user": string,
|
||||||
"event": string,
|
"event": string,
|
||||||
"writeable_tty": string,
|
"writeable_tty": string,
|
||||||
|
"process": string,
|
||||||
"tty": string,
|
"tty": string,
|
||||||
"time": string,
|
"time": string,
|
||||||
"epoch": integer, # [0]
|
"epoch": integer, # [0]
|
||||||
@@ -136,7 +137,7 @@ import jc.utils
|
|||||||
|
|
||||||
class info():
|
class info():
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
version = '1.8'
|
version = '1.9'
|
||||||
description = '`who` command parser'
|
description = '`who` command parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
@@ -254,6 +255,12 @@ def parse(data, raw=False, quiet=False):
|
|||||||
raw_output.append(output_line)
|
raw_output.append(output_line)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# some output contains process name between the username and pts
|
||||||
|
# pull the process name for use later if we can find it
|
||||||
|
user_process = None
|
||||||
|
if re.match(r'^\S+\s+[^ +-]+\s+pts\/\d+\s', line):
|
||||||
|
user_process = linedata.pop(1)
|
||||||
|
|
||||||
# user logins
|
# user logins
|
||||||
output_line['user'] = linedata.pop(0)
|
output_line['user'] = linedata.pop(0)
|
||||||
|
|
||||||
@@ -262,6 +269,9 @@ def parse(data, raw=False, quiet=False):
|
|||||||
|
|
||||||
output_line['tty'] = linedata.pop(0)
|
output_line['tty'] = linedata.pop(0)
|
||||||
|
|
||||||
|
if user_process:
|
||||||
|
output_line['process'] = user_process
|
||||||
|
|
||||||
# mac
|
# mac
|
||||||
if re.match(r'[JFMASOND][aepuco][nbrynlgptvc]', linedata[0]):
|
if re.match(r'[JFMASOND][aepuco][nbrynlgptvc]', linedata[0]):
|
||||||
output_line['time'] = ' '.join([linedata.pop(0),
|
output_line['time'] = ' '.join([linedata.pop(0),
|
||||||
|
|||||||
1
tests/fixtures/debian13/who.json
vendored
Normal file
1
tests/fixtures/debian13/who.json
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[{"user":"root","tty":"tty1","time":"Sep 1 12:20","epoch":null},{"user":"frenkye","tty":"pts/4","process":"sshd","time":"Sep 1 12:05","from":"x.x.x.x","epoch":null},{"user":"root","tty":"tty1","time":"Sep 1 12:25","epoch":null},{"user":"frenkye","tty":"pts/4","time":"Sep 1 12:05","from":"x.x.x.x","epoch":null},{"user":"frenkye","tty":"pts/443","process":"kelly","time":"Sep 1 12:05","from":"x.x.x.x","epoch":null}]
|
||||||
5
tests/fixtures/debian13/who.out
vendored
Normal file
5
tests/fixtures/debian13/who.out
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
root tty1 Sep 1 12:20
|
||||||
|
frenkye sshd pts/4 Sep 1 12:05 (x.x.x.x)
|
||||||
|
root tty1 Sep 1 12:25
|
||||||
|
frenkye pts/4 Sep 1 12:05 (x.x.x.x)
|
||||||
|
frenkye kelly pts/443 Sep 1 12:05 (x.x.x.x)
|
||||||
@@ -30,6 +30,9 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/who-login-screen.out'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/who-login-screen.out'), 'r', encoding='utf-8') as f:
|
||||||
generic_who_login_screen = f.read()
|
generic_who_login_screen = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/debian13/who.out'), 'r', encoding='utf-8') as f:
|
||||||
|
debian13_who = f.read()
|
||||||
|
|
||||||
# output
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/who.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/who.json'), 'r', encoding='utf-8') as f:
|
||||||
centos_7_7_who_json = json.loads(f.read())
|
centos_7_7_who_json = json.loads(f.read())
|
||||||
@@ -52,6 +55,9 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/who-login-screen.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/who-login-screen.json'), 'r', encoding='utf-8') as f:
|
||||||
generic_who_login_screen_json = json.loads(f.read())
|
generic_who_login_screen_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/debian13/who.json'), 'r', encoding='utf-8') as f:
|
||||||
|
debian13_who_json = json.loads(f.read())
|
||||||
|
|
||||||
|
|
||||||
def test_who_nodata(self):
|
def test_who_nodata(self):
|
||||||
"""
|
"""
|
||||||
@@ -101,5 +107,11 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(jc.parsers.who.parse(self.generic_who_login_screen, quiet=True), self.generic_who_login_screen_json)
|
self.assertEqual(jc.parsers.who.parse(self.generic_who_login_screen, quiet=True), self.generic_who_login_screen_json)
|
||||||
|
|
||||||
|
def test_who_debian13(self):
|
||||||
|
"""
|
||||||
|
Test 'who' on Debian13
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.who.parse(self.debian13_who, quiet=True), self.debian13_who_json)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user