mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-13 01:20:24 +02:00
add idle time fields to finger parser
This commit is contained in:
18
EXAMPLES.md
18
EXAMPLES.md
@ -960,9 +960,14 @@ finger | jc --finger -p # or: jc -p finger
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "*tty1",
|
||||
"idle": "13d",
|
||||
"login_time": "Mar 22 21:14"
|
||||
"tty": "tty1",
|
||||
"idle": "14d",
|
||||
"login_time": "Mar 22 21:14",
|
||||
"tty_writeable": false,
|
||||
"idle_minutes": 0,
|
||||
"idle_hours": 0,
|
||||
"idle_days": 14,
|
||||
"total_idle_minutes": 20160
|
||||
},
|
||||
{
|
||||
"login": "jdoe",
|
||||
@ -970,7 +975,12 @@ finger | jc --finger -p # or: jc -p finger
|
||||
"tty": "pts/0",
|
||||
"idle": null,
|
||||
"login_time": "Apr 5 15:33",
|
||||
"details": "(192.168.1.22)"
|
||||
"details": "(192.168.1.22)",
|
||||
"tty_writeable": true,
|
||||
"idle_minutes": 0,
|
||||
"idle_hours": 0,
|
||||
"idle_days": 0,
|
||||
"total_idle_minutes": 0
|
||||
}
|
||||
]
|
||||
```
|
||||
|
@ -24,12 +24,42 @@ Compatibility:
|
||||
Examples:
|
||||
|
||||
$ finger | jc --finger -p
|
||||
[
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "tty1",
|
||||
"idle": "14d",
|
||||
"login_time": "Mar 22 21:14",
|
||||
"tty_writeable": false,
|
||||
"idle_minutes": 0,
|
||||
"idle_hours": 0,
|
||||
"idle_days": 14,
|
||||
"total_idle_minutes": 20160
|
||||
},
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "pts/0",
|
||||
"idle": null,
|
||||
"login_time": "Apr 5 15:33",
|
||||
"details": "(192.168.1.22)",
|
||||
"tty_writeable": true,
|
||||
"idle_minutes": 0,
|
||||
"idle_hours": 0,
|
||||
"idle_days": 0,
|
||||
"total_idle_minutes": 0
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ finger | jc --finger -p -r
|
||||
[
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "*tty1",
|
||||
"idle": "13d",
|
||||
"idle": "14d",
|
||||
"login_time": "Mar 22 21:14"
|
||||
},
|
||||
{
|
||||
@ -39,7 +69,8 @@ Examples:
|
||||
"idle": null,
|
||||
"login_time": "Apr 5 15:33",
|
||||
"details": "(192.168.1.22)"
|
||||
}
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
@ -66,13 +97,17 @@ Returns:
|
||||
|
||||
[
|
||||
{
|
||||
"login": string,
|
||||
"name": string,
|
||||
"tty": string,
|
||||
"idle": string, # null if empty
|
||||
"login_time": string,
|
||||
"details": string,
|
||||
"tty_writeable": boolean
|
||||
"login": string,
|
||||
"name": string,
|
||||
"tty": string,
|
||||
"idle": string, # null if empty
|
||||
"login_time": string,
|
||||
"details": string,
|
||||
"tty_writeable": boolean,
|
||||
"idle_minutes": integer,
|
||||
"idle_hours": integer,
|
||||
"idle_days": integer,
|
||||
"total_idle_minutes": integer
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -22,12 +22,42 @@ Compatibility:
|
||||
Examples:
|
||||
|
||||
$ finger | jc --finger -p
|
||||
[
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "tty1",
|
||||
"idle": "14d",
|
||||
"login_time": "Mar 22 21:14",
|
||||
"tty_writeable": false,
|
||||
"idle_minutes": 0,
|
||||
"idle_hours": 0,
|
||||
"idle_days": 14,
|
||||
"total_idle_minutes": 20160
|
||||
},
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "pts/0",
|
||||
"idle": null,
|
||||
"login_time": "Apr 5 15:33",
|
||||
"details": "(192.168.1.22)",
|
||||
"tty_writeable": true,
|
||||
"idle_minutes": 0,
|
||||
"idle_hours": 0,
|
||||
"idle_days": 0,
|
||||
"total_idle_minutes": 0
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ finger | jc --finger -p -r
|
||||
[
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "*tty1",
|
||||
"idle": "13d",
|
||||
"idle": "14d",
|
||||
"login_time": "Mar 22 21:14"
|
||||
},
|
||||
{
|
||||
@ -37,7 +67,8 @@ Examples:
|
||||
"idle": null,
|
||||
"login_time": "Apr 5 15:33",
|
||||
"details": "(192.168.1.22)"
|
||||
}
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import re
|
||||
@ -74,13 +105,17 @@ def process(proc_data):
|
||||
|
||||
[
|
||||
{
|
||||
"login": string,
|
||||
"name": string,
|
||||
"tty": string,
|
||||
"idle": string, # null if empty
|
||||
"login_time": string,
|
||||
"details": string,
|
||||
"tty_writeable": boolean
|
||||
"login": string,
|
||||
"name": string,
|
||||
"tty": string,
|
||||
"idle": string, # null if empty
|
||||
"login_time": string,
|
||||
"details": string,
|
||||
"tty_writeable": boolean,
|
||||
"idle_minutes": integer,
|
||||
"idle_hours": integer,
|
||||
"idle_days": integer,
|
||||
"total_idle_minutes": integer
|
||||
}
|
||||
]
|
||||
"""
|
||||
@ -92,9 +127,27 @@ def process(proc_data):
|
||||
entry['tty_writeable'] = False
|
||||
|
||||
if 'idle' in entry:
|
||||
entry['idle_minutes'] = 0
|
||||
entry['idle_hours'] = 0
|
||||
entry['idle_days'] = 0
|
||||
|
||||
if entry['idle'] == '-':
|
||||
entry['idle'] = None
|
||||
|
||||
if entry['idle'] and entry['idle'].isnumeric():
|
||||
entry['idle_minutes'] = int(entry['idle'])
|
||||
|
||||
if entry['idle'] and ':' in entry['idle']:
|
||||
entry['idle_hours'] = int(entry['idle'].split(':')[0])
|
||||
entry['idle_minutes'] = int(entry['idle'].split(':')[1])
|
||||
|
||||
if entry['idle'] and 'd' in entry['idle']:
|
||||
entry['idle_days'] = int(entry['idle'].replace('d', ''))
|
||||
|
||||
entry['total_idle_minutes'] = (entry['idle_days'] * 1440) + \
|
||||
(entry['idle_hours'] * 60) + \
|
||||
entry['idle_minutes']
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
|
1
tests/fixtures/ubuntu-18.04/finger.json
vendored
Normal file
1
tests/fixtures/ubuntu-18.04/finger.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"login":"kbrazil","name":"Kelly Brazil","tty":"tty1","idle":"14d","login_time":"Mar 22 21:14","tty_writeable":false,"idle_minutes":0,"idle_hours":0,"idle_days":14,"total_idle_minutes":20160},{"login":"kbrazil","name":"Kelly Brazil","tty":"pts/0","idle":null,"login_time":"Apr 5 15:33","details":"(192.168.1.22)","tty_writeable":true,"idle_minutes":0,"idle_hours":0,"idle_days":0,"total_idle_minutes":0},{"login":"kbrazil","name":"Kelly Brazil","tty":"pts/1","idle":"1:00","login_time":"Apr 6 09:04","details":"(192.168.1.22)","tty_writeable":true,"idle_minutes":0,"idle_hours":1,"idle_days":0,"total_idle_minutes":60},{"login":"kbrazil","name":"Kelly Brazil","tty":"pts/0","idle":"14","login_time":"Apr 5 12:30","tty_writeable":true,"idle_minutes":14,"idle_hours":0,"idle_days":0,"total_idle_minutes":14},{"login":"kbrazil","name":"Kelly Brazil","tty":"pts/0","idle":"14","login_time":"Apr 5 2020","tty_writeable":true,"idle_minutes":14,"idle_hours":0,"idle_days":0,"total_idle_minutes":14},{"login":"kbrazil","name":"Kelly Brazil","tty":"pts/0","idle":"14","login_time":"Apr 5 2021","details":"(192.168.1.23)","tty_writeable":true,"idle_minutes":14,"idle_hours":0,"idle_days":0,"total_idle_minutes":14},{"login":"kbrazil","name":"Kelly Brazil","tty":"pts/1","idle":"1:00","login_time":"Apr 6 09:04","details":"(192.168.1.22) other details","tty_writeable":true,"idle_minutes":0,"idle_hours":1,"idle_days":0,"total_idle_minutes":60}]
|
8
tests/fixtures/ubuntu-18.04/finger.out
vendored
Normal file
8
tests/fixtures/ubuntu-18.04/finger.out
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
Login Name Tty Idle Login Time Office Office Phone
|
||||
kbrazil Kelly Brazil *tty1 14d Mar 22 21:14
|
||||
kbrazil Kelly Brazil pts/0 Apr 5 15:33 (192.168.1.22)
|
||||
kbrazil Kelly Brazil pts/1 1:00 Apr 6 09:04 (192.168.1.22)
|
||||
kbrazil Kelly Brazil pts/0 14 Apr 5 12:30
|
||||
kbrazil Kelly Brazil pts/0 14 Apr 5 2020
|
||||
kbrazil Kelly Brazil pts/0 14 Apr 5 2021 (192.168.1.23)
|
||||
kbrazil Kelly Brazil pts/1 1:00 Apr 6 09:04 (192.168.1.22) other details
|
Reference in New Issue
Block a user