1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-08-10 22:41:51 +02:00

lower() headers

This commit is contained in:
Kelly Brazil
2019-10-25 14:58:15 -07:00
parent 7e44c4278a
commit 5f1ec67348
10 changed files with 481 additions and 464 deletions

461
README.md
View File

@@ -88,37 +88,37 @@ jc PARSER [OPTIONS]
$ df | jc --df -p $ df | jc --df -p
[ [
{ {
"Filesystem": "udev", "filesystem": "udev",
"1K-blocks": "977500", "1k-blocks": "977500",
"Used": "0", "used": "0",
"Available": "977500", "available": "977500",
"Use_percent": "0%", "use_percent": "0%",
"Mounted": "/dev" "mounted": "/dev"
}, },
{ {
"Filesystem": "tmpfs", "filesystem": "tmpfs",
"1K-blocks": "201732", "1k-blocks": "201732",
"Used": "1180", "used": "1204",
"Available": "200552", "available": "200528",
"Use_percent": "1%", "use_percent": "1%",
"Mounted": "/run" "mounted": "/run"
}, },
{ {
"Filesystem": "/dev/sda2", "filesystem": "/dev/sda2",
"1K-blocks": "20508240", "1k-blocks": "20508240",
"Used": "5747284", "used": "5748312",
"Available": "13696152", "available": "13695124",
"Use_percent": "30%", "use_percent": "30%",
"Mounted": "/" "mounted": "/"
}, },
{ {
"Filesystem": "tmpfs", "filesystem": "tmpfs",
"1K-blocks": "1008648", "1k-blocks": "1008648",
"Used": "0", "used": "0",
"Available": "1008648", "available": "1008648",
"Use_percent": "0%", "use_percent": "0%",
"Mounted": "/dev/shm" "mounted": "/dev/shm"
}, }
... ...
] ]
``` ```
@@ -649,46 +649,55 @@ $ ls -l /bin | jc --ls -p
$ lsblk | jc --lsblk -p $ lsblk | jc --lsblk -p
[ [
{ {
"NAME": "loop0", "name": "sda",
"MAJ_MIN": "7:0", "maj_min": "8:0",
"RM": "0", "rm": "0",
"SIZE": "54.5M", "size": "20G",
"RO": "1", "ro": "0",
"TYPE": "loop", "type": "disk"
"MOUNTPOINT": "/snap/core18/1223"
}, },
{ {
"NAME": "sda", "name": "sda1",
"MAJ_MIN": "8:0", "maj_min": "8:1",
"RM": "0", "rm": "0",
"SIZE": "20G", "size": "1G",
"RO": "0", "ro": "0",
"TYPE": "disk" "type": "part",
"mountpoint": "/boot"
}, },
{ {
"NAME": "sda1", "name": "sda2",
"MAJ_MIN": "8:1", "maj_min": "8:2",
"RM": "0", "rm": "0",
"SIZE": "1M", "size": "19G",
"RO": "0", "ro": "0",
"TYPE": "part" "type": "part"
}, },
{ {
"NAME": "sda2", "name": "centos-root",
"MAJ_MIN": "8:2", "maj_min": "253:0",
"RM": "0", "rm": "0",
"SIZE": "20G", "size": "17G",
"RO": "0", "ro": "0",
"TYPE": "part", "type": "lvm",
"MOUNTPOINT": "/" "mountpoint": "/"
}, },
{ {
"NAME": "sr0", "name": "centos-swap",
"MAJ_MIN": "11:0", "maj_min": "253:1",
"RM": "1", "rm": "0",
"SIZE": "64.8M", "size": "2G",
"RO": "0", "ro": "0",
"TYPE": "rom" "type": "lvm",
"mountpoint": "[SWAP]"
},
{
"name": "sr0",
"maj_min": "11:0",
"rm": "1",
"size": "1024M",
"ro": "0",
"type": "rom"
} }
] ]
``` ```
@@ -696,44 +705,12 @@ $ lsblk | jc --lsblk -p
``` ```
$ lsmod | jc --lsmod -p $ lsmod | jc --lsmod -p
[ [
...
{ {
"Module": "nf_nat_ipv4", "module": "nf_conntrack",
"Size": "14115", "size": "139224",
"Used": "1", "used": "7",
"By": [ "by": [
"iptable_nat"
]
},
{
"Module": "nf_nat",
"Size": "26583",
"Used": "3",
"By": [
"nf_nat_ipv4",
"nf_nat_ipv6",
"nf_nat_masquerade_ipv4"
]
},
{
"Module": "iptable_mangle",
"Size": "12695",
"Used": "1"
},
{
"Module": "iptable_security",
"Size": "12705",
"Used": "1"
},
{
"Module": "iptable_raw",
"Size": "12678",
"Used": "1"
},
{
"Module": "nf_conntrack",
"Size": "139224",
"Used": "7",
"By": [
"nf_nat", "nf_nat",
"nf_nat_ipv4", "nf_nat_ipv4",
"nf_nat_ipv6", "nf_nat_ipv6",
@@ -743,72 +720,99 @@ $ lsmod | jc --lsmod -p
"nf_conntrack_ipv6" "nf_conntrack_ipv6"
] ]
}, },
{
"module": "ip_set",
"size": "45799",
"used": "0"
},
{
"module": "nfnetlink",
"size": "14519",
"used": "1",
"by": [
"ip_set"
]
},
{
"module": "ebtable_filter",
"size": "12827",
"used": "1"
},
{
"module": "ebtables",
"size": "35009",
"used": "2",
"by": [
"ebtable_nat",
"ebtable_filter"
]
},
... ...
] ]
``` ```
### lsof ### lsof
``` ```
$ sudo lsof | jc --lsof -p $ sudo lsof | jc --lsof -p | more
[ [
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "cwd", "fd": "cwd",
"TYPE": "DIR", "type": "DIR",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "224", "size_off": "4096",
"NODE": "64", "node": "2",
"NAME": "/" "name": "/"
}, },
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "rtd", "fd": "rtd",
"TYPE": "DIR", "type": "DIR",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "224", "size_off": "4096",
"NODE": "64", "node": "2",
"NAME": "/" "name": "/"
}, },
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "txt", "fd": "txt",
"TYPE": "REG", "type": "REG",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "1624520", "size_off": "1595792",
"NODE": "50360451", "node": "668802",
"NAME": "/usr/lib/systemd/systemd" "name": "/lib/systemd/systemd"
}, },
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "mem", "fd": "mem",
"TYPE": "REG", "type": "REG",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "20064", "size_off": "1700792",
"NODE": "8146", "node": "656167",
"NAME": "/usr/lib64/libuuid.so.1.3.0" "name": "/lib/x86_64-linux-gnu/libm-2.27.so"
}, },
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "mem", "fd": "mem",
"TYPE": "REG", "type": "REG",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "265600", "size_off": "121016",
"NODE": "8147", "node": "655394",
"NAME": "/usr/lib64/libblkid.so.1.1.0" "name": "/lib/x86_64-linux-gnu/libudev.so.1.6.9"
}, },
... ...
] ]
@@ -974,92 +978,93 @@ $ netstat -lpn | jc --netstat -p
``` ```
$ ps -ef | jc --ps -p $ ps -ef | jc --ps -p
[ [
...
{ {
"UID": "root", "uid": "root",
"PID": "1", "pid": "545",
"PPID": "0", "ppid": "1",
"C": "0", "c": "0",
"STIME": "13:58", "stime": "Oct21",
"TTY": "?", "tty": "?",
"TIME": "00:00:05", "time": "00:00:03",
"CMD": "/lib/systemd/systemd --system --deserialize 35" "cmd": "/usr/lib/systemd/systemd-journald"
}, },
{ {
"UID": "root", "uid": "root",
"PID": "2", "pid": "566",
"PPID": "0", "ppid": "1",
"C": "0", "c": "0",
"STIME": "13:58", "stime": "Oct21",
"TTY": "?", "tty": "?",
"TIME": "00:00:00", "time": "00:00:00",
"CMD": "[kthreadd]" "cmd": "/usr/sbin/lvmetad -f"
}, },
{ {
"UID": "root", "uid": "root",
"PID": "4", "pid": "580",
"PPID": "2", "ppid": "1",
"C": "0", "c": "0",
"STIME": "13:58", "stime": "Oct21",
"TTY": "?", "tty": "?",
"TIME": "00:00:00", "time": "00:00:00",
"CMD": "[kworker/0:0H]" "cmd": "/usr/lib/systemd/systemd-udevd"
}, },
{ {
"UID": "root", "uid": "root",
"PID": "6", "pid": "659",
"PPID": "2", "ppid": "2",
"C": "0", "c": "0",
"STIME": "13:58", "stime": "Oct21",
"TTY": "?", "tty": "?",
"TIME": "00:00:00", "time": "00:00:00",
"CMD": "[mm_percpu_wq]" "cmd": "[kworker/u257:0]"
},
{
"uid": "root",
"pid": "666",
"ppid": "2",
"c": "0",
"stime": "Oct21",
"tty": "?",
"time": "00:00:00",
"cmd": "[hci0]"
}, },
... ...
] ]
``` ```
### route ### route
``` ```
$ route -n | jc --route -p $ route | jc --route -p
[ [
{ {
"Destination": "0.0.0.0", "destination": "default",
"Gateway": "192.168.71.2", "gateway": "gateway",
"Genmask": "0.0.0.0", "genmask": "0.0.0.0",
"Flags": "UG", "flags": "UG",
"Metric": "100", "metric": "100",
"Ref": "0", "ref": "0",
"Use": "0", "use": "0",
"Iface": "ens33" "iface": "ens33"
}, },
{ {
"Destination": "172.17.0.0", "destination": "172.17.0.0",
"Gateway": "0.0.0.0", "gateway": "0.0.0.0",
"Genmask": "255.255.0.0", "genmask": "255.255.0.0",
"Flags": "U", "flags": "U",
"Metric": "0", "metric": "0",
"Ref": "0", "ref": "0",
"Use": "0", "use": "0",
"Iface": "docker0" "iface": "docker0"
}, },
{ {
"Destination": "192.168.71.0", "destination": "192.168.71.0",
"Gateway": "0.0.0.0", "gateway": "0.0.0.0",
"Genmask": "255.255.255.0", "genmask": "255.255.255.0",
"Flags": "U", "flags": "U",
"Metric": "0", "metric": "100",
"Ref": "0", "ref": "0",
"Use": "0", "use": "0",
"Iface": "ens33" "iface": "ens33"
},
{
"Destination": "192.168.71.2",
"Gateway": "0.0.0.0",
"Genmask": "255.255.255.255",
"Flags": "UH",
"Metric": "100",
"Ref": "0",
"Use": "0",
"Iface": "ens33"
} }
] ]
``` ```
@@ -1094,24 +1099,24 @@ $ uptime | jc --uptime -p
$ w | jc --w -p $ w | jc --w -p
[ [
{ {
"USER": "root", "user": "root",
"TTY": "ttyS0", "tty": "ttyS0",
"FROM": "-", "from": "-",
"LOGIN_AT": "Mon20", "login_at": "Mon20",
"IDLE": "2:27", "idle": "0.00s",
"JCPU": "10.61s", "jcpu": "14.70s",
"PCPU": "10.53s", "pcpu": "0.00s",
"WHAT": "-bash" "what": "bash"
}, },
{ {
"USER": "root", "user": "root",
"TTY": "pts/0", "tty": "pts/0",
"FROM": "192.168.71.1", "from": "192.168.71.1",
"LOGIN_AT": "22:58", "login_at": "Thu22",
"IDLE": "2.00s", "idle": "22:46m",
"JCPU": "0.04s", "jcpu": "0.05s",
"PCPU": "0.00s", "pcpu": "0.05s",
"WHAT": "w" "what": "-bash"
} }
] ]
``` ```

View File

@@ -8,37 +8,37 @@ Example:
$ df | jc --df -p $ df | jc --df -p
[ [
{ {
"Filesystem": "udev", "filesystem": "udev",
"1K-blocks": "977500", "1k-blocks": "977500",
"Used": "0", "used": "0",
"Available": "977500", "available": "977500",
"Use_percent": "0%", "use_percent": "0%",
"Mounted": "/dev" "mounted": "/dev"
}, },
{ {
"Filesystem": "tmpfs", "filesystem": "tmpfs",
"1K-blocks": "201732", "1k-blocks": "201732",
"Used": "1180", "used": "1204",
"Available": "200552", "available": "200528",
"Use_percent": "1%", "use_percent": "1%",
"Mounted": "/run" "mounted": "/run"
}, },
{ {
"Filesystem": "/dev/sda2", "filesystem": "/dev/sda2",
"1K-blocks": "20508240", "1k-blocks": "20508240",
"Used": "5747284", "used": "5748312",
"Available": "13696152", "available": "13695124",
"Use_percent": "30%", "use_percent": "30%",
"Mounted": "/" "mounted": "/"
}, },
{ {
"Filesystem": "tmpfs", "filesystem": "tmpfs",
"1K-blocks": "1008648", "1k-blocks": "1008648",
"Used": "0", "used": "0",
"Available": "1008648", "available": "1008648",
"Use_percent": "0%", "use_percent": "0%",
"Mounted": "/dev/shm" "mounted": "/dev/shm"
}, }
... ...
] ]
""" """
@@ -52,7 +52,7 @@ def parse(data):
cleandata = data.splitlines() cleandata = data.splitlines()
headers = [h for h in ' '.join(cleandata[0].lower().strip().split()).split() if h] headers = [h for h in ' '.join(cleandata[0].lower().strip().split()).split() if h]
# clean up 'Use%' header # clean up 'use%' header
# even though % in a key is valid json, it can make things difficult # even though % in a key is valid json, it can make things difficult
headers = ['use_percent' if x == 'use%' else x for x in headers] headers = ['use_percent' if x == 'use%' else x for x in headers]

View File

@@ -20,7 +20,7 @@ def parse(data):
output = {} output = {}
# split lines and clear out any non-ascii chars # split lines and clear out any non-ascii chars
linedata = data.splitlines().encode('ascii', errors='ignore').decode() linedata = data.encode('ascii', errors='ignore').decode().splitlines()
# Clear any blank lines # Clear any blank lines
cleandata = list(filter(None, linedata)) cleandata = list(filter(None, linedata))

View File

@@ -348,7 +348,7 @@ def parse(data):
elif line.find('target') == 0 or line.find('pkts') == 1: elif line.find('target') == 0 or line.find('pkts') == 1:
headers = [] headers = []
headers = [h for h in ' '.join(line.strip().split()).split() if h] headers = [h for h in ' '.join(line.lower().strip().split()).split() if h]
headers.append("options") headers.append("options")
continue continue

View File

@@ -8,46 +8,55 @@ Example:
$ lsblk | jc --lsblk -p $ lsblk | jc --lsblk -p
[ [
{ {
"NAME": "loop0", "name": "sda",
"MAJ_MIN": "7:0", "maj_min": "8:0",
"RM": "0", "rm": "0",
"SIZE": "54.5M", "size": "20G",
"RO": "1", "ro": "0",
"TYPE": "loop", "type": "disk"
"MOUNTPOINT": "/snap/core18/1223"
}, },
{ {
"NAME": "sda", "name": "sda1",
"MAJ_MIN": "8:0", "maj_min": "8:1",
"RM": "0", "rm": "0",
"SIZE": "20G", "size": "1G",
"RO": "0", "ro": "0",
"TYPE": "disk" "type": "part",
"mountpoint": "/boot"
}, },
{ {
"NAME": "sda1", "name": "sda2",
"MAJ_MIN": "8:1", "maj_min": "8:2",
"RM": "0", "rm": "0",
"SIZE": "1M", "size": "19G",
"RO": "0", "ro": "0",
"TYPE": "part" "type": "part"
}, },
{ {
"NAME": "sda2", "name": "centos-root",
"MAJ_MIN": "8:2", "maj_min": "253:0",
"RM": "0", "rm": "0",
"SIZE": "20G", "size": "17G",
"RO": "0", "ro": "0",
"TYPE": "part", "type": "lvm",
"MOUNTPOINT": "/" "mountpoint": "/"
}, },
{ {
"NAME": "sr0", "name": "centos-swap",
"MAJ_MIN": "11:0", "maj_min": "253:1",
"RM": "1", "rm": "0",
"SIZE": "64.8M", "size": "2G",
"RO": "0", "ro": "0",
"TYPE": "rom" "type": "lvm",
"mountpoint": "[SWAP]"
},
{
"name": "sr0",
"maj_min": "11:0",
"rm": "1",
"size": "1024M",
"ro": "0",
"type": "rom"
} }
] ]
""" """

View File

@@ -7,44 +7,12 @@ Example:
$ lsmod | jc --lsmod -p $ lsmod | jc --lsmod -p
[ [
...
{ {
"Module": "nf_nat_ipv4", "module": "nf_conntrack",
"Size": "14115", "size": "139224",
"Used": "1", "used": "7",
"By": [ "by": [
"iptable_nat"
]
},
{
"Module": "nf_nat",
"Size": "26583",
"Used": "3",
"By": [
"nf_nat_ipv4",
"nf_nat_ipv6",
"nf_nat_masquerade_ipv4"
]
},
{
"Module": "iptable_mangle",
"Size": "12695",
"Used": "1"
},
{
"Module": "iptable_security",
"Size": "12705",
"Used": "1"
},
{
"Module": "iptable_raw",
"Size": "12678",
"Used": "1"
},
{
"Module": "nf_conntrack",
"Size": "139224",
"Used": "7",
"By": [
"nf_nat", "nf_nat",
"nf_nat_ipv4", "nf_nat_ipv4",
"nf_nat_ipv6", "nf_nat_ipv6",
@@ -54,6 +22,33 @@ $ lsmod | jc --lsmod -p
"nf_conntrack_ipv6" "nf_conntrack_ipv6"
] ]
}, },
{
"module": "ip_set",
"size": "45799",
"used": "0"
},
{
"module": "nfnetlink",
"size": "14519",
"used": "1",
"by": [
"ip_set"
]
},
{
"module": "ebtable_filter",
"size": "12827",
"used": "1"
},
{
"module": "ebtables",
"size": "35009",
"used": "2",
"by": [
"ebtable_nat",
"ebtable_filter"
]
},
... ...
] ]
""" """

View File

@@ -5,67 +5,67 @@ Usage:
Example: Example:
$ sudo lsof | jc --lsof -p $ sudo lsof | jc --lsof -p | more
[ [
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "cwd", "fd": "cwd",
"TYPE": "DIR", "type": "DIR",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "224", "size_off": "4096",
"NODE": "64", "node": "2",
"NAME": "/" "name": "/"
}, },
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "rtd", "fd": "rtd",
"TYPE": "DIR", "type": "DIR",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "224", "size_off": "4096",
"NODE": "64", "node": "2",
"NAME": "/" "name": "/"
}, },
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "txt", "fd": "txt",
"TYPE": "REG", "type": "REG",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "1624520", "size_off": "1595792",
"NODE": "50360451", "node": "668802",
"NAME": "/usr/lib/systemd/systemd" "name": "/lib/systemd/systemd"
}, },
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "mem", "fd": "mem",
"TYPE": "REG", "type": "REG",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "20064", "size_off": "1700792",
"NODE": "8146", "node": "656167",
"NAME": "/usr/lib64/libuuid.so.1.3.0" "name": "/lib/x86_64-linux-gnu/libm-2.27.so"
}, },
{ {
"COMMAND": "systemd", "command": "systemd",
"PID": "1", "pid": "1",
"TID": null, "tid": null,
"USER": "root", "user": "root",
"FD": "mem", "fd": "mem",
"TYPE": "REG", "type": "REG",
"DEVICE": "253,0", "device": "8,2",
"SIZE_OFF": "265600", "size_off": "121016",
"NODE": "8147", "node": "655394",
"NAME": "/usr/lib64/libblkid.so.1.1.0" "name": "/lib/x86_64-linux-gnu/libudev.so.1.6.9"
}, },
... ...
] ]
@@ -84,12 +84,13 @@ def parse(data):
if cleandata: if cleandata:
# find column value of last character of each header # find column value of last character of each header
header_row = cleandata.pop(0) header_text = cleandata.pop(0).lower()
headers = header_row.lower().split()
# clean up 'size/off' header # clean up 'size/off' header
# even though forward slash in a key is valid json, it can make things difficult # even though forward slash in a key is valid json, it can make things difficult
headers = ['size_off' if x == 'size/off' else x for x in headers] header_row = header_text.replace('size/off', 'size_off')
headers = header_row.split()
header_spec = [] header_spec = []
for i, h in enumerate(headers): for i, h in enumerate(headers):
@@ -107,11 +108,11 @@ def parse(data):
index = spec[0] index = spec[0]
header_name = spec[1] header_name = spec[1]
col = spec[2] - 1 col = spec[2] - 1 # subtract one since column starts at 0 instead of 1
if header_name == 'command' or header_name == 'name': if header_name == 'command' or header_name == 'name':
continue continue
if entry[col] == string.whitespace: if entry[col] in string.whitespace:
temp_line.insert(index, None) temp_line.insert(index, None)
name = ' '.join(temp_line[9:]) name = ' '.join(temp_line[9:])

View File

@@ -11,45 +11,56 @@ Example:
$ ps -ef | jc --ps -p $ ps -ef | jc --ps -p
[ [
...
{ {
"UID": "root", "uid": "root",
"PID": "1", "pid": "545",
"PPID": "0", "ppid": "1",
"C": "0", "c": "0",
"STIME": "13:58", "stime": "Oct21",
"TTY": "?", "tty": "?",
"TIME": "00:00:05", "time": "00:00:03",
"CMD": "/lib/systemd/systemd --system --deserialize 35" "cmd": "/usr/lib/systemd/systemd-journald"
}, },
{ {
"UID": "root", "uid": "root",
"PID": "2", "pid": "566",
"PPID": "0", "ppid": "1",
"C": "0", "c": "0",
"STIME": "13:58", "stime": "Oct21",
"TTY": "?", "tty": "?",
"TIME": "00:00:00", "time": "00:00:00",
"CMD": "[kthreadd]" "cmd": "/usr/sbin/lvmetad -f"
}, },
{ {
"UID": "root", "uid": "root",
"PID": "4", "pid": "580",
"PPID": "2", "ppid": "1",
"C": "0", "c": "0",
"STIME": "13:58", "stime": "Oct21",
"TTY": "?", "tty": "?",
"TIME": "00:00:00", "time": "00:00:00",
"CMD": "[kworker/0:0H]" "cmd": "/usr/lib/systemd/systemd-udevd"
}, },
{ {
"UID": "root", "uid": "root",
"PID": "6", "pid": "659",
"PPID": "2", "ppid": "2",
"C": "0", "c": "0",
"STIME": "13:58", "stime": "Oct21",
"TTY": "?", "tty": "?",
"TIME": "00:00:00", "time": "00:00:00",
"CMD": "[mm_percpu_wq]" "cmd": "[kworker/u257:0]"
},
{
"uid": "root",
"pid": "666",
"ppid": "2",
"c": "0",
"stime": "Oct21",
"tty": "?",
"time": "00:00:00",
"cmd": "[hci0]"
}, },
... ...
] ]
@@ -63,5 +74,11 @@ def parse(data):
cleandata = data.splitlines() cleandata = data.splitlines()
headers = [h for h in ' '.join(cleandata[0].lower().strip().split()).split() if h] headers = [h for h in ' '.join(cleandata[0].lower().strip().split()).split() if h]
# clean up '%cpu' and '%mem' headers
# even though % in a key is valid json, it can make things difficult
headers = ['cpu_percent' if x == '%cpu' else x for x in headers]
headers = ['mem_percent' if x == '%mem' else x for x in headers]
raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:]) raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:])
return [dict(zip(headers, r)) for r in raw_data] return [dict(zip(headers, r)) for r in raw_data]

View File

@@ -6,47 +6,37 @@ Usage:
Example: Example:
$ route -n | jc --route -p $ route | jc --route -p
[ [
{ {
"Destination": "0.0.0.0", "destination": "default",
"Gateway": "192.168.71.2", "gateway": "gateway",
"Genmask": "0.0.0.0", "genmask": "0.0.0.0",
"Flags": "UG", "flags": "UG",
"Metric": "100", "metric": "100",
"Ref": "0", "ref": "0",
"Use": "0", "use": "0",
"Iface": "ens33" "iface": "ens33"
}, },
{ {
"Destination": "172.17.0.0", "destination": "172.17.0.0",
"Gateway": "0.0.0.0", "gateway": "0.0.0.0",
"Genmask": "255.255.0.0", "genmask": "255.255.0.0",
"Flags": "U", "flags": "U",
"Metric": "0", "metric": "0",
"Ref": "0", "ref": "0",
"Use": "0", "use": "0",
"Iface": "docker0" "iface": "docker0"
}, },
{ {
"Destination": "192.168.71.0", "destination": "192.168.71.0",
"Gateway": "0.0.0.0", "gateway": "0.0.0.0",
"Genmask": "255.255.255.0", "genmask": "255.255.255.0",
"Flags": "U", "flags": "U",
"Metric": "0", "metric": "100",
"Ref": "0", "ref": "0",
"Use": "0", "use": "0",
"Iface": "ens33" "iface": "ens33"
},
{
"Destination": "192.168.71.2",
"Gateway": "0.0.0.0",
"Genmask": "255.255.255.255",
"Flags": "UH",
"Metric": "100",
"Ref": "0",
"Use": "0",
"Iface": "ens33"
} }
] ]
""" """

View File

@@ -8,24 +8,24 @@ Example:
$ w | jc --w -p $ w | jc --w -p
[ [
{ {
"USER": "root", "user": "root",
"TTY": "ttyS0", "tty": "ttyS0",
"FROM": "-", "from": "-",
"LOGIN_AT": "Mon20", "login_at": "Mon20",
"IDLE": "2:27", "idle": "0.00s",
"JCPU": "10.61s", "jcpu": "14.70s",
"PCPU": "10.53s", "pcpu": "0.00s",
"WHAT": "-bash" "what": "bash"
}, },
{ {
"USER": "root", "user": "root",
"TTY": "pts/0", "tty": "pts/0",
"FROM": "192.168.71.1", "from": "192.168.71.1",
"LOGIN_AT": "22:58", "login_at": "Thu22",
"IDLE": "2.00s", "idle": "22:46m",
"JCPU": "0.04s", "jcpu": "0.05s",
"PCPU": "0.00s", "pcpu": "0.05s",
"WHAT": "w" "what": "-bash"
} }
] ]
""" """